From 8ab72ecd563e4bdcb94eac3f8c9d18d0a0a2d502 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期二, 10 六月 2025 16:31:34 +0800
Subject: [PATCH] bug修复

---
 strategy/低吸脚本_辨识度_v6.py               |   10 ++++-
 strategy/time_series_backtest.py      |    6 +-
 strategy/strategy_variable_factory.py |   11 +++--
 strategy/strategy_params_settings.py  |   34 ++++++++++++++++-
 api/outside_api_callback.py           |   22 +++++++++-
 strategy/data_downloader.py           |    1 
 6 files changed, 69 insertions(+), 15 deletions(-)

diff --git a/api/outside_api_callback.py b/api/outside_api_callback.py
index 85655a4..647730f 100644
--- a/api/outside_api_callback.py
+++ b/api/outside_api_callback.py
@@ -43,8 +43,20 @@
         鑾峰彇浜ゆ槗鍙傛暟
         @return:
         """
-        result = strategy_params_settings.settings.to_json_str()
-        return {"code": 0, "data": result}
+        result = strategy_params_settings.StrategyParamsSettingsManager().get_settings().to_json_str()
+        return {"code": 0, "data": json.loads(result)}
+
+    def __on_set_settings(self, data):
+        """
+        璁剧疆浜ゆ槗鍙傛暟
+        @return:
+        """
+        settings = strategy_params_settings.StrategyParamsSettingsManager().get_settings()
+        for k in data:
+            settings.__setattr__(k, data[k])
+        strategy_params_settings.StrategyParamsSettingsManager().set_settings(settings)
+        # 鍚屾鍙傛暟璁剧疆
+        return {"code": 0, "data": {}}
 
     def __on_get_env(self, need_hsitory_data):
         """
@@ -64,7 +76,8 @@
             else:
                 # 濡傛灉鍦�16:00涔嬪悗閲囩敤涓嬩竴涓氦鏄撴棩
                 day = TradeDateManager().get_next_trade_day(tool.get_now_date_str())
-            fdata["history_data"]["leading_limit_up_block_codes_count"] = env_info.get_leading_limit_up_block_codes_count(
+            fdata["history_data"][
+                "leading_limit_up_block_codes_count"] = env_info.get_leading_limit_up_block_codes_count(
                 day)
 
             if tool.get_now_time_str() < '16:00:00':
@@ -103,6 +116,9 @@
         result_json = {}
         if ctype == "get_settings":
             result_json = self.__on_get_settings()
+        elif ctype == 'set_settings':
+            del data["ctype"]
+            result_json = self.__on_set_settings(data)
         elif ctype == 'get_env':
             result_json = self.__on_get_env(data.get("history"))
         elif ctype == 'update_leading_limit_up_datas':
diff --git a/strategy/data_downloader.py b/strategy/data_downloader.py
index 1831770..3580ec8 100644
--- a/strategy/data_downloader.py
+++ b/strategy/data_downloader.py
@@ -114,6 +114,7 @@
                     # 淇濆瓨Tick绾�
                     with open(tick_path, encoding='utf-8', mode='w') as f:
                         f.write(f"{results}")
+                    print("鍓╀綑鏁伴噺锛�", len(set(batch_codes) - excute_codes))
                 finally:
                     excute_codes.add(code)
                     if show_log:
diff --git a/strategy/strategy_params_settings.py b/strategy/strategy_params_settings.py
index 8e415d9..d7ae94d 100644
--- a/strategy/strategy_params_settings.py
+++ b/strategy/strategy_params_settings.py
@@ -3,6 +3,10 @@
 """
 import json
 
+from db.mysql_data_delegate import Mysqldb
+from utils import tool
+
+
 class StrategyParamsSettings:
     # 绂佹涔板叆
     STATE_FORBIDDEN_BUY = 0
@@ -14,6 +18,8 @@
         self.trade_state = 1
         # 涔板叆閲戦
         self.buy_money = 2000
+        # 鏈�澶т拱鍏ョエ鐨勬暟閲�
+        self.max_buy_codes_count = 10
         # 浠锋牸鍖洪棿
         self.price_range = (3, 60)
         # 鑰侀鏉愭定鍋滄暟
@@ -49,7 +55,7 @@
         # 鏄惁鍙拱浠婃棩娑ㄥ仠杩囩殑绁�
         self.can_buy_limited_up = False
         # 鏈�浣庡紑鐩樻定骞�
-        self.min_open_rate = -0.03
+        self.min_open_rate = 0.00001
         # 鍙拱鐨勬定骞呮瘮渚�
         self.avaiable_rates = (-0.03, 0.07)
         # 浠婃棩娑ㄥ仠浠烽渶绐佺牬XX鏃ユ渶楂樹环,None琛ㄧず姝ゆ潯鏁版嵁涓嶇敓鏁�
@@ -72,4 +78,28 @@
         return obj
 
 
-settings: StrategyParamsSettings = StrategyParamsSettings()
\ No newline at end of file
+@tool.singleton
+class StrategyParamsSettingsManager:
+    def __init__(self):
+        self.musql = Mysqldb()
+        self.__settings = StrategyParamsSettings()
+        self.__load_data()
+
+    def __load_data(self):
+        sql = f"select `value` from config where `key` = 'low_suction_settings'"
+        setting_str_list = self.musql.select_one(sql)
+        if setting_str_list and setting_str_list[0]:
+            self.__settings = StrategyParamsSettings.to_obj(setting_str_list[0])
+
+    def set_settings(self, settings: StrategyParamsSettings):
+        sql = f"update config set `value` = '{settings.to_json_str()}'  where `key` = 'low_suction_settings'"
+        self.musql.execute(sql)
+        self.__settings = settings
+
+    def get_settings(self):
+        return self.__settings
+
+
+if __name__ == "__main__":
+    settings = StrategyParamsSettingsManager().get_settings()
+    StrategyParamsSettingsManager().set_settings(settings)
diff --git a/strategy/strategy_variable_factory.py b/strategy/strategy_variable_factory.py
index 8dfc58b..3658704 100644
--- a/strategy/strategy_variable_factory.py
+++ b/strategy/strategy_variable_factory.py
@@ -203,7 +203,7 @@
     def load_target_plate_and_codes(self):
         """
         鍔犺浇鐩爣鏉垮潡涓庡搴旂殑浠g爜锛�
-        浠庢渶杩�120涓氦鏄撴棩鐨勭湡姝f定鍋滄暟鎹腑
+        浠庢渶杩�60涓氦鏄撴棩鐨勭湡姝f定鍋滄暟鎹腑
         @return: {"鏉垮潡":[浠g爜]}
         """
         end_date = self.trade_days[:60][-1]
@@ -234,10 +234,11 @@
             if results:
                 results = [x for x in results if
                            (tool.is_can_buy_code(x[0]) and x[0] in valid_codes and x[0] not in exclude_codes)]
-                max_count = len(results) // 3 if len(results) % 3 == 0 else len(results) // 3 + 1
-                results = results[:max_count]
-                # 鍙栧墠10
-                results = results[:10]
+                # 鍙栧墠1/3涓旀定鍋滄暟鏄墠10
+                # max_count = len(results) // 3 if len(results) % 3 == 0 else len(results) // 3 + 1
+                # results = results[:max_count]
+                # # 鍙栧墠10
+                # results = results[:10]
                 codes = [x[0] for x in results]
                 fresults[kpl_util.filter_block(b)] = codes
         return fresults
diff --git a/strategy/time_series_backtest.py b/strategy/time_series_backtest.py
index c837a59..d9f007a 100644
--- a/strategy/time_series_backtest.py
+++ b/strategy/time_series_backtest.py
@@ -3,7 +3,7 @@
 from strategy.data_analyzer import KPLLimitUpDataAnalyzer
 from strategy.data_downloader import DataDownloader
 from strategy.low_suction_strategy import LowSuctionOriginDataExportManager
-from strategy.strategy_params_settings import StrategyParamsSettings
+from strategy.strategy_params_settings import StrategyParamsSettings, StrategyParamsSettingsManager
 from strategy.strategy_variable import StockVariables
 from strategy.strategy_variable_factory import DataLoader, StrategyVariableFactory
 from third_data import kpl_util
@@ -13,7 +13,7 @@
 
 class BackTest:
 
-    def __init__(self, day, script_name="浣庡惛鑴氭湰_杈ㄨ瘑搴v3.py", settings=StrategyParamsSettings()):
+    def __init__(self, day, script_name="浣庡惛鑴氭湰_杈ㄨ瘑搴v3.py", settings=StrategyParamsSettingsManager().get_settings()):
         self.day = day
         scripts = ""
         with open(script_name, mode='r', encoding='utf-8') as f:
@@ -783,7 +783,7 @@
     #         "2025-05-15", "2025-05-16", "2025-05-19", "2025-05-20",  "2025-05-21", "2025-05-22"]
     days = ["2025-05-12", "2025-05-13", "2025-05-14", "2025-05-15", "2025-05-16", "2025-05-19", "2025-05-20",
             "2025-05-21", "2025-05-22", "2025-05-23", "2025-05-26", "2025-05-27", "2025-05-28", "2025-05-29",
-            "2025-05-30", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06", "2025-06-09"]
+            "2025-05-30", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06", "2025-06-09", "2025-06-10"]
     days.reverse()
     for day in days:
         if day not in back_test_dict:
diff --git "a/strategy/\344\275\216\345\220\270\350\204\232\346\234\254_\350\276\250\350\257\206\345\272\246_v6.py" "b/strategy/\344\275\216\345\220\270\350\204\232\346\234\254_\350\276\250\350\257\206\345\272\246_v6.py"
index 8757c61..6ef315a 100644
--- "a/strategy/\344\275\216\345\220\270\350\204\232\346\234\254_\350\276\250\350\257\206\345\272\246_v6.py"
+++ "b/strategy/\344\275\216\345\220\270\350\204\232\346\234\254_\350\276\250\350\257\206\345\272\246_v6.py"
@@ -27,6 +27,13 @@
         if target_code.find("60") != 0 and target_code.find("00") != 0 and target_code.find("30") != 0:
             return False, "绉戝垱鏉跨殑绁ㄤ笉涔�"
 
+    if sv.鏉垮潡鎴愪氦浠g爜:
+        deal_codes = set()
+        for p in sv.鏉垮潡鎴愪氦浠g爜:
+            deal_codes |= set(sv.鏉垮潡鎴愪氦浠g爜[p])
+        if len(deal_codes) >= settings.max_buy_codes_count:
+            return False, f"涔板叆浠g爜鏁拌秴闄�({len(deal_codes)}/{settings.max_buy_codes_count})"
+
     # 鐩爣绁ㄦ澘鍧楁定鍋滀釜鏁�>=2
     can_buy_plates = set()
     for plate in sv.浠g爜鏉垮潡:
@@ -142,10 +149,9 @@
 
     limit_up_codes_count = max([(p, len(sv.寮�鐩樺暒鏈�姝f澘鍧楁定鍋�.get(p, []))) for p in can_buy_plates], key=lambda x: x[1])[1]
 
-    threshold_money *= max(min(10 - limit_up_codes_count + 3, 10), 5)/10
+    threshold_money *= max(min(10 - limit_up_codes_count + 1, 10), 5) / 10
 
     # print(target_code, sv.鑷敱娴侀�氬競鍊�, threshold_money, limit_up_codes_count)
-
 
     # threshold_money = 200e4  # int(sv.鏄ㄦ棩鎴愪氦閲� * 0.2 * sv.浠婃棩娑ㄥ仠浠� * 0.05)
     if big_order_money < threshold_money:

--
Gitblit v1.8.0