Giter Site home page Giter Site logo

vnpy / vnpy Goto Github PK

View Code? Open in Web Editor NEW
23.6K 1.4K 8.4K 248.28 MB

基于Python的开源量化交易平台开发框架

Home Page: http://www.vnpy.com

License: MIT License

Python 98.85% Shell 0.78% Batchfile 0.37%
trading investment quant python algotrading finance fintech vnpy

vnpy's Issues

回测载入数据的问题

现在是一次性全部载入的。
建议10天或20天分段载入。
碰到TICK回测,一次性载入就没办法了。
象现在这样,一年的tick,根本没办法回测。

字符编码问题

在windows server 2012 上回测的时候 ,出现如下问题:
windows server 2012
image

该如何解决,好像之前Debian 上有类似的问题~~

连接CTP更新委托条目时随机出现异常(历史委托条目多时易出现)

界面点击“连接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运行不成功

按照指导设置好后,运行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'
请问如何解决?

tick回测bug

陈总:

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/
基于信号驱动
使用函数式编程,而不是类编程。
这样,一个信号可以挂载多个函数。
代码更加轻量级,而且更加灵活。

运行mdtest.py 提示非法用户

按照教程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    等

等等。

导入 tick时,数量多时比较快

ctaHistoryData里面,reader是读一条,存一条。这样比较慢。
通过1亿多条件记录的测试表明,如果一次性读1万条,再来存入,比较快。

策略历史持仓问题

现在的策略 self.pos 只是它当时开仓的情况。而没办法获取历史持仓。
如果之前开的仓位,今天运行策略,它认为是0。
建议每次都会交易所获取,最少init时要从交易所获取持仓情况。

oanda Api 配置文件

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/'}

vntrader的表头排序问题

pyqt4中使用setSortingEnabled(True)开启表头排序功能,是按照字符串的编码进行排序,如3 > 123, 导致在vntrader的Monitor中对 价格、成交量等数字类型的字段进行排序时排序结果都是错误的,有没有什么办法对数字格式进行排序么?
插入Monitor中的单元格都是转化成SafeUnicode的,试过不转化直接插入,结果也错误。

vtMain中oandaGateway的问题

  1. vtMain中没有验证OANDA_connect.json中的token是否正确,不管正确与否,都可以初始化成功
    image
  2. 在填写正确的token的情况下,连接之后不知道应该做什么,界面也没有反应,报错这里的错误信息也不太明白
    image

有时启动vnMain.py后行情数据记录没写进mongodb

有时启动vnMain.py后行情数据记录没写进mongodb。已经设置了DR_setting.json中的working为true, 启动vnMain.py有5次,中间1次没记录任何行情数据到mongodb,其它4次启动都能正常记录tick和bar数据到mongodb。运行期间行情数据记录窗口是一直有数据在滚动的,表示接收是正常的,写库逻辑可能有问题。

回测引擎,不支持需要读取MongoDB的策略

有部分策略需要需要调用loadBar、loadTick等函数,这些函数需要self.vtSymbol,
但是BacktestingEngine引擎中初始化策略时并没有获取vtSymbol,
看到ctaEngine是通过loadSetting函数实现的,
是不是BacktestingEngine中也需要loadSetting函数?
我个人是用简单的 engine.strategy.vtSymbol = 'pp_hot' 实现。

Language and Broker

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离数据库中历史数据的时间越来越远。是不是说,要把接受到的数据同步存入数据库?保持数据库跟当前时间一致?(拖慢速度?)

关于实盘中使用历史数据的例子,万分感谢。

Tick行情数据记录 逻辑错误

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中封装的疑问

请问下,教程3中将c++接口封装为python的时候你给的pyltsmd下的文件时怎么生成的?还是说自己写的?谢谢

关于securitytraderapi.so

完整路径:vnpy/vn.lts/ltsapi/securitytraderapi.so

请问是针对哪种platform编译的呢,mac还是linux?

获取单个CHAR的时候问题

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的也可以更改一下

debian 8 LANG为zh_CN.UTF-8,safeUnicode报错:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 2: ordinal not in range(128)

当我使用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增加 localsymbol 的问题

因为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'

不成交即撤单后再追单是否可以这样写?是否有改进的可能?求指导

` 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)`

ctaEngine一个小建议

1,有行情就直接推送到策略中去。建议初始化完成之后再推送。
2,策略初始化后,假如没有行情,建议自动订阅。感觉没必要手工先在主界面订阅。

策略参数initDays是自然日,修改为交易日的实现方式

demo策略中策略初始化时,需要读取前initDays日的数据进行计算,
做策略回测时,使用initDays=5,回测到2月15日时报错,因为春节假期的原因,没有读到数据。
一年总有这两次长假期,考虑将initDays改为交易日,关于实现方式的问题请教下群主:

  1. initDays赋值一个足够多的天数,然后在策略的onInit中再用实际需要的交易日数目过滤获取到的initData
  2. ctaEngine中loadBar函数直接计算出实际的交易日,然后获取数据后返回initData
    不知道哪种方式更好一些,谢谢

TdApi onRspUserLogin后不停的报错 TypeError: 'NoneType' object is not callable

触发条件,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

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发扬光大。

thread not start when join

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()

持仓风险

有时候策略持仓,如果策略出现问题或出现系统性风险时不能及时平仓,是否考虑下在界面加上一键平仓,持仓列表加上右键平仓选项控制单个品种的及时平仓

回测时间问题

不好意思,关闭吧,刚刚看到,已经有这个功能了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.