ccxt: Error with continuous ohlcv fetching poloniex
-
OS: macOS 10.13.6
-
Programming Language version: 3.7.6
-
CCXT version: 1.30.52 I was trying to pull ohlcv data for 5m candles from poloniex. In my code, I’m firstly put my system on wait till nearest 5min and then putting another stopper till 5mins more so that a coin entering XX:45:00 completes its 5min trade cycle by XX:50:00 and I also put a 10 seconds buffer in case if poloniex gets delayed. So right now, if my code starts at xx:37:yy time, it will wait till xx:40:00, then since will be xx:39:49, again it will wait for 5mins 10 secs i.e, xx:45:10, and ideally it should give me candle at xx:40:00 but at the very first pull, it was showing some exchange error as below:
import ccxt
import numpy as np
import pandas as pd
import time
exchange = ccxt.poloniex({'enableRateLimit': True})
exchange.load_markets()
##rounding up to nearest 5th mins
def ceil_dt(dt, delta):
return (dt + (datetime.min - dt) % delta)
now = datetime.strptime((datetime.fromtimestamp(exchange.milliseconds()/1000).strftime('%Y-%m-%d %H:%M:%S')), '%Y-%m-%d %H:%M:%S')
b=ceil_dt(now, timedelta(minutes=5))
a=exchange.milliseconds()/1000
if int(datetime.timestamp(b)-a)>0:
time.sleep(float(datetime.timestamp(b)-a))
since=exchange.milliseconds()-1*1000
t_end=exchange.milliseconds()+60*15*1000
all_c=[]
while t_end > exchange.milliseconds():
try:
time.sleep(300+10) #giving buffer
print('---------------------------------------------------------------')
print('Fetching ohlcvs since', exchange.iso8601(since))
candles = exchange.fetch_ohlcv('BTC/USDT', '5m', since, 1000)
all_c+=candles
since=candles[0][0]+1000*60*5
except ccxt.NetworkError as e:
print(e)
break
except ccxt.ExchangeError as e:
print(e)
break
Error:
GET https://poloniex.com/public?command=returnChartData¤cyPair=USDT_BTC&period=300&start=1598062499&end=1598362499
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 25 (10 by maintainers)
It’s sorted now! Thanks as usual! @kroitor
@kroitor Please look into it!