| | |
| | | from trade.l2_transaction_data_manager import HuaXinBuyOrderManager |
| | | from utils import tool, l2_huaxin_util |
| | | |
| | | # 涨停买入策略 |
| | | STRATEGY_TYPE_LIMIT_UP = 1 |
| | | # 涨幅高买入策略 |
| | | STRATEGY_TYPE_RISE_HIGH = 2 |
| | | # 涨幅高且有板块的买入策略 |
| | | STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS = 3 |
| | | |
| | | |
| | | class BuyStrategyDataManager: |
| | | __latest_transaction_price_dict = {} |
| | | # 涨停过的代码集合 |
| | | __limit_up_record_codes = set() |
| | | """ |
| | | 买入策略管理 |
| | | """ |
| | |
| | | info['BuyNo'], |
| | | info['SellNo'], info['ExecType'])]) |
| | | if int(l2_huaxin_util.convert_time(info['OrderTime']).replace(":", "")) < int("093000"): |
| | | return False, "09:30之前不下单" |
| | | return False, STRATEGY_TYPE_LIMIT_UP, "09:30之前不下单" |
| | | |
| | | code = info["SecurityID"] |
| | | try: |
| | | can_buy, msg = self.__can_place_order(code, info, backtest) |
| | | return can_buy, msg |
| | | can_buy, stategy_type, msg = self.__can_place_order(code, info, backtest) |
| | | return can_buy, stategy_type, msg |
| | | finally: |
| | | self.__latest_trade_price_dict[code] = info["TradePrice"] |
| | | |
| | |
| | | # 获取2秒内吃的档数 |
| | | rised_price = self.__get_rised_price(code, info) |
| | | if rised_price < 0.1: |
| | | return False, "2S内涨幅小于10档" |
| | | return False, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, "2S内涨幅小于10档" |
| | | pre_close_price = self.__pre_close_price_dict.get(code) |
| | | if pre_close_price is None: |
| | | return False, "没有获取到收盘价" |
| | | return False, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, "没有获取到收盘价" |
| | | |
| | | if (info["TradePrice"] - pre_close_price) / pre_close_price < 0.07: |
| | | return False, "涨幅小于7%" |
| | | return False, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, "涨幅小于7%" |
| | | |
| | | return True, f"2S内上升{int(rised_price * 100)}档" |
| | | return True, STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS, f"2S内上升{int(rised_price * 100)}档" |
| | | else: |
| | | # 判断是否涨停 |
| | | is_limit_up = info["TradePrice"] == self.__limit_up_price_dict.get(code) |
| | | limit_up_price = self.__limit_up_price_dict.get(code) |
| | | if not is_limit_up and code.find("30") == 0: |
| | | # 30开始的9.8以上的算涨停 |
| | | markekt = self.__latest_market_info_dict.get(info[0]) |
| | | if markekt and markekt[2] >= 0.098: |
| | | is_limit_up = True |
| | | limit_up_price = info["TradePrice"] |
| | | |
| | | markekt = self.__latest_market_info_dict.get(info["SecurityID"]) |
| | | if markekt and markekt[2] >= 0.098 and self.__latest_trade_price_dict.get(code): |
| | | # 上一次涨幅小于0.098 |
| | | if (self.__latest_trade_price_dict.get(code) - markekt[8]) / markekt[8] < 0.098: |
| | | return True, STRATEGY_TYPE_RISE_HIGH, f"创业板涨幅超过9.8" |
| | | if is_limit_up: |
| | | # 当前为涨停价 |
| | | if code not in self.__latest_trade_price_dict: |
| | | # 开1 |
| | | # 查询买1金额 |
| | | markekt = self.__latest_market_info_dict.get(info[0]) |
| | | markekt = self.__latest_market_info_dict.get(info["SecurityID"]) |
| | | if markekt and markekt[3] * markekt[4] >= 1e8: |
| | | async_log_util.info(logger_trade, f"{code}:买1({markekt[3] * markekt[4]})超过1亿") |
| | | return True, "买1超过1亿,开1可买" |
| | | return True, STRATEGY_TYPE_LIMIT_UP, "买1超过1亿,开1可买" |
| | | else: |
| | | return False, "开1" |
| | | return False, STRATEGY_TYPE_LIMIT_UP, "开1" |
| | | else: |
| | | if self.__latest_trade_price_dict.get(code) != limit_up_price: |
| | | # 之前那一次不是涨停价 |
| | | return True, "涨停" |
| | | return False, "" |
| | | if self.__latest_trade_price_dict.get(code) != limit_up_price and code not in self.__limit_up_record_codes: |
| | | # 初次涨停之前那一次不是涨停价 |
| | | return True, STRATEGY_TYPE_LIMIT_UP, "涨停" |
| | | |
| | | if is_limit_up: |
| | | # 加入涨停代码列表 |
| | | self.__limit_up_record_codes.add(code) |
| | | |
| | | return False, STRATEGY_TYPE_LIMIT_UP, "" |
| | | |
| | | def __get_rised_price(self, code, transaction_info, time_space=2000): |
| | | """ |