我需要以一分钟的间隔获取历史交易数据。
我正在尝试使用ccxt
. 但我得到了几个循环值。
我做错了什么?
import ccxt
import pandas as pd
import numpy as np
import time
np.set_printoptions(threshold=np.inf)
hitbtc = ccxt.hitbtc({'verbose': True})
bitmex = ccxt.bitmex()
huobi = ccxt.huobipro()
exchange = ccxt.exmo({
'apiKey': 'K-...',
'secret': 'S-...',
})
symbol = 'BTC/USD'
tf = '1m'
from_timestamp = exchange.parse8601('2019-01-10 00:00:00')
end = exchange.parse8601('2019-01-10 03:00:00')
# set timeframe in msecs
tf_multi = 60 * 1000
hold = 30
# make list to hold data
data = []
candle_no = (int(end) - int(from_timestamp)) / tf_multi + 1
print('downloading...')
while from_timestamp < end:
try:
ohlcvs = exchange.fetch_ohlcv(symbol, tf, from_timestamp)
from_timestamp += len(ohlcvs) * tf_multi
print(from_timestamp)
data += ohlcvs
print(str(len(data)) + ' of ' + str(int(candle_no)) + ' candles loaded...')
except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
time.sleep(hold)
header = ['t', 'o', 'h', 'l', 'c', 'v']
df = pd.DataFrame(data, columns=header)
open('btcusd.txt', 'w')
np.savetxt('btcusd.txt', df.o, fmt='%.8f')
// https://pastebin.com/xy1Ddb5z - btcusd.txt