From 331d8caf63a7119c8cf2d1faef28b5450b8f40f5 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 11 十月 2024 18:41:24 +0800
Subject: [PATCH] bug修复/新增加接口

---
 third_data/code_plate_key_manager.py |   92 +++++++++++++++++++++++++++++++--------------
 1 files changed, 63 insertions(+), 29 deletions(-)

diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py
index aeba8a5..884d33d 100644
--- a/third_data/code_plate_key_manager.py
+++ b/third_data/code_plate_key_manager.py
@@ -14,6 +14,7 @@
 from settings.trade_setting import MarketSituationManager
 from third_data.kpl_data_constant import LimitUpDataConstant
 from third_data.third_blocks_manager import BlockMapManager, CodeThirdBlocksManager
+from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager
 from trade.order_statistic import DealAndDelegateWithBuyModeDataManager
 from trade.radical_buy_data_manager import RedicalBuyDataManager
 from utils import global_util, tool, buy_condition_util
@@ -1128,7 +1129,7 @@
         kpl_data_constant.open_limit_up_code_dict_for_radical_buy = temp_dict
 
     @classmethod
-    def __get_current_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None):
+    def __get_current_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None, limit_up_time=None):
         """
         鑾峰彇褰撳墠娑ㄥ仠韬綅
         @param code:
@@ -1141,7 +1142,8 @@
         current_index = 0
         block_codes_infos = []
         timestamp_start, timestamp_end = kpl_block_util.open_limit_up_time_range
-        limit_up_time = time.time()
+        if limit_up_time is None:
+            limit_up_time = time.time()
         for k in LimitUpDataConstant.current_limit_up_datas:
             _code = k[0]
             if _code in exclude_codes:
@@ -1250,9 +1252,7 @@
         """
         # 9:45鐐逛箣鍓嶆定鍋滅殑鎵嶈兘涔板叆
         # 鑾峰彇褰撳墠浠g爜鐨勬定鍋滄椂闂�
-        limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code)
-        if not limit_up_timestamp:
-            limit_up_timestamp = time.time()
+        limit_up_timestamp = cls.__get_limit_up_timestamp(code)
         if int(tool.timestamp_format(limit_up_timestamp, "%H%M%S")) > 94500:
             return False, "瓒呰繃鐢熸晥鏃堕棿"
         # 鏍规嵁鏉垮潡鑱氬悎鏁版嵁
@@ -1270,7 +1270,8 @@
         # ----鑾峰彇鍘嗗彶韬綅----
         history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes)
         # ----鑾峰彇瀹炴椂韬綅----
-        current_index, current_before_codes_info = cls.__get_current_index(code, block, yesterday_limit_up_codes)
+        current_index, current_before_codes_info = cls.__get_current_index(code, block, yesterday_limit_up_codes,
+                                                                           limit_up_time=limit_up_timestamp)
         exclude_codes = set()
         if count >= 2 or (
                 count == 1 and kpl_data_constant.open_limit_up_code_dict_for_radical_buy[open_limit_up_block_codes[0]][
@@ -1282,7 +1283,8 @@
             # ----鑾峰彇鍘嗗彶韬綅----
             history_index, history_before_codes_info = cls.__get_history_index(code, block, set())
             # ----鑾峰彇瀹炴椂韬綅----
-            current_index, current_before_codes_info = cls.__get_current_index(code, block, set())
+            current_index, current_before_codes_info = cls.__get_current_index(code, block, set(),
+                                                                               limit_up_time=limit_up_timestamp)
             if history_before_codes_info and current_before_codes_info and history_before_codes_info[0][0] == \
                     current_before_codes_info[0][0]:
                 # 鍓嶆帓绗竴涓厓绱犳棤鐐告澘
@@ -1300,7 +1302,8 @@
             return False, f"寮�1鏁伴噺锛歿count}锛岄潪寮�1棣栨澘韬綅涓嶅尮閰嶏細鍘嗗彶-{history_index + 1} 瀹炴椂-{current_index + 1}"
         if history_index == 1:
             # 褰撳墠浠g爜涓鸿��2锛岃鍒ゆ柇鑰佸ぇ鏄惁鍙拱
-            if RedicalBuyDataManager.can_buy(history_before_codes_info[0][0], DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]:
+            if RedicalBuyDataManager.can_buy(history_before_codes_info[0][0],
+                                             DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]:
                 return False, f"寮�1鏁伴噺锛歿count}锛屽墠鎺掍唬鐮佸彲涔帮細{history_before_codes_info[0]}"
             return True, f"寮�1鏁伴噺锛歿count}锛屽墠鎺掍唬鐮佷笉鍙拱锛歿history_before_codes_info[0]}"
         return True, f"寮�1鏁伴噺锛歿count}锛屽巻鍙�-{history_index + 1} 瀹炴椂-{current_index + 1}"
@@ -1320,17 +1323,17 @@
         @param yesterday_limit_up_codes:
         @return:
         """
+
+        # 鑾峰彇褰撳墠浠g爜鐨勬定鍋滄椂闂�
+        limit_up_timestamp = cls.__get_limit_up_timestamp(code)
+
         # 鑾峰彇褰撳墠鐨勬澘鍧�
-        current_index, current_before_codes_info = cls.__get_current_index(code, block, set())
+        current_index, current_before_codes_info = cls.__get_current_index(code, block, set(),
+                                                                           limit_up_time=limit_up_timestamp)
         current_before_codes = [x[0] for x in current_before_codes_info]
 
         if len(current_before_codes_info) < 2:
             return False, f"鍓嶆帓浠g爜灏忎簬2涓細{current_before_codes_info}"
-
-        # 鑾峰彇褰撳墠浠g爜鐨勬定鍋滄椂闂�
-        limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code)
-        if not limit_up_timestamp:
-            limit_up_timestamp = time.time()
 
         # 褰撳墠浠g爜寮�1涓嶈兘涔�
         if limit_up_timestamp < kpl_block_util.open_limit_up_time_range[1]:
@@ -1365,20 +1368,28 @@
             exclude_codes |= set(open_limit_up_code_dict.keys())
         history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes,
                                                                            exclude_codes)
-        if history_index > 1:
-            return False, f"鎺掗櫎鍓�2锛岀洰鏍囦唬鐮佷綅浜庡巻鍙茶韩浣�-{history_index + 1}锛屽墠鎺掍唬鐮侊細{history_before_codes_info}"
-        elif history_index == 1:
-            # 棣栨澘鑰�2锛屽垽鏂墠闈㈢殑鑰佸ぇ鏄惁鏄睘浜庝笉鑳戒拱鐨勮寖鐣�
-            pre_code = history_before_codes_info[0][0]
-            # pre_code涓嶈兘涔帮紝鎵嶈兘涔�
-            if RedicalBuyDataManager.can_buy(pre_code, DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]:
-                return False, f"鍓嶆帓浠g爜鍙拱锛歿pre_code}"
-            # 璺濈鍓嶄竴涓槸鍚﹀湪10鍒嗛挓鍐�
-            if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'),
-                                   tool.timestamp_format(history_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60:
-                return False, f"璺濈涓婁釜涓嶈兘涔扮殑浠g爜娑ㄥ仠宸茶繃鍘�10鍒嗛挓锛坽history_before_codes_info[0]}锛�"
+        # 鑾峰彇鏈澘鍧椾拱鍏ヤ唬鐮佺殑鏈�澶ф暟閲�
+        max_count = RadicalBuyBlockCodeCountManager().get_block_code_count(block)
+        if history_index > max_count:
+            return False, f"鎺掗櫎鍓�2锛岀洰鏍囦唬鐮佷綅浜庡巻鍙茶韩浣�-{history_index + 1}锛屽墠鎺掍唬鐮侊細{history_before_codes_info}, 鏉垮潡鏈�澶氬彲涔皗max_count}"
+
+        if max_count == 1:
+            if history_index == 1:
+                # 棣栨澘鑰�2锛屽垽鏂墠闈㈢殑鑰佸ぇ鏄惁鏄睘浜庝笉鑳戒拱鐨勮寖鐣�
+                pre_code = history_before_codes_info[0][0]
+                # pre_code涓嶈兘涔帮紝鎵嶈兘涔�
+                if RedicalBuyDataManager.can_buy(pre_code, DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]:
+                    return False, f"鍓嶆帓浠g爜鍙拱锛歿pre_code}"
+                # 璺濈鍓嶄竴涓槸鍚﹀湪10鍒嗛挓鍐�
+                if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'),
+                                       tool.timestamp_format(history_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60:
+                    return False, f"璺濈涓婁釜涓嶈兘涔扮殑浠g爜娑ㄥ仠宸茶繃鍘�10鍒嗛挓锛坽history_before_codes_info[0]}锛�"
+            else:
+                # 璺濈涓婁釜浠g爜娑ㄥ仠5鍒嗛挓浠ュ唴
+                if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'),
+                                       tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 5 * 60:
+                    return False, f"璺濈涓婁釜浠g爜娑ㄥ仠宸茶繃鍘�5鍒嗛挓锛坽current_before_codes_info[-1]}锛�"
         else:
-            # 璺濈涓婁釜浠g爜娑ㄥ仠5鍒嗛挓浠ュ唴
             if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'),
                                    tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 5 * 60:
                 return False, f"璺濈涓婁釜浠g爜娑ㄥ仠宸茶繃鍘�5鍒嗛挓锛坽current_before_codes_info[-1]}锛�"
@@ -1387,8 +1398,16 @@
 
     @classmethod
     def __is_re_limit_up(cls, code, block):
+        """
+        鏄惁鏄偢鏉垮洖灏佸彲涔�
+        @param code:
+        @param block:
+        @return:
+        """
         # 鑾峰彇韬綅
-        current_index, current_before_codes_info = cls.__get_current_index(code, block, set())
+        current_index, current_before_codes_info = cls.__get_current_index(code, block, set(),
+                                                                           limit_up_time=cls.__get_limit_up_timestamp(
+                                                                               code))
         history_index, history_before_codes_info = cls.__get_history_index(code, block, set())
         if current_index != history_index:
             return False, f"鏈夊叾浠栫偢鏉�"
@@ -1421,6 +1440,18 @@
         if diff:
             return False, f"鏉垮潡鐐告澘涓嶆褰撳墠绁細{diff}"
         return True, ""
+
+    @classmethod
+    def __get_limit_up_timestamp(cls, code):
+        """
+        鑾峰彇浠g爜鐨勬定鍋滄椂闂达紝榛樿褰撳墠鏃堕棿
+        @param code:
+        @return:
+        """
+        limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code)
+        if not limit_up_timestamp:
+            limit_up_timestamp = time.time()
+        return limit_up_timestamp
 
     @classmethod
     def get_code_kpl_blocks(cls, code):
@@ -1490,15 +1521,18 @@
                 result = cls.__is_radical_buy_with_block_up(code, b, yesterday_limit_up_codes)
                 if result[0]:
                     can_buy_blocks.add(b)
+
                 msges.append(f"銆恵b}銆�:{result[1]}")
             fmsges.append("鏉垮潡蹇�熷惎鍔ㄥ垽鏂�##" + ",".join(msges))
 
         if not can_buy_blocks:
+            msges.clear()
             for b in keys_:
                 result = cls.__is_re_limit_up(code, b)
                 if result[0]:
                     can_buy_blocks.add(b)
-
+                    msges.append(f"銆恵b}銆�:{result[1]}")
+            fmsges.append("鏉垮潡鍥炲皝鍒ゆ柇##" + ",".join(msges))
         return can_buy_blocks, " **** ".join(fmsges)
 
 

--
Gitblit v1.8.0