From 545d65a4febc85d628aedf1547d6f9efebce34fd Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期二, 23 四月 2024 17:20:01 +0800
Subject: [PATCH] 板上放小量不下单,加红撤单比例调整

---
 constant.py               |   23 ++++++-----
 l2/cancel_buy_strategy.py |   55 +++++++++++++--------------
 l2/l2_data_manager_new.py |   37 +++++++-----------
 3 files changed, 54 insertions(+), 61 deletions(-)

diff --git a/constant.py b/constant.py
index 2b44ce3..5737b1a 100644
--- a/constant.py
+++ b/constant.py
@@ -72,15 +72,13 @@
 
 CACHE_PATH = f"{'D:' if is_windows() else '/home/userzjj'}/trade_cache"
 
-# S鎾ゆ瘮渚�
-S_CANCEL_MIN_MONEY = 98
-S_CANCEL_SECOND_RATE = 0.59
-S_CANCEL_THIRD_RATE = 0.49
-# s鎾ゅ畧鎶ゆ椂闂�
-S_CANCEL_EXPIRE_TIME = 1
+# S鎾�
+F_FAST_RATE = 0.25  # S蹇牳
+F_FAST_RATE_WITH_MUST_BUY = 0.5  # S蹇牳鍔犵孩
 
 # H鎾ゆ瘮渚�
-H_CANCEL_RATE = 0.80
+H_CANCEL_RATE = 0.80  # H鎾ゆ瘮渚�
+H_CANCEL_RATE_WITH_MUST_BUY = 0.95  # 鍔犵孩H鎾ゆ瘮渚�
 # L鎾ゆ棤娉曠敓鏁堢殑鎾ゅ崟姣斾緥
 H_CANCEL_RATE_WITH_LDOWN_CANT_INVALID = 0.69
 H_CANCEL_MIN_MONEY = 98
@@ -125,9 +123,15 @@
 
 L_CANCEL_MIN_WATCH_COUNT = 10
 # 鎾ゅ崟姣斾緥
-L_CANCEL_RATE = 0.6
+L_CANCEL_RATE = 0.6  # L鍚�
+
+L_CANCEL_RATE_WITH_MUST_BUY = 0.9  # 鍔犵孩L鍚�
+
 # L涓婃挙鍗曟瘮渚�
-L_CANCEL_RATE_UP = 0.79
+L_CANCEL_RATE_UP = 0.79  # L鍓�
+
+L_CANCEL_RATE_UP_WITH_MUST_BUY = 0.95  # 鍔犵孩L鍓�
+
 # 澶ч噾棰�
 L_CANCEL_BIG_MONEY = 100
 # 灏忛噾棰�
@@ -175,4 +179,3 @@
 
 # L2鏁版嵁鏄惁杞藉叆瀹屾垚
 L2_DATA_IS_LOADED = False
-
diff --git a/l2/cancel_buy_strategy.py b/l2/cancel_buy_strategy.py
index 098f967..7dadcc1 100644
--- a/l2/cancel_buy_strategy.py
+++ b/l2/cancel_buy_strategy.py
@@ -243,7 +243,8 @@
                 if val['orderNo'] == watch_info[1]:
                     total_num -= watch_info[2]
         min_index = min(watch_info[0])
-        sell_orders = HuaXinSellOrderStatisticManager.get_latest_transaction_datas(code, total_datas[real_place_order_info[0]]['val'][
+        sell_orders = HuaXinSellOrderStatisticManager.get_latest_transaction_datas(code, total_datas[
+            real_place_order_info[0]]['val'][
             'orderNo'])
         sell_order_num = sum([x[1] for x in sell_orders]) // 100
         rate = round(sell_order_num / total_num, 2)
@@ -361,7 +362,11 @@
             # 闃叉鍒嗘瘝涓�0
             total_fast_money = 1
         rate = round(total_deal_money / total_fast_money, 2)
-        if total_deal_money >= threash_money_w * 10000 and rate >= 0.25:
+        threshold_rate = constant.F_FAST_RATE
+        if gpcode_manager.MustBuyCodesManager().is_in_cache(code):
+            threshold_rate = constant.F_FAST_RATE_WITH_MUST_BUY
+
+        if total_deal_money >= threash_money_w * 10000 and rate >= threshold_rate:
             return True, f"杩�1s鏈夊ぇ鍗栧崟({round(total_deal_money / 10000, 1)}涓�/{threash_money_w}涓囷紝鎴愪氦鍗犳瘮锛歿total_deal_money}/{total_fast_money})"
         else:
             l2_log.s_cancel_debug(code,
@@ -566,7 +571,8 @@
         total_datas = local_today_datas.get(code)
 
         # h鎾よ绠楀繀椤昏秴杩�3鍒嗛挓
-        if tool.trade_time_sub(total_datas[-1]["val"]["time"], total_datas[real_place_order_index]["val"]["time"]) < 180:
+        if tool.trade_time_sub(total_datas[-1]["val"]["time"],
+                               total_datas[real_place_order_index]["val"]["time"]) < 180:
             l2_log.h_cancel_debug(code, "180s鍐呭泭鎷绠桯鎾�")
             return
         # -----------------璁$畻H涓�-------------------
@@ -598,7 +604,7 @@
         # 鑾峰彇m鍊兼暟鎹�
         thresh_hold_money = Buy1PriceManager().get_latest_buy1_money(code)
         # 灏佸崟棰濈殑1/10
-        thresh_hold_money = thresh_hold_money/10
+        thresh_hold_money = thresh_hold_money / 10
         thresh_hold_num = thresh_hold_money // (float(limit_up_price) * 100)
         end_index = real_place_order_index + 1
         watch_indexes = set()
@@ -776,14 +782,14 @@
                                                                                                              code))
                 cancel_num += val['num'] * (data['re'] - left_count)
             rate = round(cancel_num / total_num, 4)
-            must_buy_cancel_rate = constant.H_CANCEL_RATE_WITH_LDOWN_CANT_INVALID if code in self.__l_cancel_triggered_codes else constant.H_CANCEL_RATE
+            threshold_rate = constant.H_CANCEL_RATE_WITH_LDOWN_CANT_INVALID if code in self.__l_cancel_triggered_codes else constant.H_CANCEL_RATE
             try:
-                temp_rate = gpcode_manager.MustBuyCodesManager().get_cancel_rate_cache(code)
-                if temp_rate:
-                    must_buy_cancel_rate = temp_rate
+                must_buy = gpcode_manager.MustBuyCodesManager().is_in_cache(code)
+                if must_buy:
+                    threshold_rate = constant.H_CANCEL_RATE_WITH_MUST_BUY
             except Exception as e:
                 async_log_util.error(logger_l2_h_cancel, str(e))
-            if rate >= must_buy_cancel_rate:
+            if rate >= threshold_rate:
                 l2_log.h_cancel_debug(code, f"鎾ゅ崟姣斾緥锛歿rate}")
                 return True, total_data[-1]
         return False, None
@@ -867,9 +873,12 @@
     @classmethod
     def get_cancel_rate(cls, code, buy_exec_time, is_up=False, is_l_down_recomputed=False):
         try:
-            must_buy_cancel_rate = cls.__MustBuyCodesManager.get_cancel_rate_cache(code)
-            if must_buy_cancel_rate is not None:
-                return must_buy_cancel_rate, True
+            must_buy = cls.__MustBuyCodesManager.is_in_cache(code)
+            if must_buy:
+                if is_up:
+                    return constant.L_CANCEL_RATE_UP_WITH_MUST_BUY, True
+                else:
+                    return constant.L_CANCEL_RATE_WITH_MUST_BUY, True
         except Exception as e:
             async_log_util.error(logger_l2_l_cancel, str(e))
 
@@ -888,12 +897,7 @@
 
             deal_rate = 0
             if code in cls.__big_num_deal_rate_dict:
-                deal_rate =round( cls.__big_num_deal_rate_dict[code]/100)
-            #     if temp_rate >= 1:
-            #         if temp_rate > 3:
-            #             temp_rate = 3
-            #         deal_rate = round((temp_rate * 3.5 - 2.5) / 100, 4) if is_up else round(
-            #             (temp_rate * 5.25 - 3.75) / 100, 4)
+                deal_rate = round(cls.__big_num_deal_rate_dict[code] / 100)
 
             base_rate += block_rate
             base_rate += deal_rate
@@ -919,17 +923,16 @@
 
     @classmethod
     def set_big_num_deal_info(cls, code, buy_money, sell_money):
-        left_money_w = (buy_money-sell_money)//10000
+        left_money_w = (buy_money - sell_money) // 10000
         if left_money_w > 0:
-            rate = ((left_money_w+300)//900)*2
+            rate = ((left_money_w + 300) // 900) * 2
         else:
             rate = ((left_money_w + 599) // 900) * 2
-        if rate <-10:
+        if rate < -10:
             rate = -10
         if rate > 10:
             rate = 10
         cls.__big_num_deal_rate_dict[code] = rate
-
 
     @classmethod
     def compute_big_num_deal_info(cls, code):
@@ -2046,7 +2049,7 @@
             self.__commpute_watch_indexes(code, index, self.__real_place_order_index_dict.get(code))
 
     def need_cancel(self, code, buy_exec_index, start_index, end_index):
-        if 1>0:
+        if 1 > 0:
             return False, None, "G鎾よ娉ㄩ噴鎺�"
 
         if code not in self.__real_place_order_index_dict:
@@ -2548,12 +2551,6 @@
             if start_index <= i <= end_index:
                 # 濡傛灉鏄噺灏忛」
                 if val < 0:
-                    # 褰撳墠閲忓皬浜庢渶澶ч噺鐨�24%鍒欓渶瑕佸彇娑�
-                    if exec_time_offset >= constant.S_CANCEL_EXPIRE_TIME:
-                        if total_num <= min_volumn_big and max_buy1_volume * 0.24 > total_num:
-                            cancel_index = i
-                            cancel_msg = "灏佹澘棰濆皬浜庢渶楂樺皝鏉块鐨�24% {}/{}".format(total_num, max_buy1_volume)
-                            break
                     # 绱灏佸崟閲戦灏忎簬1000涓�
                     if total_num < min_volumn:
                         # 涓庢墽琛屼綅鐩搁殧>=5s鏃惰鍒欑敓鏁�
diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index e6274b5..023fe07 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -942,28 +942,21 @@
             trade_price = current_price_process_manager.get_trade_price(code)
             if trade_price is None:
                 return False, True, f"灏氭湭鑾峰彇鍒板綋鍓嶆垚浜や环"
-            if False and float(limit_up_price) - float(trade_price) > 0.00001:
-                # 璁$畻淇″彿璧峰浣嶇疆鍒板綋鍓嶇殑鎵嬫暟
-                order_begin_pos = cls.__get_order_begin_pos(
-                    code)
-                num_operate_map = local_today_num_operate_map.get(code)
-                total_num = 0
-                for i in range(order_begin_pos.buy_single_index, total_data[-1]["index"] + 1):
-                    data = total_data[i]
-                    val = data["val"]
-                    if not L2DataUtil.is_limit_up_price_buy(val):
-                        continue
-                    left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
-                                                                                                             data[
-                                                                                                                 "index"],
-                                                                                                             total_data,
-                                                                                                             local_today_canceled_buyno_map.get(
-                                                                                                                 code))
-                    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)
-                if total_num < thresh_hold_num * 2:
-                    return False, False, f"褰撳墠鎴愪氦浠凤紙{trade_price}锛夊皻鏈湪0妗e強浠ュ唴 涓� 绾拱棰�({total_num})灏忎簬2鍊峂鍊�({thresh_hold_num * 2})"
+            # 鍒ゆ柇鏄惁涓烘澘涓婃斁閲忥細
+            # 1.褰撳墠鎴愪氦浠蜂负娑ㄥ仠浠�
+            # 2.鎬诲崠棰濅负0
+            if abs(float(limit_up_price) - float(trade_price)) < 0.001:
+                sell_data = cls.__L2MarketSellManager.get_current_total_sell_data(code)
+                if sell_data and sell_data[1]<=0:
+                    # 鏉夸笂鏀鹃噺锛屽垽鏂槸鍚︽湁鏀鹃噺锛屾斁閲忔墠浼氫笅鍗�
+                    # 鑾峰彇鏈�杩�1s鐨勪富鍔ㄥ崠閲戦
+                    min_time =  total_data[order_begin_pos.buy_single_index]['val']['time']
+                    min_time = tool.trade_time_add_second(min_time, -1)
+                    sell_orders = HuaXinSellOrderStatisticManager.get_latest_transaction_datas(code, min_deal_time=min_time)
+                    sell_order_num = sum([x[1] for x in sell_orders])
+                    sell_money = int(float(limit_up_price) * sell_order_num)
+                    if sell_money < 2990000:
+                        return False, False, f"鏉夸笂鏀鹃噺閲戦涓嶈冻锛岃繎1s鎬诲崠锛歿sell_money}灏忎簬299w"
             # 鍒ゆ柇鎴愪氦杩涘害鏄惁璺濈鎴戜滑鐨勪綅缃緢杩�
             trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code)
             if False and not is_default and trade_index:

--
Gitblit v1.8.0