Administrator
4 天以前 48fb7a00951f91bdc707e5dd2d196e5bccb752c3
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer
from l2.huaxin import l2_huaxin_util
from l2.l2_data_manager import OrderBeginPosInfo
from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager
from l2 import l2_data_util
from l2.l2_transaction_data_processor import HuaXinTransactionDatasProcessor
from log_module import log_export, async_log_util
from utils import tool
 
 
def statistic_buy_order():
    code = "002187"
    data_map = log_export.load_huaxin_transaction_map(date="2024-04-10", with_time=True)
    datas = data_map.get(code)
    __latest_buy_order_dict = {}
    total_money = 0
    active_buy = 0
    passive_buy = 0
    for data in datas:
        time_str = data[0]
        for d in data[1]:
            if d[6] == 990054:
                if d[7] < 990054:
                    active_buy += d[2]
                    print("主动买:", time_str, d)
                else:
                    passive_buy += d[2]
                    print("被动买:", time_str, d)
            if code not in __latest_buy_order_dict:
                # 格式:[买单号,手数,单价]
                __latest_buy_order_dict[code] = [d[6], d[2], d[1], (d[3], d[1]), (d[3], d[1])]
            else:
                if __latest_buy_order_dict[code][0] == d[6]:
                    __latest_buy_order_dict[code][1] += d[2]
                    __latest_buy_order_dict[code][2] = d[1]
                    __latest_buy_order_dict[code][4] = (d[3], d[1])
                else:
                    info = __latest_buy_order_dict[code]
 
                    # 上个卖单成交完成
                    # 封存数据,计算新起点
                    # 大于50w的卖单才会保存
                    # 大于50w加入卖单
                    money = info[1] * info[2]
                    # if 101328000 > info[3] > 101324000:
                    if tool.trade_time_sub(l2_huaxin_util.convert_time(info[3][0]), "10:08:30") >= 0 and info[
                        2] >= 11.54:
                        total_money += money
                        print(int(total_money), round(money / 10000, 1), info)
                    if money >= 500000:
                        pass
                    __latest_buy_order_dict[code] = [d[6], d[2], d[1], (d[3], d[1]), (d[3], d[1])]
 
    print(f"主动买:{active_buy}", f"被动买:{passive_buy}")
 
 
# 卖单统计
def statistic_sell_order():
    def is_active_sell(sell_no, buy_no):
        return sell_no > buy_no
 
    code = "002660"
    data_map = log_export.load_huaxin_transaction_map(date=tool.get_now_date_str())
    datas = data_map.get(code)
    __latest_sell_order_dict = {}
    total_money = 0
    limit_up_price = 9.2
    last_type = -1
 
    for data in datas:
        for d in data:
            if d[6] == 24975654:
                print(d[1] * d[2], d)
 
            type = -1
            if d[7] > d[6]:
                type = 0
            else:
                type = 1
            if type == 0 and last_type == 1 and d[1] == limit_up_price:
                print("被动卖变主动卖", d)
            last_type = type
 
            # if d[6] == 21296620:
            #     if d[7] > d[6]:
            #         print("主动卖", d)
            #     else:
            #         print("被动卖", d[1] * d[2], d)
            if code not in __latest_sell_order_dict:
                __latest_sell_order_dict[code] = [d[7], d[2], d[1], (d[3], d[6]), (d[3], d[6])]
            else:
                if __latest_sell_order_dict[code][0] == d[7]:
                    __latest_sell_order_dict[code][1] += d[2]
                    __latest_sell_order_dict[code][2] = d[1]
                    __latest_sell_order_dict[code][4] = (d[3], d[6])
                else:
                    info = __latest_sell_order_dict[code]
                    money = info[1] * info[2]
                    if is_active_sell(info[0], info[3][1]) and 1000 * 10000 > money > 10 * 10000 and 7852775 > info[
                        0] > 7807625:
                        total_money += money
                        # print("主动卖:", round(money / 10000), total_money, info)
 
                    # 上个卖单成交完成
                    # 封存数据,计算新起点
                    # 大于50w的卖单才会保存
                    # 大于50w加入卖单
 
                    # if tool.trade_time_sub(l2_huaxin_util.convert_time(info[3][0]), "10:08:30") >= 0:
                    #     if info[2] >= 11.54:
                    #         total_money += money
                    #         print(money, round(total_money), info)
                    # if money >= 500000:
                    #     pass
                    __latest_sell_order_dict[code] = [d[7], d[2], d[1], (d[3], d[6]), (d[3], d[6])]
 
 
def load_sell_info():
    date = tool.get_now_date_str()
    data_map = log_export.load_huaxin_transaction_map(date=date)
    for code in data_map:
        if code != '002562':
            continue
        datas = data_map[code]
        for d in datas:
            big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, d)
    async_log_util.run_sync()
 
 
def test_sell_order_info():
    code = "600490"
    l2_data_util.load_l2_data(code, force=True)
    date = tool.get_now_date_str()
    data_map = log_export.load_huaxin_transaction_map(date=date)
    datas = data_map.get(code)
    for i in range(len(datas)):
        d = datas[i]
        big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, d)
 
        if big_sell_order_info[1] and big_sell_order_info[1][-1][0] == 559018:
            print(big_sell_order_info)
            SCancelBigNumComputer().set_real_place_order_index(code, 208, False)
            SCancelBigNumComputer().set_big_sell_order_info_for_cancel(code, big_sell_order_info,
                                                                       OrderBeginPosInfo(
                                                                           mode=OrderBeginPosInfo.MODE_ACTIVE,
                                                                           buy_single_index=0,
                                                                           buy_exec_index=13))
        # if big_sell_order_info[0] < 50 * 10000:
        #     continue
        # print(i, sum([x[1] * x[2] for x in big_sell_order_info[1]]), big_sell_order_info)
 
 
def test_process_transaction_datas():
    data_map = log_export.load_huaxin_transaction_map(date="2024-04-17")
    code = "000035"
    datas = data_map.get(code)
    l2_data_util.load_l2_data(code)
    for data in datas:
        HuaXinTransactionDatasProcessor.statistic_big_order_infos(code, data)
 
    async_log_util.run_sync()
 
    # L2TradeSingleDataProcessor.add_l2_delegate_limit_up_sell(code, {"val": {"orderNo": 123123}, "index": 123})
    #
    # for data in datas:
    #     L2TradeSingleDataProcessor.process_passive_limit_up_sell_data(code, data, 5.78)
 
 
if __name__ == '__main__':
    # s
    # real_order_time_ms = "09:30:47" + ".{0:0>3}".format(220)
    # big_sell_order_info = [1809599, [[7351750, 208000, 8.7, (11042670, 527268), (11042670, 527275)]]]
    # max_money = 0
    # for x in big_sell_order_info[1]:
    #     deal_time = l2_huaxin_util.convert_time(x[4][0], with_ms=True)
    #     if real_order_time_ms:
    #         if tool.trade_time_sub_with_ms(deal_time, real_order_time_ms) >= 0:
    #             print("123123")
    # test_process_transaction_datas()
    # BigOrderDealManager()
    pass