News for hackers. Stuff that matters.
Re:Show HN: Coinmon – Check Bitcoin Prices in Terminal by Fnoord on Tuesday November 21, 2017 @03:07PM (#15751083)
Very nice, thank you!

I'm not much into APIs or JS (CBA with auth tokens etc either) so I often forget the sheer power of jq.

I prefer to output the curl data 2>/dev/null so there's less noise and the data could be parsed further. I also want to default to eur, with the option of say usd. Finally, I want the currency to be shown as $2 and I want it uppercase.

I ended up with:

  coinmon() {
      local currency=$1
      case "$currency" in "") currency="eur";; esac
      data=`curl "https://api.coinmarketcap.com/v1/ticker/?convert=$currency" 2>/dev/null | jq ".[0] .price_$currency" | cut -d \" -f 2`
      echo "$data ${currency^^} "
  }
(Sorry for the scrollbar here on HN.)

One could also use tosheets [1] to put $data in spreadsheet or perhaps use something like gnuplot. One could also round $data to say 2 numbers behind the comma (or well, dot is being used in this case) to get a more human readable amount. This could also be implemented like df -h creates human readable output (see man df).

[1] https://news.ycombinator.com/item?id=15722108

There are no comments on this comment yet.