Administrator
2023-03-27 8535f56dbf6e410b4a09f02f95d4d49bcc8753f2
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
"""
代码信息对外输出
"""
 
# score_info 得分信息
# 下单参数信息
# 选股宝
# 市场热度
import code_volumn_manager
import global_data_loader
import global_util
import gpcode_manager
import juejin
import limit_up_time_manager
import tool
from l2 import l2_data_manager, l2_data_util, transaction_progress
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
 
 
def __format_data(code_info, score_info, buy_params_info, xgb_code_info, xgb_infos):
    html = ""
    html += f"<h2>{code_info[1]} {code_info[0]}</h2><br>"
    if score_info:
        html += "-----买前评分-------<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>"
 
    if buy_params_info:
        html += "<br>-----交易参数-------<br><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>"
 
    if xgb_code_info:
        html += "<br>-----选股宝---------<br>"
        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 xgb_infos:
        html += "<br>-----市场热度-------<br><table>"
        for info in xgb_infos:
            html += f"<tr><td>{info}</td></tr>"
        html += "</tr>"
    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)/10000,2)}万手】÷前高量【{round(max_60[0]/10000,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}万】")
        # 资金力度
        score_list_new.append(score_list[8])
        score_source_list_new.append(f"累计金额【{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字型】")
 
        if not score_source_list[3][1][0] and not score_source_list[3][2][0] and not score_source_list[3][4][0] and not \
                score_source_list[3][5][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"首板溢价率【{score_source_list[4][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]}个炸板")
        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))
        __base_L2PlaceOrderParamsManager = l2_trade_factor.L2PlaceOrderParamsManager(code, False, volume_rate,
                                                                                     code_volumn_manager.get_volume_rate_index(
                                                                                         volume_rate),
                                                                                     (score, score_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}】笔")
        # 成交进度
        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)
        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:
        for block in xgb_latest_datas:
            limit_up_count = 0
            for code_data in block[2]:
                if len(code_data[4]) > 6:
                    limit_up_count += 1
            xgb_infos.append(f"【{block[0]}】,涨幅【{block[1]}】,共【{limit_up_count}】个涨停")
 
    return __format_data(code_info, score_info, buy_params_info, xgb_code_info, xgb_infos)
 
 
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