| | |
| | | 数据导出工具 |
| | | """ |
| | | import json |
| | | import logging |
| | | import os |
| | | import time |
| | | |
| | |
| | | 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: |
| | |
| | | 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 |
| | |
| | | num_operate_map[ |
| | | code]) |
| | | if buy_index == data["index"]: |
| | | ws.write(index, 8, "{}-{}".format(d["index"], d["val"]["time"]), cancel_style) |
| | | break |
| | | try: |
| | | ws.write(index, 8, "{}-{}".format(d["index"], d["val"]["time"]), cancel_style) |
| | | break |
| | | 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) |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | export_l2_excel("002765") |
| | | export_l2_excel("002207") |