| | |
| | | 激进买数据管理 |
| | | """ |
| | | import json |
| | | import logging |
| | | import time |
| | | |
| | | import constant |
| | |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2.l2_transaction_data_manager import BigOrderDealManager, HuaXinBuyOrderManager |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_l2_radical_buy, logger_debug |
| | | from log_module.log import logger_l2_radical_buy, logger_debug, logger_l2_radical_buy_data |
| | | from third_data import kpl_data_manager, kpl_block_util, huaxin_l1_data_manager, kpl_util, kpl_data_constant |
| | | from third_data.code_plate_key_manager import TargetCodePlateKeyManager, KPLCodeJXBlockManager |
| | | from third_data.kpl_data_constant import LimitUpDataConstant, LimitUpCodesBlockRecordManager |
| | | from third_data.kpl_data_manager import CodeHighLevel |
| | | from third_data.third_blocks_manager import BlockMapManager |
| | | from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager |
| | | from trade.order_statistic import DealAndDelegateWithBuyModeDataManager |
| | |
| | | @param total_sell_volume: 总卖量 |
| | | @return: 是否可以买, 原因 |
| | | """ |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | k_format = None |
| | | if not constant.TEST: |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if k_format: |
| | | if not k_format[13]: |
| | | return False, "近60个交易日无涨停" |
| | |
| | | if not zylt_can_buy: |
| | | return False, "自由流通市值不满足扫的范围" |
| | | # 判断昨日是否跌幅过大 |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if k_format and len(k_format) > 12 and k_format[12]: |
| | | return False, "上个交易日跌幅过大" |
| | | |
| | |
| | | |
| | | if is_refered: |
| | | # 参考票没有大单 |
| | | volume_rate = code_volumn_manager.CodeVolumeManager().get_volume_rate(code, with_info=False) |
| | | volume_rate = None |
| | | if not constant.TEST: |
| | | volume_rate = code_volumn_manager.CodeVolumeManager().get_volume_rate(code, with_info=False) |
| | | if volume_rate is None: |
| | | volume_rate = 0.5 |
| | | big_order_deal_enough = is_big_order_deal_enough(code, volume_rate) |
| | | big_order_deal_enough = True, "", True |
| | | if not constant.TEST: |
| | | big_order_deal_enough = is_big_order_deal_enough(code, volume_rate) |
| | | if not big_order_deal_enough[0] and big_order_deal_enough[2]: |
| | | return False, "交易前两分钟大单不足" |
| | | |
| | |
| | | # 过滤 |
| | | blocks = BlockMapManager().filter_blocks(blocks) |
| | | # 开1剔除4板以上的 |
| | | high_level = kpl_util.get_high_level_count(d[4]) |
| | | high_level = CodeHighLevel().get_high_level(code) |
| | | if high_level >= 4: |
| | | continue |
| | | temp_dict[code] = (high_level, blocks) |
| | |
| | | continue |
| | | |
| | | # 剔除4板以上的板 |
| | | if kpl_util.get_high_level_count(k[4]) >= 4 and len(blocks) > 1: |
| | | if CodeHighLevel().get_high_level(_code) >= 4 and len(blocks) > 1: |
| | | continue |
| | | |
| | | if not tool.is_can_buy_code(_code): |
| | |
| | | if block not in blocks: |
| | | continue |
| | | # 剔除4板以上且板块数量大于1个 |
| | | if kpl_util.get_high_level_count(k[12]) >= 4 and len(blocks) > 1: |
| | | if CodeHighLevel().get_high_level(_code) >= 4 and len(blocks) > 1: |
| | | continue |
| | | |
| | | if not tool.is_can_buy_code(_code): |
| | |
| | | yesterday_limit_up_codes, |
| | | exclude_codes=exclude_codes) |
| | | # 过滤不正的原因 |
| | | history_index, history_before_codes_info = cls.__filter_before_codes(block, history_index, |
| | | history_index, history_before_codes_info = cls.__filter_before_codes(code, block, history_index, |
| | | history_before_codes_info, |
| | | yesterday_limit_up_codes) |
| | | |
| | |
| | | return False, f"开1数量:{count},非开1首板身位不匹配:历史-{history_index + 1} 实时-{current_index + 1}" |
| | | if history_index == 1: |
| | | # 当前代码为老2,要判断老大是否可买 |
| | | if RadicalBuyDataManager.is_code_can_buy(history_before_codes_info[0][0], |
| | | pre_code = history_before_codes_info[0][0] |
| | | if RadicalBuyDataManager.is_code_can_buy(pre_code, |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes(), |
| | | is_refered=True)[0]: |
| | | return False, f"开1数量:{count},前排代码可买:{history_before_codes_info[0]}" |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | if pre_code in deal_codes: |
| | | return False, f"开1数量:{count},前排代码已成交:{history_before_codes_info[0]}" |
| | | else: |
| | | 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}" |
| | | return True, f"开1数量:{count},历史-{history_index + 1} 实时-{current_index + 1}, 前排代码-{current_before_codes_info},开1代码-{open_limit_up_block_codes}" |
| | | |
| | | @classmethod |
| | | def __filter_before_codes(cls, block, index, before_codes_info, yesterday_codes): |
| | | def __filter_before_codes(cls, code, block, index, before_codes_info, yesterday_codes): |
| | | """ |
| | | 过滤前排涨停原因不正/不算身位的代码 |
| | | @param code: |
| | |
| | | temp_index -= 1 |
| | | else: |
| | | temp_before_codes_info.append(b) |
| | | if temp_index != index: |
| | | async_log_util.info(logger_l2_radical_buy_data, |
| | | f"【板块前排代码过滤】#{code}#{block}#{(index, before_codes_info)}#{(temp_index, temp_before_codes_info)}") |
| | | |
| | | return temp_index, temp_before_codes_info |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | async_log_util.error(logger_debug, f"扫入板块过滤出错:{str(e)}") |
| | | return index, before_codes_info |
| | | |
| | |
| | | # 获取当前代码的涨停时间 |
| | | limit_up_timestamp = cls.__get_limit_up_timestamp(code) |
| | | |
| | | # 获取当前的板块 |
| | | # 获取当前的板块, 不要忽略开1的数据 |
| | | current_index, current_before_codes_info = cls.__get_current_index(code, block, set(), |
| | | limit_up_time=limit_up_timestamp) |
| | | limit_up_time=limit_up_timestamp, |
| | | ignore_open_limit_up=False) |
| | | current_before_codes = [x[0] for x in current_before_codes_info] |
| | | |
| | | if len(current_before_codes_info) < 2: |
| | |
| | | return False, f"距离上个代码涨停已过去10分钟({current_before_codes_info[-1]})" |
| | | |
| | | # 包含高位板的整体排序 |
| | | all_history_index, all_history_before_codes_info = cls.__get_history_index(code, block, set()) |
| | | all_history_index, all_history_before_codes_info = cls.__get_history_index(code, block, set(), |
| | | ignore_open_limit_up=False) |
| | | all_history_before_codes = [x[0] for x in all_history_before_codes_info] |
| | | # 前两个代码是否有炸板 |
| | | dif_codes = set(all_history_before_codes[:2]) - set(current_before_codes[:2]) |
| | | if dif_codes: |
| | | return False, f"前2代码有炸板:{dif_codes}, 前排代码:{all_history_before_codes}" |
| | | # 前排代码炸板不能>=2个 |
| | | dif_codes = set(all_history_before_codes) - set(current_before_codes) |
| | | if len(dif_codes) >= 2: |
| | | return False, f"板块前排有{len(dif_codes)}个炸板" |
| | | if not constant.TEST: |
| | | # 前两个代码是否有炸板 |
| | | dif_codes = set(all_history_before_codes[:2]) - set(current_before_codes[:2]) |
| | | if dif_codes: |
| | | return False, f"前2代码有炸板:{dif_codes}, 前排代码:{all_history_before_codes}" |
| | | # 前排代码炸板不能>=2个 |
| | | dif_codes = set(all_history_before_codes) - set(current_before_codes) |
| | | if len(dif_codes) >= 2: |
| | | return False, f"板块前排有{len(dif_codes)}个炸板" |
| | | |
| | | exclude_codes = set() |
| | | for x in current_before_codes_info: |
| | |
| | | exclude_codes) |
| | | |
| | | # 过滤不正的原因 |
| | | history_index, history_before_codes_info = cls.__filter_before_codes(block, origin_history_index, |
| | | history_index, history_before_codes_info = cls.__filter_before_codes(code, block, origin_history_index, |
| | | origin_history_before_codes_info, |
| | | yesterday_limit_up_codes) |
| | | |
| | |
| | | if RadicalBuyDataManager.is_code_can_buy(pre_code, |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes(), |
| | | is_refered=True)[0]: |
| | | # TODO 前排代码可买而没有买成功的可继续下单 |
| | | # 前排代码可买而没有买成功的可继续下单 |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | if pre_code in deal_codes: |
| | | return False, f"前排代码已成交:{pre_code}" |
| | |
| | | diff = history_codes - current_codes |
| | | if diff: |
| | | return False, f"板块炸板不止当前票:{diff}" |
| | | return True, "" |
| | | return True, f"历史涨停:{history_codes}" |
| | | |
| | | @classmethod |
| | | def __get_limit_up_timestamp(cls, code): |
| | |
| | | """ |
| | | # 计算 |
| | | # 获取开1的板块 |
| | | |
| | | open_limit_up_code_dict = kpl_data_constant.open_limit_up_code_dict_for_radical_buy |
| | | open_limit_up_blocks = set() |
| | | if open_limit_up_code_dict: |
| | |
| | | def __load_data(cls): |
| | | val = RedisUtils.get(cls.__get_redis(), "radical_place_order_block_records") |
| | | if val: |
| | | val = json.loads(val) |
| | | for v in val: |
| | | cls.__block_record_codes_dict[v[0]] = set(v[1]) |
| | | cls.__codes |= set(v[1]) |
| | | try: |
| | | val = json.loads(val) |
| | | for v in val: |
| | | cls.__block_record_codes_dict[v[0]] = set(v[1]) |
| | | cls.__codes |= set(v[1]) |
| | | except: |
| | | pass |
| | | |
| | | def add_record(self, code, blocks): |
| | | """ |
| | |
| | | @return: |
| | | """ |
| | | reasons = set() |
| | | limit_up_reason = None |
| | | # 当前的涨停原因 |
| | | limit_up_reason = kpl_data_manager.LimitUpDataConstant.get_limit_up_reason_with_history(code) |
| | | if limit_up_reason and limit_up_reason in constant.KPL_INVALID_BLOCKS: |
| | | limit_up_reason = None |
| | | # limit_up_reason = kpl_data_manager.LimitUpDataConstant.get_limit_up_reason_with_history(code) |
| | | # if limit_up_reason and limit_up_reason in constant.KPL_INVALID_BLOCKS: |
| | | # limit_up_reason = None |
| | | # 如果涨停原因为空就需要获取上次激进买的原因 |
| | | if limit_up_reason: |
| | | reasons.add(limit_up_reason) |