From 81f328532e366eef171b71810b221a9294dda78f Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 21 十二月 2023 14:31:58 +0800
Subject: [PATCH] 买入条件调整/L撤调整

---
 l2/cancel_buy_strategy.py |   91 +++++++++++++++++++++++++++------------------
 1 files changed, 55 insertions(+), 36 deletions(-)

diff --git a/l2/cancel_buy_strategy.py b/l2/cancel_buy_strategy.py
index f2c7814..c7f3ab8 100644
--- a/l2/cancel_buy_strategy.py
+++ b/l2/cancel_buy_strategy.py
@@ -35,6 +35,7 @@
     SecondCancelBigNumComputer().set_real_place_order_index(code, index)
     LCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index=buy_single_index)
     HourCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index)
+    GCancelBigNumComputer().set_real_place_order_index(code, index)
 
 
 class SecondCancelBigNumComputer:
@@ -686,7 +687,7 @@
                                                                                                              code))
                 cancel_num += val['num'] * (data['re'] - left_count)
             rate = round(cancel_num / total_num, 4)
-            must_buy_cancel_rate =  constant.H_CANCEL_RATE
+            must_buy_cancel_rate = constant.H_CANCEL_RATE
             try:
                 temp_rate = gpcode_manager.MustBuyCodesManager().get_cancel_rate_cache(code)
                 if temp_rate:
@@ -834,7 +835,7 @@
             if must_buy_cancel_rate is not None:
                 return must_buy_cancel_rate
         except Exception as e:
-            async_log_util.error(logger_l2_l_cancel,str(e))
+            async_log_util.error(logger_l2_l_cancel, str(e))
 
         base_rate = constant.L_CANCEL_RATE
         if is_up:
@@ -913,8 +914,6 @@
     __near_by_trade_progress_index_cache = {}
 
     __SecondCancelBigNumComputer = SecondCancelBigNumComputer()
-
-
 
     __last_l_up_compute_info = {}
 
@@ -1286,8 +1285,11 @@
         watch_indexes = set([int(i) for i in watch_indexes_info[2]])
         # 璁$畻鐩戝惉鐨勬�绘潯鏁�
         total_num = 0
+        max_num = 0
         for wi in watch_indexes:
             total_num += total_data[wi]["val"]["num"] * total_data[wi]["re"]
+            if total_data[wi]["val"]["num"] > max_num:
+                max_num = total_data[wi]["val"]["num"]
         # 鍒ゆ柇鎾ゅ崟涓槸鍚︽湁鐩戝惉涓殑绱㈠紩
         need_compute = False
         for i in range(start_index, end_index + 1):
@@ -1324,6 +1326,9 @@
 
             rate = round(canceled_num / total_num, 3)
             thresh_hold_rate = LCancelRateManager.get_cancel_rate(code)
+            # 闄ゅ紑鏈�澶у崟鐨勫奖鍝嶆潈閲�
+            temp_thresh_hold_rate = round((total_num - max_num)*0.9/total_num, 2)
+            thresh_hold_rate = min(thresh_hold_rate, temp_thresh_hold_rate)
             l2_log.l_cancel_debug(code, f"璁$畻鑼冨洿锛歿start_index}-{end_index},宸叉挙鍗曟瘮渚嬶細{rate}/{thresh_hold_rate}")
             if rate >= thresh_hold_rate:
                 canceled_indexes.sort()
@@ -1452,7 +1457,7 @@
 
     def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code):
         if buy_exec_index is None:
-            return False, "灏氭湭鎵惧埌涓嬪崟浣嶇疆", ""
+            return False, None, "灏氭湭鎵惧埌涓嬪崟浣嶇疆"
         # 瀹堟姢S鎾や互澶栫殑鏁版嵁
         if int(tool.get_now_time_str().replace(":", "")) > int("145700") and not constant.TEST:
             return False, None, ""
@@ -1666,38 +1671,52 @@
 
 # ---------------------------------G鎾�-------------------------------
 class GCancelBigNumComputer:
-    __SecondCancelBigNumComputer = SecondCancelBigNumComputer()
+    __real_place_order_index_dict = {}
+    __instance = None
 
-    # 寮�濮嬫挙鍗�
-    def start_cancel(self, code, buy_no, total_datas, m_val_num):
-        # TODO 鏆傛椂娉ㄩ噴鎺塆鎾�
-        return False, "鏆傛椂涓嶆墽琛孏鎾�"
-        thresh_num = int(m_val_num * 1)
-        place_order_index = self.__SecondCancelBigNumComputer.get_real_place_order_index_cache(code)
-        if place_order_index is None:
-            raise Exception("鏈幏鍙栧埌涓嬪崟鐪熷疄浣嶇疆")
-        buy_data = buy_order_no_map.get(buy_no)
-        if not buy_data:
-            raise Exception(f"灏氭湭鑾峰彇鍒版挙涔板崟璇︽儏鏁版嵁: order_no:{buy_no} map鏁伴噺锛歿len(buy_order_no_map)}")
-        # 浠庢垚浜や綅缃埌涓嬪崟浣嶇疆璁$畻m鍊�
-        transaction_index = buy_data["index"]
-        need_cancel = True
-        buy_nums = 0
-        for index in range(transaction_index + 1, place_order_index):
-            data = total_datas[index]
-            if L2DataUtil.is_limit_up_price_buy(data["val"]):
-                # 鑾峰彇鏄惁鍦ㄤ拱鍏ユ墽琛屼俊鍙峰懆鍥�2s
-                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, index,
-                                                                                                         total_datas,
-                                                                                                         local_today_canceled_buyno_map.get(
-                                                                                                             code))
-                if left_count > 0:
-                    buy_nums += left_count * data["val"]["num"]
-                    if buy_nums > thresh_num:
-                        break
-        if buy_nums > thresh_num:
-            need_cancel = False
-        return need_cancel, f"鎴愪氦杩涘害浣�({transaction_index})-鐪熷疄涓嬪崟浣�({place_order_index})  绾拱鎵嬫暟:{buy_nums}/1.8鍊峬鍊兼墜鏁�:{thresh_num}"
+    def __new__(cls, *args, **kwargs):
+        if not cls.__instance:
+            cls.__instance = super(GCancelBigNumComputer, cls).__new__(cls, *args, **kwargs)
+        return cls.__instance
+
+    def set_real_place_order_index(self, code, index):
+        self.__real_place_order_index_dict[code] = index
+
+    def clear(self, code=None):
+        if code:
+            if code in self.__real_place_order_index_dict:
+                self.__real_place_order_index_dict.pop(code)
+        else:
+            self.__real_place_order_index_dict.clear()
+
+    def need_cancel(self, code, buy_exec_index, start_index, end_index):
+        if code not in self.__real_place_order_index_dict:
+            return False, None, "娌℃湁鎵惧埌鐪熷疄涓嬪崟浣�"
+        real_place_order_index = self.__real_place_order_index_dict.get(code)
+        total_datas = local_today_datas.get(code)
+        # 30s鍐呮湁鏁�
+        if tool.trade_time_sub(total_datas[end_index]["val"]["time"], total_datas[buy_exec_index]["val"]["time"]) > 30:
+            return False, None, "涓嬪崟30s鍐呮墠鐢熸晥"
+
+        for i in range(start_index, end_index + 1):
+            data = total_datas[i]
+            val = data["val"]
+            if not L2DataUtil.is_limit_up_price_buy_cancel(val):
+                continue
+            if val["num"] * float(val["price"]) < 30000:
+                continue
+            buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(data,
+                                                                                                local_today_buyno_map.get(
+                                                                                                    code))
+            if buy_index is not None and buy_index < real_place_order_index:
+                return True, data, ""
+        return False, None, ""
+
+    def place_order_success(self, code):
+        self.clear(code)
+
+    def cancel_success(self, code):
+        self.clear(code)
 
 
 # ---------------------------------鐙嫍鎾�-------------------------------

--
Gitblit v1.8.0