From 3cfa1332c0807a74b4ac5a2150500841f5299147 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期三, 08 三月 2023 22:54:09 +0800
Subject: [PATCH] 首板加入,安全笔数与H撤笔数优化

---
 l2/l2_data_manager_new.py |   67 ++++++++++++++++++++++-----------
 1 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index 6ef1ca8..7ef1e69 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -172,8 +172,12 @@
                 if not code_data_util.is_same_code_with_price(code, float(datas[0]["val"]["price"])):
                     raise L2DataException(L2DataException.CODE_PRICE_ERROR,
                                           "鑲′环涓嶅尮閰� code-{} price-{}".format(code, datas[0]["val"]["price"]))
-                # 鍔犺浇鍘嗗彶鏁版嵁
-                l2.l2_data_util.load_l2_data(code)
+                # 鍔犺浇鍘嗗彶鏁版嵁,杩斿洖鏁版嵁鏄惁姝e父
+                is_normal = l2.l2_data_util.load_l2_data(code)
+                if not is_normal:
+                    print("鍘嗗彶鏁版嵁寮傚父:",code)
+                    # 鏁版嵁涓嶆甯搁渶瑕佺姝氦鏄�
+                    l2_trade_util.forbidden_trade(code)
                 # 绾犳鏁版嵁
                 datas = l2.l2_data_util.L2DataUtil.correct_data(code, local_latest_datas.get(code), datas)
                 _start_index = 0
@@ -296,9 +300,9 @@
 
             l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
                                 "宸蹭笅鍗�-涔�1缁熻鑰楁椂")
-            if constant.TEST:
-                return None, ""
-            return cancel_data, cancel_msg
+            # 涔�1涓嶄細瑙﹀彂鎾ゅ崟
+            return None, ""
+            # return cancel_data, cancel_msg
 
         # S鎾�
         @dask.delayed
@@ -324,7 +328,9 @@
             _start_time = round(t.time() * 1000)
             try:
                 b_need_cancel, b_cancel_data = HourCancelBigNumComputer.need_cancel(code, buy_exec_index, start_index,
-                                                                                    end_index, total_data, local_today_num_operate_map.get(code))
+                                                                                    end_index, total_data,
+                                                                                    local_today_num_operate_map.get(
+                                                                                        code))
                 if b_need_cancel and b_cancel_data:
                     return b_cancel_data, "H鎾ら攢姣斾緥瑙﹀彂闃堝��"
             except Exception as e:
@@ -413,7 +419,7 @@
     @classmethod
     def __buy(cls, code, capture_timestamp, last_data, last_data_index):
         __start_time = tool.get_now_timestamp()
-        can, reason = cls.__can_buy(code)
+        can, need_clear_data, reason = cls.__can_buy(code)
         __start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - __start_time, "鏈�鍚庡垽鏂槸鍚﹁兘涓嬪崟", force=True)
         # 鍒犻櫎铏氭嫙涓嬪崟
         if code in cls.unreal_buy_dict:
@@ -421,7 +427,7 @@
 
         if not can:
             l2_log.debug(code, "涓嶅彲浠ヤ笅鍗曪紝鍘熷洜锛歿}", reason)
-            if not reason.startswith("涔�1浠蜂笉涓烘定鍋滀环"):
+            if need_clear_data:
                 # 涓柇涔板叆
                 trade_manager.break_buy(code, reason)
             return
@@ -472,9 +478,18 @@
         return True, ""
 
     # 鏄惁鍙互涔�
+    # 杩斿洖鏄惁鍙互涔�,鏄惁闇�瑕佹竻闄や箣鍓嶇殑涔板叆淇℃伅锛屽師鍥�
     @classmethod
     def __can_buy(cls, code):
         __start_time = t.time()
+        # 鍒ゆ柇鏄惁涓洪鏉夸唬鐮�
+        is_first = gpcode_manager.FirstCodeManager.is_in_first_record(code)
+        if is_first:
+            # 棣栨澘浠g爜涓斿皻鏈定鍋滆繃鐨勪笉鑳戒笅鍗�
+            is_limited_up = gpcode_manager.FirstCodeManager.is_limited_up(code)
+            if not is_limited_up:
+                return False, True, "棣栨澘浠g爜锛屼笖灏氭湭娑ㄥ仠杩�"
+
         try:
             # 涔�1浠锋牸蹇呴』涓烘定鍋滀环鎵嶈兘涔�
             # buy1_price = cls.buy1PriceManager.get_price(code)
@@ -487,6 +502,10 @@
             #     return False, "涔�1浠蜂笉涓烘定鍋滀环锛屼拱1浠�-{} 娑ㄥ仠浠�-{}".format(buy1_price, limit_up_price)
             # 浠庝拱鍏ヤ俊鍙疯捣濮嬬偣鍒板綋鍓嶆暟鎹湯灏剧殑绾拱鎵嬫暟涓庡綋鍓嶇殑鍗�1鍋氭瘮杈冿紝濡傛灉姣斿崠1灏忓垯涓嶈兘涔板叆
             total_datas = local_today_datas[code]
+            if total_datas[-1]["index"] + 1 > len(total_datas):
+                return False, True, "L2鏁版嵁閿欒"
+
+
             try:
                 sell1_time, sell1_price, sell1_volumn = cls.__ths_l2_trade_queue_manager.get_sell1_info(code)
                 l2_log.buy_debug(code, "鍗�1淇℃伅涓猴細({},{},{})", sell1_time, sell1_price, sell1_volumn)
@@ -505,30 +524,30 @@
                         elif L2DataUtil.is_limit_up_price_buy_cancel(_val):
                             buy_nums -= _val["num"] * total_datas[i]["re"]
                     if buy_nums < sell1_volumn * 0.49:
-                        return False, "绾拱閲�({})灏忎簬鍗�1閲忕殑49%{} 鍗�1鏃堕棿锛歿}".format(buy_nums, sell1_volumn, sell1_time)
+                        return False, True, "绾拱閲�({})灏忎簬鍗�1閲忕殑49%{} 鍗�1鏃堕棿锛歿}".format(buy_nums, sell1_volumn, sell1_time)
             except Exception as e:
                 logging.exception(e)
 
             # 閲忔瘮瓒呰繃1.3鐨勪笉鑳戒拱
             volumn_rate = l2_trade_factor.L2TradeFactorUtil.get_volumn_rate_by_code(code)
             if volumn_rate >= 1.3:
-                return False, "鏈�澶ч噺姣旇秴杩�1.3涓嶈兘涔�"
+                return False, True, "鏈�澶ч噺姣旇秴杩�1.3涓嶈兘涔�"
 
             limit_up_time = limit_up_time_manager.get_limit_up_time(code)
             if limit_up_time is not None and l2.l2_data_util.L2DataUtil.get_time_as_second(
                     limit_up_time) >= l2.l2_data_util.L2DataUtil.get_time_as_second(
                 "14:30:00"):
-                return False, "14:30鍚庢定鍋滅殑涓嶈兘涔帮紝娑ㄥ仠鏃堕棿涓簕}".format(limit_up_time)
+                return False, True, "14:55鍚庢定鍋滅殑涓嶈兘涔帮紝娑ㄥ仠鏃堕棿涓簕}".format(limit_up_time)
 
             # 鍚屼竴鏉垮潡涓�佷簩鍚庨潰鐨勪笉鑳戒拱
             industry, codes = ths_industry_util.get_same_industry_codes(code, gpcode_manager.get_gp_list())
             if industry is None:
-                return True, "娌℃湁鑾峰彇鍒拌涓�"
+                return True, True, "娌℃湁鑾峰彇鍒拌涓�"
 
             codes_index = industry_codes_sort.sort_codes(codes, code)
             if codes_index is not None and codes_index.get(code) is not None and codes_index.get(code) > 1:
                 # 褰撹�佸ぇ鑰佷簩褰撳墠娌℃定鍋�
-                return False, "鍚屼竴鏉垮潡涓�佷笁,鑰佸洓,...涓嶈兘涔�"
+                return False, True, "鍚屼竴鏉垮潡涓�佷笁,鑰佸洓,...涓嶈兘涔�"
 
             if cls.__codeActualPriceProcessor.is_under_water(code, total_datas[-1]["val"]["time"]):
                 # 姘翠笅鎹炰笖鏉垮潡涓殑绁ㄥ皬浜�16涓嶈兘涔�
@@ -540,7 +559,7 @@
                     # 鑾峰彇鑰佸ぇ鐨勫競鍊�
                     for c in codes_index:
                         if codes_index.get(c) == 0 and global_util.zyltgb_map.get(code) > global_util.zyltgb_map.get(c):
-                            return False, "姘翠笅鎹烇紝涓嶆槸鑰佸ぇ锛屼笖鑷敱娴侀�氬競鍊煎ぇ浜庤�佸ぇ"
+                            return False, True, "姘翠笅鎹烇紝涓嶆槸鑰佸ぇ锛屼笖鑷敱娴侀�氬競鍊煎ぇ浜庤�佸ぇ"
 
             # 13:30鍚庢定鍋滐紝鏈澘鍧椾腑娑ㄥ仠绁ㄦ暟<29涓嶈兘涔�
             # if limit_up_time is not None:
@@ -576,7 +595,7 @@
             #     if global_util.industry_hot_num.get(industry) < 29:
             #         return False, "鑰佷簩锛屾湰鏉垮潡涓定鍋滅エ鏁�<29涓嶈兘涔�"
             # 鍙互涓嬪崟
-            return True, None
+            return True, False, None
         finally:
             l2_data_log.l2_time(code, round((t.time() - __start_time) * 1000), "鏄惁鍙互涓嬪崟璁$畻")
 
@@ -672,8 +691,9 @@
             return None
 
         # 寮�濮嬭绠楃殑浣嶇疆
-        start_process_index = min(buy_single_index, compute_start_index) if new_get_single else max(buy_single_index,
-                                                                                                    compute_start_index)
+        start_process_index = max(buy_single_index, compute_start_index)
+        if new_get_single:
+            start_process_index = buy_single_index
 
         # 璁$畻m鍊煎ぇ鍗�
         cls.l2BigNumForMProcessor.process(code, start_process_index,
@@ -859,6 +879,7 @@
 
         _start_time = t.time()
         total_datas = local_today_datas[code]
+        is_first_code = gpcode_manager.FirstCodeManager.is_in_first_record(code)
 
         buy_nums = origin_num
         buy_count = origin_count
@@ -869,14 +890,15 @@
         # 鐩爣鎵嬫暟
         threshold_num = round(threshold_money / (limit_up_price * 100))
 
+        place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(code)
         # 鐩爣璁㈠崟鏁伴噺
-        threshold_count = cls.__buyL2SafeCountManager.get_safe_count(code)
+        threshold_count = cls.__buyL2SafeCountManager.get_safe_count(code,is_first_code, place_order_count)
 
         buy_single_time_seconds = L2DataUtil.get_time_as_second(total_datas[buy_single_index]["val"]["time"])
 
         # 鍙互瑙﹀彂涔帮紝褰撴湁娑ㄥ仠涔颁俊鍙锋椂鎵嶄細瑙﹀彂涔�
         trigger_buy = True
-        place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count(code)
+
         if place_order_count > 3:
             place_order_count = 3
         # 闂撮殧鏈�澶ф椂闂翠緷娆′负锛�3,9,27,81
@@ -926,7 +948,8 @@
                     # 鍙粺璁�59涓囦互涓婄殑閲戦
                     # 娑ㄥ仠涔版挙
                     # 鍒ゆ柇涔板叆浣嶇疆鏄惁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓�
-                    buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, total_datas[i],
+                    buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code,
+                                                                                                     total_datas[i],
                                                                                                      local_today_num_operate_map.get(
                                                                                                          code))
                     if buy_index is not None:
@@ -1039,8 +1062,8 @@
         limit_up_time = limit_up_time_manager.get_limit_up_time(code)
         if limit_up_time is not None and l2.l2_data_util.L2DataUtil.get_time_as_second(
                 limit_up_time) >= l2.l2_data_util.L2DataUtil.get_time_as_second(
-            "14:30:00"):
-            return False, "14:30鍚庢定鍋滅殑涓嶈兘涔帮紝娑ㄥ仠鏃堕棿涓簕}".format(limit_up_time)
+            "14:55:00"):
+            return False, "14:55鍚庢定鍋滅殑涓嶈兘涔帮紝娑ㄥ仠鏃堕棿涓簕}".format(limit_up_time)
 
         # 鍚屼竴鏉垮潡涓�佷簩鍚庨潰鐨勪笉鑳戒拱
         industry, codes = ths_industry_util.get_same_industry_codes(code, gpcode_manager.get_gp_list())

--
Gitblit v1.8.0