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
| import xlwt
|
| from utils import tool
| from juejin_core import GPCodeManager
|
|
| def __export_excel(datas, path):
| wb = xlwt.Workbook(encoding="utf-8")
| ws = wb.add_sheet('sheet1')
| ws.write(0, 0, '时间')
| ws.write(0, 1, '价格')
| ws.write(0, 2, '涨幅')
| for i in range(len(datas)):
| ws.write(i + 1, 0, datas[i][0])
| ws.write(i + 1, 1, datas[i][1])
| ws.write(i + 1, 2, datas[i][2])
| wb.save(path)
|
|
| def export_tick_data(code, start_time, end_time, dir_path):
| seconds = tool.trade_time_sub(end_time, start_time)
| count = seconds // 3
| datas = GPCodeManager().get_history_tick_n(code, count, frequency="tick",
| end_time=f"{tool.get_now_date_str()} {end_time}")
| # 获取上个交易日的收盘价
| pre_price = GPCodeManager().get_pre_prices(code)
|
| datas = [(x['created_at'].strftime("%H:%M:%S"), x['price']) for x in datas]
| new_datas = []
| for d in datas:
| if tool.trade_time_sub(d[0], start_time) < 0:
| continue
| new_datas.append((d[0], d[1], round((d[1] - pre_price) * 100 / pre_price, 2)))
| __export_excel(new_datas, f"{dir_path}\\分时_{code}.xls")
|
|
| if __name__ == "__main__":
| code = "002073"
| export_tick_data(code, "09:30:00", "13:05:00", "D:\\文件传输\\新建文件夹\\L2导出文件")
|
|