vnpy / vnpy Goto Github PK
View Code? Open in Web Editor NEW基于Python的开源量化交易平台开发框架
Home Page: http://www.vnpy.com
License: MIT License
基于Python的开源量化交易平台开发框架
Home Page: http://www.vnpy.com
License: MIT License
现在是一次性全部载入的。
建议10天或20天分段载入。
碰到TICK回测,一次性载入就没办法了。
象现在这样,一年的tick,根本没办法回测。
我需要64位的,所以需要去找对应的版本,我去快期下最新版,头文件都不一样了,有些类成员找不到。
界面点击“连接CTP”后,界面开始更新历史委托条目并刷新窗口。
当历史委托条目较多(比如1000条)时,随着不断的更多的委托条目被刷新进来,有概率出现以下错误:
File "C:\Users\Jerry\Desktop\vnpy_trader\vn.trader\uiBasicWidget.py", line 263, in updateEvent self.updateData(data) File "C:\Users\Jerry\Desktop\vnpy_trader\vn.trader\uiBasicWidget.py", line 299, in updateData cell.setContent(content) File "C:\Users\Jerry\Desktop\vnpy_trader\vn.trader\uiBasicWidget.py", line 48, in setContent self.setText(text) RuntimeError: wrapped C/C++ object of type BasicCell has been deleted
此错误也可能连续出现多次。
似乎未影响后续功能的正常使用。
按照指导设置好后,运行vtMain.py,之前已经运行成功,不过现在会出现如下提示:
Traceback (most recent call last):
File "", line 44, in
main()
File "", line 36, in main
mainWindow = MainWindow(mainEngine, mainEngine.eventEngine)
File "uiMainWindow.py", line 25, in init
self.loadWindowSettings()
File "uiMainWindow.py", line 306, in loadWindowSettings
self.restoreState(settings.value('state').toByteArray())
AttributeError: 'NoneType' object has no attribute 'toByteArray'
请问如何解决?
多谢开源项目。期待API封装、编译、使用方面的教程,比如可以加入非类ctp的某些纯c api封装教程,再次感谢。
比如CTP中,两个合约的单模型如何处理?
是分成两个模型分别处理,互不影响还是一个模型中引入两个合约,来处理?
陈总:
ctaBacktesting.py 中 newTick函数,第176行,
缺少 语句 self.dt = bar.datetime, 导致字典缺少key,回测时覆盖上一笔交易,最后结果只有1笔交易。
错误标签页能不能加一个时间戳? 象日志标签页一样有时间戳可以判断什么时候出的错误。
PyQT是一个图形界面库,感觉很重。
如果只是要用到定时器,是不是可以考虑
threading.Timer
或者
sched https://docs.python.org/2/library/sched.html
lts 能不能给一个hello word的example?
比如, 如何买入,卖出
现在不太明白如何用
1.
是不是支持linux?能不能写一个安装的setup.py方便安装
1.
是不是可以搞一个微信群或者qq群方便交流
或者 https://bearychat.com/ ,这个支持保存历史聊天记录
现有的基于QT的事件搞得太复杂
不太好理解
是否可以考虑改用
http://pythonhosted.org//blinker/
基于信号驱动
使用函数式编程,而不是类编程。
这样,一个信号可以挂载多个函数。
代码更加轻量级,而且更加灵活。
按照教程3成功编译了md接口的pyd,也已在mdtest.py内输入账号、密码、BrokerID,但是运行mdtest.py 提示“非法用户”。
修改mdtest.py「真实输入为数字,此处用X指代」:
loginReq['UserID'] = 'XXXXXXX' # 参数作为字典键值的方式传入
loginReq['Password'] = 'XXXXXX' # 键名和C++中的结构体成员名对应
loginReq['BrokerID'] = 'XXXX'
在cmd内运行得到如下结果:
T:\Downloads\finance_win\vnpy\vn.lts\vnltsmd\test>python mdtest.py
Connect to 211.144.195.163:34513
Stock API(ON Session Connected[-59244543]
Session -59244543 Connected
onFrontConnected
CSecurityFtdcUserApiImplBase::RequestDirectly SessionID=-59244543
MaxOrderRef:
UserID:
TradingDay:
SessionID:0
SystemName:
BrokerID:
FrontID:0
LoginTime:
ErrorMsg:非法用户
ErrorID:-3
Send Heartbeat 1429077127
Send Heartbeat 1429077142
Heartbeat Receive Warning, CurrentTime=1429077153 LastTime=1429077132
onHeartBeatWarning
21
Send Heartbeat 1429077157
Send Heartbeat 1429077172
Send Heartbeat 1429077187
Heartbeat Receive Warning, CurrentTime=1429077196 LastTime=1429077175
按照教程3的方法编译了一下,vs2013在编译的时候提示
错误 4 error LNK1112: 模块计算机类型“X86”与目标计算机类型“x64”冲突
请教这个问题该如何解决
昨天弄回测,突然想到,可以写个组合回测啊。
列出各种参数组合传给策略,不是挺好的吗?
可惜水平差,写不出来。
这个功能挺实用的。
如这样
# dict的个数无限,名称未知
d = OrderedDict()
d['a'] = [1,2,3]
d['b'] = [0.1,0.2,0,3,0.4]
d['c'] = [10,20]
d['xxxxx'] = [1,2,3,4,5,6] 等等,参数以及值。
# 如 d['a'] = 1 d['b'] = 0.1 d['c'] = 10
# d['a'] = 1 d['b'] = 0.1 d['c'] = 20
# d['a'] = 1 d['b'] = 0.2 d['c'] = 10
# d['a'] = 1 d['b'] = 0.2 d['c'] = 20
# d['a'] = 1 d['b'] = 0.3 d['c'] = 10 等
等等。
ctaHistoryData里面,reader是读一条,存一条。这样比较慢。
通过1亿多条件记录的测试表明,如果一次性读1万条,再来存入,比较快。
现在的策略 self.pos 只是它当时开仓的情况。而没办法获取历史持仓。
如果之前开的仓位,今天运行策略,它认为是0。
建议每次都会交易所获取,最少init时要从交易所获取持仓情况。
vnoanda.py中的以下几行,有点小错误
API_SETTING['practice'] = {'rest': 'https://api-fxpractice.oanda.com',
'stream': 'https://stream-fxpractice.oanda.com'}
API_SETTING['trade'] = {'rest': 'https://api-fxpractice.oanda.com',
'stream': 'https://stream-fxtrade.oanda.com/'}
应为
API_SETTING['practice'] = {'rest': 'https://api-fxpractice.oanda.com',
'stream': 'https://stream-fxpractice.oanda.com/'}
API_SETTING['trade'] = {'rest': 'https://api-fxtrade.oanda.com',
'stream': 'https://stream-fxtrade.oanda.com/'}
pyqt4中使用setSortingEnabled(True)开启表头排序功能,是按照字符串的编码进行排序,如3 > 123, 导致在vntrader的Monitor中对 价格、成交量等数字类型的字段进行排序时排序结果都是错误的,有没有什么办法对数字格式进行排序么?
插入Monitor中的单元格都是转化成SafeUnicode的,试过不转化直接插入,结果也错误。
有时启动vnMain.py后行情数据记录没写进mongodb。已经设置了DR_setting.json中的working为true, 启动vnMain.py有5次,中间1次没记录任何行情数据到mongodb,其它4次启动都能正常记录tick和bar数据到mongodb。运行期间行情数据记录窗口是一直有数据在滚动的,表示接收是正常的,写库逻辑可能有问题。
VnTrader_1Min_Db
感觉这样更好。
VnTrader_Min1_Db 1放在后面
VnTrader_Hour1_Db
或者干脆不要加1,因为系统本身默认就是1分钟。
有部分策略需要需要调用loadBar、loadTick等函数,这些函数需要self.vtSymbol,
但是BacktestingEngine引擎中初始化策略时并没有获取vtSymbol,
看到ctaEngine是通过loadSetting函数实现的,
是不是BacktestingEngine中也需要loadSetting函数?
我个人是用简单的 engine.strategy.vtSymbol = 'pp_hot' 实现。
First off, congratulations for the robust code very nicely written.
I am wondering if you are considering to include an **English language version and support for other brokers, as i.e. Oanda. Either have a nice API which integrates seamlessly with Python.
As i did not have how to contact you by any other way, i have opened this issue.
Looking for your feedback
Thanks
20160410 晚上我把PP1605的 tick,分,日,三个历史数据存入数据库
今天 20160411下午打开vnpy实盘。(如果下午开机不行,就改为上午。跟昨天历史数据接上)
我的策略运行周期是分BAR,但是需要计算60日均线,10小时线。
该怎么操作?
随着时间的推移,内存中的BARLIST离数据库中历史数据的时间越来越远。是不是说,要把接受到的数据同步存入数据库?保持数据库跟当前时间一致?(拖慢速度?)
关于实盘中使用历史数据的例子,万分感谢。
如题
1.在开启 行情数据记录后,非交易时段登陆CTP,订阅成功返回的数据为0的Tick,会被记录到数据库中。
看行情处理代码发现函数 drEngine.procecssTickEvent,没有对Tick进行过滤,现在不知道是在函数 drEngine.procecssTickEvent中对H L O C全0的数据进行过滤还是在其它位置修改会好一点。
2.每次 集合竞价 会多记录一条一分钟的数据(20:59~21:00)。我的本机时间好像慢一秒,请忽略.
20:58:59 记录Tick数据rb1701,时间:20:59:11.0, last:2050.0, bid:2050.0, ask:2054.0
20:58:59 记录分钟线数据rb1701,时间:19:37:29.0, O:2061.0, H:2061.0, L:2061.0, C:2061.0
20:59:59 记录Tick数据rb1701,时间:21:00:11.0, last:2055.0, bid:2055.0, ask:2057.0
20:59:59 记录分钟线数据rb1701,时间:20:59:11.0, O:2050.0, H:2050.0, L:2050.0, C:2050.0
21:00:00 记录Tick数据rb1701,时间:21:00:11.5, last:2057.0, bid:2055.0, ask:2058.0
21:00:00 记录Tick数据rb1701,时间:21:00:12.0, last:2054.0, bid:2054.0, ask:2056.0
21:00:00 记录Tick数据rb1701,时间:21:00:12.5, last:2057.0, bid:2055.0, ask:2060.0
请问下,教程3中将c++接口封装为python的时候你给的pyltsmd下的文件时怎么生成的?还是说自己写的?谢谢
完整路径:vnpy/vn.lts/ltsapi/securitytraderapi.so
请问是针对哪种platform编译的呢,mac还是linux?
如题,可否加入一些常用指标,比如macd, kdj, 这样可以提高开发人员使用平台的效率。
HedgeFlag 单个char的不要用str的模块去读取,会strcpy_s,但是会在回调的时候出错,所以
建议:
改了一下获取单个char的代码
void getSingleChar(dict d,string key, char _value)
{
if (d.has_key(key))
{
object o = d[key];
extract x(o);
if (x.check())
{
string s = x();
std::cerr<<"now extract string is "<<s<<std::endl;
const char *buffer = s.c_str();
*value = buffer[0];
std::cerr<<_value<<endl;
}
}
}
另外的一些单char的也可以更改一下
希望提供mac环境下的教程
当我使用zh_CN.UTF-8作为默认语言时。那个safeUnicode方法会报错:
n: 0, header: logTime
Traceback (most recent call last):
File "/home/szc/github/vnpy/vn.trader/uiBasicWidget.py", line 243, in updateEvent
self.updateData(data)
File "/home/szc/github/vnpy/vn.trader/uiBasicWidget.py", line 288, in updateData
content = safeUnicode(data.getattribute(header))
File "/home/szc/github/vnpy/vn.trader/vtFunction.py", line 26, in safeUnicode
return unicode(value)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 2: ordinal not in range(128)
我就把它注释掉了,然后qt界面日志处时间就是乱码了。使用英语作为默认语言,就可以正确显示数字日期,形如:23:12:20。请指点一二,谢谢!
因为IB期货和国内有些不同, 在IB里面期货合约名字不变, 根据不同的过期时间来判断不同的合约.
比如: CL, 合约名称一直是CL, 根据过期时间 201606, 它的 localsymbol 为 CLM6.
还有IB的localsymbol貌似只能通过合约详情查询到.
fut = Contract()
fut.m_symbol = 'CL'
fut.m_currency = 'USD'
fut.m_secType = 'FUT'
fut.m_exchange = 'NYMEX'
fut.m_expiry = '201606'
如何载onTick里面调用onOrder里面的onOrder.status等变量?
用global吗?
请问现在是仅仅接入了华宝lts么?是否接入了期货ctp?谢谢
文档中提到了安装vc的部分内容,不知是不是必须的?
` def onOrder(self, order):
"""收到委托变化推送(必须由用户继承实现)"""
# 对于无需做细粒度委托控制的策略,可以忽略onOrder
# CTA委托类型映射
if order.direction == u'多' and order.offset == u'开仓':
orderType = u'买开'
elif order.direction == u'多' and order.offset == u'平仓':
orderType = u'买平'
elif order.direction == u'空' and order.offset == u'开仓':
orderType = u'卖开'
elif order.direction == u'空' and order.offset == u'平仓':
orderType = u'卖平'
if order.status == u'未成交':
self.cancelOrder(order.vtOrderID)
elif order.status == u'已撤销':
self.sendOrder(orderType, self.bar.close, 1)`
1,有行情就直接推送到策略中去。建议初始化完成之后再推送。
2,策略初始化后,假如没有行情,建议自动订阅。感觉没必要手工先在主界面订阅。
请问有没有现成的库可以统计回测结果?比如胜率,最大回撤,最大连续亏损等
现在还能实盘交易A股,指数吗?
demo策略中策略初始化时,需要读取前initDays日的数据进行计算,
做策略回测时,使用initDays=5,回测到2月15日时报错,因为春节假期的原因,没有读到数据。
一年总有这两次长假期,考虑将initDays改为交易日,关于实现方式的问题请教下群主:
触发条件,tdapi第一次登录一个账号时。删除所有*.con文件登录可以触发,代码
class TestTdApi(TdApi): def onFrontConnected(self): """服务器连接""" logger.info("td connected") loginReq = {} # 创建一个空字典 loginReq['UserID'] = FLAGS.username # 参数作为字典键值的方式传入 loginReq['Password'] = FLAGS.passwd # 键名和C++中的结构体成员名对应 loginReq['BrokerID'] = FLAGS.brokerid self.reqUserLogin(loginReq, 1) def onRspUserLogin(self, data, error, n, last): logger.error("td user login") def main(): apitd = TestTdApi() apitd.createFtdcTraderApi('') apitd.subscribePrivateTopic(1) apitd.subscribePublicTopic(1) apitd.registerFront("tcp://180.166.103.38:41205") apitd.init()
错误输出:
INFO:test_cli:td connected
eth1: Resource temporarily unavailable
INFO:test_cli:td user logined {'CZCETime': '11:18:56', 'SHFETime': '11:18:56', 'MaxOrderRef': '1', 'BrokerID': '3040', 'INETime': '--:--:--',
'UserID': '...', 'TradingDay': '20160426', 'SessionID': -568300646, 'SystemName': 'TradingHosting', 'FFEXTime': '11:18:56', 'FrontID':
4, 'DCETime': '11:18:57', 'LoginTime': '11:18:56'}
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
TypeError: 'NoneType' object is not callable
....
RuntimeError:can not open CFlow file in line 256 of file ../../source/userapi/ThostFtdcUserApiImplBase.cpp
Linux下运行vn.trader/vtMain.py,点击“连接ctp”,发生如上段错误,感觉很奇怪,后来偶然发现是connect()方法中的路径分隔符造成的,修改成这样即可正常完成连接:
path = os.getcwd() + '/temp/' + self.gatewayName + '/'
库中目前是这样:
path = os.getcwd() + '\temp\' + self.gatewayName + '\'
json配置文件处的容易发现,惭愧的是没有再搜索下其他地方,汗。
经测试,使用'/'在wins下也可正常工作。将来会把代码中的 \ 替换成 / ,以达到更好的跨平台性。
我是刚接触的,现在下载了,还不会使用。
教程可以有个示例就行。如pyalgotrade那样,新手可以照着教程做下去就可以让程序跑起来。
希望vnpy发扬光大。
Traceback (most recent call last):
File "D:\py\vnpy-master\vn.trader\uiMainWindow.py", line 260, in closeEvent
self.mainEngine.exit()
File "D:\py\vnpy-master\vn.trader\vtEngine.py", line 162, in exit
gateway.close()
File "D:\py\vnpy-master\vn.trader\oandaGateway\oandaGateway.py", line 128, in
close
self.api.exit()
File "D:\py\vnpy-master\vn.trader\oandaGateway\vnoanda.py", line 182, in exit
self.reqThread.join()
File "C:\Anaconda2\lib\threading.py", line 929, in join
raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started
Resolution:
vn.trader\oandaGateway\vnoanda.py
Add code at line 180 to check if API is active.
#----------------------------------------------------------------------
def exit(self):
"""退出接口"""
* if self.active:*
self.active = False
self.reqThread.join()
vn.trader\vtMain.py,要添加合约,是通过UI还是通过代码?
有时候策略持仓,如果策略出现问题或出现系统性风险时不能及时平仓,是否考虑下在界面加上一键平仓,持仓列表加上右键平仓选项控制单个品种的及时平仓
不好意思,关闭吧,刚刚看到,已经有这个功能了。
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.