Merge pull request #897 from cclauss/modernize-vnpy_api_xtpp
Modernize vnpy/api/xtp
This commit is contained in:
commit
d22c6b0e49
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from vnxtpquote import QuoteApi
|
||||
from vnxtptrader import TraderApi
|
||||
from xtp_data_type import *
|
||||
from __future__ import absolute_import
|
||||
from .vnxtpquote import QuoteApi
|
||||
from .vnxtptrader import TraderApi
|
||||
from .xtp_data_type import *
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
__author__ = u'用Python的交易员'
|
||||
|
||||
# C++和python类型的映射字典
|
||||
@ -128,7 +129,7 @@ def main():
|
||||
fcpp.close()
|
||||
fpy.close()
|
||||
|
||||
print u'data_type.py生成过程完成'
|
||||
print(u'data_type.py生成过程完成')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
__author__ = 'CHENXY'
|
||||
|
||||
from string import join
|
||||
@ -331,4 +332,4 @@ fheaderon.close()
|
||||
fheaderfunction.close()
|
||||
fwrap.close()
|
||||
|
||||
print 'md functions done'
|
||||
print('md functions done')
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
__author__ = 'CHENXY'
|
||||
|
||||
from xtp_data_type import *
|
||||
@ -27,7 +28,7 @@ def main():
|
||||
fpy.write('\n')
|
||||
|
||||
for row, line in enumerate(fcpp):
|
||||
print row
|
||||
print(row)
|
||||
# 结构体申明注释
|
||||
if '///' in line and '\t' not in line:
|
||||
py_line = '#' + line[3:]
|
||||
@ -38,7 +39,7 @@ def main():
|
||||
|
||||
# 结构体申明
|
||||
elif 'struct ' in line:
|
||||
print line
|
||||
print(line)
|
||||
content = line.split(' ')
|
||||
name = content[1].replace('\n','')
|
||||
name = name.replace('\r', '')
|
||||
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
__author__ = 'CHENXY'
|
||||
|
||||
from xtp_data_type import *
|
||||
@ -38,7 +39,7 @@ def main():
|
||||
|
||||
lcpp = replaceTabs(fcpp)
|
||||
for n, line in enumerate(lcpp):
|
||||
print n
|
||||
print(n)
|
||||
# 结构体申明注释
|
||||
if '///' in line and '\t' not in line:
|
||||
py_line = '#' + line[3:]
|
||||
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
__author__ = 'CHENXY'
|
||||
|
||||
from string import join
|
||||
@ -194,7 +195,7 @@ def createProcess(cbName, cbArgsTypeList, cbArgsValueList):
|
||||
fprocess.write(" PyLock lock;\n")
|
||||
|
||||
onArgsList = []
|
||||
print cbName, cbArgsTypeList
|
||||
print(cbName, cbArgsTypeList)
|
||||
|
||||
for i, type_ in enumerate(cbArgsTypeList):
|
||||
if 'XTPRI' in type_:
|
||||
@ -258,7 +259,7 @@ def processFunction(line):
|
||||
fcArgs = fcArgs.replace(')', '')
|
||||
|
||||
fcArgsList = fcArgs.split(', ') # 将每个参数转化为列表
|
||||
print fcArgsList
|
||||
print(fcArgsList)
|
||||
fcArgsTypeList = []
|
||||
fcArgsValueList = []
|
||||
|
||||
@ -352,4 +353,4 @@ fheaderon.close()
|
||||
fheaderfunction.close()
|
||||
fwrap.close()
|
||||
|
||||
print 'td functions done'
|
||||
print('td functions done')
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
from time import sleep
|
||||
|
||||
@ -8,11 +9,11 @@ from vnxtpquote import *
|
||||
#----------------------------------------------------------------------
|
||||
def printDict(d):
|
||||
""""""
|
||||
print '-' * 50
|
||||
print('-' * 50)
|
||||
l = d.keys()
|
||||
l.sort()
|
||||
for k in l:
|
||||
print k, d[k]
|
||||
print(k, d[k])
|
||||
|
||||
|
||||
|
||||
@ -28,32 +29,32 @@ class TestApi(QuoteApi):
|
||||
#----------------------------------------------------------------------
|
||||
def onDisconnected(self, reason):
|
||||
""""""
|
||||
print 'disconnect', reason
|
||||
print('disconnect', reason)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onError(self, data):
|
||||
""""""
|
||||
print 'error'
|
||||
print('error')
|
||||
printDict(data)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onSubMarketData(self, data, error, last):
|
||||
""""""
|
||||
print 'sub market data'
|
||||
print('sub market data')
|
||||
printDict(data)
|
||||
printDict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onUnSubMarketData(self, data, error, last):
|
||||
""""""
|
||||
print 'unsub market data'
|
||||
print('unsub market data')
|
||||
printDict(data)
|
||||
printDict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onMarketData(self, data):
|
||||
""""""
|
||||
print 'new market data'
|
||||
print('new market data')
|
||||
printDict(data)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@ -75,7 +76,7 @@ if __name__ == '__main__':
|
||||
|
||||
# 登录
|
||||
n = api.login(ip, port, user, password, 1)
|
||||
print 'login result', n
|
||||
print('login result', n)
|
||||
|
||||
# 订阅行情
|
||||
api.subscribeMarketData('000001', 2)
|
||||
|
@ -1,20 +1,23 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
from time import sleep
|
||||
|
||||
from six.moves import input
|
||||
|
||||
from vnxtptrader import *
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def printDict(d):
|
||||
""""""
|
||||
print '-' * 50
|
||||
print('-' * 50)
|
||||
l = d.keys()
|
||||
l.sort()
|
||||
for k in l:
|
||||
print k, d[k]
|
||||
|
||||
|
||||
print(k, d[k])
|
||||
|
||||
|
||||
########################################################################
|
||||
class TestApi(TraderApi):
|
||||
@ -28,79 +31,79 @@ class TestApi(TraderApi):
|
||||
#----------------------------------------------------------------------
|
||||
def onDisconnected(self, reason):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onDisconnected'
|
||||
print reason
|
||||
print('-' * 30)
|
||||
print('onDisconnected')
|
||||
print(reason)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onError(self, data):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onError'
|
||||
print('-' * 30)
|
||||
print('onError')
|
||||
printDict(data)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onOrderEvent(self, data, error):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onOrderEvent'
|
||||
print('-' * 30)
|
||||
print('onOrderEvent')
|
||||
printDict(data)
|
||||
printDict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onTradeEvent(self, data):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onTradeEvent'
|
||||
print('-' * 30)
|
||||
print('onTradeEvent')
|
||||
printDict(data)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onCancelOrderError(self, data, error):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onCancelOrderError'
|
||||
print('-' * 30)
|
||||
print('onCancelOrderError')
|
||||
printDict(data)
|
||||
printDict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onQueryOrder(self, data, error, reqid, last):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onQueryOrder'
|
||||
print('-' * 30)
|
||||
print('onQueryOrder')
|
||||
printDict(data)
|
||||
printDict(error)
|
||||
print reqid
|
||||
print last
|
||||
print(reqid)
|
||||
print(last)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onQueryTrade(self, data, error, reqid, last):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onQueryTrade'
|
||||
print('-' * 30)
|
||||
print('onQueryTrade')
|
||||
printDict(data)
|
||||
printDict(error)
|
||||
print reqid
|
||||
print last
|
||||
print(reqid)
|
||||
print(last)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onQueryPosition(self, data, error, reqid, last):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onQueryPosition'
|
||||
print('-' * 30)
|
||||
print('onQueryPosition')
|
||||
printDict(data)
|
||||
printDict(error)
|
||||
print reqid
|
||||
print last
|
||||
print(reqid)
|
||||
print(last)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onQueryAsset(self, data, error, reqid, last):
|
||||
""""""
|
||||
print '-' * 30
|
||||
print 'onQueryAsset'
|
||||
print('-' * 30)
|
||||
print('onQueryAsset')
|
||||
printDict(data)
|
||||
printDict(error)
|
||||
print reqid
|
||||
print last
|
||||
print(reqid)
|
||||
print(last)
|
||||
|
||||
|
||||
|
||||
@ -121,12 +124,12 @@ if __name__ == '__main__':
|
||||
|
||||
# 登录
|
||||
session = api.login(ip, port, user, password, 1)
|
||||
print 'login result', session
|
||||
print('login result', session)
|
||||
|
||||
# 调用同步函数查询一些信息
|
||||
print 'trading day is:', api.getTradingDay()
|
||||
print 'api version is:', api.getApiVersion()
|
||||
print 'last error is:', api.getApiLastError()
|
||||
print('trading day is:', api.getTradingDay())
|
||||
print('api version is:', api.getApiVersion())
|
||||
print('last error is:', api.getApiLastError())
|
||||
|
||||
# 查询资产
|
||||
sleep(2)
|
||||
@ -166,7 +169,7 @@ if __name__ == '__main__':
|
||||
|
||||
# 登出
|
||||
sleep(5)
|
||||
print 'logout:', api.logout(session)
|
||||
print('logout:', api.logout(session))
|
||||
|
||||
# 阻塞
|
||||
raw_input()
|
||||
input()
|
||||
|
Loading…
Reference in New Issue
Block a user