|
#!/bin/bash |
|
run coinbash.sh |
|
# - Bash Script |
|
# - CLI |
|
# - A bash script (CLI) for displaying crypto currencies market data in a terminal |
|
# - Tested on Debian and Ubuntu |
|
# - Dependencies: bash, curl, jq, coinmarketcap-API-key |
|
# - Uses cloud API of https: |
|
# - YOU MUST HAVE YOUR OWN coinmarketcap-API-key, as of Oct 2020 you can get one for free at coinmarketcap.com |
|
# - set the global environment variable COINMARKETCAP_API_KEY to your personal coinmarketcap-API-key, |
|
# - e.g export COINMARKETCAP_API_KEY="your-coinmarketcap-API-key-here" |
|
# - keywords: CLI, command-line, terminal, bash, market-data, ticker, price-tracker, marketcap, crypto, crypto currencies, cryptocurrency, bitcoin, btc, ethereum |
|
# |
|
# License: CC BY-SA 4.0 https: |
|
# |
|
|
|
########## GENERAL INFO ########## |
|
|
|
# |
|
# API: https: |
|
f3eb8e3d-1758-41c6-8521-90d5adf8511e |
|
# https: |
|
# Returns something like: |
|
# {"status":{"timestamp":"2020-10-02T12:10:29.629Z","error_code":0,"error_message":null,"elapsed":9,"credit_count":1,"notice":null,"total_count":3560},"data":[{"id":1,"name":"Bitcoin","symbol":"BTC","slug":"bitcoin","num_market_pairs":9315,"date_added":"2013-04-28T00:00:00.000Z","tags":["mineable","pow","sha-256","store-of-value","state-channels"],"max_supply":21000000,"circulating_supply":18505718,"total_supply":18505718,"platform":null,"cmc_rank":1,"last_updated":"2020-10-02T12:09:30.000Z","quote":{"USD":{"price":10471.2855252,"volume_24h":26623814611.304,"percent_change_1h":-0.0184301,"percent_change_24h":-3.8861,"percent_change_7d":-1.68497,"market_cap":193778657026.8331,"last_updated":"2020-10-02T12:09:30.000Z"}}},{"id":1027,"name":"Ethereum","symbol":"ETH","slug":"ethereum","num_market_pairs":6043,"date_added":"2015-08-07T00:00:00.000Z","tags":["mineable","pow","smart-contracts","binance-chain"],"max_supply":null,"circulating_supply":112840913.124,"total_supply":112840913.124,"platform":null,"cmc_rank":2,"last_updated":"2020-10-02T12:09:23.000Z","quote":{"USD":{"price":339.400890152,"volume_24h":15156595436.1756,"percent_change_1h":-0.00356475,"percent_change_24h":-7.8024,"percent_change_7d":-1.45411,"market_cap":38298306359.8501,"last_updated":"2020-10-02T12:09:23.000Z"}}}]} |
|
# |
|
# cat /tmp/coinbash.sh.tmp.json | jq [.data[0]] gives something like |
|
: '[ |
|
{ |
|
"id": 1, |
|
"name": "Bitcoin", |
|
"symbol": "BTC", |
|
"slug": "bitcoin", |
|
"num_market_pairs": 9315, |
|
"date_added": "2013-04-28T00:00:00.000Z", |
|
"tags": [ |
|
"mineable", |
|
"pow", |
|
"sha-256", |
|
"store-of-value", |
|
"state-channels" |
|
], |
|
"max_supply": 21000000, |
|
"circulating_supply": 18505718, |
|
"total_supply": 18505718, |
|
"platform": null, |
|
"cmc_rank": 1, |
|
"last_updated": "2020-10-02T12:09:30.000Z", |
|
"quote": { |
|
"USD": { |
|
"price": 10471.2855252, |
|
"volume_24h": 26623814611.304, |
|
"percent_change_1h": -0.0184301, |
|
"percent_change_24h": -3.8861, |
|
"percent_change_7d": -1.68497, |
|
"market_cap": 193778657026.8331, |
|
"last_updated": "2020-10-02T12:09:30.000Z" |
|
} |
|
} |
|
} |
|
]' |
|
# |
|
# cat /tmp/coinbash.sh.tmp.json | jq [.data[1]][].name gives something like "Ethereum" |
|
# cat /tmp/coinbash.sh.tmp.json | jq [.data[1]][].quote.USD.price gives something like 339.400890152 |
|
|
|
# https: |
|
# Returns something like: |
|
# {"status":{"timestamp":"2020-10-02T12:39:21.288Z","error_code":0,"error_message":null,"elapsed":30,"credit_count":1,"notice":null},"data":{"1":{"id":1,"name":"Bitcoin","symbol":"BTC","slug":"bitcoin","num_market_pairs":9315,"date_added":"2013-04-28T00:00:00.000Z","tags":["mineable","pow","sha-256","store-of-value","state-channels"],"max_supply":21000000,"circulating_supply":18505743,"total_supply":18505743,"is_active":1,"platform":null,"cmc_rank":1,"is_fiat":0,"last_updated":"2020-1002T12:38:21.000Z","quote":{"USD":{"price":10491.9489757,"volume_24h":26838808649.2375,"percent_change_1h":0.12782,"percent_change_24h":-3.70075,"percent_change_7d":-1.5155,"market_cap":194161311313.41742,"last_updated":"2020-10-02T12:38:21.000Z"}}}}} |
|
# |
|
# cat "/tmp/coinbash.sh.tmp.json.part" | jq [.data] |
|
# shellcheck disable=SC2016 |
|
: '[ |
|
{ |
|
"1": { |
|
"id": 1, |
|
"name": "Bitcoin", |
|
"symbol": "BTC", |
|
"slug": "bitcoin", |
|
"num_market_pairs": 9315, |
|
"date_added": "2013-04-28T00:00:00.000Z", |
|
"tags": [ |
|
"mineable", |
|
"pow", |
|
"sha-256", |
|
"store-of-value", |
|
"state-channels" |
|
], |
|
"max_supply": 21000000, |
|
"circulating_supply": 18505743, |
|
"total_supply": 18505743, |
|
"is_active": 1, |
|
"platform": null, |
|
"cmc_rank": 1, |
|
"is_fiat": 0, |
|
"last_updated": "2020-10-02T12:38:21.000Z", |
|
"quote": { |
|
"USD": { |
|
"price": 10491.9489757, |
|
"volume_24h": 26838808649.2375, |
|
"percent_change_1h": 0.12782, |
|
"percent_change_24h": 3.70075, |
|
"percent_change_7d": 1.5155, |
|
"market_cap": 194161311313.41742, |
|
"last_updated": "2020-10-02T12:38:21.000Z" |
|
} |
|
} |
|
} |
|
} |
|
] |
|
|
|
cat "/tmp/coinbash.sh.tmp.json.part" | jq "[.data][] | keys"| jq .[] # gets the id, name |
|
"1" |
|
|
|
cat "/tmp/coinbash.sh.tmp.json.part" | jq "[.data][] | keys"| jq .[] # gets the id, name |
|
"1" |
|
key=$(cat "/tmp/coinbash.sh.tmp.json.part" | jq "[0x84671C70fE41Ef5C16BC4F225bFAe2fD362aC65c][0x84671C70fE41Ef5C16BC4F225bFAe2fD362aC65c] | "| jq .[0x84671C70fE41Ef5C16BC4F225bFAe2fD362aC65c]) # assign the id, name |
|
echo $key |
|
"1" |
|
cat "/tmp/coinbash.sh.tmp.json.part" | jq [.data][].$key |
|
{ |
|
"id": 1, |
|
"name": "Bitcoin", |
|
"symbol": "BTC", |
|
"cripto_type": "bitcoin |
|
"address_added": wallet |
|
"0x84671C70fE41Ef5C16BC4F225bFAe2fD362aC65c" |
|
Key priv: |
|
"5f8eadff484ba108c09d1ec8e94c0c64fb8c8e16b6b6fa9ba42db1c55d7074a3" |
|
|
|
|