Administrator
2024-04-12 7545d5e6930da8b4679c7c4ff2187de810c36361
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
下单信号管理
"""
from l2 import l2_log
from log_module.log import logger_l2_trade_buy, logger_debug
 
 
class L2TradeSingleManager:
    """
    L2逐笔成交数据信号管理
    """
    __latest_sell_data = {}
 
    __latest_limit_up_sell_list_dict = {}
 
    __latest_limit_up_sell_order_no_index_dict = {}
 
    @classmethod
    def add_l2_delegate_limit_up_sell(cls, code, data):
        """
        添加涨停卖单数据,当前不是涨停成交时才加
        @param code:
        @param data:
        @return:
        """
        l2_log.info(code, logger_l2_trade_buy, f"涨停卖数据:{data['val']['orderNo']}")
        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
 
    @classmethod
    def add_l2_delegate_limit_up_sell_cancel(cls, code, order_no):
        """
        涨停卖撤
        @param code:
        @param order_no:
        @return:
        """
        if code not in cls.__latest_limit_up_sell_order_no_index_dict:
            return
        index = cls.__latest_limit_up_sell_order_no_index_dict[code].get(order_no)
        if index is None:
            return
        cls.__latest_limit_up_sell_order_no_index_dict[code].pop(order_no)
        del cls.__latest_limit_up_sell_list_dict[code][index]
 
    @classmethod
    def process_passive_limit_up_sell_data(cls, data):
        """
        添加涨停被动卖成交数据
        @param data: 数据格式:(data['SecurityID'], data['TradePrice'], data['TradeVolume'],
        #           data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'],
        #           data['SellNo'], data['ExecType'])
        @return:
        """
        try:
            # 需要判断当前单是否已经成交完成
            code = data[0]
            sell_no = data[7]
            if code not in cls.__latest_sell_data:
                cls.__latest_sell_data[code] = [sell_no, data[2]]
            else:
                if cls.__latest_sell_data[code][0] == sell_no:
                    cls.__latest_sell_data[code][1] += data[2]
                else:
                    cls.__latest_sell_data[code] = [sell_no, data[2]]
            # 判断是否是最后一笔卖单
 
            # 判断这个订单号是否成交完
            sell_list = cls.__latest_limit_up_sell_list_dict.get(code)
            if not sell_list:
                return
            sell_info = sell_list[-1]
            if sell_no == sell_info['val']['orderNo'] and sell_info["val"]["num"] == cls.__latest_sell_data[code][
                1] // 100:
                # 成交完成
                l2_log.info(code, logger_l2_trade_buy, f"找到最近的被动涨停卖单数据:{data['val']['orderNo']}, 可以触发下单")
        except Exception as e:
            logger_debug.exception(e)