Crypto backtesting
Loading...
Searching...
No Matches
fetch.sh
Go to the documentation of this file.
1#!bin/bash
2
3mkdir -p /tmp/tokens
4
5# Calculate number of entries
6readonly num_lines=$(wc -l < pairs.txt)
7current_line=0
8
9# Fetch JSON for each currency pair
10cat pairs.txt | while read line; do
11
12 # Tokenise the line
13 if [[ $line =~ ([0-9A-Z]+)[[:space:]]+([0-9A-Z]+)[[:space:]]+([A-Za-z]+) ]]; then
14
15 from=${BASH_REMATCH[1]}
16 to=${BASH_REMATCH[2]}
17 exchange=${BASH_REMATCH[3]}
18 period=hour
19
20 # Dump the JSON to tmp
21 json_filename=/tmp/tokens/$exchange-$from-$to-$period.json
22 echo "[$current_line/$num_lines] $from-$to @ $exchange written to $json_filename"
23
24 # Get prices
25 curl --silent "https://min-api.cryptocompare.com/data/histo$period?fsym=$from&tsym=$to&e=$exchange&api_key=$CCAPI&limit=2000" > $json_filename
26 sleep 0.5
27
28 # Increment counter
29 current_line=$((current_line + 1))
30 fi
31done
32
33echo
34ls -l /tmp/tokens/*.json