admin
17 小时以前 2021a36c8dac7f659b1e0f1e261309366d500cf6
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
import datetime
import hashlib
import json
import logging
import os
import time
 
import constant
from log_module.log import printlog
from utils import tool
 
 
class LogUtil:
    @classmethod
    def extract_log_from_key(cls, key, path, target_path):
        fw = open(target_path, mode='w', encoding="utf-8")
        try:
            with open(path, 'r', encoding="utf-8") as f:
                lines = f.readlines()
                for line in lines:
                    if line.find("{}".format(key)) > 0:
                        fw.write(line)
        finally:
            fw.close()
 
 
# 获取日志时间
def __get_log_time(line):
    time_ = line.split("|")[0].split(" ")[1].split(".")[0]
    return time_
 
 
def __get_async_log_time(line):
    line = line.split(" - ")[1]
    time_str = line[line.find("[") + 1:line.find("[") + 9]
    if time_str.replace(":", "").replace(".", "").isdigit():
        return time_str
    return None
 
 
__log_file_contents = {}
 
 
# 加载文件内容
def __load_file_content(path_str, expire_timespace=20):
    md5 = hashlib.md5(path_str.encode(encoding='utf-8')).hexdigest()
    if md5 in __log_file_contents and time.time() - __log_file_contents[md5][0] < expire_timespace:
        return __log_file_contents[md5][1]
    contents = []
    if os.path.exists(path_str):
        with open(path_str, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            for line in lines:
                contents.append(line)
    __log_file_contents[md5] = (time.time(), contents)
    return contents
 
 
# 加载板块强度日志
def load_market_sift_plate(date=tool.get_now_date_str()):
    """
     获取精选流入的成分股
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/kpl/market_sift_plate.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            for line in lines:
                if line:
                    time_str = __get_log_time(line)
                    try:
                        data = line.split(" - ")[1].strip()
                        data_dict = eval(data)
                        fdatas.append((time_str, data_dict))
                    except:
                        pass
    return fdatas
 
 
# 加载个股强度日志
def load_kpl_market_stock_heat(date=tool.get_now_date_str()):
    """
     获取精选流入的成分股
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/kpl/stock_of_markets_plate.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            for line in lines:
                if line:
                    time_str = __get_async_log_time(line)
                    try:
                        data = line.split(" - ")[1].strip()
                        if data.startswith("["):
                            data = data[data.find("]") + 1:].strip()
                        data_dict = eval(data)
                        fdatas.append((time_str, data_dict))
                    except:
                        pass
    return fdatas
 
 
def load_kpl_market_strong(date=tool.get_now_date_str()):
    """
     获取开盘啦历史强度
    :param date:
    :return: [("时间","分数")]
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/kpl/Overall_market_strength_score.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            for line in lines:
                if line:
                    time_str = __get_async_log_time(line)
                    try:
                        data = line.split(" - ")[1].strip()
                        if data.startswith("["):
                            data = data[data.find("]") + 1:].strip()
                        fdatas.append((time_str, int(data)))
                    except:
                        pass
    return fdatas
 
 
def load_target_codes_info(date=tool.get_now_date_str()):
    """
     获取开盘啦历史强度
    :param date:
    :return: [("时间","分数")]
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/codes/target_codes.{date}.log"
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            if lines:
                line = lines[0]
                if line:
                    try:
                        data = line.split(" - ")[1].strip()
                        if data.startswith("[") and data.find("]") < 20:
                            data = data[data.find("]") + 1:].strip()
                        return eval(data)
                    except:
                        pass
    return None
 
 
def load_k_bars(date=tool.get_now_date_str()):
    """
    加载K线数据
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/local_storage_data/all_stocks_all_K_line_property_dict.{date}.json"
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            return json.loads(lines[0])
    return None
 
 
def load_kpl_code_plates(date=tool.get_now_date_str()):
    """
    加载代码板块数据
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/kpl/kpl_code_plates.{date}.log"
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            if lines:
                line = lines[0]
                data = line.split(" - ")[1].strip()
                if data.startswith("["):
                    data = data[data.find("]") + 1:].strip()
                return eval(data)
    return None
 
 
def load_kpl_limit_up_datas(date=tool.get_now_date_str()):
    """
    加载开盘啦涨停数据
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/kpl/kpl_limit_up.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            if lines:
                for line in lines:
                    time_str = __get_async_log_time(line)
                    data = line.split(" - ")[1].strip()
                    if data.startswith("["):
                        data = data[data.find("]") + 1:].strip()
                    fdatas.append((time_str, eval(data)))
    return fdatas
 
 
def load_stock_of_markets_plate_simple(start_time_str, end_time_str, date=tool.get_now_date_str()):
    """
    加载开盘啦精选板块及其代码
    :param end_time_str: 结束时间
    :param start_time_str: 开始时间
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/kpl/stock_of_markets_plate_simple.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            while True:
                line = f.readline()
                if not line:
                    break
                time_str = __get_async_log_time(line)
                if time_str > end_time_str:
                    break
                if start_time_str <= time_str <= end_time_str:
                    data = line.split(" - ")[1].strip()
                    if data.startswith("["):
                        data = data[data.find("]") + 1:].strip()
                    fdatas.append((time_str, eval(data)))
    return fdatas
 
 
def load_deal_big_order(date=tool.get_now_date_str()):
    """
    成交大单
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/huaxin/l2/transaction.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            if lines:
                for line in lines:
                    time_str = __get_async_log_time(line)
                    if time_str:
                        data = line.split(" - ")[1].strip()
                        if data.startswith("["):
                            data = data[data.find("]") + 1:].strip()
                    else:
                        time_str = __get_log_time(line)
                        data = line.split(" - ")[1].strip()
                    fdatas.append((time_str, eval(data)))
    return fdatas
 
 
def load_ticks_data(min_time_str, max_time_str, date=tool.get_now_date_str()):
    """
    成交大单
    :param max_time_str:
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/huaxin/l2/marketdata.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            while True:
                line = f.readline()
                if not line:
                    break
                try:
                    time_str = __get_async_log_time(line)
                    if time_str:
                        data = line.split(" - ")[1].strip()
                        if data.startswith("["):
                            data = data[data.find("]") + 1:].strip()
                    else:
                        time_str = __get_log_time(line)
                        data = line.split(" - ")[1].strip()
                    if min_time_str <= time_str <= max_time_str:
                        fdatas.append((time_str, eval(data)))
                    if time_str > max_time_str:
                        break
                except Exception as e:
                    logging.exception(e)
                    print(line)
    print(fdatas[-1])
    return fdatas
 
 
def load_forbidden_plates_data(date=tool.get_now_date_str()):
    """
    禁止买入的板块
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/kpl/forbidden_plates.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            if lines:
                for line in lines:
                    time_str = __get_async_log_time(line)
                    if time_str:
                        data = line.split(" - ")[1].strip()
                        if data.startswith("["):
                            data = data[data.find("]") + 1:].strip()
                    else:
                        time_str = __get_log_time(line)
                        data = line.split(" - ")[1].strip()
                    fdatas.append((time_str, data.split("-")[0].strip(), data.split("-")[1].strip()))
    return fdatas
 
 
def load_virtual_trade_account(date=tool.get_now_date_str()):
    """
    加载虚拟交易数据
    :param date:
    :return:
    """
    path = f"{constant.get_path_prefix()}/low_suction_log/gp/virtual_account/virtual_account_money_records.{date}.log"
    fdatas = []
    if os.path.exists(path):
        with open(path, 'r', encoding="utf-8") as f:
            lines = f.readlines()
            if lines:
                for line in lines:
                    time_str = __get_async_log_time(line)
                    data = line[line.find("]") + 1:].strip()
                    fdatas.append((time_str, eval(data)))
    return fdatas
 
 
if __name__ == '__main__':
    load_k_bars('2025-07-03')
    datas = load_ticks_data("09:50:00")
    fdatas = []
    for data in datas:
        # (距离09:15:00的秒数, 时间, 强度)
        if "11:30:00" <= data[0] <= "13:00:00":
            continue
        fdatas.append([tool.trade_time_sub(data[0], "09:15:00"), data[0], data[1]])
    print(fdatas)