| | |
| | | # 最大的代码价格 |
| | | MAX_CODE_PRICE = 15 if ALL_ACTIVE_BUY else 30 |
| | | MIN_CODE_PRICE = 1 |
| | | MAX_SUBSCRIPT_CODE_PRICE = 30 if ALL_ACTIVE_BUY else 30 |
| | | MAX_SUBSCRIPT_CODE_PRICE = 50 if ALL_ACTIVE_BUY else 50 |
| | | |
| | | # L2数据是否载入完成 |
| | | L2_DATA_IS_LOADED = False |
| | |
| | | if 130100 >= now_time_int >= 112900: |
| | | return False, True, f"11:29:00-13:01:00不能交易" |
| | | |
| | | place_order_count = cls.__PlaceOrderCountManager.get_place_order_count(code) |
| | | if place_order_count > 0 and now_time_int >= 140000: |
| | | return False, True, f"14:00:00不打回封" |
| | | |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | |
| | | if constant.MIN_CODE_PRICE < float(limit_up_price) < constant.MAX_CODE_PRICE: |
| | |
| | | if not cls.__WantBuyCodesManager.is_in_cache(code): |
| | | # if cls.__TradeTargetCodeModeManager.get_mode_cache() == TradeTargetCodeModeManager.MODE_ONLY_BUY_WANT_CODES: |
| | | # return False, True, f"只买想买单中的代码" |
| | | return cls.can_buy_first(code, limit_up_price) |
| | | return cls.can_buy_first_new(code, limit_up_price) |
| | | else: |
| | | return True, False, "在想买单中" |
| | | |
| | |
| | | # if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < volume_rate_thresholds[ |
| | | # 0] and not is_special: |
| | | # return False, True, f"非强势10分钟,非强势主线后排【主线后排】, 满足自由市值,无辨识度,当日量比({cls.volume_rate_info[code][0]})小于{volume_rate_thresholds[0]}" |
| | | return True, False, can_buy_result[2] |
| | | |
| | | @classmethod |
| | | def can_buy_first_new(cls, code, limit_up_price): |
| | | now_timestamp = int(tool.get_now_time_str().replace(":", "")) |
| | | # 判断板块 |
| | | # (可以买的板块列表, 是否是独苗, 消息简介,可买的强势主线, 板块关键词) |
| | | can_buy_result = cls.__get_can_buy_block(code) |
| | | if can_buy_result is None: |
| | | return False, True, "尚未获取到板块信息" |
| | | |
| | | # 是否是强势30分钟 |
| | | is_in_strong_time_30 = now_timestamp <= int("100000") |
| | | |
| | | |
| | | # 获取市场行情 |
| | | situation = cls.__MarketSituationManager.get_situation_cache() |
| | | zylt_threshold_as_yi = buy_condition_util.get_zyltgb_threshold(situation) |
| | | zyltgb_as_yi = round(global_util.zyltgb_map.get(code) / 100000000, 2) |
| | | |
| | | if zyltgb_as_yi >= zylt_threshold_as_yi[1]: |
| | | return False, True, f"{zylt_threshold_as_yi[1]}亿以上的都不买({zyltgb_as_yi})" |
| | | |
| | | if zyltgb_as_yi < zylt_threshold_as_yi[0]: |
| | | return False, True, f"{zylt_threshold_as_yi[0]}亿以下的都不买({zyltgb_as_yi})" |
| | | |
| | | msg_list = [] |
| | | if is_in_strong_time_30: |
| | | msg_list.append("强势30分钟") |
| | | # 独苗 |
| | | if not can_buy_result[0] and can_buy_result[1]: |
| | | msg_list.append("独苗") |
| | | return True, False, "强势30分钟,独苗" |
| | | elif not can_buy_result[0]: |
| | | return False, True, f"强势30分钟,非独苗不满足身位:{can_buy_result[2]}" |
| | | else: |
| | | msg_list.append("非独苗") |
| | | # 后排,满足自由流通市值需要下单 |
| | | return True, False, can_buy_result[2] |
| | | else: |
| | | if not can_buy_result[0]: |
| | | return False, True, f"非强势30分钟,不满足身位:{can_buy_result[2]}" |
| | | return True, False, can_buy_result[2] |
| | | |
| | | @classmethod |
| | |
| | | if _val["num"] * float(_val["price"]) < 5000: |
| | | continue |
| | | |
| | | return True, i, [refer_sell_data[0], 0], '上证买入', OrderBeginPosInfo.MODE_ACTIVE if active_buy_blocks else OrderBeginPosInfo.MODE_FAST |
| | | return True, i, [refer_sell_data[0], |
| | | 0], '上证买入', OrderBeginPosInfo.MODE_ACTIVE if active_buy_blocks else OrderBeginPosInfo.MODE_FAST |
| | | return False, -1, "未获取到激进买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL |
| | | else: |
| | | # 深证 |
| | |
| | | buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count, |
| | | valid_single=True) |
| | | if buy_single_index is not None: |
| | | return True, buy_single_index, [refer_sell_data[0], 0], "上板有成交买入信号", OrderBeginPosInfo.MODE_ACTIVE if active_buy_blocks else OrderBeginPosInfo.MODE_FAST |
| | | return True, buy_single_index, [refer_sell_data[0], |
| | | 0], "上板有成交买入信号", OrderBeginPosInfo.MODE_ACTIVE if active_buy_blocks else OrderBeginPosInfo.MODE_FAST |
| | | else: |
| | | # 板上放量:只需要一笔涨停买可作为信号 |
| | | buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count, |
| | | valid_single=False) |
| | | if buy_single_index is not None: |
| | | return True, buy_single_index, [refer_sell_data[0], 0], "板上放量", OrderBeginPosInfo.MODE_ACTIVE if active_buy_blocks else OrderBeginPosInfo.MODE_NORMAL |
| | | return True, buy_single_index, [refer_sell_data[0], |
| | | 0], "板上放量", OrderBeginPosInfo.MODE_ACTIVE if active_buy_blocks else OrderBeginPosInfo.MODE_NORMAL |
| | | |
| | | return False, -1, "未获取到激进买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL |
| | | |
| | |
| | | None) |
| | | # 是否可以买入的信息 |
| | | try: |
| | | can_buy_info = l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, limit_up_price) |
| | | can_buy_info = l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first_new(code, limit_up_price) |
| | | params["trade_data"]["can_buy_info"] = can_buy_info |
| | | except: |
| | | pass |
| | |
| | | @classmethod |
| | | def __is_need_active_buy(cls, code, block, current_limit_up_datas, limit_up_record_datas, |
| | | yesterday_current_limit_up_codes): |
| | | """ |
| | | 激进买入规则:主板老大且前面有高位板/20cm |
| | | @param code: |
| | | @param block: |
| | | @param current_limit_up_datas: |
| | | @param limit_up_record_datas: |
| | | @param yesterday_current_limit_up_codes: |
| | | @return: |
| | | """ |
| | | code_limit_up_reason_dict = {} |
| | | for d in limit_up_record_datas: |
| | | code_limit_up_reason_dict[d[3]] = d[2] |
| | |
| | | # |
| | | # return False, f"板块-{block}: top4涨停板块,非主板开1,不为主板龙1(实时身位-{current_shsz_rank}:{front_current_shsz_rank_codes},历史身位-{record_shsz_rank})" |
| | | |
| | | @classmethod |
| | | def __is_block_can_buy_new(cls, code, block, current_limit_up_datas, code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, limit_up_record_datas, |
| | | current_limit_up_block_codes_dict, |
| | | high_level_code_blocks=None, high_level_block_codes=None): |
| | | """ |
| | | 该票的板块是否可以买 |
| | | @param code: |
| | | @param block: |
| | | @param current_limit_up_datas: |
| | | @param code_limit_up_reasons_dict: |
| | | @param yesterday_current_limit_up_codes: |
| | | @param limit_up_record_datas: |
| | | @param current_limit_up_block_codes_dict: |
| | | @param high_level_code_blocks: |
| | | @param high_level_block_codes: |
| | | @return: |
| | | """ |
| | | # 独苗判断 |
| | | if high_level_code_blocks is None: |
| | | high_level_code_blocks = {} |
| | | if high_level_block_codes is None: |
| | | high_level_block_codes = {} |
| | | block_codes = current_limit_up_block_codes_dict.get(block) |
| | | if block_codes is None: |
| | | block_codes = set() |
| | | # 计算是否需要激进买入 |
| | | active_buy = cls.__is_need_active_buy(code, block, current_limit_up_datas, |
| | | limit_up_record_datas, |
| | | yesterday_current_limit_up_codes) |
| | | |
| | | if not block_codes: |
| | | # 高位板泛化板块中无板块 |
| | | if not high_level_block_codes.get(block): |
| | | return False, True, f"{block}:板块无涨停", False, active_buy |
| | | elif len(block_codes) == 1 and code in block_codes: |
| | | if not high_level_block_codes.get(block): |
| | | return False, True, f"{block}:板块只有当前代码涨停", False, active_buy |
| | | # 可以买的最大排名 |
| | | # open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas, |
| | | # code_limit_up_reason_dict) |
| | | current_open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes_current(code, block, |
| | | current_limit_up_datas) |
| | | |
| | | is_strong_block = False |
| | | |
| | | # 最多买老几 |
| | | RANKS = [5, 4, 3, 3, 3, 2, 2] |
| | | RANK_TIMES = ["10:00:00", "10:30:00", "11:00:00", "11:30:00", "13:30:00", "14:00:00", "15:00:00"] |
| | | now_time_str = tool.get_now_time_str() |
| | | max_rank = 2 |
| | | for i in range(len(RANK_TIMES)): |
| | | if tool.trade_time_sub(now_time_str, RANK_TIMES[i]) <= 0: |
| | | max_rank = RANKS[i] |
| | | break |
| | | |
| | | # 需要排除的老大的代码 |
| | | exclude_first_codes = set() |
| | | |
| | | # 获取主板开1的代码 |
| | | |
| | | # 剔除高位板 |
| | | if current_open_limit_up_codes and yesterday_current_limit_up_codes: |
| | | current_open_limit_up_codes -= yesterday_current_limit_up_codes |
| | | |
| | | # 获取代码的初次涨停时间 |
| | | first_limit_up_time = time.time() |
| | | # if limit_up_record_datas: |
| | | for r in limit_up_record_datas: |
| | | if r[3] == code: |
| | | first_limit_up_time = int(r[5]) |
| | | |
| | | # 获取主板实时身位,剔除高位板 |
| | | current_shsz_rank, front_current_shsz_rank_codes = kpl_block_util.get_code_current_rank(code, block, |
| | | current_limit_up_datas, |
| | | code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, |
| | | exclude_first_codes, |
| | | len( |
| | | current_open_limit_up_codes), |
| | | shsz=True, |
| | | limit_up_time=first_limit_up_time) |
| | | if current_shsz_rank < len(current_open_limit_up_codes) + max_rank: |
| | | return True, False, f"【{block}】前排代码:{current_shsz_rank}", is_strong_block, active_buy |
| | | else: |
| | | return False, False, f"【{block}】前排代码:{front_current_shsz_rank_codes} 超过{len(current_open_limit_up_codes) + max_rank}个", is_strong_block, active_buy |
| | | |
| | | # 获取可以买的板块 |
| | | # current_limit_up_datas: 今日实时涨停 |
| | | # latest_2_day_limit_up_datas:最近2天的实时涨停(不含今日) |
| | |
| | | code_limit_up_reasons_dict = {} |
| | | load_code_block() |
| | | for block in keys: |
| | | can_buy, unique, msg, is_strong, active_buy_info = cls.__is_block_can_buy(code, block, |
| | | current_limit_up_datas, |
| | | code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, |
| | | limit_up_record_datas, |
| | | current_limit_up_block_codes_dict, |
| | | high_level_code_blocks=high_level_general_code_blocks, |
| | | high_level_block_codes=high_level_general_block_codes) |
| | | can_buy, unique, msg, is_strong, active_buy_info = cls.__is_block_can_buy_new(code, block, |
| | | current_limit_up_datas, |
| | | code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, |
| | | limit_up_record_datas, |
| | | current_limit_up_block_codes_dict, |
| | | high_level_code_blocks=high_level_general_code_blocks, |
| | | high_level_block_codes=high_level_general_block_codes) |
| | | fresults.append((block, can_buy, unique, msg, is_strong, active_buy_info)) |
| | | return fresults, keys |
| | | |
| | |
| | | @classmethod |
| | | def can_buy(cls, code): |
| | | if constant.TEST: |
| | | return ["测试"], True, cls.BLOCK_TYPE_NONE, [], set(),["化工"] |
| | | return ["测试"], True, cls.BLOCK_TYPE_NONE, [], set(), ["化工"] |
| | | # if True: |
| | | # # 测试 |
| | | # return True, "不判断板块身位" |
| | |
| | | current_limit_up_block_codes_dict, |
| | | high_level_general_code_blocks) |
| | | # 保存板块计算结果 |
| | | cls.__can_buy_compute_result_dict[code] = (can_buy_blocks, unique, msg, can_buy_strong_blocks, keys, active_buy_blocks) |
| | | cls.__can_buy_compute_result_dict[code] = ( |
| | | can_buy_blocks, unique, msg, can_buy_strong_blocks, keys, active_buy_blocks) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | |
| | | if market_sitation == MarketSituationManager.SITUATION_GOOD: |
| | | return 31, 100, 40, 100, 40, 80, 100 |
| | | # return 5.9, 41, 8.9, 25, 8.9, 19, 80 |
| | | # TODO 大规模测试 |
| | | return 5.9, 2000, 8.9, 25, 8.9, 19, 2000 |
| | | return 5.9, 200, 8.9, 25, 8.9, 19, 200 |
| | | |
| | | |
| | | # 获取量比的等级获取量 |