From 5840eb38afbbc909bacc2996738b859ad29ddf22 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 31 七月 2023 14:24:44 +0800
Subject: [PATCH] bug修复

---
 l2/l2_data_manager_new.py |   72 ++++++++++++++++++++++++++++-------
 1 files changed, 57 insertions(+), 15 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index 11d079c..2165ee6 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -29,7 +29,6 @@
 
 from line_profiler import LineProfiler
 
-
 import dask
 
 from trade.trade_manager import TradeTargetCodeModeManager
@@ -244,15 +243,18 @@
                 logger_l2_process.info("code:{} 鑾峰彇鍒颁笅鍗曠湡瀹炰綅缃細{}", code, place_order_index)
                 DCancelBigNumComputer.set_real_order_index(code, place_order_index)
             __start_time = round(t.time() * 1000)
-
-            cls.process_add_datas(code, datas, 0, __start_time)
-            # lp = LineProfiler()
-            # lp_wrap = lp(cls.process_add_datas)
-            # lp_wrap(code, datas, 0, __start_time)
-            # output = io.StringIO()
-            # lp.print_stats(stream=output)
-            # with open(f"/home/logs/profile/{code}_{round(t.time() * 1000)}.txt",'w') as f:
-            #     f.write(output.getvalue())
+            if len(datas) > 0:
+                cls.process_add_datas(code, datas, 0, __start_time)
+            else:
+                lp = LineProfiler()
+                lp.enable()
+                lp_wrap = lp(cls.process_add_datas)
+                lp_wrap(code, datas, 0, __start_time)
+                output = io.StringIO()
+                lp.print_stats(stream=output)
+                lp.disable()
+                with open(f"/home/logs/profile/{code}_{datas[0]['index']}_{datas[-1]['index']}.txt", 'w') as f:
+                    f.write(output.getvalue())
             # lp.dump_stats(f"/home/logs/profile/{code}_{round(t.time() * 1000)}.txt")
         except Exception as e:
             print("huaxin L2鏁版嵁澶勭悊寮傚父", code, str(e))
@@ -268,7 +270,6 @@
     def process_add_datas(cls, code, add_datas, capture_timestamp, __start_time):
         now_time_str = tool.get_now_time_str()
         if len(add_datas) > 0:
-            print(id(local_today_datas))
             # 鎷兼帴鏁版嵁
             local_today_datas[code].extend(add_datas)
             l2.l2_data_util.load_num_operate_map(local_today_num_operate_map, code, add_datas)
@@ -298,7 +299,21 @@
             limit_up_time = limit_up_time_manager.get_limit_up_time(code)
             if limit_up_time is None:
                 limit_up_time = tool.get_now_time_str()
-            score = first_code_score_manager.get_score(code, volume_rate, limit_up_time, True)
+            score = None
+            if len(add_datas) < 10:
+                score = first_code_score_manager.get_score(code, volume_rate, limit_up_time, True)
+            else:
+                lp = LineProfiler()
+                lp.enable()
+                lp_wrap = lp(first_code_score_manager.get_score)
+                score = lp_wrap(code, volume_rate, limit_up_time, True)
+                output = io.StringIO()
+                lp.print_stats(stream=output)
+                lp.disable()
+                with open(
+                        f"/home/logs/profile/{code}_get_score_{add_datas[0]['index']}_{add_datas[-1]['index']}.txt",
+                        'w') as f:
+                    f.write(output.getvalue())
             cls.__l2PlaceOrderParamsManagerDict[code] = l2_trade_factor.L2PlaceOrderParamsManager(code, is_first_code,
                                                                                                   volume_rate,
                                                                                                   volume_rate_index,
@@ -319,11 +334,26 @@
                 end_index = len(total_datas) - 1
                 if state == trade_manager.TRADE_STATE_BUY_DELEGATED or state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or state == trade_manager.TRADE_STATE_BUY_SUCCESS:
                     # 宸叉寕鍗�
-                    cls.__process_order(code, start_index, end_index, capture_timestamp, is_first_code)
+                    if len(add_datas) < 10:
+                        cls.__process_order(code, start_index, end_index, capture_timestamp, is_first_code)
+                    else:
+                        lp = LineProfiler()
+                        lp.enable()
+                        lp_wrap = lp(cls.__process_order)
+                        lp_wrap(code, start_index, end_index, capture_timestamp, is_first_code)
+                        output = io.StringIO()
+                        lp.print_stats(stream=output)
+                        lp.disable()
+                        with open(
+                                f"/home/logs/profile/{code}_process_order_{add_datas[0]['index']}_{add_datas[-1]['index']}.txt",
+                                'w') as f:
+                            f.write(output.getvalue())
                 else:
                     # 鏈寕鍗�,鏃堕棿鐩稿樊涓嶅ぇ鎵嶈兘鎸傚崟
                     if l2.l2_data_util.L2DataUtil.is_same_time(now_time_str, latest_time):
+
                         cls.__process_not_order(code, start_index, end_index, capture_timestamp, is_first_code)
+
 
             logger_l2_process.info("code:{} 澶勭悊鏁版嵁鑼冨洿: {}-{} 澶勭悊鏃堕棿:{} 鎴浘鏃堕棿鎴筹細{}", code, add_datas[0]["index"],
                                    add_datas[-1]["index"], round(t.time() * 1000) - __start_time,
@@ -340,8 +370,20 @@
         if round(t.time() * 1000) - __start_time > 10:
             __start_time = l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time,
                                                "鑾峰彇m鍊兼暟鎹�楁椂")
-
-        cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time, is_first_code)
+        if end_index - start_index < 10:
+            cls.__start_compute_buy(code, start_index, end_index, threshold_money, capture_time, is_first_code)
+        else:
+            lp = LineProfiler()
+            lp.enable()
+            lp_wrap = lp(cls.__start_compute_buy)
+            lp_wrap(code, start_index, end_index, threshold_money, capture_time, is_first_code)
+            output = io.StringIO()
+            lp.print_stats(stream=output)
+            lp.disable()
+            with open(
+                    f"/home/logs/profile/{code}_start_compute_buy_{start_index}_{end_index}.txt",
+                    'w') as f:
+                f.write(output.getvalue())
 
     # 娴嬭瘯涓撶敤
     @classmethod

--
Gitblit v1.8.0