-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathccxt_test_edited.py
84 lines (67 loc) · 2.67 KB
/
ccxt_test_edited.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import ccxt
from datetime import datetime, timedelta, timezone
import math
import argparse
import pandas as pd
def parse_args():
parser = argparse.ArgumentParser(description='CCXT Market Data Downloader')
parser.add_argument('-s','--symbol',
type=str,
required=True,
help='The Symbol of the Instrument/Currency Pair To Download')
parser.add_argument('-e','--exchange',
type=str,
required=True,
help='The exchange to download from')
parser.add_argument('-t','--timeframe',
type=str,
default='1d',
choices=['1m', '5m','15m', '30m','1h', '2h', '3h', '4h', '6h', '12h', '1d', '1M', '1y'],
help='The timeframe to download')
parser.add_argument('--debug',
action ='store_true',
help=('Print Sizer Debugs'))
return parser.parse_args()
# Get our arguments
args = parse_args()
# Get our Exchange
try:
exchange = getattr (ccxt, args.exchange) ()
except AttributeError:
print('-'*36,' ERROR ','-'*35)
print('Exchange "{}" not found. Please check the exchange is supported.'.format(args.exchange))
print('-'*80)
quit()
# Check if fetching of OHLC Data is supported
if exchange.has["fetchOHLCV"] == False:
print('-'*36,' ERROR ','-'*35)
print('{} does not support fetching OHLC data. Please use another exchange'.format(args.exchange))
print('-'*80)
quit()
# Check requested timeframe is available. If not return a helpful error.
if args.timeframe not in exchange.timeframes:
print('-'*36,' ERROR ','-'*35)
print('The requested timeframe ({}) is not available from {}\n'.format(args.timeframe,args.exchange))
print('Available timeframes are:')
for key in exchange.timeframes.keys():
print(' - ' + key)
print('-'*80)
quit()
# Check if the symbol is available on the Exchange
exchange.load_markets()
if args.symbol not in exchange.symbols:
print('-'*36,' ERROR ','-'*35)
print('The requested symbol ({}) is not available from {}\n'.format(args.symbol,args.exchange))
print('Available symbols are:')
for key in exchange.symbols:
print(' - ' + key)
print('-'*80)
quit()
# Get data
data = exchange.fetch_ohlcv(args.symbol, args.timeframe)
header = ['Timestamp', 'Open', 'High', 'Low', 'Close', 'Volume']
df = pd.DataFrame(data, columns=header).set_index('Timestamp')
# Save it
symbol_out = args.symbol.replace("/","")
filename = '{}-{}-{}.csv'.format(args.exchange, symbol_out,args.timeframe)
df.to_csv(filename)