chubin / rate.sx

:moneybag: curl cryptocurrencies exchange rates
http://rate.sx
MIT License
968 stars 87 forks source link

JSON output #57

Open bitcoinmeetups opened 2 years ago

bitcoinmeetups commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

This also does not work:

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

chubin commented 2 years ago

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.

bitcoinmeetups commented 2 years ago

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.