tick数据保存到csv
def tick2csv(res):
csvfiles = {}
submap = {}
csvheader = ['symbol', 'updateTime', 'lastPrice']
for id in subID:
csvname = f"./csv/{id}_tick.csv"
if not os.path.exists(csvname):
csvfile = open(csvname, 'w', newline='')
csvfile_w = csv.writer(csvfile)
csvfile_w.writerow(csvheader)
else:
csvfile = open(csvname, 'a', newline='')
csvfile_w = csv.writer(csvfile)
csvfiles[id] = csvfile
submap[id] = csvfile_w
for tick in res:
submap[tick[1]].writerow([tick[1], tick[18], tick[2]])
csvfiles[tick[1]].flush()