| | |
| | | 数据导出工具 |
| | | """ |
| | | import json |
| | | import logging |
| | | import os |
| | | import time |
| | | |
| | |
| | | # 获取L2的数据 |
| | | local_today_datas = log_export.load_l2_from_log(date) |
| | | datas = local_today_datas[code] |
| | | datas = datas[-2000:] |
| | | # 获取L2处理位置信息 |
| | | process_indexs = log_export.get_l2_process_position(code, date) |
| | | trade_indexs = log_export.get_l2_trade_position(code, date) |
| | |
| | | # 数据预处理 |
| | | 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) |
| | | buy_no_map = {} |
| | | l2.l2_data_util.load_buy_no_map(buy_no_map, code, datas) |
| | | |
| | | l2.l2_data_util.load_canceled_buy_no_map(l2.l2_data_util.local_today_canceled_buyno_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_txt = "{}/{}_{}.txt".format(dest_dir, code, local_time) |
| | | openfile = open(file_name_txt, 'w') |
| | | try: |
| | | with open(file_name_txt, 'w') as openfile: |
| | | for data in datas: |
| | | openfile.write(json.dumps(data) + "\n") |
| | | finally: |
| | | openfile.close() |
| | | wb = xlwt.Workbook(encoding="utf-8") |
| | | ws = wb.add_sheet('sheet1') |
| | | ws.write(0, 0, '序号') |
| | |
| | | ws.write(0, 6, '类型') |
| | | ws.write(0, 7, '重复数量') |
| | | ws.write(0, 8, '撤单时间') |
| | | ws.write(0, 9, '订单号') |
| | | |
| | | index = 0 |
| | | for data in datas: |
| | |
| | | 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) |
| | | ws.write(index, 1, data["val"]["time"] + (f".{data['val']['tms']}" if "tms" in data["val"] else ''), style) |
| | | cancel_time = data["val"]["cancelTime"] |
| | | if cancel_time == '0': |
| | | cancel_time = '' |
| | |
| | | else: |
| | | ws.write(index, 6, '卖撤', style) |
| | | ws.write(index, 7, data["re"], style) |
| | | ws.write(index, 9, data["val"].get("orderNo"), style) |
| | | # 查询是否撤单 |
| | | if int(data["val"]["operateType"]) == 0: |
| | | cancel = False |
| | | cancel_data = l2.l2_data_util.local_today_canceled_buyno_map.get(code).get(str(data["val"]["orderNo"])) |
| | | # 买 |
| | | 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 |
| | | if cancel_data: |
| | | try: |
| | | ws.write(index, 8, "{}-{}".format(cancel_data["index"], cancel_data["val"]["time"]), cancel_style) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | |
| | | ws.write(index, 3, "{}万".format(round(int(data["val"]["num"]) * float(data["val"]["price"]) / 100, 2)), style) |
| | | wb.save(file_name) |
| | |
| | | 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__": |
| | | export_l2_excel("002765") |
| | | try: |
| | | export_l2_excel("600476") |
| | | except Exception as e: |
| | | logging.exception(e) |