-
dsb是WT中使用的一种高性能数据格式,但由于是以二进制格式组织的,因此很多小伙伴不太清楚如何写入和读取,下面将提供两个例子供大家参考。 |
Beta Was this translation helpful? Give feedback.
Answered by
ZzzzHeJ
Jul 5, 2022
Replies: 1 comment
-
dsb写入使用pandas读取csv为dataFrame后,写入代码如下: 导入代码from wtpy.WtCoreDefs import WTSBarStruct, WTSTickStruct
from wtpy.wrapper import WtDataHelper
dthelper = WtDataHelper() bar 的写入count = len(df)
BUFFER = WTSBarStruct * count
buffer = BUFFER()
for index, row in tqdm(df.iterrows()):
curBar = buffer[index]
curBar.date = int(row["date"])
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.money = float(row["money"])
curBar.hold = float(row["hold"])
# dsb_file 是写入文件名,period是周期,可选取值为d(日线)m(分钟线)
dthelper.store_bars(barFile=dsb_file,firstBar=buffer,count=len(buffer),period=period) tick的写入count = len(df)
BUFFER = WTSTickStruct * count
buffer = BUFFER()
for index, row in tqdm(df.iterrows()):
curTick = buffer[index]
curTick.exchg = bytes(row["exchg"],'utf-8')
curTick.code = bytes(row["code"],'utf-8')
curTick.price = float(row["price"])
curTick.open = float(row["open"])
curTick.high = float(row["high"])
curTick.low = float(row["low"])
curTick.settle_price = float(row["settle_price"])
curTick.total_volume = float(row["total_volume"])
curTick.volume = float(row["volume"])
curTick.total_turnover = float(row["total_turnover"])
curTick.turn_over = float(row["turn_over"])
curTick.open_interest = float(row["open_interest"])
curTick.diff_interest = float(row["diff_interest"])
curTick.trading_date = int(row["trading_date"])
curTick.action_date = int(row["action_date"])
curTick.action_time = int(int(row["action_time"]) / 1000)
curTick.pre_close = float(row["pre_close"])
curTick.pre_settle = float(row["pre_settle"])
curTick.pre_interest = float(row["pre_interest"])
curTick.upper_limit = float(row["upper_limit"])
curTick.downper_limit = float(row["downper_limit"])
for x in range(0,5):
curTick.bid_prices[x] = float(row["bid_" + str(x+1)])
curTick.bid_qty[x] = float(row["bid_qty_" + str(x+1)])
curTick.ask_prices[x] = float(row["ask_" + str(x+1)])
curTick.ask_qty[x] = float(row["ask_qty_" + str(x+1)])
dthelper.store_ticks(tickFile=dsb_file, firstTick=buffer, count=len(buffer)) dsb读取读取可以直接调用相关接口实现,需要注意的是,读取是以文件夹为单位的,一次性读取文件夹目录下的所有dsb dtHelper = WtDataHelper()
# binFolder dsb 所在目录
# csvFolder 读取后转换的csv文件存储目录
dtHelper.dump_bars(binFolder="./storage/his/min1/SHFE/", csvFolder="min1_csv")
dtHelper.dump_ticks(binFolder="./storage/his/ticks/SHFE/20211227/", csvFolder="ticks_csv") |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ZzzzHeJ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dsb写入
使用pandas读取csv为dataFrame后,写入代码如下:
导入代码
bar 的写入