gethistoricView |
---|
1 | 1 … | #!/bin/bash |
2 | 2 … | |
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" ]] |
8 | 5 … | then |
9 | | - echo "Usage: $0 [yyyy-mm-dd]" >&2 |
| 6 … | + echo "Usage: $0 [CURRENCY] [yyyy-mm-dd]" >&2 |
10 | 7 … | exit 1 |
11 | 8 … | fi |
12 | 9 … | |
13 | 10 … | req_date="${req_date%% *}" |
14 | 11 … | |
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¤cy=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 |