wtpy使用手册

wtpy开源项目的使用


tb软件上导出bar数据转换为dsb

<p><strong>1. tb导出指数数据</strong> 数据格式如下(自己从tb导出来或者 <a href="https://pan.baidu.com/s/1cj0xO5jDKIkiLsDMYzTX7w?pwd=gp9r" title="下载地址">下载地址</a> ):</p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=e65e8f5528411c290c25000e94d929ac" alt="" /></p> <p><strong>2. 转换代码如下:</strong></p> <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 f = open('IF99.csv','r') file_data = f.readlines() #读取所有行 f.close() file_data1=[re.split(',',i) for i in file_data] names =['datetime','open','high','low','close','vol','hold'] df=pd.DataFrame(file_data1[1:],columns=names) df['date']=df['datetime'].apply(lambda x:float(x[:10].replace('/',''))).astype("int64") df['time']=df['datetime'].apply(lambda x:float(x[11:].replace(':',''))).astype("int64") df['time'] =(df['date']-19900000)*10**4 + df['time'] # 数据准备好对应的格式 ,下面的转换dsb的格式是固定的,就改下有数据的字段即可 count = len(df) BUFFER = WTSBarStruct * count buffer = BUFFER() for index, row in tqdm(df.iterrows()): curBar = buffer[index] curBar.date = int(row["date"]) curBar.time = int(row["time"]) curBar.open = float(row["open"]) curBar.high = float(row["high"]) curBar.low = float(row["low"]) curBar.close = float(row["close"]) curBar.vol = float(row["vol"]) curBar.hold = float(row["hold"]) dtHelper = WtDataHelper() dtHelper.store_bars(barFile='./IF.dsb',firstBar=buffer,count=len(buffer),period='m1') dsb_data_read=dtHelper.read_dsb_bars(barFile='./IF.dsb') # 读取 </code></pre> <p><strong>3. 转换的字段如果没有的就不用填,固定结构数据,不能多,可以少,少的会自动为0 <a href="https://dumengru.github.io/docs_wondertrader/wtcpp/folder98/folder01/folder1/file03.html" title="字段解释">字段解释</a>:</strong></p> <pre><code> uint32_t date; //日期 uint32_t reserve_; //占位符 uint64_t time; //时间 double open; //开 double high; //高 double low; //低 double close; //收 double settle; //结算 double money; //成交金额 double vol; //成交量 double hold; //总持 double add; //增仓</code></pre> <p><strong>4. 运行结果如下:</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=13effeca1ae23a797f91bbe1f894fe29" alt="" /></p>

页面列表

ITEM_HTML