From 02166225b34a7ec2c41dc8eda77c431465b8d9dd Mon Sep 17 00:00:00 2001
From: admin <admin@example.com>
Date: 星期一, 24 三月 2025 13:55:50 +0800
Subject: [PATCH] bug修改

---
 strategy/account_management.py          |   11 +++--
 strategy/local_data_management.py       |   41 ++++++++++++++++++++
 strategy/index_market_trend_strategy.py |    2 
 strategy/kpl_api.py                     |    2 
 main.py                                 |   23 +++++++----
 strategy/order_methods.py               |    5 ++
 strategy/data_cache.py                  |   26 +++++++------
 7 files changed, 82 insertions(+), 28 deletions(-)

diff --git a/main.py b/main.py
index 5f5344b..154134c 100644
--- a/main.py
+++ b/main.py
@@ -18,7 +18,8 @@
 # 寮曞叆鍘嗗彶K绾挎柟娉曟ā鍧�
 # 寮曞叆鐬椂鍒嗘椂琛屾儏妯″潡
 # 寮曞叆璐︽埛绠$悊妯″潡銆愯繘琛岃祫閲戝拰浠撲綅绠$悊銆�
-from strategy import kpl_api, data_cache, check_timer, all_K_line, instant_time_market, account_management, order_methods
+from strategy import kpl_api, data_cache, check_timer, all_K_line, instant_time_market, account_management, \
+    order_methods, local_data_management
 from huaxin_client import l2_market_client
 from log_module import async_log_util
 from trade import huaxin_trade_data_update
@@ -53,6 +54,8 @@
     account_management.position_management()
     # 鍒濆鍖�.瀹炰緥鍖栫紦瀛樹腑鐨勫叏灞�鏁版嵁
     data_cache.DataCache()
+    # 璇诲彇鏈湴K绾挎暟鎹� 骞舵洿鏂板埌data_cache
+
     # 鍒濆鍖朅鑲℃墍鏈夌洰鏍囩エ鏍囩殑淇℃伅
     data_cache.all_stocks = utils.juejin_api.JueJinApi.get_target_codes()
     # 鑾峰彇鐩爣鏍囩殑K绾�---鍒濆鍖�
@@ -61,13 +64,17 @@
 
     # 鐩存帴璋冪敤鐩爣鏍囩殑鎸囨爣K绾垮啓鍏ユ湰鍦版枃浠�
     # all_K_line.all_stocks_all_k_line_dict_write()
+    local_data_management.read_local_K_line_data()
+    # 璇诲彇鏈湴涓偂鎵�灞炴澘鍧楁暟鎹� 骞舵洿鏂板埌data_cache
+    local_data_management.read_local_all_stocks_plate_data()
 
-    # 鍏堜娇鐢╦son.load()鐩存帴浠庢枃浠朵腑璇诲彇銆愬凡缁忓瓨鍌ㄥ湪鏈湴鐨凨绾挎寚鏍囧睘鎬у瓧鍏搞�戝苟瑙f瀽JSON鏁版嵁
-    if os.path.exists(constant.K_BARS_PATH):
-        with open(constant.K_BARS_PATH, 'r', encoding='utf-8') as f:
-            data_cache.all_stocks_all_K_line_property_dict = json.load(f)
-            print(
-                f"data_cache.all_stocks_all_K_line_property_dict鐨勪釜鏁�==={len(data_cache.all_stocks_all_K_line_property_dict)}")
+    # todo 2025-03-25 娴嬭瘯鏃犺鍗冲彲鍒犻櫎涓嬮儴娉ㄩ噴
+    # # 鍏堜娇鐢╦son.load()鐩存帴浠庢枃浠朵腑璇诲彇銆愬凡缁忓瓨鍌ㄥ湪鏈湴鐨凨绾挎寚鏍囧睘鎬у瓧鍏搞�戝苟瑙f瀽JSON鏁版嵁
+    # if os.path.exists(constant.K_BARS_PATH):
+    #     with open(constant.K_BARS_PATH, 'r', encoding='utf-8') as f:
+    #         data_cache.all_stocks_all_K_line_property_dict = json.load(f)
+    #         print(
+    #             f"data_cache.all_stocks_all_K_line_property_dict鐨勪釜鏁�==={len(data_cache.all_stocks_all_K_line_property_dict)}")
 
     # # 鑾峰彇鐩爣鏍囩殑K绾�---鍒濆鍖�
     # all_K_line.main_index_k_line_history.init(data_cache.DataCache().today_date, data_cache.DataCache().next_trading_day, data_cache.DataCache().main_index_stocks)
@@ -172,7 +179,7 @@
     huaxin_trade_data_update.run()
 
     # 绛夊緟5s锛岀瓑鍏朵粬绾跨▼/杩涚▼鍚姩瀹屾瘯
-    time.sleep(5)
+    time.sleep(15)
 
     try:
         # 鍒濆鍖栨暟鎹�
diff --git a/strategy/account_management.py b/strategy/account_management.py
index 1e42c3f..13ef8fa 100644
--- a/strategy/account_management.py
+++ b/strategy/account_management.py
@@ -84,17 +84,18 @@
             if currentPosition != 0:
                 # 褰撳墠鎸佷粨
                 # print(f"褰撳墠鎸佷粨=={securityName}")
-                if availablePosition != 0 and historyPosFrozen != 0:  # 濡傛灉 鍙敤璧勯噾 鍜� 鏄ㄤ粨鍐荤粨 閮戒笉绛変簬0  鏄ㄦ棩鏀剁洏浠疯幏鍙栧埌闈�0鍊兼椂锛堜笉鐭ュ悕鍘熷洜瀵艰嚧鏈変簺绁ㄤ細鑾峰彇鍒�0鍊煎鑷村悗缁叕寮忔姤閿欙紝闃绘intraday_growth鍑芥暟姝e父杩愯锛�
+                # 濡傛灉 鍙敤浠撲綅绛変簬0 涓� 鏄ㄤ粨鍐荤粨(鎸傚崟濮旀墭涓�)绛変簬0  鏄ㄦ棩鏀剁洏浠疯幏鍙栧埌闈�0鍊兼椂锛堜笉鐭ュ悕鍘熷洜瀵艰嚧鏈変簺绁ㄤ細鑾峰彇鍒�0鍊煎鑷村悗缁叕寮忔姤閿欙紝闃绘intraday_growth鍑芥暟姝e父杩愯锛�
+                if availablePosition == 0 and historyPosFrozen == 0:
+                    # 鏂板鎸佷粨
+                    logger.info(f"浠婃棩鏂板鎸佷粨==={securityName}")
+                    data_cache.addition_position_symbols_set.add(securityID)
+                else:
                     data_cache.available_symbols_set.add(securityID)
                     if historyPosFrozen != 0:
                         logger.info(f"鏄ㄦ棩鎸佷粨==={securityName}==鎸傚崟涓�嬨�嬫寕鍗曟暟閲忥細{historyPosFrozen}")
                     else:
                         logger.info(f"鏄ㄦ棩鎸佷粨==={securityName}===鎸佷粨鍙敤锛歿availablePosition}")
 
-                else:
-                    # 鏂板鎸佷粨
-                    logger.info(f"浠婃棩鏂板鎸佷粨==={securityName}")
-                    data_cache.addition_position_symbols_set.add(securityID)
         # todo 鑷富鐨勮绠楁寔浠撴暟閲� 绠$敤 杩樻槸 鏈嶅姟绔嵆鏃舵煡璇㈠悓姝ユ湁鐢� 鏈夊緟楠岃瘉
         logger.info(f"浠婃棩鍙敤鎸佷粨鏁伴噺====================================銆恵len(data_cache.available_symbols_set)}銆�")
         logger.info(
diff --git a/strategy/data_cache.py b/strategy/data_cache.py
index 282250b..74b5a8e 100644
--- a/strategy/data_cache.py
+++ b/strategy/data_cache.py
@@ -132,16 +132,17 @@
 UPDATE_DATA_TIME = datetime.time(18, 31, 00).strftime("%H:%M:%S")  # 瀹氫箟鏇存柊鏁版嵁鏃堕棿
 PROGRAM_SLEEP_TIME = datetime.time(23, 00, 00).strftime("%H:%M:%S")  # 瀹氫箟绋嬪簭浼戠湢鏃堕棿
 
-# 璇诲彇宸茬粡鑾峰彇鍒板苟瀛樺偍鍦ㄦ湰鍦扮殑鐩爣鑼冨洿鐨勪釜鑲$殑鏉垮潡姒傚康
-# 璇诲彇JSON鏂囦欢骞惰В鏋愪负瀛楀吀
-if os.path.exists(constant.ALL_STOCKS_PLATE_PATH):
-    with open(constant.ALL_STOCKS_PLATE_PATH, 'r',
-              encoding='utf-8') as f:
-        json_data = f.read()
-else:
-    json_data = "{}"
-all_stocks_plate_dict = json.loads(json_data)
-logger.info(f"all_stocks_plate_dict鐨勬暟閲�={len(all_stocks_plate_dict)}")
+# todo 2025-03-25 鍚庢棤BUG鍗冲彲褰诲簳鍒犻櫎涓嬪娉ㄩ噴閮ㄥ垎
+# # 璇诲彇宸茬粡鑾峰彇鍒板苟瀛樺偍鍦ㄦ湰鍦扮殑鐩爣鑼冨洿鐨勪釜鑲$殑鏉垮潡姒傚康
+# # 璇诲彇JSON鏂囦欢骞惰В鏋愪负瀛楀吀
+# if os.path.exists(constant.ALL_STOCKS_PLATE_PATH):
+#     with open(constant.ALL_STOCKS_PLATE_PATH, 'r',
+#               encoding='utf-8') as f:
+#         json_data = f.read()
+# else:
+#     json_data = "{}"
+# all_stocks_plate_dict = json.loads(json_data)
+# logger.info(f"all_stocks_plate_dict鐨勬暟閲�={len(all_stocks_plate_dict)}")
 
 # 鍒濆鍖栧綋鏃ュ綋鏃舵渶楂樹环
 high_price = 0
@@ -165,8 +166,10 @@
 # 鍒濆鍖栧疄鏃跺ぇ鐩樿鎯呮儏缁患鍚堝己搴﹀垎鏃跺垪琛�
 time_sharing_market_strong_dirt = {}
 
-# 涓篕绾垮睘鎬ф寚鏍囧瓧鍏稿垵濮嬪寲
+# 涓烘墍鏈変釜鑲$殑甯﹀睘鎬绾� 瀛楀吀鍒濆鍖�
 all_stocks_all_K_line_property_dict = {}
+# 涓烘寚鏁扮殑甯﹀睘鎬绾� 瀛楀吀鍒濆鍖�
+all_index_k_line_property_dict = {}
 # 澹版槑K绾垮睘鎬т腑鎵�鏈夋定鍋滅被鍨�
 limit_up_type = ['one_line_limit_up', 'limit_down_then_limit_up', 'limit_up_then_limit_down_then_limit_up',
                  'limit_up']
@@ -175,7 +178,6 @@
 # 澹版槑K绾垮睘鎬т腑鎵�鏈夌偢鏉跨被鍨�
 frying_plate_type = ['frying_plate', 'first_frying_plate', 'one_line_limit_up_then_frying_plate',
                      'one_line_limit_up_then_frying_plate_then_limit_down', 'not_first_frying_plate']
-
 # 瀹氫箟涓�涓綋鏃ュ垎鏃跺唴鎵�鏈変釜鑲$殑寮�鐩樹环瀛楀吀
 all_stocks_current_open = {}
 # 瀹氫箟涓�涓綋鏃ュ垎鏃跺唴鎵�鏈変釜鑲$殑瀹炴椂鏈�楂樹环鍜屾渶浣庝环瀛楀吀
diff --git a/strategy/index_market_trend_strategy.py b/strategy/index_market_trend_strategy.py
index 95d4873..32f6379 100644
--- a/strategy/index_market_trend_strategy.py
+++ b/strategy/index_market_trend_strategy.py
@@ -143,6 +143,7 @@
     else:
         index_composite_tick_increase = '涓夊ぇ鎸囨暟锛氭定璺屼笉涓�'
     logger.info(f"寮�鐩樻寚鏁板紑鐩樼灛鏃惰蛋鍔挎挱鎶ワ細{index_composite_tick_increase}")
+    logger.info(f"鎸囨暟甯﹀睘鎬绾挎暟鎹殑鏄ㄦ棩鏄惁涓虹┖:{data_cache.all_index_k_line_property_dict['000001'][0]}")
     return index_trend_expectation_score
 
 
@@ -396,7 +397,6 @@
     except Exception as error:
         print(f"An error occurred while converting the data to JSON: {error}")
     logger.info(f"鍔犲睘鎬х殑鎸囨暟k绾垮啓瀹屼簡锛亄tool.get_now_time_str()}")
-
 
 if __name__ == '__main__':
     # all_index_K_line_dict = get_index_K_line()
diff --git a/strategy/kpl_api.py b/strategy/kpl_api.py
index fc65270..4ff40b8 100644
--- a/strategy/kpl_api.py
+++ b/strategy/kpl_api.py
@@ -741,7 +741,7 @@
         try:
             if data_cache.position_automatic_management_switch is True:
                 now_time = tool.get_now_time_str()
-                if data_cache.SERVER_RESTART_TIME < now_time < data_cache.UPDATE_DATA_TIME:
+                if data_cache.L1_DATA_START_TIME < now_time < data_cache.UPDATE_DATA_TIME:
                     # 鑾峰彇澶х洏缁煎悎寮哄害鍒嗘暟
                     data_cache.real_time_market_strong = get_market_strong()
                     # data_cache.time_sharing_market_strong_dirt = time_sharing_market_strong_dirt.update({now: data_cache.real_time_market_strong})
diff --git a/strategy/local_data_management.py b/strategy/local_data_management.py
new file mode 100644
index 0000000..2c62064
--- /dev/null
+++ b/strategy/local_data_management.py
@@ -0,0 +1,41 @@
+import json
+import os
+
+import constant
+from strategy import data_cache
+
+
+from log_module.log import logger_common
+# 鑾峰彇logger瀹炰緥
+logger = logger_common
+
+
+# 璇诲彇鏈湴鐨勬墍鏈夊甫灞炴�绾挎暟鎹紙鎵�鏈変釜鑲绾垮強鎸囨暟绾匡級
+def read_local_K_line_data():
+    # 鍏堜娇鐢╦son.load()鐩存帴浠庢枃浠朵腑璇诲彇銆愬凡缁忓瓨鍌ㄥ湪鏈湴鐨凨绾挎寚鏍囧睘鎬у瓧鍏搞�戝苟瑙f瀽JSON鏁版嵁
+    if os.path.exists(constant.K_BARS_PATH):
+        with open(constant.K_BARS_PATH, 'r', encoding='utf-8') as f:
+            data_cache.all_stocks_all_K_line_property_dict = json.load(f)
+            print(
+                f"data_cache.all_stocks_all_K_line_property_dict鐨勪釜鏁�==={len(data_cache.all_stocks_all_K_line_property_dict)}")
+
+    # 鍏堜娇鐢╦son.load()鐩存帴浠庢枃浠朵腑璇诲彇銆愬凡缁忓瓨鍌ㄥ湪鏈湴鐨凨绾挎寚鏍囧睘鎬у瓧鍏搞�戝苟瑙f瀽JSON鏁版嵁
+    if os.path.exists(constant.INDEX_K_BARS_PATH):
+        with open(constant.INDEX_K_BARS_PATH, 'r', encoding='utf-8') as f:
+            data_cache.all_index_k_line_property_dict = json.load(f)
+            print(
+                f"data_cache.all_stocks_all_K_line_property_dict鐨勪釜鏁�==={len(data_cache.all_index_k_line_property_dict)}")
+
+
+# 璇诲彇鏈湴鐨勪釜鑲℃墍灞炴蹇垫澘鍧楁暟鎹�
+def read_local_all_stocks_plate_data():
+    # 璇诲彇宸茬粡鑾峰彇鍒板苟瀛樺偍鍦ㄦ湰鍦扮殑鐩爣鑼冨洿鐨勪釜鑲$殑鏉垮潡姒傚康
+    # 璇诲彇JSON鏂囦欢骞惰В鏋愪负瀛楀吀
+    if os.path.exists(constant.ALL_STOCKS_PLATE_PATH):
+        with open(constant.ALL_STOCKS_PLATE_PATH, 'r',
+                  encoding='utf-8') as f:
+            json_data = f.read()
+    else:
+        json_data = "{}"
+    all_stocks_plate_dict = json.loads(json_data)
+    logger.info(f"all_stocks_plate_dict鐨勬暟閲�={len(all_stocks_plate_dict)}")
\ No newline at end of file
diff --git a/strategy/order_methods.py b/strategy/order_methods.py
index 5388bd6..6a9a1b0 100644
--- a/strategy/order_methods.py
+++ b/strategy/order_methods.py
@@ -25,7 +25,10 @@
         # 鏆傚仠鑷姩涔�
         logger.info(f"鍦ㄤ氦鏄撴柟娉曞嚱鏁板 鍏抽棴浜� 鑷姩涔�")
         return
-
+    if current_price < 3 or current_price > 50:
+        # 褰撳墠鍗曚环瓒呭嚭棰勮闄愬埗
+        logger.info(f"褰撳墠鏍囩殑涓偂{sec_name}鍗曚环瓒呭嚭棰勮闄愬埗锛侀璁惧��3 < current_price < 50,褰撳墠鏈�鏂颁环{current_price}")
+        return
     price = round(float(current_price), 2)
     volume = (int(buy_order_value / price) // 100) * 100
     if volume < 100:

--
Gitblit v1.8.0