def get_kline_column_names(exchange_name): if exchange_name == BINANCE_SPOT_EXCHANGE_NAME: return BinanceExchange.get_kline_column_names() elif exchange_name == BINANCE_MARGIN_EXCHANGE_NAME: return BinanceMargin.get_kline_column_names() elif exchange_name == OKEX_SPOT_EXCHANGE_NAME: return OkexExchange.get_kline_column_names() else: return None
def __init__(self, instance_id, config, db_orders_name): self.instance_id = instance_id self.config = config self.db_orders_name = db_orders_name self._db = md.MongoDB(mongo_user, mongo_pwd, db_name, db_url) self._db.ensure_index(db_orders_name, [("instance_id",1),("symbol",1)]) self.can_buy_time = None exchange = config["exchange"] if exchange == "binance": self.kline_column_names = BinanceExchange.get_kline_column_names() elif exchange == "okex": self.kline_column_names = OkexExchange.get_kline_column_names()
def __init__(self, instance_id, config, db_orders_name=None): self.instance_id = instance_id self.config = config exchange = config["exchange"] if exchange == "binance": self.kline_column_names = BinanceExchange.get_kline_column_names() elif exchange == "okex": self.kline_column_names = OkexExchange.get_kline_column_names() self.md_db = md.MongoDB(mongo_user, mongo_pwd, exchange, db_url) self.td_db = md.MongoDB(mongo_user, mongo_pwd, "xquant", db_url) self.value = 100 if db_orders_name: self.db_orders_name = db_orders_name self.td_db.ensure_index(db_orders_name, [("instance_id", 1), ("symbol", 1)]) self.can_open_time = None self.tp_cc = {"base_open": 0}
exit(1) size = 1000 tmp_time = start_time while tmp_time < end_time: print(tmp_time, end=" ") if (tmp_time + size * interval) > end_time: batch = int((end_time - tmp_time)/interval) else: batch = size # print(batch) klines = exchange.get_klines(symbol, args.k, size=batch, since=1000*int(tmp_time.timestamp())) klines_df = pd.DataFrame(klines, columns=exchange.get_kline_column_names()) klen = len(klines) print("klines len: ", klen) #print(klines) #print("klines[0]: ", klines.ix[0]) #print("klines[-1]: ", klines.ix[klen-1]) #print("records: ", klines.to_dict('records')) if not db.insert_many(collection, klines_df.to_dict('records')): for item in klines_df.to_dict('records'): db.insert_one(collection, item) tmp_time += batch * interval # df = db.get_kline(no_id=False) # pd.set_option('display.max_columns', None) # pd.set_option('display.max_rows', None)
while tmp_time < end_time: print(tmp_time, end=" ") size_interval = size * interval if (tmp_time + size_interval) > end_time: batch = int((end_time - tmp_time) / interval) else: batch = size # print(batch) klines = exchange.get_klines(symbol, args.k, size=batch, since=1000 * int(tmp_time.timestamp())) klines_df = pd.DataFrame(klines, columns=exchange.get_kline_column_names()) klen = len(klines) print("klines len: ", klen) for i in range(klen - 1, -1, -1): last_open_time = datetime.fromtimestamp( klines_df["open_time"].values[i] / 1000) if last_open_time + interval <= end_time: break klines_df = klines_df.drop([i]) # last_kline = klines[i] # print("%s %s" % (datetime.fromtimestamp(last_kline[0]/1000),last_kline)) if not db.insert_many(collection, klines_df.to_dict('records')): for item in klines_df.to_dict('records'): db.insert_one(collection, item)