| | |
| | | """ |
| | | 数据导出工具 |
| | | """ |
| | | import json |
| | | import os |
| | | import time |
| | | |
| | |
| | | def export_l2_data(code, datas, dest_dir="D:/export/l2"): |
| | | 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: |
| | | for data in datas: |
| | | openfile.write(json.dumps(data)+"\n") |
| | | finally: |
| | | openfile.close() |
| | | wb = xlwt.Workbook() |
| | | ws = wb.add_sheet('sheet1') |
| | | ws.write(0, 0, '序号') |
| | |
| | | |
| | | ws.write(index, 2, cancel_time) |
| | | ws.write(index, 3, data["val"]["price"]) |
| | | ws.write(index, 4, data["val"]["num"]) |
| | | if int(data["val"]["operateType"]) == 1 or int(data["val"]["operateType"]) == 2: |
| | | ws.write(index, 4, 0-int(data["val"]["num"])) |
| | | else: |
| | | ws.write(index, 4, int(data["val"]["num"])) |
| | | |
| | | limit_price="" |
| | | if int(data["val"]["limitPrice"]) == 1: |
| | |
| | | ws.write(index, 5, '买撤 ({})'.format(limit_price)) |
| | | else: |
| | | ws.write(index, 5, '买撤') |
| | | elif int(data["val"]["operateType"]) == 2: |
| | | if len(limit_price) > 0: |
| | | ws.write(index, 5, '卖 ({})'.format(limit_price)) |
| | | else: |
| | | ws.write(index, 5, '卖') |
| | | elif int(data["val"]["operateType"]) == 3: |
| | | if len(limit_price) > 0: |
| | | ws.write(index, 5, '卖撤 ({})'.format(limit_price)) |
| | | else: |
| | | ws.write(index, 5, '卖撤') |
| | | ws.write(index, 6, data["re"]) |
| | | wb.save(file_name) |
| | | return file_name |