Merge pull request #897 from cclauss/modernize-vnpy_api_xtpp

Modernize vnpy/api/xtp
This commit is contained in:
vn.py 2018-05-30 09:35:35 +08:00 committed by GitHub
commit d22c6b0e49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 56 deletions

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from vnxtpquote import QuoteApi from __future__ import absolute_import
from vnxtptrader import TraderApi from .vnxtpquote import QuoteApi
from xtp_data_type import * from .vnxtptrader import TraderApi
from .xtp_data_type import *

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
__author__ = u'用Python的交易员' __author__ = u'用Python的交易员'
# C++和python类型的映射字典 # C++和python类型的映射字典
@ -128,7 +129,7 @@ def main():
fcpp.close() fcpp.close()
fpy.close() fpy.close()
print u'data_type.py生成过程完成' print(u'data_type.py生成过程完成')
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY' __author__ = 'CHENXY'
from string import join from string import join
@ -331,4 +332,4 @@ fheaderon.close()
fheaderfunction.close() fheaderfunction.close()
fwrap.close() fwrap.close()
print 'md functions done' print('md functions done')

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY' __author__ = 'CHENXY'
from xtp_data_type import * from xtp_data_type import *
@ -27,7 +28,7 @@ def main():
fpy.write('\n') fpy.write('\n')
for row, line in enumerate(fcpp): for row, line in enumerate(fcpp):
print row print(row)
# 结构体申明注释 # 结构体申明注释
if '///' in line and '\t' not in line: if '///' in line and '\t' not in line:
py_line = '#' + line[3:] py_line = '#' + line[3:]
@ -38,7 +39,7 @@ def main():
# 结构体申明 # 结构体申明
elif 'struct ' in line: elif 'struct ' in line:
print line print(line)
content = line.split(' ') content = line.split(' ')
name = content[1].replace('\n','') name = content[1].replace('\n','')
name = name.replace('\r', '') name = name.replace('\r', '')

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY' __author__ = 'CHENXY'
from xtp_data_type import * from xtp_data_type import *
@ -38,7 +39,7 @@ def main():
lcpp = replaceTabs(fcpp) lcpp = replaceTabs(fcpp)
for n, line in enumerate(lcpp): for n, line in enumerate(lcpp):
print n print(n)
# 结构体申明注释 # 结构体申明注释
if '///' in line and '\t' not in line: if '///' in line and '\t' not in line:
py_line = '#' + line[3:] py_line = '#' + line[3:]

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY' __author__ = 'CHENXY'
from string import join from string import join
@ -194,7 +195,7 @@ def createProcess(cbName, cbArgsTypeList, cbArgsValueList):
fprocess.write(" PyLock lock;\n") fprocess.write(" PyLock lock;\n")
onArgsList = [] onArgsList = []
print cbName, cbArgsTypeList print(cbName, cbArgsTypeList)
for i, type_ in enumerate(cbArgsTypeList): for i, type_ in enumerate(cbArgsTypeList):
if 'XTPRI' in type_: if 'XTPRI' in type_:
@ -258,7 +259,7 @@ def processFunction(line):
fcArgs = fcArgs.replace(')', '') fcArgs = fcArgs.replace(')', '')
fcArgsList = fcArgs.split(', ') # 将每个参数转化为列表 fcArgsList = fcArgs.split(', ') # 将每个参数转化为列表
print fcArgsList print(fcArgsList)
fcArgsTypeList = [] fcArgsTypeList = []
fcArgsValueList = [] fcArgsValueList = []
@ -352,4 +353,4 @@ fheaderon.close()
fheaderfunction.close() fheaderfunction.close()
fwrap.close() fwrap.close()
print 'td functions done' print('td functions done')

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import os import os
from time import sleep from time import sleep
@ -8,11 +9,11 @@ from vnxtpquote import *
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def printDict(d): def printDict(d):
"""""" """"""
print '-' * 50 print('-' * 50)
l = d.keys() l = d.keys()
l.sort() l.sort()
for k in l: for k in l:
print k, d[k] print(k, d[k])
@ -28,32 +29,32 @@ class TestApi(QuoteApi):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onDisconnected(self, reason): def onDisconnected(self, reason):
"""""" """"""
print 'disconnect', reason print('disconnect', reason)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onError(self, data): def onError(self, data):
"""""" """"""
print 'error' print('error')
printDict(data) printDict(data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onSubMarketData(self, data, error, last): def onSubMarketData(self, data, error, last):
"""""" """"""
print 'sub market data' print('sub market data')
printDict(data) printDict(data)
printDict(error) printDict(error)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onUnSubMarketData(self, data, error, last): def onUnSubMarketData(self, data, error, last):
"""""" """"""
print 'unsub market data' print('unsub market data')
printDict(data) printDict(data)
printDict(error) printDict(error)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onMarketData(self, data): def onMarketData(self, data):
"""""" """"""
print 'new market data' print('new market data')
printDict(data) printDict(data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@ -75,7 +76,7 @@ if __name__ == '__main__':
# 登录 # 登录
n = api.login(ip, port, user, password, 1) n = api.login(ip, port, user, password, 1)
print 'login result', n print('login result', n)
# 订阅行情 # 订阅行情
api.subscribeMarketData('000001', 2) api.subscribeMarketData('000001', 2)

View File

@ -1,20 +1,23 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import os import os
from time import sleep from time import sleep
from six.moves import input
from vnxtptrader import * from vnxtptrader import *
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def printDict(d): def printDict(d):
"""""" """"""
print '-' * 50 print('-' * 50)
l = d.keys() l = d.keys()
l.sort() l.sort()
for k in l: for k in l:
print k, d[k] print(k, d[k])
######################################################################## ########################################################################
class TestApi(TraderApi): class TestApi(TraderApi):
@ -28,79 +31,79 @@ class TestApi(TraderApi):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onDisconnected(self, reason): def onDisconnected(self, reason):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onDisconnected' print('onDisconnected')
print reason print(reason)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onError(self, data): def onError(self, data):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onError' print('onError')
printDict(data) printDict(data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onOrderEvent(self, data, error): def onOrderEvent(self, data, error):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onOrderEvent' print('onOrderEvent')
printDict(data) printDict(data)
printDict(error) printDict(error)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onTradeEvent(self, data): def onTradeEvent(self, data):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onTradeEvent' print('onTradeEvent')
printDict(data) printDict(data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onCancelOrderError(self, data, error): def onCancelOrderError(self, data, error):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onCancelOrderError' print('onCancelOrderError')
printDict(data) printDict(data)
printDict(error) printDict(error)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onQueryOrder(self, data, error, reqid, last): def onQueryOrder(self, data, error, reqid, last):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onQueryOrder' print('onQueryOrder')
printDict(data) printDict(data)
printDict(error) printDict(error)
print reqid print(reqid)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onQueryTrade(self, data, error, reqid, last): def onQueryTrade(self, data, error, reqid, last):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onQueryTrade' print('onQueryTrade')
printDict(data) printDict(data)
printDict(error) printDict(error)
print reqid print(reqid)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onQueryPosition(self, data, error, reqid, last): def onQueryPosition(self, data, error, reqid, last):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onQueryPosition' print('onQueryPosition')
printDict(data) printDict(data)
printDict(error) printDict(error)
print reqid print(reqid)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onQueryAsset(self, data, error, reqid, last): def onQueryAsset(self, data, error, reqid, last):
"""""" """"""
print '-' * 30 print('-' * 30)
print 'onQueryAsset' print('onQueryAsset')
printDict(data) printDict(data)
printDict(error) printDict(error)
print reqid print(reqid)
print last print(last)
@ -121,12 +124,12 @@ if __name__ == '__main__':
# 登录 # 登录
session = api.login(ip, port, user, password, 1) session = api.login(ip, port, user, password, 1)
print 'login result', session print('login result', session)
# 调用同步函数查询一些信息 # 调用同步函数查询一些信息
print 'trading day is:', api.getTradingDay() print('trading day is:', api.getTradingDay())
print 'api version is:', api.getApiVersion() print('api version is:', api.getApiVersion())
print 'last error is:', api.getApiLastError() print('last error is:', api.getApiLastError())
# 查询资产 # 查询资产
sleep(2) sleep(2)
@ -166,7 +169,7 @@ if __name__ == '__main__':
# 登出 # 登出
sleep(5) sleep(5)
print 'logout:', api.logout(session) print('logout:', api.logout(session))
# 阻塞 # 阻塞
raw_input() input()