Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON output #57

Open
bitcoinmeetups opened this issue Jan 6, 2022 · 6 comments
Open

JSON output #57

bitcoinmeetups opened this issue Jan 6, 2022 · 6 comments

Comments

@bitcoinmeetups
Copy link

Hello,

I'm BM. A very nice and polite guy.

Feature requests:

  1. Choosing which columns to display. For example I don't want the graph in the rightmost column.

  2. Output as plain text. When I try to use curl rate.sx > rates.txt the valuable data gets obscured by all the formatting. It's currently not possible to do that. Please make it so that we can simply choose the data we want and output to plain text without coloring, lines, graphics etc. Example:

BTC. Price: 39000. Changes +1%
ETH. Price: 2000. Changes +2%

Thanks.

@chubin
Copy link
Owner

chubin commented Jan 16, 2022

Good features. Absolutely needed. At the moment, I am working on the new rendering engine, where such things could be trivially implemented. I could propose a couple of workarounds that you could use until that time.

If you don't need colors, you can switch them off by ?T:

$ curl rate.sx/btc?T

▶ Bitcoin (BTC) ▶ Sat 15 +1d -0.05%


  │                   43700.0
  │ ⡇                    ⡎⡅
  │ ⡇                   ⢸ ⢱
  │ ⡇                   ⡇ ⠸⡀
  │ ⡇                   ⡇  ⢇
  │ ⡇                   ⡃  ⢸
  │ ⡇                  ⣄⡇   ⢱
  │ ⡇            ⡀    ⢀⠇⠁   ⢘
  │ ⡇           ⢸⢇   ⢠⠋      ⡇
  │ ⡇          ⢀⡎⢸ ⢀⠴⡜       ⢣ ⢀
  │ ⡇     ⢠⠴⣰⣤⢺⡇⠁⠸⣀⡊ ⠁       ⢸⢠⢘⡄ ⢰⡇
  │ ⡇     ⡇ ⠃⠁ ⠁  ⠁          ⠈⠏⠇⡆ ⡇⢑
  │ ⡇    ⢠⠃                     ⢱⢸ ⠘⣄                           ⡠⡄
  │ ⡇    ⡜                      ⠈⠁  ⠸⡀                       ⢠⣀⠇⠁⠸⡀
  │ ⡇ ⢀⠄⡦⡅                           ⡇                      ⢀⠇    ⢑    ⢀⢆
  │ ⡇ ⢸⠈                             ⢱   ⡆                ⢀⠾⡜      ⡧⡀ ⢀⠇⢸⡀
  │ ⡇ ⢸                              ⢸ ⣾⢰⢣ ⣀  ⡀        ⣀⡀ ⡸         ⠆⡎⠙  ⢸     ⡀
  │ ⡇ ⢸                              ⠈⠜ ⠋⠘⠴⠉⠢⠴⢣   ⢀  ⡀⡎⠁⠱⡀⠇              ⢸    ⡎⢣⣰
  │ ⡇ ⡎                                       ⢰   ⡼⢸⠞ ⠁  ⠲⠁               ⡇ ⢰⢄⡇⠈⠋⡆
  │ ⡇ ⡇                                        ⡇⢀⣄⠟⡜                      ⡇⢸⠇⠘   ⢱
  │ ⡇ ⡇                                        ⠣⠜⠑ ⠇                      ⡇⡇     ⢸
  │ ⠻⣠⠃                                                                   ⢇⡇     ⢸ ⡀
  │                                                                       ⠈⠁     ⠈⡆⡇
  │                                                                               ⡇⡇
  │                                                                               ⡇⡇
  │                                                                               ⣿
  │                                                                            42800.0
  └────────────────────────────────────────────────────────────────────────────────

begin: $42937 (Sat 15 14:00) // end: $42917 (Sun 16 13:50)
high: $43691 (Sat 15 20:30) // low: $42761 (Sun 16 13:30)
avg: $43186 // median: $43226 // change: -20.125 (-0.05%)
Use @ for interval specification: /btc@10d, /eth@4w, /xrp@January (more in /:help)

Combining that with standard UNIX/Linux tools, you can easily achieve
what you need:

$ curl -s rate.sx/btc?T | grep ^[abh]
begin: $42937 (Sat 15 14:00) // end: $42917 (Sun 16 13:50)
high: $43691 (Sat 15 20:30) // low: $42761 (Sun 16 13:30)
avg: $43186 // median: $43226 // change: -20.125 (-0.05%)

or

$ curl -s rate.sx/?T | cut -c 12-18,38-45 | grep -o ' [A-Z].*%'
 BTC   0.21%
 ETH   0.35%
 BNB   0.51%
 USDT  -0.00%
 ADA   10.88%
 SOL   2.95%
 USDC  0.04%
 XRP   -0.34%
 LUNA  3.32%
 DOT   1.27%

@bitcoinmeetups
Copy link
Author

Good morning. This is nice:
curl rate.sx/?T | cut -c 12-18,38-45 | grep -o ' [A-Z].*%'

However it does not seem to work for curl rate.sx/?n=100. Any way to get it to work for the top 100 or 200 cryptocurrencies?

Also what exactly does cut do here? I read man cut but I still don't get exactly what it does in this context.

@bitcoinmeetups
Copy link
Author

I assume it cuts based on horizontal position but it doesn't make sense because 12-18 is not exactly the right position. Instead currency code seems to be positioned between 10-12.

@bitcoinmeetups
Copy link
Author

This also does not work:

curl -s rate.sx/?n=100 | cut --output-delimiter="│" -f 3,5 | grep -o ' [A-Z].*%'

@chubin
Copy link
Owner

chubin commented Apr 2, 2022

I think, if you just need the data, without any visualization, the best approach would be to use JSON. It is not yet possible, but the feature could be added.

@chubin chubin changed the title Feature request JSON output Apr 2, 2022
@bitcoinmeetups
Copy link
Author

I wrote a little script to parse it, I think I got the first 100 cryptocurrencies kind of parsed correctly. Yes, maybe JSON output would be useful.

A little + sign before the positive changes would be nice too. At the moment the negative changes are preceded by - minus sign but the positive changes are not preceded by anything. Would make it slightly easier to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants