@@ -180,7 +180,7 @@ VERSION="false" # for --version argument;
180
180
DOONLYCLEANUP=" false" # for --cleanup argument;
181
181
# shellcheck disable=SC2034
182
182
COUNTER=0 # this is a counter of arguments
183
- VERSIONDESC=" 2017-NOV-27 "
183
+ VERSIONDESC=" 2020-OCT-03 "
184
184
MYAPP=jq # this package is required, a json parser
185
185
MYAPP2=curl # this package is required
186
186
# https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?start=1&convert=USD&limit=10
@@ -196,7 +196,7 @@ TORIFY="false"
196
196
TOPDEFAULT=10 # default
197
197
TOP=$TOPDEFAULT # init
198
198
FIAT=" USD" # default fiat currency
199
- FIATARRAY=(AUD BRL CAD CHF CLP CNY CZK DKK EUR GBP HKD HUF IDR ILS INR JPY KRW MXN MYR NOK NZD PHP PKR PLN RUB SEK SGD THB TRY TWD USD ZAR)
199
+ FIATARRAY=(BTC ETH USDT XRP BCH BNB DOT LINK CRO BSV LTC XAU XAG XPT XPD AUD BRL CAD CHF CLP CNY CZK DKK EUR GBP HKD HUF IDR ILS INR JPY KRW MXN MYR NOK NZD PHP PKR PLN RUB SEK SGD THB TRY TWD USD ZAR)
200
200
EUR=" false"
201
201
CCSYMBOLSARRAY=()
202
202
CCSYMBOLSLIST=" " # string of crypt currencies seperated by comma (,) without spaces ( ). E.g. btc,eth,ltc
@@ -226,7 +226,10 @@ function usage() {
226
226
echo " ${0##*/ } : If necessary it installs packages $MYAPP and $MYAPP2 ."
227
227
echo " ${0##*/ } : Inspiration and basic idea from ${bold} https://github.com/bichenkk/coinmon${reset} "
228
228
echo " ${0##*/ } : Real-time market data from ${bold} https://www.coinmarketcap.com${reset} "
229
- echo " ${0##*/ } : The default currency is USD and it supports AUD, BRL, CAD, CHF, CLP, CNY, CZK, "
229
+ echo " ${0##*/ } : The default currency is USD and it supports "
230
+ echo " ${0##*/ } : BTC, ETH, USDT, XRP, BCH, BNB, DOT, LINK, CRO, BSV, LTC, "
231
+ echo " ${0##*/ } : XAU, XAG, XPT, XPD, "
232
+ echo " ${0##*/ } : AUD, BRL, CAD, CHF, CLP, CNY, CZK, "
230
233
echo " ${0##*/ } : DKK, EUR, GBP, HKD, HUF, IDR, ILS, INR, JPY, KRW, MXN, MYR, NOK, NZD, "
231
234
echo " ${0##*/ } : PHP, PKR, PLN, RUB, SEK, SGD, THB, TRY, TWD, ZAR."
232
235
echo " ${0##*/ } : ${0##*/ } uses a temporary file $JSONFILE which gets automatically removed."
@@ -239,6 +242,8 @@ function usage() {
239
242
echo " ${0##*/ } : Example: ${0##*/ } -t -n 7 -e ... uses Tor, prints market info of top 7 crypto currencies, "
240
243
echo " ${0##*/ } : uses EUR for prices"
241
244
echo " ${0##*/ } : Example: ${0##*/ } -e ... shortcut for -f EUR, uses Euro for prices"
245
+ echo " ${0##*/ } : Example: ${0##*/ } -f BTC ... gives prices in Bitcoin (BTC)"
246
+ echo " ${0##*/ } : Example: ${0##*/ } -f XAU ... gives prices in Gold Troy ounces (XAU)"
242
247
echo " ${0##*/ } : Example: ${0##*/ } -f AUD ... gives prices in Australian Dollars (AUD)"
243
248
echo " ${0##*/ } : Example: ${0##*/ } -l btc ... lists only BTC"
244
249
echo " ${0##*/ } : Example: ${0##*/ } -l btc,eth,ltc ... lists BTC, ETH and LTC "
@@ -262,6 +267,7 @@ function usage() {
262
267
echo " ${0##*/ } : DO-ONLY-CLEANUP: Performs only cleanup, then exits [type: flag]"
263
268
echo " ${0##*/ } : ${bold} --torify, -t${reset} "
264
269
echo " ${0##*/ } : TORIFY: Request the data via Tor onion network [type: flag]"
270
+ echo " ${0##*/ } : Was disabled in latest Coinmarketcap.com API."
265
271
echo " ${0##*/ } : ${bold} --top, -n${reset} "
266
272
echo " ${0##*/ } : TOP: How many crypto currencies should be displayed [type: integer] [default: $TOP ]"
267
273
echo " ${0##*/ } : ${bold} --fiat, -f${reset} "
@@ -364,10 +370,10 @@ function printHeader() {
364
370
max_supply=" Max-Supply"
365
371
percent_change_1h=" 1h-Change"
366
372
# dont put anything like ${bold} ${reset} here, it confuses `column` later
367
- printf " %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t% 17s\t%17s\t%17s\t%17s\t%17s\n" " $rank " " $symbol " " $name " " $price " " $price_btc " " $percent_change_1h " " $percent_change_24h " " $percent_change_7d " " $a24h_volume " " $available_supply " " $total_supply " " $max_supply " " $market_cap "
373
+ printf " %s\t%s\t%s\t%s\t%s\t%s\t%s\t%17s\t%17s\t%17s\t%17s\t%17s\n" " $rank " " $symbol " " $name " " $price " " $percent_change_1h " " $percent_change_24h " " $percent_change_7d " " $a24h_volume " " $available_supply " " $total_supply " " $max_supply " " $market_cap "
368
374
else
369
375
# dont put anything like ${bold} ${reset} here, it confuses `column` later
370
- printf " %s\t%s\t%s\t%s\t%s\t%s\t%s\t% 17s\n" " $rank " " $symbol " " $name " " $price " " $price_btc " " $percent_change_24h " " $percent_change_7d " " $market_cap "
376
+ printf " %s\t%s\t%s\t%s\t%s\t%s\t%17s\n" " $rank " " $symbol " " $name " " $price " " $percent_change_24h " " $percent_change_7d " " $market_cap "
371
377
fi
372
378
}
373
379
@@ -454,7 +460,8 @@ function processEntry() {
454
460
# price="${price%\"}"
455
461
# price="${price#\"}"
456
462
[ $seperator == " ," ] && price=${price// ./ ,} # replace all dots
457
- price_btc=" ---" # no longer offered in same API call
463
+ # price_btc=$(echo "$1" | jq ".quote.BTC.price") ==> Free API key does NOT support more than 1 currency!
464
+ price_btc=" ---"
458
465
# price_btc="${price_btc%\"}"
459
466
# price_btc="${price_btc#\"}"
460
467
[ $seperator == " ," ] && price_btc=${price_btc// ./ ,} # replace all dots
@@ -495,9 +502,9 @@ function processEntry() {
495
502
# percent_change_1h="${percent_change_1h%\"}"
496
503
# percent_change_1h="${percent_change_1h#\"}"
497
504
[ $seperator == " ," ] && percent_change_1h=${percent_change_1h// ./ ,} # replace all dots
498
- printf " %d\t%s\t%s\t%'7.2f \t%3s\t% +6.1f%%\t%+6.1f%%\t%+6.1f%%\t%'17.f\t%'17.f\t%'17.f\t%'17.f\t%'17.f\n" " $rank " " $symbol " " $name " " $price " " $price_btc " " $percent_change_1h " " $percent_change_24h " " $percent_change_7d " " $a24h_volume " " $available_supply " " $total_supply " " $max_supply " " $market_cap " 2> /dev/null
505
+ printf " %d\t%s\t%s\t%'1.8f \t%+6.1f%%\t%+6.1f%%\t%+6.1f%%\t%'17.f\t%'17.f\t%'17.f\t%'17.f\t%'17.f\n" " $rank " " $symbol " " $name " " $price " " $percent_change_1h " " $percent_change_24h " " $percent_change_7d " " $a24h_volume " " $available_supply " " $total_supply " " $max_supply " " $market_cap " 2> /dev/null
499
506
else
500
- printf " %d\t%s\t%s\t%'7.2f \t%3s\t% +6.1f%%\t%+6.1f%%\t%'17.f\n" " $rank " " $symbol " " $name " " $price " " $price_btc " " $percent_change_24h " " $percent_change_7d " " $market_cap " 2> /dev/null
507
+ printf " %d\t%s\t%s\t%'1.8f \t%+6.1f%%\t%+6.1f%%\t%'17.f\n" " $rank " " $symbol " " $name " " $price " " $percent_change_24h " " $percent_change_7d " " $market_cap " 2> /dev/null
501
508
fi
502
509
503
510
if [ " $useccsymbolslist " == " true" ]; then
@@ -512,7 +519,8 @@ function processEntry() {
512
519
513
520
function main() {
514
521
if [ " $COINMARKETCAP_API_KEY " == " " ]; then
515
- echo " ${0##*/ } : ${red}${bold} Coinmarketcap-API-key missing.${reset} Global environment variable \" COINMARKETCAP_API_KEY\" is not set. Go to https://coinmarketcap.com and get your personal API key. Then assign it to environment variable \" COINMARKETCAP_API_KEY\" ."
522
+ echo " ${0##*/ } : ${red}${bold} Coinmarketcap-API-key missing.${reset} Global environment variable \" COINMARKETCAP_API_KEY\" is not set."
523
+ echo " ${0##*/ } : Go to https://coinmarketcap.com and get your personal API key. Then assign it to environment variable \" COINMARKETCAP_API_KEY\" ."
516
524
exit 13
517
525
fi
518
526
# process arguments
@@ -535,6 +543,9 @@ function main() {
535
543
;;
536
544
torify | t | tor | -torify | -t | -tor | --torify | --t | --tor)
537
545
TORIFY=" true"
546
+ echo " ${0##*/ } : ${red}${bold} This feature has been disabled by the API. It requires a captcha. Sorry.${reset} "
547
+ echo " ${0##*/ } : ${red}${bold} TOR use no longer allowed in the new API version.${reset} "
548
+ exit 33
538
549
;;
539
550
top | n | number | -top | -n | -number | --top | --n | --number)
540
551
if ! [[ " $2 " =~ ^[0-9]+$ ]]; then
@@ -623,6 +634,7 @@ function main() {
623
634
# shellcheck disable=SC2034
624
635
FIATLC=${FIAT,,} # lowercase
625
636
fi
637
+ # I tried this: `CONVERT="?convert=BTC,${FIATUC}"` but it gave error `Free version does not support more than 1 currency`.
626
638
CONVERT=" ?convert=${FIATUC} "
627
639
[ " $DEBUG " == " true" ] && echo " ${0##*/ } : ${green}${bold} Converting to fiat $FIATUC .${reset} "
628
640
@@ -715,6 +727,18 @@ function main() {
715
727
for name in " ${CCNAMESARRAY[@]} " ; do
716
728
[ " $DEBUG " == " true" ] && echo " ${0##*/ } : DEBUG: $TORIFYCMD curl -H \" X-CMC_PRO_API_KEY: $COINMARKETCAP_API_KEY \" -H \" Accept: application/json\" -s \" ${DATAURL} quotes/latest${CONVERT} &slug=${name} \" > \" ${JSONFILE} .part\" "
717
729
$TORIFYCMD curl -H " X-CMC_PRO_API_KEY: $COINMARKETCAP_API_KEY " -H " Accept: application/json" -s " ${DATAURL} quotes/latest${CONVERT} &slug=${name} " > " ${JSONFILE} .part"
730
+ errorstatus=$( cat " ${JSONFILE} .part" | jq " [.status.error_code][]" )
731
+ if [ " $errorstatus " != " 0" ]; then
732
+ echo " ${0##*/ } : ${red} Error: The https://coinmarketcap.com/ API returned error code \" $errorstatus \" . Aborting.${reset} "
733
+ echo " ${0##*/ } : 400 400 Bad Request"
734
+ echo " ${0##*/ } : 1002 401 Unauthorized"
735
+ echo " ${0##*/ } : 1006 403 Forbidden"
736
+ echo " ${0##*/ } : 1008 429 Too Many Requests"
737
+ echo " ${0##*/ } : 500 500 Internal Server Error "
738
+ echo " ${0##*/ } : Timestamp: $( cat " ${JSONFILE} .part" | jq " [.status.timestamp][]" ) "
739
+ echo " ${0##*/ } : Message: $( cat " ${JSONFILE} .part" | jq " [.status.error_message][]" ) "
740
+ exit " $ret "
741
+ fi
718
742
# shellcheck disable=SC2046
719
743
if [ $( grep -c " id not found" " ${JSONFILE} .part" ) -eq 1 ]; then
720
744
echo " ${0##*/ } : ${yellow} WARNING: No crypto currency with name \" $name \" was not found.${reset} Skipping it."
@@ -736,6 +760,18 @@ function main() {
736
760
LIMIT=" &limit=${TOP} "
737
761
[ " $DEBUG " == " true" ] && echo " ${0##*/ } : DEBUG: $TORIFYCMD curl -H \" X-CMC_PRO_API_KEY: $COINMARKETCAP_API_KEY \" -H \" Accept: application/json\" s \" ${DATAURL} listings/latest${CONVERT}${LIMIT} &start=1\" > \" ${JSONFILE} \" "
738
762
$TORIFYCMD curl -H " X-CMC_PRO_API_KEY: $COINMARKETCAP_API_KEY " -H " Accept: application/json" -s " ${DATAURL} listings/latest${CONVERT}${LIMIT} &start=1" > " ${JSONFILE} "
763
+ errorstatus=$( cat " ${JSONFILE} " | jq " [.status.error_code][]" )
764
+ if [ " $errorstatus " != " 0" ]; then
765
+ echo " ${0##*/ } : ${red} Error: The https://coinmarketcap.com/ API returned error code \" $errorstatus \" . Aborting.${reset} "
766
+ echo " ${0##*/ } : 400 400 Bad Request"
767
+ echo " ${0##*/ } : 1002 401 Unauthorized"
768
+ echo " ${0##*/ } : 1006 403 Forbidden"
769
+ echo " ${0##*/ } : 1008 429 Too Many Requests"
770
+ echo " ${0##*/ } : 500 500 Internal Server Error "
771
+ echo " ${0##*/ } : Timestamp: $( cat " ${JSONFILE} " | jq " [.status.timestamp][]" ) "
772
+ echo " ${0##*/ } : Message: $( cat " ${JSONFILE} " | jq " [.status.error_message][]" ) "
773
+ exit " $ret "
774
+ fi
739
775
fi
740
776
setSeperator
741
777
ii=0
0 commit comments