From df4cee929486a993868a15c13cd67e56b861907b Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 02 二月 2024 10:57:01 +0800
Subject: [PATCH] 修改G撤无大单情况/仓位不足主动撤单比例修改

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

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index f437e18..3c597a5 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -298,7 +298,7 @@
     def set_real_place_order_index(cls, code, index, order_begin_pos: OrderBeginPosInfo):
         trade_record_log_util.add_real_place_order_position_log(code, index, order_begin_pos.buy_single_index)
         l2_log.debug(code, "璁剧疆鐪熷疄涓嬪崟浣嶏細{}", index)
-        cancel_buy_strategy.set_real_place_position(code, index, order_begin_pos.buy_single_index,is_default = False)
+        cancel_buy_strategy.set_real_place_position(code, index, order_begin_pos.buy_single_index, is_default=False)
 
     # 澶勭悊鍗庨懌L2鏁版嵁
     @classmethod
@@ -436,7 +436,7 @@
                     cls.__process_order(code, start_index, end_index, capture_timestamp, is_first_code)
                 else:
                     # 鏈寕鍗�,鏃堕棿鐩稿樊涓嶅ぇ鎵嶈兘鎸傚崟
-                    #if tool.trade_time_sub(latest_time, "09:32:00") < 0 or l2.l2_data_util.L2DataUtil.is_same_time(now_time_str, latest_time):
+                    # if tool.trade_time_sub(latest_time, "09:32:00") < 0 or 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)
 
             async_log_util.info(logger_l2_process, "code:{} 澶勭悊鏁版嵁鑼冨洿: {}-{} 澶勭悊鏃堕棿:{} 鎴浘鏃堕棿鎴筹細{}", code,
@@ -629,7 +629,7 @@
                 trade_result_manager.real_buy_success(code, cls.__TradePointManager)
                 l2_log.debug(code, "澶勭悊涔板叆鎴愬姛1")
                 cancel_buy_strategy.set_real_place_position(code, local_today_datas.get(code)[-1]["index"],
-                                                            order_begin_pos.buy_single_index,is_default=True)
+                                                            order_begin_pos.buy_single_index, is_default=True)
                 l2_log.debug(code, "澶勭悊涔板叆鎴愬姛2")
                 params_desc = cls.__l2PlaceOrderParamsManagerDict[code].get_buy_rank_desc()
                 l2_log.debug(code, params_desc)
@@ -846,7 +846,7 @@
         if cls.__PauseBuyCodesManager.is_in_cache(code):
             return False, True, f"璇ヤ唬鐮佽鏆傚仠浜ゆ槗"
 
-        if int( tool.get_now_time_str().replace(":","")) >= 145700:
+        if int(tool.get_now_time_str().replace(":", "")) >= 145700:
             return False, True, f"14:57鍚庝笉鑳戒氦鏄�"
 
         limit_up_price = gpcode_manager.get_limit_up_price(code)
@@ -862,7 +862,7 @@
 
         # ---------鍧囦环绾︽潫-------------
         average_rate = cls.__Buy1PriceManager.get_average_rate(code)
-        if average_rate and average_rate <= 0.01 and tool.trade_time_sub(tool.get_now_time_str(),"10:30:00") >= 0:
+        if average_rate and average_rate <= 0.01 and tool.trade_time_sub(tool.get_now_time_str(), "10:30:00") >= 0:
             return False, True, f"鍧囦环娑ㄥ箙({average_rate})灏忎簬1%"
 
         total_data = local_today_datas.get(code)
@@ -1356,14 +1356,14 @@
         if order_begin_pos.mode == OrderBeginPosInfo.MODE_FAST:
 
             threshold_money = order_begin_pos.threshold_money
-            new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, not_buy_msg = cls.__sum_buy_num_for_order_fast(
+            new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg = cls.__sum_buy_num_for_order_fast(
                 code,
                 start_process_index,
                 compute_end_index,
                 order_begin_pos.num,
                 order_begin_pos.count,
                 threshold_money,
-                order_begin_pos.buy_single_index)
+                order_begin_pos.buy_single_index, order_begin_pos.max_num_set)
             threshold_money = threshold_money_new
             order_begin_pos.threshold_money = threshold_money
         else:
@@ -1513,8 +1513,8 @@
             return False, -1, "鎬诲崠涓虹┖"
         if cls.__L2MarketSellManager.is_refer_sell_time_used(code, refer_sell_data[0]):
             return False, -1, "鎬诲崠缁熻鏃堕棿宸茶浣跨敤"
-        # 鏄惁澶т簬500涓�
-        if refer_sell_data[1] <= 500 * 10000:
+        # 鏄惁澶т簬2000涓�
+        if refer_sell_data[1] <= 2000 * 10000:
             return False, -1, "鎬诲崠灏忎簬鎸囧畾閲戦"
         # 缁熻涔嬪墠鐨勫崠
         threshold_money = refer_sell_data[1]
@@ -1620,8 +1620,8 @@
         max_space_time_ms = cls.__l2PlaceOrderParamsManagerDict[code].get_time_range() * 1000
         # 濡傛灉澶у崟鍚湁鐜囧ぇ浜�50%锛屽垯鏃堕棿鍥婃嫭鑼冨洿鎻愰珮鍒�3s
         if max_num_set and origin_count:
-            if len(max_num_set)/origin_count > 0.5:
-                max_space_time_ms = 3*1000
+            if len(max_num_set) / origin_count > 0.5:
+                max_space_time_ms = 3 * 1000
 
         # 鏈�澶т拱閲�
         max_buy_num = 0
@@ -1733,7 +1733,7 @@
     # 璁$畻蹇�熶拱鍏�
     @classmethod
     def __sum_buy_num_for_order_fast(cls, code, compute_start_index, compute_end_index, origin_num, origin_count,
-                                     threshold_money_origin, buy_single_index):
+                                     threshold_money_origin, buy_single_index, max_num_set):
         _start_time = t.time()
         total_datas = local_today_datas[code]
         # is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code)
@@ -1757,6 +1757,10 @@
         max_space_time_ms = 3 * 1000
         # 涓嶄笅鍗曠殑淇℃伅
         not_buy_msg = ""
+        max_buy_num_set = set(max_num_set)
+        place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
+        if place_order_count is None:
+            place_order_count = 0
         for i in range(compute_start_index, compute_end_index + 1):
             data = total_datas[i]
             _val = total_datas[i]["val"]
@@ -1766,12 +1770,12 @@
                 cls.__TradePointManager.delete_buy_point(code)
                 if i == compute_end_index:
                     # 鏁版嵁澶勭悊瀹屾瘯
-                    return None, buy_nums, buy_count, None, threshold_money, f"銆恵i}銆戜俊鍙蜂笉杩炵画锛屽泭鎷椂闂�-{max_space_time_ms}ms"
+                    return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, f"銆恵i}銆戜俊鍙蜂笉杩炵画锛屽泭鎷椂闂�-{max_space_time_ms}ms"
                 else:
                     # 璁$畻涔板叆淇″彿锛屼笉鑳藉悓涓�鏃堕棿寮�濮嬭绠�
                     for ii in range(buy_single_index + 1, compute_end_index + 1):
                         if total_datas[buy_single_index]["val"]["time"] != total_datas[ii]["val"]["time"]:
-                            return None, buy_nums, buy_count, ii, threshold_money, f"銆恵i}銆戜俊鍙蜂笉杩炵画锛屽泭鎷椂闂�-{max_space_time_ms}ms"
+                            return None, buy_nums, buy_count, ii, threshold_money, max_buy_num_set, f"銆恵i}銆戜俊鍙蜂笉杩炵画锛屽泭鎷椂闂�-{max_space_time_ms}ms"
             if L2DataUtil.is_sell(_val):
                 threshold_money += _val["num"] * int(float(_val["price"]) * 100)
                 threshold_num = round(threshold_money / (limit_up_price * 100))
@@ -1780,6 +1784,8 @@
                 threshold_num = round(threshold_money / (limit_up_price * 100))
             # 娑ㄥ仠涔�
             elif L2DataUtil.is_limit_up_price_buy(_val):
+                if l2_data_util.is_big_money(_val):
+                    max_buy_num_set.add(i)
                 trigger_buy = True
                 # 鍙粺璁�59涓囦互涓婄殑閲戦
                 buy_nums += int(_val["num"]) * int(total_datas[i]["re"])
@@ -1793,8 +1799,10 @@
                                                                                                     local_today_buyno_map.get(
                                                                                                         code))
                 if buy_index is not None:
+
                     # 鎵惧埌涔版挙鏁版嵁鐨勪拱鍏ョ偣
                     if buy_index >= buy_single_index:
+                        max_buy_num_set.discard(buy_index)
                         buy_nums -= int(_val["num"]) * int(data["re"])
                         buy_count -= int(data["re"])
                         l2_log.buy_debug(code, "{}鏁版嵁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍚� 鎾や拱绾拱鎵嬫暟锛歿} 鐩爣鎵嬫暟锛歿}", i, buy_nums, threshold_num)
@@ -1804,6 +1812,7 @@
                             # 鍚屼竴绉�,褰撲綔涔板叆淇″彿涔嬪悗澶勭悊
                             buy_nums -= int(_val["num"]) * int(data["re"])
                             buy_count -= int(data["re"])
+                            max_buy_num_set.discard(buy_index)
                             # 澶у崟鎾ら攢
                             l2_log.buy_debug(code, "{}鏁版嵁涔板叆浣嶄笌棰勪及涔板叆浣嶅湪鍚屼竴绉�", i)
                 else:
@@ -1823,20 +1832,26 @@
             if buy_count < 5:
                 not_buy_msg = f"銆恵i}銆戝畨鍏ㄧ瑪鏁颁笉瓒筹紝{buy_count}/{5}"
                 continue
+
+            if place_order_count == 0:
+                if len(max_buy_num_set) < 1:
+                    not_buy_msg = f"銆恵i}銆戦娆′笅鍗曟棤澶у崟"
+                    continue
+
             try:
                 info = cls.__trade_log_placr_order_info_dict[code]
                 info.set_trade_factor(threshold_money, 0, [])
             except Exception as e:
                 async_log_util.error(logger_l2_error, f"璁板綍浜ゆ槗鍥犲瓙鍑洪敊锛歿str(e)}")
 
-            return i, buy_nums, buy_count, None, threshold_money, "鍙互涓嬪崟"
+            return i, buy_nums, buy_count, None, threshold_money, max_buy_num_set, "鍙互涓嬪崟"
 
         l2_log.buy_debug(code, "灏氭湭鑾峰彇鍒颁拱鍏ユ墽琛岀偣(蹇�熶拱鍏�)锛岃捣濮嬭绠椾綅缃細{} 缁熻绾拱鎵嬫暟锛歿} 鐩爣绾拱鎵嬫暟锛歿}  缁熻绾拱鍗曟暟锛歿}",
                          compute_start_index,
                          buy_nums,
                          threshold_num, buy_count)
 
-        return None, buy_nums, buy_count, None, threshold_money, not_buy_msg
+        return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, not_buy_msg
 
 
 def test_trade_record():

--
Gitblit v1.8.0