From 5ed30c03ddfedd4cf79cd8fea9fc45b05821d898 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 16 十月 2023 12:44:07 +0800
Subject: [PATCH] 真实下单位置计算方法修改

---
 third_data/data_server.py                    |   18 ++++----
 l2/huaxin/huaxin_delegate_postion_manager.py |   71 +++++++++++++++++++++++++----------
 test/l2_trade_test.py                        |    2 
 l2/l2_data_manager_new.py                    |    4 +
 4 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/l2/huaxin/huaxin_delegate_postion_manager.py b/l2/huaxin/huaxin_delegate_postion_manager.py
index 31fa507..deb69d6 100644
--- a/l2/huaxin/huaxin_delegate_postion_manager.py
+++ b/l2/huaxin/huaxin_delegate_postion_manager.py
@@ -3,9 +3,12 @@
 """
 import time
 
+from huaxin_client import constant as huaxin_client_constant
+from l2 import l2_data_util
 from l2.l2_data_util import L2DataUtil
 from log_module import async_log_util
 from log_module.log import hx_logger_trade_debug, logger_real_place_order_position
+from utils import tool
 
 _place_order_info_dict = {}
 
@@ -31,7 +34,7 @@
 
 
 # L2鏁版嵁鍒楄〃
-def get_l2_place_order_position(code, datas):
+def get_l2_place_order_position(code, limit_up_price, datas):
     order_info = get_order_info(code)
     if not order_info:
         # 鏆傛棤涓嬪崟淇℃伅
@@ -44,33 +47,61 @@
     is_sz = code.startswith("00")
     # 鎻愪氦鍒颁氦鏄撴墍鐨勬椂闂撮浼�
     min_space_time_ms = -1 if is_sz else 50
+
+    shadow_place_order_index = None
+    # 鏌ユ壘褰卞瓙鎸傚崟
     for d in datas:
+        val = d['val']
+        # 鍒ゆ柇褰卞瓙璁㈠崟浣嶇疆
+        if val["num"] != huaxin_client_constant.SHADOW_ORDER_VOLUME // 100:
+            continue
+        if abs(tool.get_buy_min_price(limit_up_price) - float(val["price"])) >= 0.01:
+            continue
+        if d["index"] <= exec_data["index"]:
+            continue
+        if L2DataUtil.time_sub_as_ms(val, exec_data['val']) >= 1000:
+            continue
+        shadow_place_order_index = d["index"]
+        break
+    if shadow_place_order_index is None:
+        return None
+    total_datas = l2_data_util.local_today_datas.get(code)
+    start_index = max(shadow_place_order_index - 10, 0)
+    end_index = min(shadow_place_order_index + 10, datas[-1]["index"])
+    real_place_index = None
+    # 浠庝腑闂村悜涓ゅご閬嶅巻
+    for i in range(shadow_place_order_index - 1, start_index, -1):
+        d = total_datas[i]
         if d["val"]["num"] != volume // 100:
             continue
         if abs(float(price) - float(d["val"]["price"])) >= 0.01:
             continue
-
         # 蹇呴』鏄拱鍏�
         if not L2DataUtil.is_limit_up_price_buy(d["val"]):
             continue
-
-        # 涓嶅彲鑳芥瘮涓嬪崟鎵ц浣嶇疆杩樻棭
-        if d["index"] <= exec_data["index"]:
-            continue
-        # 鏃堕棿宸笉鑳藉皬浜庨浼颁笅鍗曠敤鏃�
-        if L2DataUtil.time_sub_as_ms(d['val'], exec_data['val']) <= min_space_time_ms:
-            continue
-        # 鐪熷疄涓嬪崟浣嶇疆涓庢寕鍗曚綅缃笉鑳界浉宸�1s
-        if L2DataUtil.time_sub_as_ms(d["val"], exec_data['val']) >= 1000:
-            continue
-        # 鑾峰彇鍒颁簡涓嬪崟浣嶇疆
-        async_log_util.info(hx_logger_trade_debug, f"鐪熷疄涓嬪崟浣嶇疆锛歿code}-{d['index']}")
-        async_log_util.info(logger_real_place_order_position, f"鐪熷疄涓嬪崟浣嶇疆锛歿code}-{d['index']}")
-        if code in _place_order_info_dict:
-            _place_order_info_dict.pop(code)
-        __place_order_position[code] = d['index']
-        return d["index"]
-    return None
+        real_place_index = i
+        break
+    if not real_place_index:
+        for i in range(shadow_place_order_index + 1, end_index):
+            d = total_datas[i]
+            if d["val"]["num"] != volume // 100:
+                continue
+            if abs(float(price) - float(d["val"]["price"])) >= 0.01:
+                continue
+            # 蹇呴』鏄拱鍏�
+            if not L2DataUtil.is_limit_up_price_buy(d["val"]):
+                continue
+            real_place_index = i
+            break
+    if not real_place_index:
+        real_place_index = shadow_place_order_index
+    # 鑾峰彇鍒颁簡涓嬪崟浣嶇疆
+    async_log_util.info(hx_logger_trade_debug, f"鐪熷疄涓嬪崟浣嶇疆锛歿code}-{real_place_index}")
+    async_log_util.info(logger_real_place_order_position, f"鐪熷疄涓嬪崟浣嶇疆锛歿code}-{real_place_index}")
+    if code in _place_order_info_dict:
+        _place_order_info_dict.pop(code)
+    __place_order_position[code] = real_place_index
+    return real_place_index
 
 
 # 鑾峰彇鐪熷疄涓嬪崟浣嶇疆
diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index e263301..a9a6755 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -337,7 +337,8 @@
             if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN:
                 try:
                     # 鑾峰彇涓嬪崟浣嶇疆
-                    place_order_index = huaxin_delegate_postion_manager.get_l2_place_order_position(code, add_datas)
+                    place_order_index = huaxin_delegate_postion_manager.get_l2_place_order_position(code, float(
+                        gpcode_manager.get_limit_up_price(code)), add_datas)
                     if place_order_index:
                         buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos(
                             code)
@@ -1304,6 +1305,7 @@
     except:
         pass
 
+
 if __name__ == "__main__":
     test_trade_record()
     # yesterday_limit_up_data_records = kpl_data_manager.get_current_limit_up_data_records(1)[0][1]
diff --git a/test/l2_trade_test.py b/test/l2_trade_test.py
index dd6428a..a647b9f 100644
--- a/test/l2_trade_test.py
+++ b/test/l2_trade_test.py
@@ -176,7 +176,7 @@
         l2.l2_data_util.load_l2_data(code)
         total_datas = deepcopy(l2.l2_data_util.local_today_datas[code])
         huaxin_delegate_postion_manager.place_order(code, 17.36, 100, total_datas[753])
-        huaxin_delegate_postion_manager.get_l2_place_order_position(code,total_datas[755:1038])
+        huaxin_delegate_postion_manager.get_l2_place_order_position(code, total_datas[755:1038])
 
     @unittest.skip("璺宠繃姝ゅ崟鍏冩祴璇�")
     def test_h_cancel(self):
diff --git a/third_data/data_server.py b/third_data/data_server.py
index c8189f9..7d52171 100644
--- a/third_data/data_server.py
+++ b/third_data/data_server.py
@@ -532,15 +532,15 @@
                                             current_limit_up_datas = []
                                         if not limit_up_record_datas:
                                             limit_up_record_datas = []
-                                        if CodePlateKeyBuyManager.is_need_cancel(code, limit_up_reasons.get(code),
-                                                                                 current_limit_up_datas,
-                                                                                 limit_up_record_datas,
-                                                                                 yesterday_current_limit_up_codes,
-                                                                                 before_blocks_dict):
-                                            # TODO 娴嬭瘯鏆傛椂娉ㄩ噴
-                                            l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code,
-                                                                                                f"娑ㄥ仠鍘熷洜锛坽limit_up_reasons.get(code)}锛変笉鏄�佸ぇ鎾ゅ崟",
-                                                                                                "鏉垮潡鎾�")
+                                        # TODO 娴嬭瘯鏆傛椂娉ㄩ噴
+                                        # if CodePlateKeyBuyManager.is_need_cancel(code, limit_up_reasons.get(code),
+                                        #                                          current_limit_up_datas,
+                                        #                                          limit_up_record_datas,
+                                        #                                          yesterday_current_limit_up_codes,
+                                        #                                          before_blocks_dict):
+                                        #     l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code,
+                                        #                                                         f"娑ㄥ仠鍘熷洜锛坽limit_up_reasons.get(code)}锛変笉鏄�佸ぇ鎾ゅ崟",
+                                        #                                                         "鏉垮潡鎾�")
                             except Exception as e:
                                 logger_debug.exception(e)
                 kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(), result_list_)

--
Gitblit v1.8.0