From f5b416d9cb5214ff0e46ca6305098085d2fe8742 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期三, 27 九月 2023 18:02:11 +0800
Subject: [PATCH] L2与交易之间的通信采用队列方式/实现L撤单比例动态计算

---
 l2/l2_data_manager_new.py |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index 0bf1a28..788e81f 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -213,7 +213,7 @@
     __last_buy_single_dict = {}
     __TradeBuyQueue = transaction_progress.TradeBuyQueue()
     __latest_process_order_unique_keys = {}
-    __latest_process_not_order_unique_keys = {}
+    __latest_process_not_order_unique_keys_count = {}
     # 鍒濆鍖�
     __TradePointManager = l2_data_manager.TradePointManager()
     __SecondCancelBigNumComputer = SecondCancelBigNumComputer()
@@ -762,7 +762,8 @@
                 return False, True, f"灏氭湭鑾峰彇鍒板綋鍓嶆垚浜や环"
             if float(limit_up_price) - float(trade_price) > 0.00001:
                 # 璁$畻淇″彿璧峰浣嶇疆鍒板綋鍓嶇殑鎵嬫暟
-                buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos(code)
+                buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos(
+                    code)
                 num_operate_map = local_today_num_operate_map.get(code)
                 total_num = 0
                 for i in range(buy_single_index, total_data[-1]["index"] + 1):
@@ -776,9 +777,9 @@
                                                                                                           num_operate_map)
                     total_num += left_count * val["num"]
                 m_base_val = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
-                thresh_hold_num = m_base_val//(float(gpcode_manager.get_limit_up_price(code))*100)
+                thresh_hold_num = m_base_val // (float(gpcode_manager.get_limit_up_price(code)) * 100)
                 if total_num < thresh_hold_num * 2:
-                    return False, False, f"褰撳墠鎴愪氦浠凤紙{trade_price}锛夊皻鏈湪0妗e強浠ュ唴 涓� 绾拱棰�({total_num})灏忎簬2鍊峂鍊�({thresh_hold_num*2})"
+                    return False, False, f"褰撳墠鎴愪氦浠凤紙{trade_price}锛夊皻鏈湪0妗e強浠ュ唴 涓� 绾拱棰�({total_num})灏忎簬2鍊峂鍊�({thresh_hold_num * 2})"
             # 鍒ゆ柇鎴愪氦杩涘害鏄惁璺濈鎴戜滑鐨勪綅缃緢杩�
             trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code)
             if False and not is_default and trade_index:
@@ -946,12 +947,14 @@
         if compute_end_index < compute_start_index:
             return
 
-        unique_key = f"{compute_start_index}-{compute_end_index}"
-        if cls.__latest_process_not_order_unique_keys.get(code) == unique_key:
+        unique_key = f"{code}-{compute_start_index}-{compute_end_index}"
+        if cls.__latest_process_not_order_unique_keys_count.get(unique_key) and cls.__latest_process_not_order_unique_keys_count.get(unique_key) > 2:
             async_log_util.error(logger_l2_error,
                                  f"閲嶅澶勭悊鏁版嵁锛歝ode-{code} start_index-{compute_start_index} end_index-{compute_end_index}")
             return
-        cls.__latest_process_not_order_unique_keys[code] = unique_key
+        if unique_key not in cls.__latest_process_not_order_unique_keys_count:
+            cls.__latest_process_not_order_unique_keys_count[unique_key] = 0
+        cls.__latest_process_not_order_unique_keys_count[unique_key] += 1
 
         _start_time = tool.get_now_timestamp()
         total_datas = local_today_datas[code]
@@ -972,7 +975,8 @@
             if cls.__last_buy_single_dict.get(code) == _index:
                 has_single = None
                 _index = None
-
+            if _index == 106:
+                print("杩涘叆璋冭瘯")
             buy_single_index = _index
             if has_single:
                 cls.__last_buy_single_dict[code] = buy_single_index
@@ -1069,6 +1073,7 @@
     # compute_data_count 鐢ㄤ簬璁$畻鐨刲2鏁版嵁鏁伴噺
     @classmethod
     def __compute_order_begin_pos(cls, code, start_index, continue_count, end_index):
+
         second_930 = 9 * 3600 + 30 * 60 + 0
         # 鍊掓暟100鏉℃暟鎹煡璇�
         datas = local_today_datas[code]
@@ -1093,7 +1098,9 @@
                     continue
 
             if L2DataUtil.is_limit_up_price_buy(_val):
-
+                # 瀵绘壘鍓嶉潰continue_count-1涓定鍋滀拱
+                # for j in range(start_index - 1, -1, -1):
+                #     if  datas[j]["val"]
                 if last_index is None or (datas[last_index]["val"]["time"] == datas[i]["val"]["time"]):
                     if start is None:
                         start = i

--
Gitblit v1.8.0