Administrator
5 天以前 c05044c53a5d0213ef33b2b3bdbb57a328300ad2
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
"""
低吸策略
"""
import json
import os
 
import constant
from db.mysql_data_delegate import Mysqldb
from strategy import strategy_variable
 
 
class BackTest:
    """
    回退测试
    """
 
 
class LowSuctionOriginDataExportManager:
    """
    原始数据导出
    """
 
    def __init__(self, day):
        """
        初始化设置
        @param day: 日期
        """
        self.day = day
 
    def __export_logs(self, path_):
        """
        导出日志
        @param path_:日志路径
        @return:日志列表
        """
        path_str = f"{constant.get_path_prefix()}/{path_}"
        if os.path.exists(path_str):
            with open(path_str, encoding='utf-8', mode='r') as f:
                return f.readlines()
        return None
 
    def __get_log_time(self, line, with_ms=True):
        if with_ms:
            time_ = line.split("|")[0].split(" ")[1]
        else:
            time_ = line.split("|")[0].split(" ")[1].split(".")[0]
        return time_
 
    def __get_async_log_time(self, line, with_ms=True):
        line = line.split(" - ")[1]
        if with_ms:
            time_str = line[line.find("[") + 1:line.find("[") + 9 + 4]
        else:
            time_str = line[line.find("[") + 1:line.find("[") + 9]
        return time_str
 
    def export_new_block(self):
        """
        导出新板块
        @return:[(日期,代码,新题材板块)]
        """
        fdatas = []
        lines = self.__export_logs(f"logs/gp/trade/trade_record.{self.day}.log")
        for line in lines:
            time_str = self.__get_async_log_time(line)
            data = line[line.find("]") + 1:].strip()
            data = json.loads(data)
            if data["type"] == 'action' and data["data"].get("type") == '新题材':
                code = data["code"]
                blocks = eval(data["data"].get("msg").replace("新题材辨识度设置:", ""))
                fdatas.append((time_str, code, blocks))
        fdatas.sort(key=lambda x: x[0])
        return fdatas
 
    def export_special_codes(self):
        """
        导出新板块
        @return:{板块:{代码}}
        """
        lines = self.__export_logs(f"logs/gp/plates/special_codes.{self.day}.log")
        if lines:
            line = lines[0]
            line = line[line.find(" - ") + 3:]
            return eval(line)
        return None
 
    def export_latest_gaobiao(self):
        """
        导出最近高标
        @return:{板块:{代码}}
        """
        lines = self.__export_logs(f"logs/gp/kpl/kpl_latest_gaobiao.{self.day}.log")
        if lines:
            line = lines[0]
            line = line[line.find(" - ") + 3:]
            return eval(line)
        return None
 
    def export_block_in_datas(self):
        """
        板块流入
        @return:[(板块,流入金额)]
        """
        lines = self.__export_logs(f"logs/gp/kpl/kpl_jx_in.{self.day}.log")
        fdatas = []
        for line in lines:
            if line.find("原数据:") < 0:
                continue
            time_str = self.__get_async_log_time(line)
            line = line[line.find("原数据:") + 4:]
            line = line[:line.find("板块:")]
            temp_list = eval(line)
            data = [(x[1], x[3]) for x in temp_list]
            fdatas.append((time_str, data))
        return fdatas
 
    def export_block_out_datas(self):
        """
        板块流入
        @return:[(板块,流入金额)]
        """
        lines = self.__export_logs(f"logs/gp/kpl/kpl_jx_out.{self.day}.log")
        fdatas = []
        for line in lines:
            if line.find("原数据:") < 0:
                continue
            time_str = self.__get_async_log_time(line)
            line = line[line.find("原数据:") + 4:]
            line = line[:line.find("板块:")]
            temp_list = eval(line)
            data = [(x[1], x[3]) for x in temp_list]
            fdatas.append((time_str, data))
        return fdatas
 
    def export_limit_up_list(self):
        """
        涨停列表
        @return:
        """
        lines = self.__export_logs(f"logs/gp/kpl/kpl_limit_up.{self.day}.log")
        fdatas = []
        for line in lines:
            time_str = self.__get_log_time(line)
            line = line[line.find(" - ") + 3:]
            temp_list = eval(line)
            fdatas.append((time_str, temp_list))
        return fdatas
 
    def export_kpl_market_strong(self):
        """
        市场强度
        @return:
        """
        lines = self.__export_logs(f"logs/gp/kpl/kpl_market_strong.{self.day}.log")
        fdatas = []
        for line in lines:
            time_str = self.__get_log_time(line)
            line = line[line.find(" - ") + 3:].strip()
            strong = int(line)
            fdatas.append((time_str, strong))
        return fdatas
 
    def export_zylt_volume(self):
        """
        导出自由流通量
        @return:
        """
        lines = self.__export_logs(f"logs/gp/code_attribute/zylt_gb.{self.day}.log")
        for line in lines:
            line = line[line.find(" - ") + 3:].strip()
            return eval(line)
        return None
 
    def export_big_order_deal(self, min_money=299e4):
        """
        大单成交
        @return: {"代码":[(买单号, 量, 金额, 时间, 最终成交价)]}
        """
 
        fdatas = {}
        lines = self.__export_logs(f"logs/huaxin_local/l2/transaction_accurate_big_order.{self.day}.log")
        if lines:
            for line in lines:
                line = line[line.find(" - ") + 3:].strip()
                data = eval(line)
                if data[1] != 0:
                    continue
                if data[2][2] < min_money:
                    continue
                if data[0] not in fdatas:
                    fdatas[data[0]] = []
                fdatas[data[0]].append(data[2])
        return fdatas
 
    def export_all_big_order_deal(self, min_money=299e4):
        """
        所有大单成交,包含买,卖
        @return: {"代码":[代码,卖/买, (买单号, 量, 金额, 时间, 最终成交价)]}
        """
 
        fdatas = {}
        lines = self.__export_logs(f"logs/huaxin_local/l2/transaction_accurate_big_order.{self.day}.log")
        if lines:
            for line in lines:
                line = line[line.find(" - ") + 3:].strip()
                data = eval(line)
                if data[2][2] < min_money:
                    continue
                if data[0] not in fdatas:
                    fdatas[data[0]] = []
                fdatas[data[0]].append(data)
        return fdatas
 
    def export_big_sell_order_deal(self, min_money=299e4):
        """
        大单成交
        @return: {"代码":[(买单号, 量, 金额, 时间, 最终成交价)]}
        """
        fdatas = {}
        lines = self.__export_logs(f"logs/huaxin_local/l2/transaction_accurate_big_order.{self.day}.log")
        for line in lines:
            line = line[line.find(" - ") + 3:].strip()
            data = eval(line)
            if data[1] != 1:
                continue
            if data[2][2] < min_money:
                continue
            if data[0] not in fdatas:
                fdatas[data[0]] = []
            fdatas[data[0]].append(data[2])
        return fdatas
 
    def export_big_order_deal_by(self, min_money=299e4):
        """
        大单成交
        @return: {"代码":[(买单号, 量, 金额, 时间, 最终成交价)]}
        """
        buy_order_nos = set()
        fdatas = {}
        lines = self.__export_logs(f"logs/huaxin_local/l2/transaction_big_order.{self.day}.log")
        if lines:
            for line in lines:
                line = line[line.find(" - ") + 3:].strip()
                data = eval(line)
                if data[1] != 0:
                    continue
                if data[2][2] < min_money:
                    continue
                if data[2][0] in buy_order_nos:
                    continue
                if data[0] not in fdatas:
                    fdatas[data[0]] = []
                fdatas[data[0]].append(data[2])
        return fdatas
 
    def export_big_sell_order_deal_by(self, min_money=299e4):
        """
        大单成交
        @return: {"代码":[(买单号, 量, 金额, 时间, 最终成交价)]}
        """
        buy_order_nos = set()
        fdatas = {}
        lines = self.__export_logs(f"logs/huaxin_local/l2/transaction_big_order.{self.day}.log")
        for line in lines:
            line = line[line.find(" - ") + 3:].strip()
            data = eval(line)
            if data[1] != 1:
                continue
            if data[2][2] < min_money:
                continue
            if data[2][0] in buy_order_nos:
                continue
            if data[0] not in fdatas:
                fdatas[data[0]] = []
            fdatas[data[0]].append(data[2])
        return fdatas
 
    def export_code_plates(self):
        """
        代码板块
        @return: {"代码":[(买单号, 量, 金额, 时间, 最终成交价)]}
        """
        lines = self.__export_logs(f"logs/gp/plates/code_plates.{self.day}.log")
        for line in lines:
            if line:
                line = line[line.find(" - ") + 3:].strip()
                data = eval(line)
        return data
 
    def export_current_limit_up_records(self):
        """
        导出当日历史涨停
        @return: [(代码, 代码名称, 涨停原因, 涨停时间, 高度信息, 自由流通市值,是否炸板)]
        """
        results = Mysqldb().select_all(
            f"select r.`_code`, r.`_code_name`, r.`_hot_block_name`, r.`_limit_up_time`, r.`_limit_up_high_info`, r.`_zylt_val`, r.`_open`  from kpl_limit_up_record r where r._day = '{self.day}'")
        return results
 
 
class LowSuctionDataManager:
    """
    低吸数据管理
    """
 
    def __init__(self):
        pass
 
    def set_tick_data(self, tick_data):
        """
        tick数据: (代码, 现价, 涨幅, 量, 当前时间, 买1价, 买1量, 买2价, 买2量, 更新时间)
        根据tick数据驱动是否可以买
        @param tick_data:
        @return:
        """
        pass
 
    def set_kpl_limit_up_list(self, limit_up_list):
        """
        设置涨停列表
        @return:
        """
 
    def set_new_block(self, code, blocks):
        """
        设置新题材
        @param code: 代码
        @param blocks: 板块
        @param is_limit_up:
        @return:
        """
 
    def set_kpl_market_strong(self, strong):
        """
        开盘啦市场强度
        @param strong:
        @return:
        """
 
    def set_code_special_blocks_dict(self, data):
        """
        设置代码的辨识度板块
        @param data:
        @return:
        """
 
    def set_code_zylt_gb_dict(self, data):
        """
        设置代码的自由流通股本
        @param data:
        @return:
        """
 
    def set_block_in_info(self, data):
        """
        设置板块流入信息
        @param data:
        @return:
        """
        pass
 
    def set_forbidden_refer_codes(self, data):
        """
        设置参考禁止的代码
        @return:
        """
        pass
 
    def set_k_bars_dict(self, data):
        """
        设置K线字典
        @param data:
        @return:
        """
 
 
if __name__ == "__main__":
    fdatas = LowSuctionOriginDataExportManager("2025-06-09").export_big_order_deal_by()
    fdatas = fdatas.get("000795")
    print(sum([x[2] for x in fdatas]))
    result = eval("1>2")
    print(type(result))
    print(eval(strategy_variable.大单表达式))