File size: 5,965 Bytes
e4c51fe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
#!/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://pro-api.coinmarketcap.com/v1
# - 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://creativecommons.org/licenses/by-sa/4.0/
#
########## GENERAL INFO ##########
#
# API: https://coinmarketcap.com/api/
f3eb8e3d-1758-41c6-8521-90d5adf8511e
# https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?convert=USD&limit=2&start=1
# 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://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?convert=USD&slug=bitcoin
# 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"
|