| | |
| | | p12 = __has_limit_up(code, record_datas, 90) |
| | | # 最近5天是否跌停 |
| | | p13 = __is_latest_limit_down(code, record_datas, 5) |
| | | # 60个交易日是否曾涨停 |
| | | p14 = __has_limited_up(code, record_datas, 60) |
| | | # 昨日是否涨停过 |
| | | p15 = __has_limited_up(code, record_datas, 1) |
| | | |
| | | return p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13 |
| | | return p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15 |
| | | |
| | | |
| | | # 是否具有K线形态 |
| | |
| | | return False |
| | | |
| | | |
| | | # 多少天内是否曾涨停 |
| | | def __has_limited_up(code, datas, day_count): |
| | | datas = copy.deepcopy(datas) |
| | | datas.sort(key=lambda x: x["bob"]) |
| | | if len(datas) > day_count: |
| | | datas = datas[0 - day_count:] |
| | | if len(datas) >= 1: |
| | | for i in range(0, len(datas)): |
| | | item = datas[i] |
| | | if __is_limited_up(code, item): |
| | | return True |
| | | return False |
| | | |
| | | |
| | | # 首板涨停溢价率 |
| | | def get_limit_up_premium_rate(code, datas): |
| | | datas = copy.deepcopy(datas) |
| | |
| | | |
| | | # 获取参考卖的数据 |
| | | def get_refer_sell_data(self, code, time_str): |
| | | """ |
| | | 获取可引用的总卖额 |
| | | @param code: |
| | | @param time_str: 当前数据截止时间 |
| | | @return: (time_str, round(money), volume, sell_1_info) |
| | | """ |
| | | cuurent = self.__current_total_sell_data_cache.get(code) |
| | | if cuurent is None: |
| | | return None |
| | |
| | | for code in sell_order_map: |
| | | cls.__total_sell_datas_dict[code] = sell_order_map[code] |
| | | |
| | | |
| | | def add_buy_datas(self, code, datas): |
| | | """ |
| | | 添加大买单数据 |
| | |
| | | |
| | | # 统计所有的成交量 |
| | | __deal_volume_list_dict = {} |
| | | # 统计主动买的成交量 |
| | | __deal_active_buy_volume_list_dict = {} |
| | | |
| | | @classmethod |
| | | def statistic_total_deal_volume(cls, code, datas): |
| | | # 只统计被动买 |
| | | if code not in cls.__deal_volume_list_dict: |
| | | cls.__deal_volume_list_dict[code] = [] |
| | | |
| | | time_dict = {} |
| | | for d in datas: |
| | | # 只统计被动买 |
| | |
| | | # 删除超过5条数据 |
| | | if len(cls.__deal_volume_list_dict[code]) > 5: |
| | | cls.__deal_volume_list_dict[code] = cls.__deal_volume_list_dict[code][-5:] |
| | | |
| | | try: |
| | | # 统计主动买的成交量 |
| | | if code not in cls.__deal_active_buy_volume_list_dict: |
| | | cls.__deal_active_buy_volume_list_dict[code] = [] |
| | | for d in datas: |
| | | # 只统计主动买 |
| | | if d[7] > d[6]: |
| | | continue |
| | | time_str = '' |
| | | if d[3] in time_dict: |
| | | time_str = time_dict[d[3]] |
| | | else: |
| | | time_dict[d[3]] = l2_huaxin_util.convert_time(d[3]) |
| | | time_str = time_dict[d[3]] |
| | | if cls.__deal_active_buy_volume_list_dict[code]: |
| | | if cls.__deal_active_buy_volume_list_dict[code][-1][0] == time_str: |
| | | # 如果是同一秒 |
| | | cls.__deal_active_buy_volume_list_dict[code][-1][1] += d[2] |
| | | else: |
| | | # 不是同一秒 |
| | | cls.__deal_active_buy_volume_list_dict[code].append([time_str, d[2]]) |
| | | else: |
| | | cls.__deal_active_buy_volume_list_dict[code].append([time_str, d[2]]) |
| | | # 删除超过10条数据 |
| | | if len(cls.__deal_active_buy_volume_list_dict[code]) > 10: |
| | | cls.__deal_active_buy_volume_list_dict[code] = cls.__deal_active_buy_volume_list_dict[code][-10:] |
| | | except: |
| | | pass |
| | | |
| | | time_dict.clear() |
| | | |
| | | @classmethod |
| | |
| | | # 从倒数第二个数据计算 |
| | | for i in range(len(deal_list) - 1, -1, -1): |
| | | if tool.trade_time_sub(fdatas[0][0], deal_list[i][0]) < 2: |
| | | fdatas.append(deal_list[i]) |
| | | return fdatas |
| | | |
| | | @classmethod |
| | | def get_latest_6s_active_buy_deal_volumes(cls, code): |
| | | """ |
| | | 获取最近6s的主动买成交 |
| | | @param code: |
| | | @return: [(时间,量)] |
| | | """ |
| | | deal_list = cls.__deal_active_buy_volume_list_dict.get(code) |
| | | if not deal_list: |
| | | return [] |
| | | fdatas = [deal_list[-1]] |
| | | # 从倒数第二个数据计算 |
| | | for i in range(len(deal_list) - 1, -1, -1): |
| | | if tool.trade_time_sub(fdatas[0][0], deal_list[i][0]) < 6: |
| | | fdatas.append(deal_list[i]) |
| | | return fdatas |
| | | |
| | |
| | | total_sell_info[0] += int(latest_sell_order_info[1] * latest_sell_order_info[2]) |
| | | big_sell_orders.reverse() |
| | | total_sell_info[1] = big_sell_orders |
| | | # ----------------统计涨停主动买----------------- |
| | | try: |
| | | for d in datas: |
| | | if is_active_sell(d[7], d[6]): |
| | | # 被动买 |
| | | continue |
| | | # 是否是涨停 |
| | | if d[1] == limit_up_price: |
| | | # 有涨停主动买 |
| | | L2TradeSingleDataManager.set_limit_up_active_buy(code, datas[-1][3]) |
| | | break |
| | | except: |
| | | pass |
| | | |
| | | return total_sell_info |
| | | |
| | | # 获取最近成交数据 |
| | |
| | | @return: |
| | | """ |
| | | |
| | | def OnLimitUpActiveBuy(self, code, huaxin_timestamp): |
| | | """ |
| | | 涨停主动买触发 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | |
| | | |
| | | class L2TradeSingleDataManager: |
| | | __callback = None |
| | |
| | | # cls.__callback.OnTradeSingle(code, 0, cls.TYPE_ACTIVE, cls.__latest_sell_active_deal_data_dict[code]) |
| | | |
| | | @classmethod |
| | | def set_limit_up_active_buy(cls, code, huaxin_timestamp): |
| | | cls.__callback.OnLimitUpActiveBuy(code, huaxin_timestamp) |
| | | |
| | | @classmethod |
| | | def get_valid_trade_single(cls, code, latest_time_with_ms): |
| | | """ |
| | | 获取有效的成交下单信号 |
| | |
| | | filter=lambda record: record["extra"].get("name") == "l2_not_buy_reasons", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_path("l2", "l2_radical_buy"), |
| | | filter=lambda record: record["extra"].get("name") == "l2_radical_buy", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_path("juejin", "juejin_tick"), |
| | | filter=lambda record: record["extra"].get("name") == "juejin_tick", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | |
| | | |
| | | logger_buy_strategy = __mylogger.get_logger("buy_strategy") |
| | | |
| | | logger_l2_radical_buy = __mylogger.get_logger("l2_radical_buy") |
| | | |
| | | # -------------------------------华鑫日志--------------------------------- |
| | | hx_logger_l2_orderdetail = __mylogger.get_logger("hx_l2_orderdetail") |
| | | hx_logger_l2_transaction = __mylogger.get_logger("hx_l2_transaction") |
| | |
| | | from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer, LCancelRateManager |
| | | from output.limit_up_data_filter import IgnoreCodeManager |
| | | from third_data import kpl_util, kpl_data_manager, kpl_api, block_info |
| | | from third_data.code_plate_key_manager import RealTimeKplMarketData, KPLPlateForbiddenManager, CodePlateKeyBuyManager |
| | | from third_data.code_plate_key_manager import RealTimeKplMarketData, KPLPlateForbiddenManager, CodePlateKeyBuyManager, \ |
| | | RadicalBuyBlockManager |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | | from third_data.kpl_data_manager import KPLDataManager, KPLLimitUpDataRecordManager, \ |
| | | KPLCodeLimitUpReasonManager |
| | |
| | | pass |
| | | try: |
| | | OpenLimitUpGoodBlocksBuyStrategy.set_current_limit_up_data(result_list_) |
| | | CodePlateKeyBuyManager.compute_open_limit_up_code_dict_for_radical_buy(result_list_) |
| | | RadicalBuyBlockManager.compute_open_limit_up_code_dict_for_radical_buy(result_list_) |
| | | except: |
| | | pass |
| | | |
| | |
| | | import constant |
| | | import outside_api_command_manager |
| | | from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer |
| | | from code_attribute import gpcode_manager, code_volumn_manager, global_data_loader, zyltgb_util |
| | | from code_attribute import gpcode_manager, code_volumn_manager, global_data_loader, zyltgb_util, code_nature_analyse |
| | | from code_attribute.code_l1_data_manager import L1DataManager |
| | | from code_attribute.gpcode_manager import CodePrePriceManager |
| | | from huaxin_client import l2_data_transform_protocol |
| | |
| | | from l2.cancel_buy_strategy import GCancelBigNumComputer, \ |
| | | DCancelBigNumComputer |
| | | from l2.code_price_manager import Buy1PriceManager |
| | | from l2.huaxin import huaxin_target_codes_manager |
| | | from l2.huaxin import huaxin_target_codes_manager, l2_huaxin_util |
| | | from l2.huaxin.huaxin_target_codes_manager import HuaXinL1TargetCodesManager |
| | | from l2.l2_data_manager import TradePointManager, OrderBeginPosInfo |
| | | from l2.l2_data_util import L2DataUtil |
| | | from l2.l2_sell_manager import L2MarketSellManager |
| | | from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager, BigOrderDealManager |
| | | from l2.l2_transaction_data_processor import HuaXinTransactionDatasProcessor |
| | | from l2.place_order_single_data_manager import L2TradeSingleCallback, L2TradeSingleDataManager |
| | | from log_module import async_log_util, log_export |
| | | from log_module.log import hx_logger_contact_debug, hx_logger_trade_callback, \ |
| | | hx_logger_l2_orderdetail, hx_logger_l2_market_data, logger_l2_g_cancel, logger_debug, \ |
| | | logger_system, logger_trade, logger_local_huaxin_l1_trade_info, logger_l2_codes_subscript |
| | | logger_system, logger_trade, logger_local_huaxin_l1_trade_info, logger_l2_codes_subscript, logger_l2_radical_buy |
| | | from third_data import block_info, kpl_data_manager, history_k_data_manager, huaxin_l1_data_manager |
| | | from third_data.code_plate_key_manager import KPLCodeJXBlockManager, CodePlateKeyBuyManager |
| | | from third_data.code_plate_key_manager import KPLCodeJXBlockManager, CodePlateKeyBuyManager, RadicalBuyBlockManager |
| | | from third_data.history_k_data_util import JueJinApi |
| | | from trade import trade_manager, l2_trade_util, \ |
| | | trade_data_manager, trade_constant |
| | |
| | | # 格式 (代码,现价,涨幅,量,更新时间,买1价格,买1量) |
| | | price = d[1] |
| | | L1DataManager.set_l1_current_price(code, price) |
| | | huaxin_l1_data_manager.set_buy1_data(code,d[5], d[6]) |
| | | huaxin_l1_data_manager.set_buy1_data(code, d[5], d[6]) |
| | | |
| | | # 获取L1现价 |
| | | @classmethod |
| | |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | |
| | | def OnLimitUpActiveBuy(self, code, huaxin_timestamp): |
| | | try: |
| | | # 判断最近60个交易日有无涨停 |
| | | # 判断昨日是否涨停过 |
| | | async_log_util.info(logger_l2_radical_buy, f"涨停主动买:{code}-{huaxin_timestamp}") |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if k_format and k_format[13] and not k_format[14]: |
| | | # 判断是否有大单,判断最近的主动买占了总买额的多少 |
| | | refer_sell_data = L2MarketSellManager().get_refer_sell_data(code, l2_huaxin_util.convert_time( |
| | | huaxin_timestamp)) |
| | | async_log_util.info(logger_l2_radical_buy, f"参考总卖额:{code}-{refer_sell_data}") |
| | | refer_sell_time = refer_sell_data[0] |
| | | # 获取最近的主动买成交量 |
| | | deal_infos = HuaXinSellOrderStatisticManager.get_latest_6s_active_buy_deal_volumes(code) |
| | | async_log_util.info(logger_l2_radical_buy, f"最近主动买成交:{code}-{deal_infos}") |
| | | async_log_util.info(logger_l2_radical_buy) |
| | | if refer_sell_data and refer_sell_data[1] > 100 * 1e4: |
| | | # 总卖额要大于100w |
| | | deal_volume = 0 |
| | | for i in range(len(deal_infos) - 1, -1, -1): |
| | | # >=统计到的总卖 |
| | | if int(refer_sell_time.replace(":", "")) > int(deal_infos[i][0].replace(":", "")): |
| | | break |
| | | deal_volume += deal_infos[i][1] |
| | | # 判断参考时间之后是否有大单成交 |
| | | big_deal_money_list = BigOrderDealManager().get_total_buy_money_list(code) |
| | | if len(big_deal_money_list)>0: |
| | | # 有大单成交 |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | if yesterday_codes is None: |
| | | yesterday_codes = set() |
| | | result = RadicalBuyBlockManager.is_radical_buy(code, yesterday_codes) |
| | | async_log_util.info(logger_l2_radical_buy, f"计算板块结果:{code}-{result}") |
| | | except Exception as e: |
| | | async_log_util.info(logger_debug, f"激进买计算异常:{str(e)}") |
| | | |
| | | |
| | | # 回调 |
| | | my_l2_data_callback = MyL2DataCallback() |
| | |
| | | from settings.trade_setting import MarketSituationManager |
| | | from third_data.history_k_data_manager import HistoryKDataManager |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | | from third_data.kpl_data_constant import LimitUpDataConstant |
| | | from utils import global_util, tool, buy_condition_util, init_data_util |
| | | from log_module import log, async_log_util |
| | | from db import redis_manager_delegate as redis_manager |
| | |
| | | cls.__can_buy_compute_result_dict[code] = ( |
| | | can_buy_blocks, unique, msg, can_buy_strong_blocks, keys, active_buy_blocks) |
| | | |
| | | |
| | | class RadicalBuyBlockManager: |
| | | """ |
| | | 激进买板块管理 |
| | | """ |
| | | __TargetCodePlateKeyManager = TargetCodePlateKeyManager() |
| | | |
| | | @classmethod |
| | | def compute_open_limit_up_code_dict_for_radical_buy(cls, current_limit_up_datas): |
| | | """ |
| | |
| | | @param current_limit_up_datas: |
| | | @return: |
| | | """ |
| | | timestamp_start = time.mktime( |
| | | time.strptime(datetime.datetime.now().strftime("%Y-%m-%d") + " 09:25:00", '%Y-%m-%d %H:%M:%S')) |
| | | timestamp_end = time.mktime(time.strptime(datetime.datetime.now().strftime("%Y-%m-%d") + " 09:30:00", '%Y-%m-%d %H:%M:%S')) |
| | | timestamp_start, timestamp_end = kpl_block_util.open_limit_up_time_range |
| | | temp_dict = {} |
| | | for d in current_limit_up_datas: |
| | | code = d[0] |
| | |
| | | # 计算是否开1 |
| | | if int(d[2]) >= timestamp_end or int(d[2]) < timestamp_start: |
| | | continue |
| | | # 剔除5板以上的 |
| | | if d[4].find("连板") > 0 and int(d[4].replace("连板", "")) >= 5: |
| | | continue |
| | | buy1_money = huaxin_l1_data_manager.get_buy1_money(code) |
| | | if not buy1_money or buy1_money < 1e8: |
| | | # 买1是否大于5000w |
| | | if not buy1_money or buy1_money < 5e7: |
| | | continue |
| | | if not tool.is_can_buy_code(code): |
| | | continue |
| | | # 买1是否大于1亿 |
| | | blocks = {d[5]} |
| | | if d[6]: |
| | | blocks |= set(d[6].split("、")) |
| | | blocks -= constant.KPL_INVALID_BLOCKS |
| | | temp_dict[code] = (kpl_util.get_high_level_count(d[4]), d[6]) |
| | | temp_dict[code] = (kpl_util.get_high_level_count(d[4]), blocks) |
| | | kpl_data_constant.open_limit_up_code_dict_for_radical_buy = temp_dict |
| | | |
| | | @classmethod |
| | | def is_radical_buy(cls, code): |
| | | def __get_current_index(cls, code, block, yesterday_limit_up_codes): |
| | | """ |
| | | 获取当前涨停身位 |
| | | @param code: |
| | | @param block: |
| | | @param yesterday_limit_up_codes: |
| | | @return: 索引,前排代码信息([(代码, 涨停时间)]) |
| | | """ |
| | | current_index = 0 |
| | | block_codes_infos = [] |
| | | timestamp_start, timestamp_end = kpl_block_util.open_limit_up_time_range |
| | | limit_up_time = time.time() |
| | | for k in LimitUpDataConstant.current_limit_up_datas: |
| | | _code = k[0] |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | | if not blocks: |
| | | blocks = set() |
| | | if _code == code: |
| | | # 获取当前代码涨停时间 |
| | | limit_up_time = int(k[2]) |
| | | continue |
| | | # 不是这个板块 |
| | | if block not in blocks: |
| | | continue |
| | | if not tool.is_can_buy_code(_code): |
| | | continue |
| | | # 剔除开1的数据 |
| | | if timestamp_start <= int(k[2]) < timestamp_end: |
| | | continue |
| | | # 剔除高位板 |
| | | if _code in yesterday_limit_up_codes: |
| | | continue |
| | | # 代码.涨停时间 |
| | | block_codes_infos.append((_code, int(k[2]))) |
| | | block_codes_infos.append((code, limit_up_time)) |
| | | block_codes_infos.sort(key=lambda x: x[1]) |
| | | before_codes_info = [] |
| | | for i in range(0, len(block_codes_infos)): |
| | | if block_codes_infos[i][0] == code: |
| | | current_index = i |
| | | break |
| | | else: |
| | | before_codes_info.append(block_codes_infos[i]) |
| | | |
| | | return current_index, before_codes_info |
| | | |
| | | @classmethod |
| | | def __get_history_index(cls, code, block, yesterday_limit_up_codes): |
| | | """ |
| | | 获取历史涨停身位 |
| | | @param code: |
| | | @param block: |
| | | @param current_limit_up_datas: |
| | | @return: |
| | | """ |
| | | history_index = 0 |
| | | block_codes_infos = [] |
| | | timestamp_start, timestamp_end = kpl_block_util.open_limit_up_time_range |
| | | limit_up_time = time.time() |
| | | for k in LimitUpDataConstant.history_limit_up_datas: |
| | | _code = k[3] |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | | if _code == code: |
| | | # 获取当前代码涨停时间 |
| | | limit_up_time = int(k[5]) |
| | | continue |
| | | # 不是这个板块 |
| | | if block not in blocks: |
| | | continue |
| | | if not tool.is_can_buy_code(_code): |
| | | continue |
| | | # 剔除开1的数据 |
| | | if timestamp_start <= int(k[5]) < timestamp_end: |
| | | continue |
| | | # 剔除高位板 |
| | | if _code in yesterday_limit_up_codes: |
| | | continue |
| | | # 代码.涨停时间 |
| | | block_codes_infos.append((_code, int(k[5]))) |
| | | block_codes_infos.append((code, limit_up_time)) |
| | | block_codes_infos.sort(key=lambda x: x[1]) |
| | | before_codes_info = [] |
| | | for i in range(0, len(block_codes_infos)): |
| | | if block_codes_infos[i][0] == code: |
| | | history_index = i |
| | | break |
| | | else: |
| | | before_codes_info.append(block_codes_infos[i]) |
| | | return history_index, before_codes_info |
| | | |
| | | @classmethod |
| | | def __is_radical_buy_with_open_limitup(cls, code, block, yesterday_limit_up_codes): |
| | | """ |
| | | 是否需要激进买(某个板块开1) |
| | | 1.有>=2个开1买老2 |
| | | 2.有1个开1的买老3 |
| | | @param code: |
| | | @param block: |
| | | @param yesterday_limit_up_codes 昨日涨停代码 |
| | | @return: |
| | | """ |
| | | # 10点之前才能买入 |
| | | if int(tool.get_now_time_str().replace(":", "")) > 100000: |
| | | return False, "超过生效时间" |
| | | |
| | | # 根据板块聚合数据 |
| | | open_limit_up_block_codes = {} |
| | | for c in kpl_data_constant.open_limit_up_code_dict_for_radical_buy: |
| | | blocks = kpl_data_constant.open_limit_up_code_dict_for_radical_buy[c][1] |
| | | for b in blocks: |
| | | if b not in open_limit_up_block_codes: |
| | | open_limit_up_block_codes[b] = set() |
| | | open_limit_up_block_codes[b].add(c) |
| | | if block not in open_limit_up_block_codes: |
| | | return False, "板块未开1" |
| | | |
| | | count = len(open_limit_up_block_codes.get(block)) |
| | | # ----获取历史身位---- |
| | | history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes) |
| | | # ----获取实时身位---- |
| | | current_index, current_before_codes_info = cls.__get_current_index(code, block, yesterday_limit_up_codes) |
| | | if count >= 2: |
| | | # 买老2 |
| | | if history_index == 0 and current_index == 0: |
| | | return True, f"开1数量:{count}" |
| | | else: |
| | | return False, f"开1数量:{count},身位不匹配:历史-{history_index} 实时-{current_index}" |
| | | else: |
| | | # 买老3 |
| | | if history_index == 1 and current_index == 1: |
| | | return True, f"开1数量:{count}" |
| | | else: |
| | | return False, f"开1数量:{count},身位不匹配:历史-{history_index} 实时-{current_index}" |
| | | |
| | | @classmethod |
| | | def __is_radical_buy_with_block_up(cls, code, block, yesterday_limit_up_codes): |
| | | """ |
| | | 是否激进买(板块突然涨起来) |
| | | 老大和老二的涨停时间相差5分钟内 |
| | | 老三的涨停时间距离老大涨停在10分钟内就买 |
| | | @param code: |
| | | @param block: |
| | | @param yesterday_limit_up_codes: |
| | | @return: |
| | | """ |
| | | # 获取当前的板块 |
| | | current_index, current_before_codes_info = cls.__get_current_index(code, block, set()) |
| | | if current_index != 2: |
| | | return False, f"只能买老3,当前身位-{current_index + 1}" |
| | | history_index, history_before_codes_info = cls.__get_history_index(code, block, set()) |
| | | if history_index != current_index or len(current_before_codes_info) != len(history_before_codes_info): |
| | | return False, f"前排代码有炸板" |
| | | if len(current_before_codes_info) < 2: |
| | | return False, f"前排代码小于2个" |
| | | # 老大,老二必须相隔5分钟内 |
| | | if current_before_codes_info[0][1] >= kpl_block_util.open_limit_up_time_range[1]: |
| | | return False, f"有开1" |
| | | |
| | | if current_before_codes_info[1][1] - current_before_codes_info[0][1] < 5 * 60: |
| | | # 获取当前代码的涨停时间 |
| | | limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code) |
| | | if not limit_up_timestamp: |
| | | limit_up_timestamp = time.time() |
| | | if limit_up_timestamp - current_before_codes_info[0][1] < 10 * 60: |
| | | return True, f"前排涨停:{current_before_codes_info}" |
| | | return False, "前排涨停时间间隔不满足条件" |
| | | |
| | | @classmethod |
| | | def is_radical_buy(cls, code, yesterday_limit_up_codes): |
| | | """ |
| | | 是否是激进买 |
| | | @param code: |
| | | @return: |
| | | @return: {激进买的板块}, 原因 |
| | | """ |
| | | # 获取今日开一的代码,剔除5板以上的 |
| | | current_limit_up_datas = kpl_data_constant.current_limit_up_datas |
| | | # 计算 |
| | | |
| | | # 获取开1的板块 |
| | | open_limit_up_code_dict = kpl_data_constant.open_limit_up_code_dict_for_radical_buy |
| | | if not open_limit_up_code_dict: |
| | | return False, "没有首板开1的数据" |
| | | open_limit_up_blocks = set() |
| | | for c in open_limit_up_code_dict: |
| | | open_limit_up_blocks |= open_limit_up_code_dict[c][1] |
| | | # 获取代码的板块 |
| | | keys_, k1_, k11_, k2_, k3_, k4_ = cls.__TargetCodePlateKeyManager.get_plate_keys(code, contains_today=False) |
| | | # 获取 |
| | | match_blocks = open_limit_up_blocks & keys_ |
| | | if not match_blocks: |
| | | return False, "没匹配到开1的板块" |
| | | can_buy_blocks = set() |
| | | msges = [] |
| | | for b in match_blocks: |
| | | # 判断板块是否该激进买 |
| | | result = cls.__is_radical_buy_with_open_limitup(code, b, yesterday_limit_up_codes) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result}") |
| | | if can_buy_blocks: |
| | | return can_buy_blocks, "开1满足条件:" + ",".join(msges) |
| | | if not can_buy_blocks: |
| | | msges.clear() |
| | | for b in match_blocks: |
| | | # 板块快速启动 |
| | | result = cls.__is_radical_buy_with_block_up(code, b, yesterday_limit_up_codes) |
| | | if result[0]: |
| | | can_buy_blocks.add(b) |
| | | msges.append(f"【{b}】:{result}") |
| | | return can_buy_blocks, "开1不满足条件,板块快速启动:" + ",".join(msges) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | |
| | | return 0, [] |
| | | |
| | | |
| | | # 开1时间范围 |
| | | open_limit_up_time_range = time.mktime( |
| | | time.strptime(tool.get_now_date_str() + " 09:25:00", '%Y-%m-%d %H:%M:%S')), time.mktime( |
| | | time.strptime(tool.get_now_date_str() + " 09:30:00", '%Y-%m-%d %H:%M:%S')) |
| | | |
| | | if __name__ == "__main__": |
| | | pass |
| | |
| | | # 当前涨停数据 |
| | | current_limit_up_datas = [] |
| | | import constant |
| | | from third_data import kpl_block_util |
| | | |
| | | # 用于计算激进买开1的板数:{"代码":(几版,板块)} |
| | | open_limit_up_code_dict_for_radical_buy = None |
| | | # 用于计算激进买开1的板数:{"代码":(几版,{板块})} |
| | | open_limit_up_code_dict_for_radical_buy = None |
| | | |
| | | |
| | | class LimitUpDataConstant: |
| | | """ |
| | | 当前涨停数据的数据 |
| | | """ |
| | | __history_code_blocks_dict = {} |
| | | __history_code_data_dict = {} |
| | | history_limit_up_datas = [] |
| | | current_limit_up_datas = [] |
| | | |
| | | @classmethod |
| | | def set_current_limit_up_datas(cls, current_limit_up_datas): |
| | | cls.current_limit_up_datas = current_limit_up_datas |
| | | |
| | | @classmethod |
| | | def set_history_limit_up_datas(cls, history_limit_up_datas_): |
| | | cls.history_limit_up_datas = history_limit_up_datas_ |
| | | for d in cls.history_limit_up_datas: |
| | | blocks = {d[2]} |
| | | # 开1才能包含推荐原因 |
| | | if d[6] and kpl_block_util.open_limit_up_time_range[0] <= int(d[5]) < \ |
| | | kpl_block_util.open_limit_up_time_range[1]: |
| | | blocks |= set(d[6].split("、")) |
| | | blocks -= constant.KPL_INVALID_BLOCKS |
| | | cls.__history_code_blocks_dict[d[3]] = blocks |
| | | cls.__history_code_data_dict[d[3]] = d |
| | | |
| | | @classmethod |
| | | def get_blocks_with_history(cls, code): |
| | | """ |
| | | 根据历史涨停获取板块 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | return cls.__history_code_blocks_dict.get(code) |
| | | |
| | | @classmethod |
| | | def get_first_limit_up_time(cls, code): |
| | | if code in cls.__history_code_data_dict: |
| | | return int(cls.__history_code_data_dict[code][5]) |
| | | return None |
| | |
| | | import constant |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import async_log_util, log |
| | | from third_data.kpl_data_constant import LimitUpDataConstant |
| | | from utils import tool |
| | | |
| | | # 开盘啦历史涨停数据管理 |
| | |
| | | cls.latest_origin_datas = records |
| | | cls.__LimitUpCodesPlateKeyManager.set_today_limit_up( |
| | | [(r[0], r[5], r[6].split('、') if r[6] else []) for r in records]) |
| | | kpl_data_constant.current_limit_up_datas = records |
| | | LimitUpDataConstant.set_current_limit_up_datas(records) |
| | | |
| | | code_reasons_dict = {} |
| | | reason_codes_dict = {} |
| | |
| | | if dd[0] in cls.latest_datas: |
| | | cls.latest_datas.pop(dd[0]) |
| | | cls.total_datas = KPLLimitUpDataRecordManager.list_all(tool.get_now_date_str()) |
| | | LimitUpDataConstant.set_history_limit_up_datas(cls.total_datas) |
| | | |
| | | @classmethod |
| | | def load_total_datas(cls): |