Administrator
2025-06-10 efe62c0c92bee36da5179f34bb73e8ee4db6f814
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
182
183
184
"""
交易记录日志工具
"""
 
# 下单信息
import json
 
from log_module import async_log_util
from log_module.log import logger_trade_record
 
TYPE_PLACE_ORDER = "place_order"  # 下单
TYPE_REAL_PLACE_ORDER_POSITION = "real_place_order_position"  # 真实下单位置
TYPE_CANCEL_WATCH_INDEXES = "cancel_watch_indexes"  # 撤单监听位置
TYPE_FORBIDDEN_BUY = "forbidden_buy"  # 禁止买入
TYPE_CANT_PLACE_ORDER = "can_not_place_order"  # 不能下单
TYPE_CANCEL = "cancel"  # 撤单
TYPE_ACTION = "action"  # 针对代码的操作
 
 
class PlaceOrderInfo(object):
    def __init__(self, buy_single_index=None, buy_exec_index=None, m_val=None, safe_count=None, big_num_indexes=None,
                 kpl_blocks=None, kpl_match_blocks=None, mode=None, mode_desc=None, sell_info=None,
                 block_info=None):
        self.buy_single_index = buy_single_index
        self.buy_exec_index = buy_exec_index
        self.m_val = m_val
        self.safe_count = safe_count
        self.big_num_indexes = big_num_indexes
        self.kpl_blocks = kpl_blocks
        self.kpl_match_blocks = kpl_match_blocks
        self.mode = mode
        self.mode_desc = mode_desc
        self.sell_info = sell_info
        self.block_info = block_info
 
    def set_block_info(self, block_info):
        """
        @param block_info:(板块,流入金额)
        @return:
        """
        self.block_info = block_info
 
    def set_buy_index(self, buy_single_index, buy_exec_index):
        self.buy_single_index = buy_single_index
        self.buy_exec_index = buy_exec_index
 
    def set_sell_info(self, sell_info):
        self.sell_info = sell_info
 
    def set_trade_factor(self, m_val, safe_count, big_num_indexes):
        self.m_val = m_val
        self.safe_count = safe_count
        self.big_num_indexes = big_num_indexes
 
    def set_kpl_blocks(self, kpl_blocks):
        self.kpl_blocks = kpl_blocks
 
    def set_kpl_match_blocks(self, kpl_blocks):
        self.kpl_match_blocks = kpl_blocks
 
    def to_json_str(self):
        return json.dumps(vars(self))
 
    def to_dict(self):
        return vars(self)
 
    @classmethod
    def to_object(cls, json_str: str):
        d = json.loads(json_str)
        return PlaceOrderInfo(**d)
 
 
# 撤单揽括信息
class CancelWatchIndexesInfo(object):
    CANCEL_TYPE_H = "h_cancel"
    CANCEL_TYPE_S = "s_cancel"
    CANCEL_TYPE_L_UP = "l_cancel_up"
    CANCEL_TYPE_L_DOWN = "l_cancel_down"
    CANCEL_TYPE_D = "d_cancel"
 
    def __init__(self, cancel_type, buy_single_index, watch_indexes: list):
        self.cancel_type = cancel_type
        self.watch_indexes = watch_indexes
        self.buy_single_index = buy_single_index
 
    def to_json_str(self):
        return json.dumps(vars(self))
 
    def to_dict(self):
        return vars(self)
 
    @classmethod
    def to_object(cls, json_str: str):
        d = json.loads(json_str)
        return CancelWatchIndexesInfo(**d)
 
 
# 添加日志
def __add_log(type, code, data):
    try:
        fdata = {"code": code, "type": type, "data": data}
        async_log_util.info(logger_trade_record, json.dumps(fdata))
    except:
        pass
 
 
# 添加下单日志
def add_place_order_log(code, info: PlaceOrderInfo):
    __add_log(TYPE_PLACE_ORDER, code, info.to_dict())
 
 
# 加入禁止买入
def add_forbidden_buy_log(code, msg):
    __add_log(TYPE_FORBIDDEN_BUY, code, {"msg": msg})
 
 
__latest_cant_place_order_log_msg_dict = {}
 
 
# 不能买
def add_cant_place_order_log(code, msg):
    if __latest_cant_place_order_log_msg_dict.get(code) == msg:
        return
    __latest_cant_place_order_log_msg_dict[code] = msg
    __add_log(TYPE_CANT_PLACE_ORDER, code, {"msg": msg})
 
 
# 真实下单位置
def add_real_place_order_position_log(code, index, buy_single_index):
    __add_log(TYPE_REAL_PLACE_ORDER_POSITION, code, {"index": index, "buy_single_index": buy_single_index})
 
 
# 撤单策略监听位置
def add_cancel_watch_indexes_log(code, info: CancelWatchIndexesInfo):
    __add_log(TYPE_CANCEL_WATCH_INDEXES, code, info.to_dict())
 
 
# 添加撤单信息
def add_cancel_msg_log(code, real_place_order_index, msg):
    __add_log(TYPE_CANCEL, code, {"msg": msg, "real_place_order_index": real_place_order_index})
 
 
# 加红信息
def add_must_buy(code, msg=""):
    __add_log(TYPE_ACTION, code, {"type": "加红", "msg": msg})
 
 
# 加绿
def add_green(code, msg=""):
    __add_log(TYPE_ACTION, code, {"type": "加绿", "msg": msg})
 
 
# 加白
def add_white_buy(code, msg=""):
    __add_log(TYPE_ACTION, code, {"type": "加白", "msg": msg})
 
 
# 加想
def add_want_buy(code, msg=""):
    __add_log(TYPE_ACTION, code, {"type": "加想", "msg": msg})
 
 
# 移想
def remove_want_buy(code, msg=""):
    __add_log(TYPE_ACTION, code, {"type": "移想", "msg": msg})
 
 
# 加临时辨识度票
def add_temp_special_codes(code, msg=""):
    __add_log(TYPE_ACTION, code, {"type": "新题材", "msg": msg})
 
 
# 加下单耗时
def add_place_order_use_time(code, msg):
    __add_log(TYPE_ACTION, code, {"type": "下单耗时", "msg": msg})
 
 
# 加白
def add_common_msg(code, type_, msg=""):
    __add_log(TYPE_ACTION, code, {"type": type_, "msg": msg})
 
 
if __name__ == "__main__":
    pass