def request(self, url=None, method='get', param=None, path_fields=None): security_item = param['security_item'] start_timestamp = param['start_timestamp'] size = param['size'] ccxt_level = param['ccxt_level'] level = param['level'] ccxt_exchange = CCXTAccount.get_ccxt_exchange(security_item.exchange) if ccxt_exchange.has['fetchOHLCV']: limit = CCXTAccount.get_kdata_limit(security_item.exchange) limit = min(size, limit) kdata_list = [] try: if CCXTAccount.exchange_conf[ security_item.exchange]['support_since']: kdatas = ccxt_exchange.fetch_ohlcv(security_item.code, timeframe=ccxt_level, since=start_timestamp) else: kdatas = ccxt_exchange.fetch_ohlcv(security_item.code, timeframe=ccxt_level, limit=limit) # always ignore the latest one,because it's not finished for kdata in kdatas[0:-1]: current_timestamp = kdata[0] if level == TradingLevel.LEVEL_1DAY: current_timestamp = to_time_str(current_timestamp) kdata_json = { 'timestamp': to_pd_timestamp(current_timestamp), 'open': kdata[1], 'high': kdata[2], 'low': kdata[3], 'close': kdata[4], 'volume': kdata[5], 'name': security_item.name, 'provider': 'ccxt', 'level': level.value } kdata_list.append(kdata_json) return kdata_list except Exception as e: logger.exception("record_kdata for security:{} failed".format( security_item.id)) else: logger.warning("exchange:{} not support fetchOHLCV".format( security_item.exchange))
def record(self, entity, start, end, size, timestamps): if self.start_timestamp: start = max(self.start_timestamp, to_pd_timestamp(start)) start_timestamp = to_time_str(start) ccxt_exchange = CCXTAccount.get_ccxt_exchange(entity.exchange) if ccxt_exchange.has['fetchOHLCV']: limit = CCXTAccount.get_kdata_limit(entity.exchange) limit = min(size, limit) kdata_list = [] if CCXTAccount.exchange_conf[entity.exchange]['support_since']: kdatas = ccxt_exchange.fetch_ohlcv( entity.code, timeframe=self.ccxt_trading_level, since=start_timestamp) else: kdatas = ccxt_exchange.fetch_ohlcv( entity.code, timeframe=self.ccxt_trading_level, limit=limit) # always ignore the latest one,because it's not finished for kdata in kdatas[0:-1]: current_timestamp = kdata[0] if self.level == IntervalLevel.LEVEL_1DAY: current_timestamp = to_time_str(current_timestamp) kdata_json = { 'timestamp': to_pd_timestamp(current_timestamp), 'open': kdata[1], 'high': kdata[2], 'low': kdata[3], 'close': kdata[4], 'volume': kdata[5], 'name': entity.name, 'provider': 'ccxt', 'level': self.level.value } kdata_list.append(kdata_json) return kdata_list else: self.logger.warning("exchange:{} not support fetchOHLCV".format( entity.exchange))