From cbe19ea6066a600cbd0b5110db5d43f8252d14a8 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 13 六月 2024 11:23:53 +0800
Subject: [PATCH] L撤成交进度相关改进

---
 utils/data_export_util.py |   60 ++++++++++++++++++++----------------------------------------
 1 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/utils/data_export_util.py b/utils/data_export_util.py
index fdb347b..146f6ce 100644
--- a/utils/data_export_util.py
+++ b/utils/data_export_util.py
@@ -14,8 +14,12 @@
 from l2.huaxin import l2_huaxin_util
 from log_module import log, log_export
 from l2 import l2_data_source_util
+from log_module.log import logger_debug
 from trade import deal_big_money_manager
 from utils import tool
+
+# 缂撳瓨L2鏁版嵁锛屾牸寮忥細{"鏃ユ湡":{鏁版嵁}}
+__l2_data_cache = {}
 
 
 def export_l2_excel(code, date=None):
@@ -26,11 +30,16 @@
 
 # 鑾峰彇L2鐨勬暟鎹�
 def get_l2_datas(code, today_datas=None, date=None, max_time=None):
+    __start_time = time.time()
     if date is None:
         date = tool.get_now_date_str()
     datas = today_datas
     if datas is None:
-        local_today_datas = log_export.load_l2_from_log(date)
+        if date in __l2_data_cache:
+            local_today_datas = __l2_data_cache.get(date)
+        else:
+            local_today_datas = log_export.load_l2_from_log(date)
+            __l2_data_cache[date] = local_today_datas
         datas = local_today_datas.get(code)
     if not datas:
         datas = []
@@ -75,7 +84,6 @@
             if trade_indexs[i][1] == index:
                 return trade_indexs[i]
         return None
-
     # 鏁版嵁棰勫鐞�
     num_operate_map = {}
     l2.l2_data_util.load_num_operate_map(num_operate_map, code, datas)
@@ -83,19 +91,23 @@
     sell_no_map = {}
     l2.l2_data_util.load_buy_no_map(buy_no_map, code, datas)
     l2.l2_data_util.load_sell_no_map(sell_no_map, code, datas)
-
     l2.l2_data_util.load_canceled_buy_no_map(l2.l2_data_util.local_today_canceled_buyno_map, code, datas)
-
     # num_dict = {}
     # for data in datas:
     #     if data["val"]["num"] not in num_dict:
     #         num_dict[data["val"]["num"]] = []
     #     num_dict[data["val"]["num"]].append(data)
-
+    logger_debug.info(f"寰幆缁勮鏁版嵁寮�濮嬶細闀垮害-{len(datas)} 涓诲姩鍗栭暱搴�-{len(active_sell_nos)}")
     index = 0
     fdatas = []
+    # 鏁版嵁澶灏遍渶瑕佽繃婊ゆ帀灏忛噾棰�
+    is_data_too_large = len(datas) > 20000
     for data in datas:
         index += 1
+        if is_data_too_large and data['val']['num'] * float(data['val']['price']) < 5000:
+            if data["index"] not in real_position_indexes:
+                continue
+
         # 鍏堢Щ闄�
         if data['val']['orderNo'] in active_sell_nos:
             # 杩囨护涓诲姩鍗�
@@ -190,8 +202,8 @@
                     logging.exception(e)
             else:
                 deal_info = deal_list_dict.get(str(data["val"].get("orderNo")))
-                if deal_info:
-                    cancel_info = l2_huaxin_util.convert_time(deal_info[3],
+                if deal_info and len(deal_info) >= 5:
+                    cancel_info = l2_huaxin_util.convert_time(deal_info[4],
                                                               with_ms=True)
         format_data.append(cancel_info)
         cancel_order_info = None
@@ -208,39 +220,7 @@
         format_data.append(cancel_order_info)
         format_data.append(data["val"].get("orderNo"))
         fdatas.append((style_int, trade_info, format_data))
-
-    # 灏嗚鍗曞彿绱㈠紩
-    order_no_index_map = {}
-    for i in range(len(fdatas)):
-        d = fdatas[i][2]
-        if d[6].find('鎾�') >= 0:
-            continue
-        order_no_index_map[int(d[10])] = i
-    order_no_indexes = [(k, order_no_index_map[k]) for k in order_no_index_map]
-    order_no_indexes.sort(key=lambda x: x[0])
-    # 涓嶆坊鍔犱富鍔ㄥ崠鏁版嵁
-    # if sell_nos:
-    #     for sell_info in sell_nos:
-    #         if sell_info[1] * sell_info[2] < 50 * 10000:
-    #             continue
-    #         for i in range(len(order_no_indexes) - 1):
-    #             if order_no_indexes[i][0] < sell_info[0] < order_no_indexes[i + 1][0]:
-    #                 item = []
-    #                 item.append(order_no_indexes[i + 1][1])
-    #                 item.append(l2_huaxin_util.convert_time(sell_info[3][0], with_ms=True))
-    #                 item.append("")
-    #                 item.append(
-    #                     "{}涓�".format(round(sell_info[1] * sell_info[2] / 10000, 1)))
-    #                 item.append(sell_info[2])
-    #                 item.append(sell_info[1] // 100)
-    #                 item.append("涓诲姩鍗�")
-    #                 item.append(1)
-    #                 item.append(l2_huaxin_util.convert_time(sell_info[4][0], with_ms=True))
-    #                 item.append(None)
-    #                 item.append(sell_info[0])
-    #                 fdatas.insert(order_no_indexes[i + 1][1], (0, None, item))
-    #                 break
-
+    logger_debug.info("寰幆缁勮鏁版嵁瀹屾垚")
     return fdatas
 
 

--
Gitblit v1.8.0