wondertrader / wtpy Goto Github PK
View Code? Open in Web Editor NEWwtpy是基于wondertrader为底层的针对python的子框架
License: MIT License
wtpy是基于wondertrader为底层的针对python的子框架
License: MIT License
root@iZ0jl3nc5j5s6c69yrpgreZ:~/wtpy-master/demos/datakit_fut# python3 runDT.py
/usr/local/lib/python3.8/dist-packages/wtpy/wrapper/linux/libWtDtPorter.so
<CDLL '/usr/local/lib/python3.8/dist-packages/wtpy/wrapper/linux/libWtDtPorter.so', handle 2859ef0 at 0x7fdd2b1cdd30>
Segmentation fault
C++和Python混在一起太难搞了,不知道哪里配的不对
web-ui可以起来了,后端用的是monitor吧,想问下monitor怎么启动
你好,我参考发布在B站的《Linux环境下运行wtpy的HFT策略》,在Ubuntu下尝试HFT时,执行python run.py报错, 而之后尝试在windows10下能够正常运行,配置文件和代码都相同。
Ubuntu下的错误包括
(一)找不到文件,好像是文件名前多了"lib": libtts_thosttraderapi_se.so: cannot open shared object file: No such file or directory
(二) segmentation violation
这是运行后的全部信息
[06.14 22:32:54 - info ] WonderTrader HFT production framework initialziedversion: UNIX v0.9.7 Build@Apr 4 2023 08:54:27
[06.14 22:32:54 - info ] Trading sessions loaded
[06.14 22:32:54 - info ] Commodities configuration file ../common/commodities.json loaded
[06.14 22:32:54 - info ] Contracts configuration file ../common/contracts.json loaded, 5 exchanges
[06.14 22:32:54 - info ] Holidays loaded
[06.14 22:32:54 - info ] Hot rules loaded
[06.14 22:32:54 - info ] Trading environment initialized, engine name: HFT
[06.14 22:32:54 - info ] Running mode: Production
[06.14 22:32:54 - debug] Filters configuration file filters.yaml not exists
[06.14 22:32:54 - info ] 38 fee templates loaded
[06.14 22:32:54 - warning] RiskMon is not configured, portfilio fund will be updated every 5s
[06.14 22:32:54 - info ] WtDataReader initialized, rt dir is ../FUT_Data/rt/, hist dir is ../FUT_Data/his/, adjust_flag is 0
[06.14 22:32:54 - info ] No adjusting factor file configured, loading skipped
[06.14 22:32:54 - info ] Data manager initialized
[06.14 22:32:54 - info ] Action policies initialized
[06.14 22:32:54 - info ] Reading parser config from tdparsers.yaml...
[06.14 22:32:54 - info ] [parser0] Parser module /home/ubuntu/.conda/envs/wtpy/lib/python3.10/site-packages/wtpy/wrapper/linux/parsers/libParserCTP.so loaded
[06.14 22:32:54 - info ] [parser0] Parser initialzied, check_time: false
[06.14 22:32:54 - info ] 1 parsers loaded
[06.14 22:32:54 - info ] Reading trader config from tdtraders.yaml...
[06.14 22:32:54 - info ] [simnow] Risk control rule default of trading channel loaded
[06.14 22:32:54 - info ] [simnow] Trader module /home/ubuntu/.conda/envs/wtpy/lib/python3.10/site-packages/wtpy/wrapper/linux/traders/libTraderCTP.so loaded
/home/ubuntu/.conda/envs/wtpy/lib/python3.10/site-packages/wtpy/wrapper/linux/traders/libtts_thosttraderapi_se.so: cannot open shared object file: No such file or directory
[06.14 22:32:54 - info ] 1 traders loaded
[06.14 22:32:54 - info ] 1 parsers started
[06.14 22:32:54 - error] segmentation violation
而在windows下,看起来没有类似的错误:
[06.14 22:45:21 - info ] WonderTrader HFT production framework initialzied,version: X64 v0.9.7 Build@Apr 4 2023 10:13:38
[06.14 22:45:21 - info ] Trading sessions loaded
[06.14 22:45:21 - info ] Commodities configuration file ../common/commodities.json loaded
[06.14 22:45:21 - info ] Contracts configuration file ../common/contracts.json loaded, 5 exchanges
[06.14 22:45:21 - info ] Holidays loaded
[06.14 22:45:21 - info ] Hot rules loaded
[06.14 22:45:21 - info ] Trading environment initialized, engine name: HFT
[06.14 22:45:21 - info ] Running mode: Production
[06.14 22:45:21 - debug] Filters configuration file filters.yaml not exists
[06.14 22:45:21 - info ] 38 fee templates loaded
[06.14 22:45:21 - warning] RiskMon is not configured, portfilio fund will be updated every 5s
[06.14 22:45:21 - info ] WtDataReader initialized, rt dir is ../FUT_Data/rt/, hist dir is ../FUT_Data/his/, adjust_flag is 0
[06.14 22:45:21 - info ] No adjusting factor file configured, loading skipped
[06.14 22:45:21 - info ] Data manager initialized
[06.14 22:45:21 - info ] Action policies initialized
[06.14 22:45:21 - info ] Reading parser config from tdparsers.yaml...
[06.14 22:45:21 - info ] [parser0] Parser module C:/Users/xxxxx/.conda/envs/wtpy/lib/site-packages/wtpy/wrapper/x64/parsers/ParserCTP.dll loaded
[06.14 22:45:21 - info ] [parser0] Parser initialzied, check_time: false
[06.14 22:45:21 - info ] 1 parsers loaded
[06.14 22:45:21 - info ] Reading trader config from tdtraders.yaml...
[06.14 22:45:21 - info ] [simnow] Risk control rule default of trading channel loaded
[06.14 22:45:21 - info ] [simnow] Trader module C:/Users/xxxxx/.conda/envs/wtpy/lib/site-packages/wtpy/wrapper/x64/traders/TraderCTP.dll loaded
[06.14 22:45:21 - info ] 1 traders loaded
[06.14 22:45:21 - info ] 1 parsers started
[06.14 22:45:21 - info ] registerFront: tcp://121.37.80.177:20002
[06.14 22:45:21 - info ] 1 trading channels started
[06.14 22:45:21 - info ] Market Data subscribed: CFFEX.IF.2306
[06.14 22:45:21 - info ] Trading day 20230615 begun
press any key to exit
[06.14 22:45:21 - info ] [ParserCTP] Market data server connected
[06.14 22:45:21 - info ] [ParserCTP] Market data server logined, 20230614
[06.14 22:45:21 - info ] [ParserCTP] Market data of 653 contracts subscribed totally
[06.14 22:45:21 - info ] [TraderCTP][9999-6374] Login succeed, AppID: simnow_client_test, Sessionid: 141635, login time: 22:45:21...
[06.14 22:45:21 - info ] [TraderCTP][9999-6374] Login succeed, trading date: 20230615...
[06.14 22:45:21 - info ] [TraderCTP][9999-6374] Querying confirming state of settlement data...
[06.14 22:45:21 - info ] [TraderCTP][9999-6374] Confirming settlement data...
[06.14 22:45:21 - info ] [TraderCTP][9999-6374] Trading channel initialized...
[06.14 22:45:21 - info ] [simnow] Trader login succeed, trading date: 20230615
[06.14 22:45:22 - info ] [simnow] Position data updated
[06.14 22:45:25 - info ] [simnow] Trading channel ready
[06.14 22:45:26 - info ] 理论价格3956.700000,最新价:3956.600000
[06.14 22:45:26 - info ] 出现正向信号
以下是其他信息:
版本:
Ubuntu 20.04.3 LTS
Python 3.10.10
wtpy-0.9.7.2和wtpy-0.9.8都报错
目录:demos\hft_fut\
配置文件(使用的是OpenCTP的7x24环境):
tdparsers.yaml
parsers:
tdtraders.yaml
traders:
运行例子cta_stk_bt,但是 df_bars.volumes返回都是0
date bartime open high low close settle money volume hold diff
20190103 201901030945 2961.0 2963.2 2955.2 2962.0 0.0 0.0 0.0 0.0 0.0
web-ui启动后,是不是还有个后台服务要起,给前端提供支持
def add_sel_strategy(self, strategy:BaseSelStrategy, date:int, time:int, period:str, slippage:int = 0):
#if isinstance(strategy, EtSelStrategy):
# strategy.setEngine(self)
id = self.__wrapper__.create_sel_context(strategy.name(), date, time, period, slippage)
self.__sel_ctxs__[id] = SelContext(id, strategy, self.__wrapper__, self)
slippage作为第五个参数传入,但是WtWrapper里定义的是第七个
def create_sel_context(self, name:str, date:int, time:int, period:str, trdtpl:str = 'CHINA', session:str = "TRADING", slippage:int = 0) -> int:
没玩过期货,刚接触量化,居然加群还要回答这种问题吗。。
我运行wtpy demo里的demos\sel_fut_bt\runBT.py,只是将set_sel_strategy的参数time由5改成10,然后在DualThrust_Sel.py里的on_calculate里加了输出时间的语句print('=========',context.stra_get_date(),'curTime',curTime)。运行结果是如下重复内容,是不对的吧。
4.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
========= 20190910 curTime 2112
[04.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
========= 20190910 curTime 2112
[04.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
========= 20190910 curTime 2112
[04.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
========= 20190910 curTime 2112
[04.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
========= 20190910 curTime 2112
[04.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
========= 20190910 curTime 2112
[04.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
========= 20190910 curTime 2112
[04.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
========= 20190910 curTime 2112
[04.29 19:58:04 - info ] DCE.i.HOT 向上突破655.0>=%654.1,多仓进场
希望能再出一个更简化的context,把on_tick,on_bar都合并到on_calculate中去,逻辑是订阅了tick数据,则不必等到bar闭合而是tick或者order或者trade有更新就可以触发on_calculate计算,否则要等到bar闭合再触发计算。这样使用习惯上就mc,tb,文华,天勤这些比较接近,迁移也没那么难了。毕竟很多搞交易的还是不是程序员出身,真的不太擅长也搞不懂回调,写起来觉得别扭。另外一些偏高频的策略也可以用这个context来实现,比如偏高频一点的套利,现在那个demo是用cta_context实现的,但是实盘如果没有tick数据,肯定不行,如果要用hft_context来实现,难度又大了不少
我看到你们有ctp 期权的接口了,请问有期权自动交易的例子吗?感谢。
0.9.6 dev 分支
订阅 SHFE.ru2306P13500, testUDP监听到了行情
在cta和hft引擎里订阅SHFE.ru.ru2306P13500 都无法触发on tick 或者 on bar, INE的期权合约也不行
但是CFFEX的期权合约可以触发on bar,无法触发 on tick
ubuntu 20.04
$ ldd -r /usr/local/lib/python3.8/dist-packages/wtpy/wrapper/linux/libWtPorter.so
linux-vdso.so.1 (0x00007ffff7c72000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4f61490000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4f6146d000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4f61280000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4f61131000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4f61110000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4f60f10000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4f616db000)
undefined symbol: _ZN3otp14HftStraBaseCtx11getOrderTagEj (/usr/local/lib/python3.8/dist-packages/wtpy/wrapper/linux/libWtPorter.so)
$ c++filt _ZN3otp14HftStraBaseCtx11getOrderTagEj
otp::HftStraBaseCtx::getOrderTag(unsigned int)
如果我要回测一个tick数据的策略,10年 2500天,每天28000个tick数据,这样的一次回测大概需要多久
Line 374 in c10b681
在监控服务中,当删除一个任务后,点击刷新任务,会出现KeyError错误
from wtpy import WtBtEngine
from StraDualThrust import StraDualThrust
if name == "main":
#创建一个运行环境,并加入策略
engine = WtBtEngine()
engine.init('.\Common\', "configbt.json")
engine.configBacktest(201909100930,201910311500)
engine.configBTStorage(mode="csv", path=".\storage\")
engine.commitBTConfig() #代码里的配置项,会覆盖配置文件configbt.json里的配置项
有以下报错
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/mingzhu/Desktop/ming/code/python/FinRL/FinRL/test_wtpy/runBT.py", line 8, in
engine = WtBtEngine()
File "/Users/mingzhu/opt/anaconda3/lib/python3.8/site-packages/wtpy/WtUtilDefs.py", line 5, in getinstance
instances[cls] = cls(*args,**kwargs)
File "/Users/mingzhu/opt/anaconda3/lib/python3.8/site-packages/wtpy/WtBtEngine.py", line 26, in init
self.wrapper = WtBtWrapper(self) #api接口转换器
File "/Users/mingzhu/opt/anaconda3/lib/python3.8/site-packages/wtpy/WtUtilDefs.py", line 5, in getinstance
instances[cls] = cls(*args,**kwargs)
File "/Users/mingzhu/opt/anaconda3/lib/python3.8/site-packages/wtpy/wrapper/WtBtWrapper.py", line 32, in init
self.api = cdll.LoadLibrary(_path)
File "/Users/mingzhu/opt/anaconda3/lib/python3.8/ctypes/init.py", line 459, in LoadLibrary
return self._dlltype(name)
File "/Users/mingzhu/opt/anaconda3/lib/python3.8/ctypes/init.py", line 381, in init
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/mingzhu/opt/anaconda3/lib/python3.8/site-packages/wtpy/wrapper/linux/libWtBtPorter.so, 6): no suitable image found. Did find:
/Users/mingzhu/opt/anaconda3/lib/python3.8/site-packages/wtpy/wrapper/linux/libWtBtPorter.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03
/Users/mingzhu/opt/anaconda3/lib/python3.8/site-packages/wtpy/wrapper/linux/libWtBtPorter.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03
python-BaseException
假设现在c++模块的wondertrader编译好,如何将编译好生成的.so文件导到linux文件下。现在没有在c++的wondertrader看到文件结构是一样的
hft_buy和hft_sell都缺少一个参数(应该是"flag"), 运行HFTdemo回测会报错
stra_get_last_exittime c++返回过来的uint64没问题
但是到python里面数字就不对了
但是stra_get_last_entrytime确没有问题
试了好几个试不出来呀。。。
赞wondertrader的工作,从专业程序员角度来看,非常棒!
QData数据源支持导出ticks数据,但datahelper还不支持导出ticks,希望增加ticks数据导出的接口
查看了下应该是底层, WtDtHelper.cpp文件里缺了这个字段.
另外, 可以考虑将输出的小数位数作为参数暴露出来吗, 比如外汇品种小数位数大于3数据就不对了
使用的是simnow通道,订阅期货期权后可以下单(如CFFEX.IO.IO2303-C-4100),但是写入持仓时发现code变成了CFFEX.IO.2230,这导致on_order回调函数无法触发,持仓的查询也有问题,可能是行情转码发生了错误。
不够简洁
使用如下代码生成主力连接数据时,会生成202207180930至今所有数据,endTime参数未发挥作用。
ticks = dtServo.get_ticks("CFFEX.IF.HOT", fromTime=202207180930, endTime=202207201500).to_df()
ticks.to_csv(".\CFFEX.IF.HOT_202207180930_202207201500_ticks.csv")
如题。
optimizer.add_listed_param(name="stopProfitPercent", val_list=[0])
当有两个可变参数的时候,name太长engine.run_backtest()这里就会在第一次for循环中断,且没有报错,很难debug。
参数名改成spp就好了
按照下面方式给WtEngine添加 extended data loader 后会抛出异常
engine = WtEngine(eType = EngineType.ET_CTA, logCfg = 'logcfg.yaml')
engine.set_extended_data_loader(loader)
异常
AttributeError: 'WtWrapper' object has no attribute 'on_load_his_bars'
’
从代码来看 WtWrapper 没有 on_load_his_bars 方法
在ubuntu18.04 运行cta_fut demo时出现以下错误信息
/sys/firmware/dmi/tables/smbios_entry_point: Permission denied
/dev/mem: Permission denied
/sys/firmware/dmi/tables/smbios_entry_point: Permission denied
/dev/mem: Permission denied
br-a4e4731004df: No such file or directory
br-c69f3900d779: No such file or directory
br-955fb704febf: No such file or directory
br-68ba5b86cd7a: No such file or directory
br-92629d4b8839: No such file or directory
br-554617ef66cd: No such file or directory
br-8aa48a3bec40: No such file or directory
其中 b4
开头的字符串,为网络接口id。
初步怀疑与ctp的接口有关, 参看
https://www.vnpy.com/forum/topic/3035-ubuntu-xia-yun-xing-bao-cuo
应该不影响程序的运行,需要进一步测试。
主要是因为依赖的wondertrader部分文件采用了GBK编码。
请等待wondertrader修改文件编码。
作为临时的解决方案,可以采用https://github.com/qiuwei/wtpy 的dev分支。
运行 wtpy/demos/cta_stk_bt/runBT.py
报以下错误:
/home/wqiu/.cache/pypoetry/virtualenvs/playground-gu9jURa0-py3.7/lib/python3.7/site-packages/wtpy/wrapper/linux/libWtBtPorter.so
Traceback (most recent call last):
File "runBT.py", line 7, in <module>
engine = WtBtEngine(EngineType.ET_CTA)
File "/home/wqiu/.cache/pypoetry/virtualenvs/playground-gu9jURa0-py3.7/lib/python3.7/site-packages/wtpy/WtBtEngine.py", line 22, in getinstance
instances[cls] = cls(*args,**kwargs)
File "/home/wqiu/.cache/pypoetry/virtualenvs/playground-gu9jURa0-py3.7/lib/python3.7/site-packages/wtpy/WtBtEngine.py", line 31, in __init__
self.__wrapper__ = WtBtWrapper() #api接口转换器
File "/home/wqiu/.cache/pypoetry/virtualenvs/playground-gu9jURa0-py3.7/lib/python3.7/site-packages/wtpy/wrapper/WtBtWrapper.py", line 204, in __init__
self.api = cdll.LoadLibrary(_path)
File "/home/wqiu/miniconda3/lib/python3.7/ctypes/__init__.py", line 442, in LoadLibrary
return self._dlltype(name)
File "/home/wqiu/miniconda3/lib/python3.7/ctypes/__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/wqiu/.cache/pypoetry/virtualenvs/playground-gu9jURa0-py3.7/lib/python3.7/site-packages/wtpy/wrapper/linux/libWtBtPorter.so: undefined symbol: mysql_close
比如说我的策略想跑几个月,这期间始终订阅某个期货品种的主力合约,而主力合约的代码会不断地变化,此时我应该如何订阅?形如 context.stra_get_bars(SHFE.rb.HOT)可以吗?
[mod]C++底层二进制文件更新到dev分支最新编译版本【截止到2022.12.13 22:16】
回测K线能正常合成,但实盘时合成K线依然有问题
[mod]C++底层二进制文件更新到dev最新编译版本【截止到2022.12.15 17:15】
更新后 cta_fut 初始化后会直接卡住
engine.configBTStorage(mode="csv", path="../storage/")
执行demo,path路径设置错误,engine不会报错,会直接退出,希望增加报错流程
Hftcontext.py 类的stra_cancel_all 中的WtWrapper.hft_cancel_all 因为 ret 中含有int 类型,无法在 python3
中使用bytes.decode(ret)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.