Crypto backtesting
Loading...
Searching...
No Matches
fetch_free.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 # Break out if there's a blank line
13 [[ -z $line ]] && break
14
15 # Tokenise the line
16 if [[ $line =~ ([0-9A-Z]+)[[:space:]]+([0-9A-Z]+)[[:space:]]+([A-Za-z]+) ]]; then
17
18 from=${BASH_REMATCH[1]}
19 to=${BASH_REMATCH[2]}
20 exchange=${BASH_REMATCH[3]}
21 period=hour
22
23 # Dump the JSON to tmp
24 json_filename=/tmp/tokens/$exchange-$from-$to.json
25 echo "[$current_line/$num_lines] $from-$to @ $exchange written to $json_filename"
26
27 # Get prices
28 curl --silent "https://min-api.cryptocompare.com/data/histo$period?fsym=$from&tsym=$to&e=$exchange&limit=2000" > $json_filename
29 sleep 0.5
30
31 # Increment counter
32 current_line=$((current_line + 1))
33 fi
34done
35
36echo
37ls -l /tmp/tokens/*.json