Administrator
2024-07-25 9d39b293bde97f31f522010373aad1dd3f654c07
策略修改
2个文件已修改
41 ■■■■■ 已修改文件
trade/buy_strategy.py 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_manager.py 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_strategy.py
@@ -88,21 +88,25 @@
        """
        def can_buy_for_stategy_1():
            # 获取2秒内吃的档数
            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秒内吃的档数
                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]}"
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)