Administrator
2023-03-30 8ef576b9a1809dd52dacaafe960db456b09e9e0b
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
"""
代码信息对外输出
"""
 
# score_info 得分信息
# 下单参数信息
# 选股宝
# 市场热度
import code_volumn_manager
import global_data_loader
import global_util
import gpcode_manager
import juejin
import limit_up_time_manager
import log
import tool
from l2 import l2_data_manager, l2_data_util, transaction_progress, l2_data_manager_new, code_price_manager
from third_data import hot_block_data_process
from trade import first_code_score_manager, l2_trade_factor
from trade.l2_trade_factor import L2TradeFactorUtil
import trade.deal_big_money_manager
 
 
def __format_data(code_info, score_info, buy_params_info, xgb_code_info, xgb_infos, codes_score, trade_info):
    html = ""
    html += f"<h2>{code_info[1]} {code_info[0]}</h2><br>"
 
 
 
    if score_info:
        html += "<b>-----买前评分-------</b><br>"
        score_types = ["换手量能", "竞价强度", "资金力度", "日线形态", "历史股性", "板块热度", "上板时间", "市值大小", "股价大小"]
        html += "<table style='font-size:25px'>"
        for i in range(0, len(score_info[1])):
            html += f"<tr><td>{score_types[i]}</td><td>{score_info[1][i]}</td><td>{score_info[2][i]}</td></tr>"
        html += f"<tr><td><b>评分求和:</td><td>{score_info[0]}</b></td><td></td></tr>"
        html += f"</table><br>"
 
    if buy_params_info:
        html += "<b><br>-----交易参数-------<br></b><table>"
        titles = ["买入意愿", "安全笔数", "动态M值", "买前大单", "成交进度", "买入信号", "买入执行位"]
        for i in range(0, len(titles)):
            html += f"<tr><td>{titles[i]}:</td><td>{buy_params_info[i]}</td></tr>"
        html += "</table><br>"
 
    if xgb_code_info:
        html += "<b><br>-----选股宝---------<br></b>"
        xgb_code_info_dates = ["今天", "昨天", "前天", "之前"]
        for i in range(0, len(xgb_code_info)):
            html += f"{xgb_code_info_dates[i]}:<br>"
            if xgb_code_info[i]:
                for info in xgb_code_info[i]:
                    if i == 0:
                        html += f"【<font color='red'>{info[0]}</font>】,共【<font color='red'>{info[1]}</font>】只票涨停<br>第【<font color='red'>{info[2]}</font>】涨停,现价【<font color='red'>{info[3]}</font>】元,涨幅【<font color='red'>{info[4]}</font>】<br><br>"
                    else:
                        html += f"【{info[0]}】,共【{info[1]}】只票涨停<br>第【{info[2]}】涨停,现价【{info[3]}】元,涨幅【{info[4]}】<br><br>"
            else:
                html += f"无<br>"
    if codes_score[0]:
        html += "<b>-----主动买入-------</b><br>"
        html += "<table>"
        for i in range(0, len(codes_score[0])):
            if i % 4 == 0:
                html += "<tr>"
            html += f"<td><font color='red'>{codes_score[0][i][1]}:{codes_score[0][i][2]}</font></td>"
            if i % 4 == 3 or i == len(codes_score[0]) - 1:
                html += "</tr>"
        html += "</table><br>"
 
    if codes_score[1]:
        html += "<b>-----被动买入-------</b><br>"
        html += "<table>"
        for i in range(0, len(codes_score[1])):
            if i % 4 == 0:
                html += "<tr>"
            html += f"<td><font color='#000080'>{codes_score[1][i][1]}:{codes_score[1][i][2]}</font></td>"
            if i % 4 == 3 or i == len(codes_score[1]) - 1:
                html += "</tr>"
        html += "</table><br>"
 
    if codes_score[2]:
        html += "<b>-----不买入-------</b><br>"
        html += "<table>"
        for i in range(0, len(codes_score[2])):
            if i % 4 == 0:
                html += "<tr>"
            html += f"<td>{codes_score[2][i][1]}:{codes_score[2][i][2]}</td>"
            if i % 4 == 3 or i == len(codes_score[1]) - 1:
                html += "</tr>"
        html += "</table><br>"
 
    if trade_info:
        html += "<b>-----今日挂撤记录-------</b><br>"
        html += "<br>今日是否炸板:"
        if trade_info[0]:
            html += f"炸板-{trade_info[0]}"
        else:
            html += f"未炸板"
        if trade_info[1]:
            html += "<table>"
            for i in range(0, len(trade_info[1])):
                if i % 2 == 0:
                    html += "<tr>"
                html += f"<td>第{i + 1}次下单 评分{trade_info[1][i][1][0][0]} {trade_info[1][i][0]} </td>"
                if i % 2 == 1 or i == len(codes_score[0]) - 1:
                    html += "</tr>"
            html += "</table><br>"
        html += "<br>"
 
    if xgb_infos:
        html += "<b><br>-----市场热度-------<br></b><table>"
        for info in xgb_infos:
            html += f"<tr><td><font size='3'>{info[0]}</font><br><div style='margin-left:100px;'>{info[1]}</div></td></tr>"
        html += "</tr>"
    html += "<br><br>"
    return html
 
 
def get_output_html(code):
    day = tool.get_now_date_str()
    is_target_code = gpcode_manager.FirstCodeManager.is_in_first_record(code)
    code_info = [code, gpcode_manager.get_code_name(code)]
    score_info = None
    buy_params_info = None
    xgb_infos = None
    if is_target_code:
        limit_up_price = gpcode_manager.get_limit_up_price(code)
        limit_up_time = limit_up_time_manager.get_limit_up_time(code)
        volume_rate, volume_info = code_volumn_manager.get_volume_rate(code, True)
        (score, score_list), score_source_list = first_code_score_manager.get_score(code, volume_rate, limit_up_time,
                                                                                    True)
        ################################买前评分################################
        # ["换手量能", "竞价强度", "资金力度", "K线形态", "历史股性", "板块热度", "上板时间", "市值大小","股价大小"]
        score_list_new = []
        score_source_list_new = []
        # 换手量能
        score_list_new.append(score_list[6])
        # 获取当前量信息
        max_60, yest = code_volumn_manager.get_histry_volumn(code)
        today = code_volumn_manager.get_today_volumn(code)
        score_source_list_new.append(
            f"实时量【{round(int(today) / 1000000, 2)}万手】÷前高量【{round(max_60[0] / 1000000, 2)}万手-{max_60[1]}】=【{round(score_source_list[6] * 100, 2)}%】")
        # 竞价强度
        score_list_new.append(score_list[2])
        score_source_list_new.append(f"开盘啦今日委停【{score_source_list[2] if score_source_list[2] else 0}万】")
        total_datas = l2_data_util.local_today_datas.get(code)
        if total_datas is None:
            l2_data_util.load_l2_data(code)
            total_datas = l2_data_util.local_today_datas.get(code)
        # 资金力度
        deal_indexes = trade.deal_big_money_manager.get_traded_indexes(code)
        deal_info = ""
        if deal_indexes:
            temps = []
            for index in deal_indexes:
                temps.append(int(index))
            temps.sort()
            start_index = temps[0]
            end_index = temps[-1]
            deal_info = f"【{total_datas[start_index]['val']['time']}&{total_datas[start_index]['val']['num']}手-{total_datas[end_index]['val']['time']}&{total_datas[end_index]['val']['num']}手】,"
 
        score_list_new.append(score_list[8])
        score_source_list_new.append(
            f"{deal_info}<br>累计金额【{score_source_list[8][0] // 10000}万】&固定m值【{score_source_list[8][1] // 10000}万】")
        # K线形态
        k_score = 0
        k_source = []
        for k in score_list[3]:
            k_score += k
 
        # (15个交易日是否涨幅24.9%,是否破前高,是否超跌,是否接近前高,是否N,是否V)
        for k in range(0, len(score_source_list[3])):
            if k == 0:
                if score_source_list[3][k][0]:
                    k_source.append("【涨幅过高】")
            elif k == 1:
                if score_source_list[3][k][0]:
                    k_source.append("【突破前高】")
            elif k == 2:
                if score_source_list[3][k][0]:
                    k_source.append("【超跌补涨】")
            elif k == 3:
                if score_source_list[3][k][0]:
                    k_source.append(f"【逼近前高-{score_source_list[3][k][1]}】")
            elif k == 4:
                if score_source_list[3][k][0]:
                    k_source.append("【N字型】")
            elif k == 5:
                if score_source_list[3][k][0]:
                    k_source.append("【V字型】")
            elif k == 6:
                if not score_source_list[3][k][0]:
                    k_source.append("【不满足任何形态】")
            elif k == 7:
                if score_source_list[3][k][0]:
                    k_source.append("【天量大阳】")
 
        score_list_new.append(k_score)
        score_source_list_new.append("/".join(k_source))
        # 历史股性
        nature_score = 0
        nature_source = []
        for k in score_list[4]:
            nature_score += k
 
        for n in range(0, len(score_source_list[4])):
            if n == 0:
                if not score_source_list[4][n]:
                    nature_source.append("无涨停")
                else:
                    nature_source.append("有涨停")
            if n == 1:
                nature_source.append(f"首板溢价率【{round(score_source_list[4][2],2)}】")
 
        score_list_new.append(nature_score)
        score_source_list_new.append(",".join(nature_source))
 
        # 板块热度
        hot_block_score = 0
        hot_block_source = []
        for k in score_list[5]:
            hot_block_score += k
        for n in range(0, len(score_source_list[5])):
            if n == 1:
                hot_block_source.append(f"【{score_source_list[5][0]}】共{score_source_list[5][n]}个涨停")
            elif n == 2:
                hot_block_source.append(f"共{score_source_list[5][n]}个炸板")
            elif n == 4:
                if score_source_list[5][n]:
                    hot_block_source.append(f"【{score_source_list[5][n][0][0]}】{score_source_list[5][n][1]}")
        score_list_new.append(hot_block_score)
        score_source_list_new.append(",".join(hot_block_source))
 
        # 上板时间
        score_list_new.append(score_list[7])
        score_source_list_new.append(f"上板时间【{score_source_list[7]}】")
        # 市值大小
        score_list_new.append(score_list[0])
        score_source_list_new.append(f"自由市值【{round(score_source_list[0] / 100000000, 2)}亿】")
        # 股价大小
        score_list_new.append(score_list[1])
        score_source_list_new.append(f"现价【{score_source_list[1]}】元")
 
        score_info = (score, score_list_new, score_source_list_new)
 
        # zyltgb, limit_price, bidding, k_form, code_nature, hot_block, volume_rate, limit_up_time,
        # deal_big_money
 
        ###############################下单信息###############################
        # 获取买入意愿
        volume_rate = score_source_list[6]
        __L2PlaceOrderParamsManager = l2_trade_factor.L2PlaceOrderParamsManager(code, True, volume_rate,
                                                                                code_volumn_manager.get_volume_rate_index(
                                                                                    volume_rate),
                                                                                (
                                                                                    (score, score_list),
                                                                                    score_source_list))
        __base_L2PlaceOrderParamsManager = l2_trade_factor.L2PlaceOrderParamsManager(code, False, volume_rate,
                                                                                     code_volumn_manager.get_volume_rate_index(
                                                                                         volume_rate),
                                                                                     ((score, score_list),
                                                                                      score_source_list))
        buy_params_info = []
        if -1 < __L2PlaceOrderParamsManager.score_index < 3:
            buy_params_info.append("<font color='red'>【主动买入】</font>")
        elif __L2PlaceOrderParamsManager.score_index < 0:
            buy_params_info.append("【不执行买入】")
        else:
            buy_params_info.append("【被动买入】")
        # 安全笔数
        safe_count = __L2PlaceOrderParamsManager.get_safe_count()
        base_safe_count, min_count, max_count = L2TradeFactorUtil.get_safe_buy_count(code, True)
        buy_params_info.append(f"固定安全笔数【{base_safe_count}】笔,衰减后安全笔数【{safe_count}】笔")
        # 动态M值
        m = __L2PlaceOrderParamsManager.get_m_val()
        zyltgb = global_util.zyltgb_map.get(code)
        if zyltgb is None:
            global_data_loader.load_zyltgb()
            zyltgb = global_util.zyltgb_map.get(code)
        base_m = L2TradeFactorUtil.get_base_safe_val(zyltgb)
        buy_params_info.append(f"固定M值【{base_m / 10000}万】,动态M值【{m[0] / 10000}万】    ")
        # 买前大单
        big_num = __L2PlaceOrderParamsManager.get_big_num_count()
        base_big_num = __base_L2PlaceOrderParamsManager.get_big_num_count()
        buy_params_info.append(f"固定买前大单【{base_big_num}】笔,衰减后买前大单【{big_num}】笔")
        # 成交进度
        trade_progress, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code)
        if trade_progress is None or trade_progress < 0 or is_default:
            buy_params_info.append("未识别")
        else:
            data = total_datas[trade_progress]
            buy_params_info.append(
                f"【{data['val']['time']}】、【{data['val']['num']}手】、【{round(data['val']['num'] * float(data['val']['price']) * 100 / 10000, 1)}万】")
 
        # 买入信号
        buy_single_index, buy_exec_index, compute_index, num, count, max_num_set, volume_rate = l2_data_manager.TradePointManager.get_buy_compute_start_data(
            code)
 
        if buy_single_index is None:
            buy_params_info.append("无信号")
        else:
            data = total_datas[buy_single_index]
            buy_params_info.append(
                f"【{data['val']['time']}】、【{data['val']['num']}手】、【{round(data['val']['num'] * float(data['val']['price']) * 100 / 10000, 1)}万】")
 
        if buy_exec_index is None or buy_exec_index < 0:
            buy_params_info.append("未下单")
        else:
            data = total_datas[buy_exec_index]
            buy_params_info.append(
                f"【{data['val']['time']}】、【{data['val']['num']}手】、【{round(data['val']['num'] * float(data['val']['price']) * 100 / 10000, 1)}万】")
 
    ##############################选股宝##################################
    xgb_code_info = []
    for i in range(0, 4):
        xgb_datas = hot_block_data_process.XGBHotBlockDataManager.list_by_code(code, day)
        datas = []
        if xgb_datas:
            for data in xgb_datas:
                block = data[2]
                block_datas = hot_block_data_process.XGBHotBlockDataManager.list_by_block(block, day)
                block_datas = list(block_datas)
                limit_up_count = 0
                limit_up_time = None
                for d in block_datas:
                    if len(d[4]) > 6:
                        limit_up_count += 1
                        if d[3] == code:
                            limit_up_time = d[4]
 
                # 根据涨停时间排序
                block_datas.sort(key=lambda d: (d[4] if len(d[4]) > 6 else '15:00:00'))
 
                for i in range(len(block_datas)):
                    if block_datas[i][3] == code:
                        datas.append(
                            (block, limit_up_count, (i + 1) if limit_up_time is not None else (limit_up_count + 1),
                             block_datas[i][5], block_datas[i][6]))
                        break
        xgb_code_info.append(datas)
        day = juejin.JueJinManager.get_previous_trading_date(day)
 
    ##############################热门风口##################################
    xgb_infos = []
    xgb_latest_datas = hot_block_data_process.XGBHotBlockDataManager.latest_datas
    if not xgb_latest_datas:
        xgb_infos.append('暂未获取到数据')
    else:
        # 获取今日的所有数据
        datas_record = hot_block_data_process.XGBHotBlockDataManager.list_all(tool.get_now_date_str())
        datas_record_dict = {}
        for data in datas_record:
            block = data[2]
            if block not in datas_record_dict:
                datas_record_dict[block] = []
            # 代码,代码名称,涨停时间,首次涨停时间
            datas_record_dict[block].append((data[3], data[9], data[4], data[8], block))
 
        for block in xgb_latest_datas:
            limit_up_count = 0
            codes = datas_record_dict.get(block[0])
            for code_data in block[2]:
                if len(code_data[4]) > 6:
                    limit_up_count += 1
            # 获取板块中的代码
            block_codes_set = set()
            for d in block[2]:
                code = d[0][1].split(".")[0]
                block_codes_set.add(code)
 
            if codes:
                codes_data_html = "<table><tr>"
                count = 0
                for code_data in codes:
                    if code_data[4] != block[0]:
                        # 不是该板块数据
                        continue
                    count += 1
                    codes_data_html += "<td>"
                    # 如果代码涨停时间或者没有在最新的代码中
                    if (len(code_data[2]) < 6 or code_data[0] not in block_codes_set) and len(code_data[3]) > 6:
                        # 炸板
                        codes_data_html += f"<font color='#000080'>{code_data[1]}:{code_data[0]}&nbsp;&nbsp;</font>"
                    elif len(code_data[2]) > 6:
                        # 涨停
                        codes_data_html += f"<font color='#FF3232'>{code_data[1]}:{code_data[0]}&nbsp;&nbsp;</font>"
                    else:
                        codes_data_html += f"{code_data[1]}:{code_data[0]}&nbsp;&nbsp;"
                    codes_data_html += "</td>"
                    if count % 4 == 0:
                        codes_data_html += "</tr><tr>"
                codes_data_html += "</tr></table>"
                xgb_infos.append((f"***【{block[0]}】,涨幅【{block[1]}】,共【{limit_up_count}】个涨停", codes_data_html))
    codes_score = __load_codes_scores()
    trade_info = __load_trade_record(code)
    return __format_data(code_info, score_info, buy_params_info, xgb_code_info, xgb_infos, codes_score, trade_info)
 
 
def __load_codes_scores():
    # 获取所有监听中的代码
    codes = gpcode_manager.get_first_gp_codes()
    scores = l2_data_manager_new.L2TradeDataProcessor.get_code_scores()
    for code in codes:
        if code not in scores:
            # 获取分数
            limit_up_time = limit_up_time_manager.get_limit_up_time(code)
            if limit_up_time is None:
                continue
            volume_rate, volume_info = code_volumn_manager.get_volume_rate(code, True)
            (score, score_list), score_source_list = first_code_score_manager.get_score(code, volume_rate,
                                                                                        limit_up_time,
                                                                                        True)
            scores[code] = score
    # 筛选180分以上的代码
    scores_list = []
    for code in scores:
        code_name = gpcode_manager.get_code_name(code)
        scores_list.append((code, code_name, scores[code]))
    scores_list.sort(key=lambda x: x[2], reverse=True)
    fscores_list = [[], [], []]
    for score in scores_list:
        if score[2] >= 180:
            fscores_list[0].append(score)
        elif score[2] >= 100:
            fscores_list[1].append(score)
        else:
            fscores_list[2].append(score)
 
    return fscores_list
 
 
def __load_trade_record(code):
    # 获取炸板信息
    limit_up_info = code_price_manager.Buy1PriceManager.get_limit_up_info(code)
    break_time = limit_up_info[1]
    records = log.load_buy_score_recod(code)
    return break_time, records
 
 
if __name__ == '__main__':
    code = "002410"
    day = '2023-03-27'
    xgb_datas = hot_block_data_process.XGBHotBlockDataManager.list_by_code(code, day)
    datas = []
    if xgb_datas:
        for data in xgb_datas:
            block = data[2]
            block_datas = hot_block_data_process.XGBHotBlockDataManager.list_by_block(block, day)
            block_datas = list(block_datas)
            limit_up_count = 0
            limit_up_time = None
            for d in block_datas:
                if len(d[4]) > 6:
                    limit_up_count += 1
                    if d[3] == code:
                        limit_up_time = d[4]
 
            # 根据涨停时间排序
            block_datas.sort(key=lambda d: (d[4] if len(d[4]) > 6 else '15:00:00'))
 
            for i in range(len(block_datas)):
                if block_datas[i][3] == code:
                    datas.append((block, limit_up_count, (i + 1) if limit_up_time is not None else (limit_up_count + 1),
                                  block_datas[i][5], block_datas[i][6]))
                    break