csv的tick数据转换为dsb
<ol>
<li>
<p>下载提供的tick数据 <a href="https://pan.baidu.com/s/1A_uGYIvwCye-7rqYSe1ciQ?pwd=vbp7" title="csv数据 ">csv数据 </a></p>
</li>
<li>转换代码如下:</li>
</ol>
<pre><code class="language-python"># -*- coding: utf-8 -*-
import re
import pandas as pd
import time
from wtpy.wrapper import WtDataHelper
from wtpy.WtCoreDefs import WTSBarStruct, WTSTickStruct
from tqdm import tqdm
df=pd.read_csv('IF2109.csv')
df['action_time']=df['datetime'].apply(lambda x:x[-12:-4].replace(':','')).astype("int64")
df['action_date']=df['datetime'].apply(lambda x: x[:10].replace('-','')).astype("int64")
df['update_millisec']=df['datetime'].apply(lambda x: x[-3:]).astype("int64")
df['action_time']=df['action_time']*1000+df['update_millisec'].astype('int64')
df['exchg']='CFFEX'
df['code']='IF2109'
count = len(df)
BUFFER = WTSTickStruct * count
buffer = BUFFER()
for index, row in tqdm(df.iterrows()):
#print(index)
curTick = buffer[index]
curTick.exchg = bytes(row["exchg"],'utf-8')
curTick.code = bytes(row["code"],'utf-8')
curTick.action_date = int(row["action_date"])
curTick.action_time = int(row["action_time"])
curTick.upper_limit = float(row["limit_up"])
curTick.lower_limit = float(row["limit_down"])
curTick.price = float(row["last"])
curTick.open = float(row["open"])
curTick.high = float(row["high"])
curTick.low = float(row["low"])
curTick.volume = float(row["volume"])
curTick.open_interest = float(row["open_interest"])
curTick.trading_date = int(row["action_date"])
curTick.pre_close = float(row["prev_close"])
curTick.pre_settle = float(row["prev_settlement"])
curTick.bid_prices[0] = float(row["b1" ])
curTick.bid_qty[0] = float(row["b1_v" ])
curTick.ask_prices[0] = float(row["a1" ])
curTick.ask_qty[0] = float(row["a1_v" ])
dtHelper = WtDataHelper()
dsbname="IF2109.dsb"
dtHelper.store_ticks(tickFile=dsbname, firstTick=buffer, count=len(buffer))
dsb_data_read=dtHelper.read_dsb_ticks(tickFile=dsbname)# 读取 </code></pre>
<ol>
<li>运行结果:
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c881a915e14d1fc7f82e367bfdafe72c" alt="" /></li>
</ol>
<p><strong>4. <a href="https://dumengru.github.io/docs_wondertrader/wtcpp/folder98/folder01/folder1/file03.html" title="tick数据dsb格式字段解释">tick数据dsb格式字段解释</a></strong></p>
<pre><code>double price; //最新价
double open; //开盘价
double high; //最高价
double low; //最低价
double settle_price; //结算价
double upper_limit; //涨停价
double lower_limit; //跌停价
double total_volume; //总成交量
double volume; //成交量
double total_turnover; //总成交额
double turn_over; //成交额
double open_interest; //总持
double diff_interest; //增仓
uint32_t trading_date; //交易日,如20140327
uint32_t action_date; //自然日期,如20140327
uint32_t action_time; //发生时间,精确到毫秒,如105932000
uint32_t reserve_; //占位符
double pre_close; //昨收价
double pre_settle; //昨结算
double pre_interest; //上日总持
double bid_prices[10]; //委买价格
double ask_prices[10]; //委卖价格
double bid_qty[10]; //委买量
double ask_qty[10]; //委卖量</code></pre>