Administrator
9 天以前 622d2ebab2f86482e84a54e36dce09dc6162e613
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
"""
推送消息管理器
"""
import concurrent.futures
 
from utils import middle_api_protocol
 
TYPE_ORDER_ALMOST_DEAL = "order_almost_deal"  # 订单即将成交
 
TYPE_DELEGATE_QUEUE_CHANGE = "delegate_queue_change"  # 委托队列变化
 
TYPE_DELEGATE_ORDER_DANGER = "delegate_order_danger"  # 委托的订单危险
 
thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=5)
 
__order_almost_deal_filter_dict = {}
 
__delegate_order_danger_filter_dict = {}
 
 
# 推送订单快成交信息
def push_order_almost_deal(code, code_name, buy_single_index, msg, ctype='', force=False):
    if code not in __order_almost_deal_filter_dict:
        __order_almost_deal_filter_dict[code] = set()
    notify_key = f"{buy_single_index}_{ctype}"
    if force or notify_key not in __order_almost_deal_filter_dict[code]:
        __order_almost_deal_filter_dict[code].add(notify_key)
        # 强制推送或这次下单之前未推送
        __push_msg(TYPE_ORDER_ALMOST_DEAL,
                   data={"code": code, "code_name": code_name, "msg": msg})
 
 
# 推送委托的订单危险信息
def push_delegate_order_danger(code, code_name, buy_single_index, msg, ctype='', force=False):
    if code not in __delegate_order_danger_filter_dict:
        __delegate_order_danger_filter_dict[code] = set()
    notify_key = f"{buy_single_index}_{ctype}"
    if force or notify_key not in __delegate_order_danger_filter_dict[code]:
        __delegate_order_danger_filter_dict[code].add(notify_key)
        # 强制推送或这次下单之前未推送
        __push_msg(TYPE_DELEGATE_ORDER_DANGER,
                   data={"code": code, "code_name": code_name, "msg": msg})
 
 
# 推送委托队列变化消息
def push_delegate_queue_update():
    __push_msg(TYPE_DELEGATE_QUEUE_CHANGE)
 
 
# 添加消息
def __push_msg(msg_type, data=None):
    def push():
        fdata = {"type": msg_type}
        if data:
            fdata["data"] = data
        middle_api_protocol.request(middle_api_protocol.load_push_msg(fdata))
 
    thread_pool.submit(push)