git ssb

0+

cel / ledger-scripts



Commit f1521af2d73e96acaa4e96dfc60dbfc50373845a

Update gethistoric

cel committed on 6/11/2018, 8:31:48 PM
Parent: ac0d1af3da51197514f0473648b31169fb35fa97

Files changed

README.mdchanged
gethistoricchanged
README.mdView
@@ -107,16 +107,11 @@
107107
108108 BTC, altcoins, gold, silver, Havelock Investments, CryptoStocks,
109109 NASDAQ, and sovereign currencies.
110110
111-#### `getquote.sh`
112-
113-Get quotes for things. Written in POSIX shell. Depends on curl and jq.
114-Currently it does not support as many tickers as `getquote.pl` does.
115-
116111 #### `gethistoric`
117112
118-Get past quotes for BTC/USD, using BitcoinAverage's API.
113 +Get past quotes for some currencies.
119114
120115 #### `claws-filter`
121116
122117 Detect transactions in incoming emails through the Claws Mail client and write
gethistoricView
@@ -1,24 +1,22 @@
11 #!/bin/bash
22
3-HISTORIC_CSV=/tmp/historic-btc.csv
4-HISTORIC_URL='https://api.bitcoinaverage.com/history/USD/per_day_all_time_history.csv'
5-
6-req_date="$1"
7-if [[ -z "$req_date" ]]
3 +req_date="$2"
4 +if [[ -z "$req_date" ]] || [[ -z "$1" ]]
85 then
9- echo "Usage: $0 [yyyy-mm-dd]" >&2
6 + echo "Usage: $0 [CURRENCY] [yyyy-mm-dd]" >&2
107 exit 1
118 fi
129
1310 req_date="${req_date%% *}"
1411
15-if [[ ! -e $HISTORIC_CSV ]] && ! curl -s $HISTORIC_URL -o $HISTORIC_CSV
16-then
17- echo Failed to download historic quotes >&2
18- exit 1
19-fi
20-
21-line=$(grep $req_date $HISTORIC_CSV)
22-line2="${line#*,*,*,}"
23-line3="${line2%,*}"
24-echo $line3
12 +case $1 in
13 + BTC)
14 + echo -n \$
15 + curl -s "http://api.coindesk.com/v1/bpi/historical/close.json?start=$req_date&end=$req_date&currency=USD" | jq ".bpi[\"$req_date\"]"
16 + ;;
17 + ZEC|ETH|ETC|REP)
18 + ts=$(date +%s --date="$req_date")
19 + echo -n \$
20 + curl -s "https://min-api.cryptocompare.com/data/pricehistorical?fsym=$1&tsyms=USD&ts=$ts" | jq ".$1.USD"
21 + ;;
22 +esac

Built with git-ssb-web