| | |
| | | redis_manager.RedisUtils.setex_async(self.__db, f"market_info_for_radical-{code}", tool.get_expire(), |
| | | json.dumps(info)) |
| | | |
| | | def set_market_info(self, code, time_str, limit_up_price, buy1_info, sell2_info): |
| | | def set_market_info(self, code, time_str, limit_up_price, buy1_info, sell1_info): |
| | | """ |
| | | 设置行情信息 |
| | | @param code: |
| | | @param time_str: 行情时间 |
| | | @param limit_up_price: 涨停价格 |
| | | @param buy1_info: 买1信息 (价格,量) |
| | | @param sell2_info: 卖2信息 (价格,量) |
| | | @param sell1_info: 卖1信息 (价格,量) |
| | | @return: |
| | | """ |
| | | if abs(buy1_info[0] - limit_up_price) < 0.0001: |
| | |
| | | self.__set_code_limit_up_info(code, self.__code_limit_up_info_dict[code]) |
| | | else: |
| | | # 尚未涨停,判断炸板 |
| | | if sell2_info and sell2_info[1] > 0: |
| | | if sell1_info and sell1_info[1] > 0: |
| | | # 出现买2 |
| | | if code in self.__code_limit_up_info_dict: |
| | | if not self.__code_limit_up_info_dict[code][1]: |
| | |
| | | if history_index == 1: |
| | | # 当前代码为老2,要判断老大是否可买 |
| | | pre_code = history_before_codes_info[0][0] |
| | | if RadicalBuyDataManager.is_code_can_buy(pre_code, |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes(), |
| | | is_refered=True)[0]: |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | if pre_code in deal_codes: |
| | | return False, f"开1数量:{count},前排代码已成交:{history_before_codes_info[0]}" |
| | | else: |
| | | if not cls.__is_not_buy_success(pre_code): |
| | | return False, f"开1数量:{count},前排代码未下过单:{pre_code}" |
| | | return True, f"开1数量:{count},前排代码尚未成交:{history_before_codes_info[0]}" |
| | | return True, f"开1数量:{count},前排代码不可买:{history_before_codes_info[0]},历史前排-{history_before_codes_info},开1代码-{open_limit_up_block_codes}" |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | if pre_code in deal_codes: |
| | | return False, f"开1数量:{count},前排代码已成交:{history_before_codes_info[0]}" |
| | | |
| | | # if RadicalBuyDataManager.is_code_can_buy(pre_code, |
| | | # DealAndDelegateWithBuyModeDataManager().get_deal_codes(), |
| | | # is_refered=True)[0]: |
| | | # deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | # if pre_code in deal_codes: |
| | | # return False, f"开1数量:{count},前排代码已成交:{history_before_codes_info[0]}" |
| | | # else: |
| | | # if not cls.__is_not_buy_success(pre_code): |
| | | # return False, f"开1数量:{count},前排代码未下过单:{pre_code}" |
| | | # return True, f"开1数量:{count},前排代码尚未成交:{history_before_codes_info[0]}" |
| | | # return True, f"开1数量:{count},前排代码不可买:{history_before_codes_info[0]},历史前排-{history_before_codes_info},开1代码-{open_limit_up_block_codes}" |
| | | return True, f"开1数量:{count},历史-{history_index + 1} 实时-{current_index + 1}, 前排代码-{current_before_codes_info},开1代码-{open_limit_up_block_codes}" |
| | | |
| | | @classmethod |
| | |
| | | history_index_first, history_before_codes_info_first = cls.__get_history_index(code, block, |
| | | yesterday_limit_up_codes, |
| | | ignore_open_limit_up=False) |
| | | all_history_before_codes = [x[0] for x in history_before_codes_info_first] |
| | | all_first_history_before_codes = [x[0] for x in history_before_codes_info_first] |
| | | if not constant.TEST: |
| | | # 前两个代码是否有炸板 |
| | | # dif_codes = set(all_history_before_codes[:2]) - set(current_before_codes[:2]) |
| | |
| | | # return False, f"前2代码有炸板:{dif_codes}, 前排代码:{all_history_before_codes}" |
| | | # 前排代码炸板不能>=2个 |
| | | # 前排首板代码炸板数量在2个及以上不能买 |
| | | dif_codes = set(all_history_before_codes) - set(current_before_codes) |
| | | dif_codes = set(all_first_history_before_codes) - set(current_before_codes) |
| | | if len(dif_codes) >= 2: |
| | | return False, f"板块前排首板有{len(dif_codes)}个炸板" |
| | | |
| | | # 剔除所有开1的票 |
| | | exclude_codes = set() |
| | | for x in current_before_codes_info: |
| | | for x in all_history_before_codes_info: |
| | | if x[1] < kpl_block_util.open_limit_up_time_range[1]: |
| | | exclude_codes.add(x[0]) |
| | | # 除去前二代码与开1代码之后是否为首板老大:所有开1的视为1个 |
| | | open_count = len(exclude_codes) |
| | | if open_count > 0 and open_count + 1 <= len(current_before_codes): |
| | | # 前排有开1 |
| | | exclude_codes |= set(current_before_codes[open_count:open_count + START_BUY_RANK - 1]) |
| | | # 前排有开1且除开开1之后是首板老大 |
| | | exclude_codes |= set(all_history_before_codes_info[open_count:open_count + START_BUY_RANK]) |
| | | else: |
| | | exclude_codes |= set(current_before_codes[:START_BUY_RANK]) |
| | | |
| | | # 排除首板老大 |
| | | exclude_codes |= set(all_history_before_codes_info[:START_BUY_RANK]) |
| | | # 开1排除 |
| | | open_limit_up_code_dict = kpl_data_constant.open_limit_up_code_dict_for_radical_buy |
| | | if open_limit_up_code_dict: |
| | | exclude_codes |= set(open_limit_up_code_dict.keys()) |
| | |
| | | if history_index == 1: |
| | | # 首板老2,判断前面的老大是否是属于不能买的范畴 |
| | | pre_code = history_before_codes_info[0][0] |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | if pre_code in deal_codes: |
| | | return False, f"前排代码已成交:{pre_code}" |
| | | return True, f"被顺位代码({pre_code}) 尚未成交" |
| | | |
| | | # pre_code不能买,才能买 |
| | | if RadicalBuyDataManager.is_code_can_buy(pre_code, |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes(), |
| | | is_refered=True)[0]: |
| | | # 前排代码可买而没有买成功的可继续下单 |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | if pre_code in deal_codes: |
| | | return False, f"前排代码已成交:{pre_code}" |
| | | # if RadicalBuyDataManager.is_code_can_buy(pre_code, |
| | | # DealAndDelegateWithBuyModeDataManager().get_deal_codes(), |
| | | # is_refered=True)[0]: |
| | | # # 前排代码可买而没有买成功的可继续下单 |
| | | # deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | # if pre_code in deal_codes: |
| | | # return False, f"前排代码已成交:{pre_code}" |
| | | # pre_code不是因为买不进 |
| | | if not cls.__is_not_buy_success(pre_code): |
| | | return False, f"前排代码没下过单:{pre_code}" |
| | | # if not cls.__is_not_buy_success(pre_code): |
| | | # return False, f"前排代码没下过单:{pre_code}" |
| | | |
| | | # 前面一个代码不能买,前一个代码必须与前前个代码涨停时间相差15分钟内 |
| | | for i in range(len(all_history_before_codes_info) - 1, -1, -1): |
| | | if all_history_before_codes_info[i][0] == pre_code: |
| | | if i > 0 and tool.trade_time_sub( |
| | | tool.timestamp_format(all_history_before_codes_info[i][1], '%H:%M:%S'), |
| | | tool.timestamp_format(all_history_before_codes_info[i - 1][1], |
| | | '%H:%M:%S')) >= THRESHOLD_MINUTES * 60: |
| | | return False, f"被顺位代码({pre_code}) 与上个代码涨停时间>={THRESHOLD_MINUTES}分钟 ({all_history_before_codes_info[i]}##{all_history_before_codes_info[i - 1]})" |
| | | else: |
| | | return True, f"被顺位代码({pre_code}) 与上个代码涨停时间<{THRESHOLD_MINUTES}分钟 ({all_history_before_codes_info[i]})" |
| | | return False, f"没找到顺位代码({pre_code})的前排代码" |
| | | # for i in range(len(all_history_before_codes_info) - 1, -1, -1): |
| | | # if all_history_before_codes_info[i][0] == pre_code: |
| | | # if i > 0 and tool.trade_time_sub( |
| | | # tool.timestamp_format(all_history_before_codes_info[i][1], '%H:%M:%S'), |
| | | # tool.timestamp_format(all_history_before_codes_info[i - 1][1], |
| | | # '%H:%M:%S')) >= THRESHOLD_MINUTES * 60: |
| | | # return False, f"被顺位代码({pre_code}) 与上个代码涨停时间>={THRESHOLD_MINUTES}分钟 ({all_history_before_codes_info[i]}##{all_history_before_codes_info[i - 1]})" |
| | | # else: |
| | | # return True, f"被顺位代码({pre_code}) 与上个代码涨停时间<{THRESHOLD_MINUTES}分钟 ({all_history_before_codes_info[i]})" |
| | | # return False, f"没找到顺位代码({pre_code})的前排代码" |
| | | else: |
| | | # 代码为目标代码 |
| | | pass |
| | |
| | | return True, f"满足买入需求: 实时前排代码-{current_before_codes_info} 历史前排代码-{history_before_codes_info}" |
| | | |
| | | @classmethod |
| | | def __is_re_limit_up(cls, code, block): |
| | | def __is_first_can_buy(cls, code, block): |
| | | """ |
| | | 是否是炸板回封可买 |
| | | 老大是否可买:整个板块数量>=2个代码老大可买 |
| | | @param code: |
| | | @param block: |
| | | @return: |
| | |
| | | history_index, history_before_codes_info = cls.__get_history_index(code, block, set()) |
| | | if current_index != history_index: |
| | | return False, f"有其他炸板" |
| | | if current_index > 1: |
| | | return False, f"不是前2的板块" |
| | | if current_index >= 1: |
| | | return False, f"不是板块老大" |
| | | history_codes = set() |
| | | # 获取板块炸板情况 |
| | | for k in LimitUpDataConstant.history_limit_up_datas: |
| | | _code = k[3] |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | | blocks = BlockMapManager().filter_blocks(blocks) |
| | | blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) |
| | | if not blocks: |
| | | blocks = set() |
| | | # 不是这个板块 |
| | | if block in blocks: |
| | | history_codes.add(_code) |
| | | if len(history_codes) < 3: |
| | | return False, f"板块历史涨停小于3个:{history_codes}" |
| | | if len(history_codes) < 2: |
| | | return False, f"板块历史涨停小于2个:{history_codes}" |
| | | # 获取当前涨停数量 |
| | | current_codes = set() |
| | | for k in LimitUpDataConstant.current_limit_up_datas: |
| | | _code = k[0] |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | | if not blocks: |
| | | blocks = set() |
| | | blocks = BlockMapManager().filter_blocks(blocks) |
| | | # 不是这个板块 |
| | | if block in blocks: |
| | | current_codes.add(_code) |
| | | current_codes.add(code) |
| | | diff = history_codes - current_codes |
| | | if diff: |
| | | return False, f"板块炸板不止当前票:{diff}" |
| | | # current_codes = set() |
| | | # for k in LimitUpDataConstant.current_limit_up_datas: |
| | | # _code = k[0] |
| | | # blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) |
| | | # if not blocks: |
| | | # blocks = set() |
| | | # blocks = BlockMapManager().filter_blocks(blocks) |
| | | # # 不是这个板块 |
| | | # if block in blocks: |
| | | # current_codes.add(_code) |
| | | # current_codes.add(code) |
| | | # diff = history_codes - current_codes |
| | | # if diff: |
| | | # return False, f"板块炸板不止当前票:{diff}" |
| | | return True, f"历史涨停:{history_codes}" |
| | | |
| | | @classmethod |
| | |
| | | block_codes = BlockSpecialCodesManager().get_block_codes(block) |
| | | if not block_codes or code not in block_codes: |
| | | return False, "无辨识度" |
| | | history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes) |
| | | history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes, ignore_open_limit_up=False) |
| | | if history_index > 5: |
| | | return False, f"处于首板老{history_index + 1}" |
| | | if history_index >= 4: |
| | | # 判断量是否换够 |
| | | volume_rate = CodeVolumeManager().get_volume_rate_refer_in_5days(code) |
| | | if volume_rate < 0.8: |
| | | return False, f"处于首板老{history_index + 1},量比({volume_rate})<0.8" |
| | | # if history_index >= 4: |
| | | # # 判断量是否换够 |
| | | # volume_rate = CodeVolumeManager().get_volume_rate_refer_in_5days(code) |
| | | # if volume_rate < 0.8: |
| | | # return False, f"处于首板老{history_index + 1},量比({volume_rate})<0.8" |
| | | |
| | | # 前排最多允许1个炸板 |
| | | limit_up_timestamp = cls.__get_limit_up_timestamp(code) |
| | | # 获取当前的板块, 不要忽略开1的数据 |
| | | current_index, current_before_codes_info = cls.__get_current_index(code, block, set(), |
| | | current_index, current_before_codes_info = cls.__get_current_index(code, block, yesterday_limit_up_codes, |
| | | limit_up_time=limit_up_timestamp, |
| | | ignore_open_limit_up=False) |
| | | if history_index - current_index > 1: |
| | |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in keys_: |
| | | result = cls.__is_re_limit_up(code, b) |
| | | result = cls.__is_first_can_buy(code, b) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result[1]}") |