From 045a5aa6434da6e83c3d850b17e7e58cd7b55ef5 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 15 五月 2023 15:46:32 +0800 Subject: [PATCH] 开盘啦板块影响交易逻辑 --- data_export_util.py | 154 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 119 insertions(+), 35 deletions(-) diff --git a/data_export_util.py b/data_export_util.py index 7cc574b..aa3457d 100644 --- a/data_export_util.py +++ b/data_export_util.py @@ -7,15 +7,53 @@ import xlwt +import gpcode_manager +import l2_data_util +import l2.l2_data_util +import log +from l2 import l2_data_source_util +from trade import deal_big_money_manager -def export_l2_data(code, datas, dest_dir="D:/export/l2"): + +def export_l2_excel(code, date=None): + # 鑾峰彇L2鐨勬暟鎹� + local_today_datas = log.load_l2_from_log(date) + datas = local_today_datas[code] + # 鑾峰彇L2澶勭悊浣嶇疆淇℃伅 + process_indexs = log.get_l2_process_position(code, date) + trade_indexs = log.get_l2_trade_position(code, date) + export_l2_data(code, datas, process_indexs, trade_indexs) + + +def export_l2_data(code, datas, process_indexs, trade_indexs, dest_dir="D:/export/l2"): + def find_process_index(index): + for i in range(0, len(process_indexs)): + if process_indexs[i][0] <= index <= process_indexs[i][1]: + return i + return len(process_indexs) + + def find_trade_index(index): + for i in range(0, len(trade_indexs)): + if trade_indexs[i][1] == index: + return trade_indexs[i] + return None + + # 鏁版嵁棰勫鐞� + num_operate_map = {} + l2.l2_data_util.load_num_operate_map(num_operate_map, code, datas) + num_dict = {} + for data in datas: + if data["val"]["num"] not in num_dict: + num_dict[data["val"]["num"]] = [] + num_dict[data["val"]["num"]].append(data) + local_time = time.strftime("%Y%m%dT%H%M%S", time.localtime(time.time())) - file_name = "{}/{}_{}.xls".format(dest_dir, code, local_time) + file_name = "{}/{}_{}_{}.xls".format(dest_dir, code, gpcode_manager.get_code_name(code), local_time) file_name_txt = "{}/{}_{}.txt".format(dest_dir, code, local_time) - openfile = open(file_name_txt,'w') + openfile = open(file_name_txt, 'w') try: for data in datas: - openfile.write(json.dumps(data)+"\n") + openfile.write(json.dumps(data) + "\n") finally: openfile.close() wb = xlwt.Workbook() @@ -23,60 +61,97 @@ ws.write(0, 0, '搴忓彿') ws.write(0, 1, '鏃堕棿') ws.write(0, 2, '涔版挙闂撮殧') - ws.write(0, 3, '浠锋牸') - ws.write(0, 4, '鎵嬫暟') - ws.write(0, 5, '绫诲瀷') - ws.write(0, 6, '閲嶅鏁伴噺') + ws.write(0, 3, '閲戦') + ws.write(0, 4, '浠锋牸') + ws.write(0, 5, '鎵嬫暟') + ws.write(0, 6, '绫诲瀷') + ws.write(0, 7, '閲嶅鏁伴噺') + ws.write(0, 8, '鎾ゅ崟鏃堕棿') + index = 0 for data in datas: index += 1 - ws.write(index, 0, data["index"]) - ws.write(index, 1, data["val"]["time"]) + trade_info = find_trade_index(data["index"]) + font = xlwt.Font() + if trade_info: + if trade_info[0] == 0: + font.colour_index = 53 + elif trade_info[0] == 1: + font.colour_index = 17 + elif trade_info[0] == 2: + font.colour_index = 10 + ws.write(index, 8, trade_info[2]) + style = None + if find_process_index(data["index"]) % 2 == 0: + style = xlwt.easyxf('pattern: pattern solid') + else: + style = xlwt.easyxf('pattern: pattern solid, fore_colour light_yellow') + style.font = font + cancel_style = xlwt.easyxf('pattern: pattern solid, fore_colour gray25') + + ws.write(index, 0, data["index"], style) + ws.write(index, 1, data["val"]["time"], style) cancel_time = data["val"]["cancelTime"] if cancel_time == '0': cancel_time = '' + else: + cancel_time = "{}".format(cancel_time) if len(cancel_time) > 0: if int(data["val"]["cancelTimeUnit"]) == 0: - cancel_time += "s"; + cancel_time += "s" elif int(data["val"]["cancelTimeUnit"]) == 1: - cancel_time += "m"; + cancel_time += "m" elif int(data["val"]["cancelTimeUnit"]) == 2: - cancel_time += "h"; + cancel_time += "h" - ws.write(index, 2, cancel_time) - ws.write(index, 3, data["val"]["price"]) + ws.write(index, 2, cancel_time, style) + ws.write(index, 4, data["val"]["price"], style) if int(data["val"]["operateType"]) == 1 or int(data["val"]["operateType"]) == 2: - ws.write(index, 4, 0-int(data["val"]["num"])) + ws.write(index, 5, 0 - int(data["val"]["num"]), style) else: - ws.write(index, 4, int(data["val"]["num"])) + ws.write(index, 5, int(data["val"]["num"]), style) - limit_price="" + limit_price = "" if int(data["val"]["limitPrice"]) == 1: - limit_price="娑ㄥ仠" + limit_price = "娑ㄥ仠" elif int(data["val"]["limitPrice"]) == 2: - limit_price="璺屽仠" + limit_price = "璺屽仠" if int(data["val"]["operateType"]) == 0: - if len(limit_price)>0: - ws.write(index, 5, '涔� ({})'.format(limit_price)) + if len(limit_price) > 0: + ws.write(index, 6, '涔� ({})'.format(limit_price), style) else: - ws.write(index, 5, '涔�') + ws.write(index, 6, '涔�', style) elif int(data["val"]["operateType"]) == 1: if len(limit_price) > 0: - ws.write(index, 5, '涔版挙 ({})'.format(limit_price)) + ws.write(index, 6, '涔版挙 ({})'.format(limit_price), style) else: - ws.write(index, 5, '涔版挙') + ws.write(index, 6, '涔版挙', style) elif int(data["val"]["operateType"]) == 2: if len(limit_price) > 0: - ws.write(index, 5, '鍗� ({})'.format(limit_price)) + ws.write(index, 6, '鍗� ({})'.format(limit_price), style) else: - ws.write(index, 5, '鍗�') + ws.write(index, 6, '鍗�', style) elif int(data["val"]["operateType"]) == 3: if len(limit_price) > 0: - ws.write(index, 5, '鍗栨挙 ({})'.format(limit_price)) + ws.write(index, 6, '鍗栨挙 ({})'.format(limit_price), style) else: - ws.write(index, 5, '鍗栨挙') - ws.write(index, 6, data["re"]) + ws.write(index, 6, '鍗栨挙', style) + ws.write(index, 7, data["re"], style) + # 鏌ヨ鏄惁鎾ゅ崟 + if int(data["val"]["operateType"]) == 0: + cancel = False + # 涔� + for d in num_dict[data["val"]["num"]]: + if int(d["val"]["operateType"]) == 1: + buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, d, + num_operate_map[ + code]) + if buy_index == data["index"]: + ws.write(index, 8, "{}-{}".format(d["index"], d["val"]["time"]), cancel_style) + break + + ws.write(index, 3, "{}涓�".format(round(int(data["val"]["num"]) * float(data["val"]["price"]) / 100, 2)), style) wb.save(file_name) return file_name @@ -104,11 +179,11 @@ if cancel_time > 0: cancel_time = "{}".format(cancel_time) if data["cancelTimeUnit"] == 0: - cancel_time += "s"; + cancel_time += "s" elif data["cancelTimeUnit"] == 1: - cancel_time += "m"; + cancel_time += "m" elif data["cancelTimeUnit"] == 2: - cancel_time += "h"; + cancel_time += "h" ws.write(index, 2, cancel_time) ws.write(index, 3, data["price"]) @@ -121,6 +196,15 @@ return file_name +def test(code): + progresses = log.export_trade_progress(code) + local_today_datas = log.load_l2_from_log("2023-04-04") + datas = local_today_datas[code] + num_operate_map = {} + l2.l2_data_util.load_num_operate_map(num_operate_map, code, datas) + for progress in progresses: + deal_big_money_manager.set_trade_progress(code, progress, datas, num_operate_map[code]) + + if __name__ == "__main__": - _t = "1661391666562" - print(_t[-3:]) + export_l2_excel("002864") -- Gitblit v1.8.0