def init_klines_1min(q_ws, q_loop, q_keeper, cv, evt_init_1min, evt_first_Nmin, evt_loop): """init step 1, !!!attention if the start time just pass the :00 and :05 will put an empty DataFrame""" # because the bug in ws, the sleep time may be less than real, so sleep more in here evt_init_1min.wait() sleep(5) bm = BitMEX_API(testing=config.testing, api_key=config.API_KEY, api_secret=config.API_SECRET) startTime = datetime.datetime.utcnow().replace(microsecond=0, second=0) num_bars = startTime.minute % 5 + 1 startTime = startTime - datetime.timedelta(minutes=(num_bars - 1)) sleep(15) ohlc_history_1min = bm.fetchOHLC(binSize='1m', count=num_bars, startTime=startTime) q_ws.put(ohlc_history_1min) logger.info('******init 1-min klines****** DONE') logger.debug(ohlc_history_1min) Thread(target=init_first_Nmin, name='init_first_Nmin', args=( q_ws, q_loop, q_keeper, cv, evt_first_Nmin, evt_loop, )).start() evt_first_Nmin.set()
def init_klines_Nmin(): """init step 1""" bm = BitMEX_API(testing=config.testing, api_key=config.API_KEY, api_secret=config.API_SECRET) num_bars = config.EMA_slow + 75 trading_period = str(N) + 'm' startTime = datetime.datetime.utcnow().replace( microsecond=0, second=0) - datetime.timedelta(minutes=num_bars * 5) ohlc_history_Nmin = bm.fetchOHLC(binSize=trading_period, count=num_bars, startTime=startTime) return ohlc_history_Nmin