From 7adad3e127f11ffcd69836257fee2e15f1565daf Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 29 五月 2025 16:18:58 +0800
Subject: [PATCH] 没有订阅的代码,计算比较准确的总大单阈值

---
 trade/buy_radical/radical_buy_data_manager.py |   94 ++++++++++++++++++++++++++++++++--------------
 servers/data_server.py                        |   21 ++++++++++
 2 files changed, 86 insertions(+), 29 deletions(-)

diff --git a/servers/data_server.py b/servers/data_server.py
index a911462..384cbd5 100644
--- a/servers/data_server.py
+++ b/servers/data_server.py
@@ -950,6 +950,27 @@
                                 th_sell = 0
                             deal_big_money_info = radical_buy_data_manager.get_total_deal_big_order_info(
                                 code, gpcode_manager.get_limit_up_price_as_num(code))
+                            if deal_big_money_info[1] == 0 and len(codes) == 1:
+                                deal_big_money_info = list(deal_big_money_info)
+                                # 娌℃湁璁㈤槄L2浼氬嚭鐜版病鏈夊�肩殑鎯呭喌锛屽鏋滄定鍋滆繃灏辨媺鍙栦箣鍓嶇殑娑ㄥ仠涔�/鍗栧ぇ鍗�
+                                deal_big_orders_result = radical_buy_data_manager.request_deal_big_orders(code)
+                                if deal_big_orders_result:
+                                    buy_datas, sell_datas = deal_big_orders_result[0], deal_big_orders_result[1]
+                                    limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
+                                    limit_up_price_money_list = [x[0] for x in buy_datas if x[1] == limit_up_price]
+                                    threshold_money = BeforeSubDealBigOrderManager.compute_re_limit_up_big_money_threshold(
+                                        limit_up_price_money_list)
+                                    # 璁剧疆涔板崟闃堝��
+                                    th_buy = threshold_money
+                                    buy_money = sum(limit_up_price_money_list)
+                                    sell_money = sum([x[0] for x in sell_datas if x[1] == limit_up_price])
+                                    # 娑ㄥ仠澶у崟鍑�涔板叆
+                                    deal_big_money_info[1] = buy_money - sell_money
+                                    deal_big_money_info[
+                                        2] = radical_buy_data_manager.compute_total_deal_big_order_threshold_money(code,
+                                                                                                                   limit_up_price,
+                                                                                                                   threshold_money)
+
                             big_money_rate = radical_buy_data_manager.TotalDealBigOrderInfoManager.get_big_order_rate(
                                 code)
                             if not big_money_rate:
diff --git a/trade/buy_radical/radical_buy_data_manager.py b/trade/buy_radical/radical_buy_data_manager.py
index c011a22..cb58cc5 100644
--- a/trade/buy_radical/radical_buy_data_manager.py
+++ b/trade/buy_radical/radical_buy_data_manager.py
@@ -107,6 +107,19 @@
         redis_manager.RedisUtils.setex_async(self.__db, f"radical_big_sell_order_threshold-{code}", tool.get_expire(),
                                              f"{threshold_money}")
 
+    @classmethod
+    def compute_re_limit_up_big_money_threshold(cls, limit_up_price_money_list):
+        """
+        鑾峰彇鍥炲皝鐨勫ぇ鍗曢槇鍊�
+        @param limit_up_price_money_list:
+        @return:
+        """
+        average_money = sum(limit_up_price_money_list) // len(limit_up_price_money_list)
+        max_money = max(limit_up_price_money_list)
+        # 鍙杕ax((骞冲潎鍊�+鏈�澶у崟涓�鍗�)/2, 骞冲潎鍊�)
+        threshold_money = max((max_money // 2 + average_money) // 2, average_money)
+        return threshold_money
+
     def set_big_deal_order_list(self, code, buy_money_list, sell_money_list, limit_up_price):
         """
         璁剧疆澶у崟鎴愪氦鏁版嵁
@@ -146,11 +159,7 @@
             total_deal_buy_money += info[0]
             total_deal_buy_money_info_list.append(info)
         if limit_up_price_money_list:
-            # 璁$畻澶у崟鐨勯槇鍊�
-            average_money = sum(limit_up_price_money_list) // len(limit_up_price_money_list)
-            max_money = max(limit_up_price_money_list)
-            # 鍙杕ax((骞冲潎鍊�+鏈�澶у崟涓�鍗�)/2, 骞冲潎鍊�)
-            threshold_money = max((max_money // 2 + average_money) // 2, average_money)
+            threshold_money = self.compute_re_limit_up_big_money_threshold(limit_up_price_money_list)
             self.set_big_order_threshold(code, threshold_money)
         self.__already_total_deal_big_order_money[code] = (total_deal_buy_money, pre_limit_up_price_money_list)
         async_log_util.info(logger_l2_radical_buy_data,
@@ -1761,6 +1770,24 @@
     return buy_money, before_buy_money, sell_money, before_sell_money
 
 
+def compute_total_deal_big_order_threshold_money(code, limit_up_price, threshold_money_per_order):
+    """
+    璁$畻绱澶у崟瓒冲鐨勯槇鍊�
+    @param code:
+    @param limit_up_price:
+    @param threshold_money_per_order: 鍧囧ぇ鍗曢槇鍊�
+    @return:
+    """
+
+    TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT = round(
+        code_volumn_manager.CodeVolumeManager().get_radical_buy_refer_volume(code,
+                                                                             limit_up_price) * limit_up_price / 1e8,
+        2) * 3
+    if tool.is_ge_code(code):
+        TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT *= 1.5
+    return TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT * threshold_money_per_order
+
+
 def get_total_deal_big_order_info(code, limit_up_price, is_for_buy=False):
     """
     鎬绘垚浜ゅぇ鍗曞晩鏄惁瓒冲
@@ -1769,15 +1796,9 @@
     """
 
     THRESHOLD_MONEY, is_temp_threshold_money = BeforeSubDealBigOrderManager().get_big_order_threshold_info(code)
-
-    TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT = round(
-        code_volumn_manager.CodeVolumeManager().get_radical_buy_refer_volume(code,
-                                                                             limit_up_price) * limit_up_price / 1e8,
-        2) * 3
-    if tool.is_ge_code(code):
-        TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT *= 3.3
-
-    TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY_WITH_COMPUTE = TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT * THRESHOLD_MONEY
+    TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY_WITH_COMPUTE = compute_total_deal_big_order_threshold_money(code,
+                                                                                                     limit_up_price,
+                                                                                                     THRESHOLD_MONEY)
 
     human_setting_money = TotalDealBigOrderThresholdMoneyManager().get_money_cache(code)
     if human_setting_money is not None:
@@ -2131,6 +2152,26 @@
         return round(0 - 0.44 * fvolume_rate + 0.722, 3)
 
 
+def request_deal_big_orders(code_):
+    """
+    璇锋眰澶у崟鎴愪氦
+    @param code_:
+    @return:
+    """
+    response_data = requests.get(
+        "http://127.0.0.1:9005/get_big_order_list?code=" + code_)
+    r_str = response_data.text
+    response_data = json.loads(r_str)
+    if response_data["code"] == 0:
+        datas = response_data["data"]
+        async_log_util.info(logger_debug, f"鎷夊彇璁㈤槄涔嬪墠鐨勬暟鎹細{code_}-{datas}")
+        if datas:
+            buy_datas = datas["buy"]
+            sell_datas = datas["sell"]
+            return buy_datas, sell_datas
+    return None
+
+
 def pull_pre_deal_big_orders(code_):
     """
     鎷夊彇璁㈤槄涔嬪墠鎴愪氦鐨勫ぇ鍗�
@@ -2140,21 +2181,15 @@
     # 鍙湁娑ㄥ仠杩囩殑浠g爜鎵嶉渶瑕佹媺澶у崟
     if code_ not in LimitUpDataConstant.get_history_limit_up_codes():
         return
-    response_data = requests.get(
-        "http://127.0.0.1:9005/get_big_order_list?code=" + code_)
-    r_str = response_data.text
-    response_data = json.loads(r_str)
-    if response_data["code"] == 0:
-        datas = response_data["data"]
-        async_log_util.info(logger_debug, f"鎷夊彇璁㈤槄涔嬪墠鐨勬暟鎹細{code_}-{datas}")
-        if datas:
-            try:
-                buy_datas = datas["buy"]
-                sell_datas = datas["sell"]
-                BeforeSubDealBigOrderManager().set_big_deal_order_list(code_, buy_datas, sell_datas,
-                                                                       gpcode_manager.get_limit_up_price_as_num(code_))
-            except Exception as e:
-                logger_debug.exception(e)
+
+    result = request_deal_big_orders(code_)
+    if result:
+        try:
+            buy_datas, sell_datas = result[0], result[1]
+            BeforeSubDealBigOrderManager().set_big_deal_order_list(code_, buy_datas, sell_datas,
+                                                                   gpcode_manager.get_limit_up_price_as_num(code_))
+        except Exception as e:
+            logger_debug.exception(e)
 
 
 def pull_pre_deal_big_orders_by_codes(codes):
@@ -2180,6 +2215,7 @@
         return datas
     return None
 
+
 def list_l2_big_order_deal_info(codes):
     """
     鑾峰彇鎴愪氦澶у崟淇℃伅

--
Gitblit v1.8.0