| | |
| | | |
| | | __latest_limit_up_sell_list_dict = {} |
| | | |
| | | __latest_limit_up_sell_order_no_index_dict = {} |
| | | __latest_limit_up_sell_order_no_set_dict = {} |
| | | |
| | | @classmethod |
| | | def add_l2_delegate_limit_up_sell(cls, code, data): |
| | |
| | | if code not in cls.__latest_limit_up_sell_list_dict: |
| | | cls.__latest_limit_up_sell_list_dict[code] = [] |
| | | cls.__latest_limit_up_sell_list_dict[code].append(data) |
| | | if code not in cls.__latest_limit_up_sell_order_no_index_dict: |
| | | cls.__latest_limit_up_sell_order_no_index_dict[code] = {} |
| | | cls.__latest_limit_up_sell_order_no_index_dict[code][data['val']['orderNo']] = len( |
| | | cls.__latest_limit_up_sell_list_dict[code]) - 1 |
| | | if code not in cls.__latest_limit_up_sell_order_no_set_dict: |
| | | cls.__latest_limit_up_sell_order_no_set_dict[code] = set() |
| | | cls.__latest_limit_up_sell_order_no_set_dict[code].add(data['val']['orderNo']) |
| | | # 只保留前20的数据 |
| | | if len(cls.__latest_limit_up_sell_list_dict[code]) > 20: |
| | | cls.__latest_limit_up_sell_list_dict[code] = cls.__latest_limit_up_sell_list_dict[code][-20:] |
| | | # 删除之前的map |
| | | for d in cls.__latest_limit_up_sell_list_dict[code][0:-20]: |
| | | cls.__latest_limit_up_sell_order_no_set_dict[code].discard(d["val"]["orderNo"]) |
| | | |
| | | @classmethod |
| | | def add_l2_delegate_limit_up_sell_cancel(cls, code, order_no): |
| | |
| | | @param order_no: |
| | | @return: |
| | | """ |
| | | if code not in cls.__latest_limit_up_sell_order_no_index_dict: |
| | | if code not in cls.__latest_limit_up_sell_order_no_set_dict: |
| | | return |
| | | index = cls.__latest_limit_up_sell_order_no_index_dict[code].get(order_no) |
| | | if index is None: |
| | | order_no_set = cls.__latest_limit_up_sell_order_no_set_dict[code] |
| | | if order_no not in order_no_set: |
| | | return |
| | | cls.__latest_limit_up_sell_order_no_index_dict[code].pop(order_no) |
| | | cls.__latest_limit_up_sell_list_dict[code].pop(index) |
| | | cls.__latest_limit_up_sell_order_no_set_dict[code].discard(order_no) |
| | | |
| | | for i in range(0, len(cls.__latest_limit_up_sell_list_dict[code])): |
| | | if cls.__latest_limit_up_sell_list_dict[code][i]['val']['orderNo'] == order_no: |
| | | cls.__latest_limit_up_sell_list_dict[code].pop(i) |
| | | break |
| | | |
| | | @classmethod |
| | | def process_passive_limit_up_sell_data(cls, data): |
| | |
| | | return |
| | | sell_info = sell_list[-1] |
| | | sell_info_num = sell_info['val']['num'] |
| | | deal_num = cls.__latest_sell_data[code][1]//100 |
| | | deal_num = cls.__latest_sell_data[code][1] // 100 |
| | | |
| | | l2_log.info(code, logger_l2_trade_buy, f"最近涨停卖:{sell_info['val']['orderNo']} 卖量:{sell_info_num} 成交量:{deal_num}") |
| | | l2_log.info(code, logger_l2_trade_buy, |
| | | f"最近涨停卖:{sell_info['val']['orderNo']} 卖量:{sell_info_num} 成交量:{deal_num}") |
| | | if sell_no == sell_info['val']['orderNo'] and sell_info_num == deal_num: |
| | | # 成交完成 |
| | | L2TradeSingleDataManager.set_latest_sell_data(code, data) |
| | | l2_log.info(code, logger_l2_trade_buy,f"{code}#找到最近的被动涨停卖单数据:{sell_info['val']['orderNo']}, 可以触发下单") |
| | | l2_log.info(code, logger_l2_trade_buy, f"{code}#找到最近的被动涨停卖单数据:{sell_info['val']['orderNo']}, 可以触发下单") |
| | | |
| | | # l2_log.info(code, logger_l2_trade_buy, f"找到最近的被动涨停卖单数据:{data['val']['orderNo']}, 可以触发下单") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | |
| | | |
| | | class L2TradeSingleCallback: |
| | | """ |
| | | 交易信号回调 |
| | | """ |
| | | |
| | | def OnTradeSingle(self, code, _type, data): |
| | | """ |
| | | 交易数据信号回调 |
| | | @param code: |
| | | @param _type: 类型:0-TYPE_PASSIVE 1-TYPE_ACTIVE |
| | | @param data: (逐笔成交数据,生效时间) |
| | | @return: |
| | | """ |
| | | |
| | | |
| | | class L2TradeSingleDataManager: |
| | | __callback = None |
| | | |
| | | TYPE_PASSIVE = 0 |
| | | TYPE_ACTIVE = 1 |
| | | |
| | |
| | | |
| | | # 由被动向主动卖成交转变的数据 |
| | | __latest_sell_active_deal_data_dict = {} # 格式为:{code:(逐笔成交数据,生效时间(带ms))} |
| | | |
| | | @classmethod |
| | | def set_callback(cls, callback: L2TradeSingleCallback): |
| | | cls.__callback = callback |
| | | |
| | | @classmethod |
| | | def set_latest_sell_data(cls, code, data): |
| | |
| | | deal_time = l2_huaxin_util.convert_time(data[3], True) |
| | | # 生效时间在1s以内 |
| | | cls.__latest_sell_data_dict[code] = (data, tool.trade_time_add_millionsecond(deal_time, 1000)) |
| | | if cls.__callback: |
| | | cls.__callback.OnTradeSingle(code, cls.__latest_sell_data_dict[code]) |
| | | |
| | | @classmethod |
| | | def set_sell_passive_to_active_datas(cls, code, passive_data, active_data): |
| | |
| | | # 生效时间在1s以内 |
| | | cls.__latest_sell_active_deal_data_dict[code] = ( |
| | | active_data, tool.trade_time_add_millionsecond(deal_time, 1000)) |
| | | if cls.__callback: |
| | | cls.__callback.OnTradeSingle(code, cls.__latest_sell_active_deal_data_dict[code]) |
| | | |
| | | @classmethod |
| | | def get_valid_trade_single(cls, code, latest_time_with_ms): |