| | |
| | | """ |
| | | |
| | | 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: |
| | |
| | | |
| | | 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: |
| | |
| | | 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]}" |
| | | |
| | | |