""" 涨停卖数据管理 """ from code_attribute import gpcode_manager from l2 import l2_log from log_module import async_log_util from log_module.log import hx_logger_l2_sell_delegate, hx_logger_l2_sell_deal class L2LimitUpSellDataManager: """ 涨停卖数据管理: 用来扫代码使用,当涨停卖有成交的时候就代表在吃最后一档 此时统计涨停卖的金额作为快照 当板上成交额大于涨停卖数据一定的比值就下单 """ # 卖单集合 __order_no_set_dict = {} # 订单号与数据的对照表:{code:{orderno:[order_no,price,volume]}} __order_no_data_map_dict = {} # 挂起的卖手数 __delegating_sell_num_dict = {} @classmethod def add_l2_origin_data(cls, code, origin_datas): """ 添加L2委托原始数据 @param code: 代码 @param origin_datas: 原始数据 @return: """ try: if code not in cls.__order_no_set_dict: cls.__order_no_set_dict[code] = set() if code not in cls.__order_no_data_map_dict: cls.__order_no_data_map_dict[code] = {} if code not in cls.__delegating_sell_num_dict: cls.__delegating_sell_num_dict[code] = 0 limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) for d in origin_datas: order_no, price, volume = d[8], d[1], d[2] if price != limit_up_price: continue if d[9] == 'D': if d[3] != '1': # 卖撤 cls.__order_no_set_dict[code].discard(order_no) cls.__delegating_sell_num_dict[code] -= volume async_log_util.l2_data_log.info(hx_logger_l2_sell_delegate, f"{code}-卖撤-{order_no, price, volume}") else: if d[3] != '1': # 卖 cls.__order_no_data_map_dict[code][order_no] = (order_no, price, volume) cls.__order_no_set_dict[code].add(order_no) cls.__delegating_sell_num_dict[code] += volume async_log_util.l2_data_log.info(hx_logger_l2_sell_delegate, f"{code}-卖-{order_no, price, volume}") except: pass @classmethod def get_delegating_sell_num(cls, code): """ 获取处于委托状态的卖单总手数 @param code: @return: """ return cls.__delegating_sell_num_dict.get(code) @classmethod def set_deal_datas(cls, code, datas): """ 设置成交的卖单 @param code: @param datas: q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'],data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'],data['SellNo'], data['ExecType'])) @return: 是否触发计算 """ try: limit_up_price = gpcode_manager.get_limit_up_price_as_num(code) has_limit_up_active_buy = False order_no_set = cls.__order_no_set_dict.get(code) if order_no_set is None: order_no_set = set() for d in datas: if d[1] != limit_up_price: continue # 是否有涨停主动买成交 if d[6] < d[7]: continue has_limit_up_active_buy = True break total_deal_volume = 0 if code in cls.__delegating_sell_num_dict: for d in datas: # 减去 if d[7] in order_no_set: total_deal_volume += d[2] cls.__delegating_sell_num_dict[code] -= total_deal_volume if has_limit_up_active_buy: # 打印日志 async_log_util.l2_data_log.info(hx_logger_l2_sell_deal, f"有涨停主动卖:{code}-{datas[-1][3]}-{cls.__delegating_sell_num_dict.get(code)}, 成交量-{total_deal_volume}") except: pass @classmethod def clear_data(cls, code): """ 清除数据:当出现主动卖的时候就可以清除数据 @param code: @return: """ if code in cls.__order_no_set_dict: cls.__order_no_set_dict.pop(code) if code in cls.__order_no_data_map_dict: cls.__order_no_data_map_dict.pop(code) if code in cls.__delegating_sell_num_dict: cls.__delegating_sell_num_dict.pop(code)