| | |
| | | """ |
| | | 数据导出工具 |
| | | """ |
| | | import copy |
| | | import json |
| | | import logging |
| | | import os |
| | |
| | | import l2.l2_data_util |
| | | from l2.huaxin import l2_huaxin_util |
| | | from log_module import log, log_export |
| | | from l2 import l2_data_source_util |
| | | from l2 import l2_data_source_util, l2_data_util |
| | | from log_module.log import logger_debug |
| | | from trade import deal_big_money_manager |
| | | from utils import tool |
| | |
| | | |
| | | |
| | | # 获取L2的数据 |
| | | def get_l2_datas(code, today_datas=None, date=None, max_time=None): |
| | | def get_l2_datas(code, today_datas=None, date=None, end_index=None): |
| | | __start_time = time.time() |
| | | if date is None: |
| | | date = tool.get_now_date_str() |
| | |
| | | active_sell_set = active_sell_map.get(code) |
| | | if not active_sell_set: |
| | | active_sell_set = set() |
| | | # 如果有截至位置 |
| | | if end_index: |
| | | datas = copy.deepcopy(datas) |
| | | for i in range(len(datas)): |
| | | if datas[i]["index"] == end_index: |
| | | datas = datas[:i] |
| | | break |
| | | |
| | | fdatas = export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes, deal_list_dict, sell_nos, |
| | | active_sell_set, cancel_reasons) |
| | | return fdatas |
| | |
| | | if trade_indexs[i][1] == index: |
| | | return trade_indexs[i] |
| | | return None |
| | | |
| | | # 最新的一条数据 |
| | | latest_data = datas[-1] |
| | | latest_time_str_with_ms = l2.l2_data_util.L2DataUtil.get_time_with_ms(latest_data["val"]) |
| | | |
| | | |
| | | # 数据预处理 |
| | | num_operate_map = {} |
| | |
| | | if int(data["val"]["operateType"]) == 0: |
| | | cancel_data = l2.l2_data_util.local_today_canceled_buyno_map.get(code).get(str(data["val"]["orderNo"])) |
| | | # 买 |
| | | if cancel_data: |
| | | if cancel_data and latest_data["index"] >= cancel_data["index"]: |
| | | # 如果撤单索引不能比最近数据索引还大 |
| | | try: |
| | | left_num = data["val"]["num"] - cancel_data["val"]["num"] |
| | | if left_num > 0: |
| | |
| | | else: |
| | | deal_info = deal_list_dict.get(str(data["val"].get("orderNo"))) |
| | | if deal_info and len(deal_info) >= 5: |
| | | cancel_info = l2_huaxin_util.convert_time(deal_info[4], |
| | | with_ms=True) |
| | | # 成交时间不能比当前索引时间大 |
| | | if tool.trade_time_sub_with_ms(cancel_info , latest_time_str_with_ms) <= 0: |
| | | cancel_info = l2_huaxin_util.convert_time(deal_info[4], |
| | | with_ms=True) |
| | | format_data.append(cancel_info) |
| | | cancel_order_info = None |
| | | if trade_info: |