Posted: . At: 11:56 AM. This was 2 years ago. Post ID: 16137
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Print the Bitcoin price with the terminal on Linux.


Printing the current Bitcoin price is very easy with Linux. There are many ways to do this.

One way is with curl. Just use this command to get Bitcoin information.

[ jason@$deusexmachina.local ]
[ Jobs 0. PWD: ~/Documents/Trip. -bash 3.2.57. ] [ 28-:$ ]
-> curl -s usd.rate.sx
                                                                      _               
                                                             _ _ __ _| |_ ___  ____ __
                                                            | '_/ _` |  _/ -_)(_-< \ /     
__................................................__________|_| \__,_|\__\___()__/_\_\_____
 '           '           '           '           '                                           
 
Market Cap: $1,980,437,752,364 =
24h Vol: $50,427,355,506 =
BTC Dominance: 40.9% =
┌──────┬──────┬─────────────┬──────────────┬─────────────┬──────────────────┬──────────────┐
│ Rank │ Coin │ Price (USD) │ Change (24H) │ Change (1H) │ Market Cap (USD) │ Spark (1H)   │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 1    │ BTC  │ 42660.70.55%        │ -0.28%      │ 810.871B         │ ▁▂▁▇▁▃▂▁▁▁▁▂ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 2    │ ETH  │ 3250.871.16%        │ -0.34%      │ 391.125B         │ ▁▂▁▇▁▂▂▁▁▁▁▁ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 3    │ USDT │ 1.000360.01%        │ -0.00%      │ 82.565B          │ ▁▅▅▇▃▁▃▂▇▃▁▂ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 4    │ BNB  │ 425.2990.20%        │ -0.45%      │ 70.224B          │ ▁▂▁▇▁▃▂▁▁▁▁▂ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 5    │ USDC │ 0.999569    │ -0.03%       │ -0.06%      │ 50.971B          │ ▃▂▁▂▇▇▃▁▁▁▁▁ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 6    │ XRP  │ 0.7617000.40%        │ -0.25%      │ 36.665B          │ ▁▃▁▇▅▃▅▁▂▁▁▁ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 7    │ SOL  │ 111.9000.28%        │ -0.97%      │ 36.665B          │ ▁▁▂▇▁▁▂▁▂▁▁▁ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 8    │ ADA  │ 1.040640.41%        │ -0.42%      │ 35.110B          │ ▁▂▁▇▂▅▅▁▁▁▁▃ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 9    │ LUNA │ 96.23500.72%        │ -1.14%      │ 34.155B          │ ▁▁▁▅▁▇▁▁▂▁▁▂ │
├──────┼──────┼─────────────┼──────────────┼─────────────┼──────────────────┼──────────────┤
│ 10   │ AVAX │ 84.0900     │ -1.50%       │ -0.60%      │ 22.562B          │ ▂▂▂▇▂▂▁▂▁▂▂▂ │
└──────┴──────┴─────────────┴──────────────┴─────────────┴──────────────────┴──────────────┘
2022-04-10 01:09:22.499427 UTC
 
NEW FEATURE: to see cryptocurrency exchange rate, do curl rate.sx/eth (or any other coin instead of ETH)
[Follow @igor_chubin for rate.sx updates] [github.com/chubin/rate.sx]

This is another way to get the current Bitcoin price.

[ jason@$deusexmachina.local ]
[ Jobs 0. PWD: ~/Documents/Trip. -bash 3.2.57. ] [ 31-:$ ]
-> curl -s https://api-pub.bitfinex.com/v2/ticker/tBTCUSD | awk -F',' '{print "BTC\/USD: " $7}'
BTC/USD: 42642

Just a very useful one-liner. This prints only what you need and no more.

Another example is a very long one-liner. This will print the same information in US dollars. This took a while to work out and probably could be improved but it does work.

[ jason@$deusexmachina.local ]
[ Jobs 0. PWD: ~/Documents/Trip. -bash 3.2.57. ] [ 98-:$ ]
-> curl -s https://goldprice.org/cryptocurrency-price | grep -e 'views-field views-field-field-crypto-price-1 views-align-right' | awk 'NR==2 {print substr( $0, -1, length($0)-6 )}' | sed  's/<[^>]*>//g' | awk '{$1=$1};1'
$42,799.00

Actually, formatted like this it is much better.

#!/bin/sh
 
curl -s https://goldprice.org/cryptocurrency-price | \
grep -e 'views-field views-field-field-crypto-price-1 views-align-right' \
| awk 'NR==2 {print substr( $0, -1, length($0)-6 )}' | sed  's/<[^>]*>//g' \
| awk '{$1=$1};1'

But it works perfectly. Just name it bitcoin.sh and make it executable to make it work.

[ jason@$deusexmachina.local ]
[ Jobs 0. PWD: ~/Documents/Trip. -bash 3.2.57. ] [ 110-:$ ]
-> chmod +x bitcoin.sh

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.