From 9d39b293bde97f31f522010373aad1dd3f654c07 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 25 七月 2024 17:23:07 +0800
Subject: [PATCH] 策略修改

---
 trade/trade_manager.py |    3 +++
 trade/buy_strategy.py  |   38 ++++++++++++++++++++++----------------
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/trade/buy_strategy.py b/trade/buy_strategy.py
index 6013f9d..94fc4c8 100644
--- a/trade/buy_strategy.py
+++ b/trade/buy_strategy.py
@@ -88,21 +88,25 @@
         """
 
         def can_buy_for_stategy_1():
-            # 鑾峰彇2绉掑唴鍚冪殑妗f暟
-            rised_price,  msg = self.__get_rised_price(code, info)
-            limit_up_price = self.__limit_up_price_dict.get(code)
-            threshold_rate_money = round(0.8*float(limit_up_price)/100, 2)
-            if rised_price < threshold_rate_money:
-                return False, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, f"2S鍐呮定骞呭皬浜巤int(threshold_rate_money*100)}妗�"
-            pre_close_price = self.__pre_close_price_dict.get(code)
-            if pre_close_price is None:
-                return False, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, "娌℃湁鑾峰彇鍒版敹鐩樹环"
-            rate = (info["TradePrice"] - pre_close_price) / pre_close_price
-            if code.find("30") == 0 and rate >= 0.19:
-                return True, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, f"2S鍐呬笂鍗噞int(rised_price * 100)}妗�({msg})  娑ㄥ箙({rate})>19% "
-            if code.find("30") != 0 and rate >= 0.09:
-                return True, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, f"2S鍐呬笂鍗噞int(rised_price * 100)}妗�({msg})  娑ㄥ箙({rate})>9%"
-            return False, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, f"涓嶆弧瓒充拱鍏ユ潯浠�"
+            try:
+                limit_up_price = self.__limit_up_price_dict.get(code)
+                threshold_rate_money = round(0.8 * float(limit_up_price) / 100, 2)
+
+                min_price = None
+                pre_close_price = self.__pre_close_price_dict.get(code)
+                if pre_close_price:
+                    min_price = round( (1 + (0.07 if tool.is_shsz_code(code) else 0.17))*pre_close_price, 2)
+                # 鑾峰彇2绉掑唴鍚冪殑妗f暟
+                rised_price, msg = self.__get_rised_price(code, info, min_price=min_price)
+                if rised_price < threshold_rate_money:
+                    return False, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, f"2S鍐呮定骞呭皬浜巤int(threshold_rate_money*100)}妗�"
+                pre_close_price = self.__pre_close_price_dict.get(code)
+                if pre_close_price is None:
+                    return False, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, "娌℃湁鑾峰彇鍒版敹鐩樹环"
+                rate = (info["TradePrice"] - pre_close_price) / pre_close_price
+                return True, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, f"2S鍐呬笂鍗噞int(rised_price * 100)}妗�({msg})"
+            except Exception as e:
+                logger_trade.error(f"涔板叆绛栫暐1鍑洪敊锛歿code} - {str(e)}")
 
         def can_buy_for_stategy_2():
             if code.find("30") == 0 and False:
@@ -143,7 +147,7 @@
 
         return [can_buy_for_stategy_1(), can_buy_for_stategy_2(), can_buy_for_stategy_3()]
 
-    def __get_rised_price(self, code, transaction_info, time_space=2000):
+    def __get_rised_price(self, code, transaction_info, time_space=2000, min_price = None):
         """
         鑾峰彇鎸囧畾鏃堕棿鍐呰偂浠蜂笂鍗囩殑浠锋牸
         :param code:
@@ -169,6 +173,8 @@
                 if self.__latest_transaction_price_dict[code]:
                     # 鍒犻櫎绗竴涓厓绱�
                     self.__latest_transaction_price_dict[code].pop(0)
+        if min_price and self.__latest_transaction_price_dict[code][0][0]< min_price:
+            return 0, f"{self.__latest_transaction_price_dict[code]}"
         return self.__latest_transaction_price_dict[code][-1][0] - self.__latest_transaction_price_dict[code][0][0], f"{self.__latest_transaction_price_dict[code]}"
 
 
diff --git a/trade/trade_manager.py b/trade/trade_manager.py
index 43c1ee4..81bc85c 100644
--- a/trade/trade_manager.py
+++ b/trade/trade_manager.py
@@ -2,6 +2,8 @@
 浜ゆ槗绠$悊
 """
 from db.redis_manager_delegate import RedisManager, RedisUtils
+from log_module import async_log_util
+from log_module.log import logger_trade
 from utils import constant, tool
 
 
@@ -38,6 +40,7 @@
 
     # 璁剧疆浜ゆ槗鐘舵��
     def set_trade_state(self, code, strategy_type, state):
+        async_log_util.info(logger_trade, f"set_trade_state: {code}-{strategy_type}-{state}")
         k = f"{code}-{strategy_type}"
         self.__trade_state_cache[k] = state
         RedisUtils.setex_async(constant.REDIS_DB, f"trade_state-{k}", tool.get_expire(), state)

--
Gitblit v1.8.0