def QA_fetch_future_day_adv( code, start, end=None, if_drop_index=True, # 🛠 todo collections 参数没有用到, 且数据库是固定的, 这个变量后期去掉 collections=DATABASE.index_day): ''' :param code: code: 字符串str eg 600085 :param start: 字符串str 开始日期 eg 2011-01-01 :param end: 字符串str 结束日期 eg 2011-05-01 :param if_drop_index: Ture False , dataframe drop index or not :param collections: mongodb 数据库 :return: ''' '获取期货日线' end = start if end is None else end start = str(start)[0:10] end = str(end)[0:10] # 🛠 todo 报告错误 如果开始时间 在 结束时间之后 # 🛠 todo 如果相等 res = QA_fetch_future_day(code, start, end, format='pd') if res is None: print( "QA Error QA_fetch_future_day_adv parameter code=%s start=%s end=%s call QA_fetch_future_day return None" % (code, start, end)) else: res_set_index = res.set_index(['date', 'code']) # if res_set_index is None: # print("QA Error QA_fetch_index_day_adv set index 'date, code' return None") # return None return QA_DataStruct_Future_day(res_set_index)
def get_future_day(self, codelist, start, end): codelist = promise_list(codelist) columns_raw = [ 'date', 'order_book_id', 'limit_up', 'limit_down', 'open_interest', 'prev_settlement', 'settlement', 'open', 'high', 'low', 'close', 'volume', 'total_turnover' ] res = self.client.query_dataframe( "SELECT * FROM quantaxis.future_cn_day WHERE ((`date` >= '{}')) \ AND (`date` <= '{}') AND (`order_book_id` IN ({}))". format(start, end, "'{}'".format( "','".join(codelist)))).loc[:, columns_raw].drop_duplicates( ['date', 'order_book_id']) return QA_DataStruct_Future_day( res.assign(date=pd.to_datetime(res.date), code=res.order_book_id, amount=res.total_turnover, position=res.open_interest, price=res.settlement).set_index(['date', 'code']))