Merge pull request #895 from cclauss/modernize-vnpy_api_xspeed

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

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from vnxspeedmd import MdApi from __future__ import absolute_import
from vnxspeedtd import TdApi from .vnxspeedmd import MdApi
from xspeed_data_type import defineDict from .vnxspeedtd import TdApi
from .xspeed_data_type import defineDict

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY' __author__ = 'CHENXY'
# C++和python类型的映射字典 # C++和python类型的映射字典
@ -48,7 +49,7 @@ def process_typedef(line):
else: else:
keyword = content[-1] keyword = content[-1]
keyword = keyword.replace(';\n', '') keyword = keyword.replace(';\n', '')
print content, keyword print(content, keyword)
if '[' in keyword: if '[' in keyword:
i = keyword.index('[') i = keyword.index('[')
@ -97,15 +98,15 @@ def main():
py_line = process_line(line) py_line = process_line(line)
if py_line: if py_line:
fpy.write(py_line.decode('gbk').encode('utf-8')) fpy.write(py_line.decode('gbk').encode('utf-8'))
print n print(n)
fcpp.close() fcpp.close()
fpy.close() fpy.close()
print u'data_type.py生成过程完成' print(u'data_type.py生成过程完成')
except Exception, e: except Exception as e:
print u'data_type.py生成过程出错' print(u'data_type.py生成过程出错')
print e print(e)
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
@ -224,7 +225,7 @@ def processFunction(line):
fcArgsTypeList.append(content[1]) # 参数类型列表 fcArgsTypeList.append(content[1]) # 参数类型列表
fcArgsValueList.append(content[3]) # 参数数据列表 fcArgsValueList.append(content[3]) # 参数数据列表
print fcArgsTypeList print(fcArgsTypeList)
if len(fcArgsTypeList)>0 and fcArgsTypeList[0] in structDict: if len(fcArgsTypeList)>0 and fcArgsTypeList[0] in structDict:
createFunction(fcName, fcArgsTypeList, fcArgsValueList) createFunction(fcName, fcArgsTypeList, fcArgsValueList)
@ -286,10 +287,10 @@ define_count = 1
for line in fcpp: for line in fcpp:
if " virtual void On" in line: if " virtual void On" in line:
print 'callback' print('callback')
processCallBack(line) processCallBack(line)
elif " virtual int" in line: elif " virtual int" in line:
print 'function' print('function')
processFunction(line) processFunction(line)
fcpp.close() fcpp.close()

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY' __author__ = 'CHENXY'
from xspeed_data_type import * from xspeed_data_type import *
@ -47,10 +48,10 @@ def main():
n = line.index('//') n = line.index('//')
line = line[:n] line = line[:n]
print no, ':', line print(no, ':', line)
content = line.split('\t') content = line.split('\t')
print content print(content)
typedef = content[1] typedef = content[1]
type_ = typedefDict[typedef] type_ = typedefDict[typedef]

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
@ -33,7 +34,7 @@ def processCallBack(line):
cbArgsTypeList.append(content[0]) # 参数类型列表 cbArgsTypeList.append(content[0]) # 参数类型列表
cbArgsValueList.append(content[1]) # 参数数据列表 cbArgsValueList.append(content[1]) # 参数数据列表
else: else:
print content print(content)
cbArgsTypeList.append(content[1]) # 参数类型列表 cbArgsTypeList.append(content[1]) # 参数类型列表
cbArgsValueList.append(content[2]+content[3]) # 参数数据列表 cbArgsValueList.append(content[2]+content[3]) # 参数数据列表
@ -230,8 +231,8 @@ def processFunction(line):
fcArgsTypeList.append(content[1]) # 参数类型列表 fcArgsTypeList.append(content[1]) # 参数类型列表
fcArgsValueList.append(content[3]) # 参数数据列表 fcArgsValueList.append(content[3]) # 参数数据列表
print line print(line)
print fcArgsTypeList print(fcArgsTypeList)
if len(fcArgsTypeList)>0 and fcArgsTypeList[0] in structDict: if len(fcArgsTypeList)>0 and fcArgsTypeList[0] in structDict:
createFunction(fcName, fcArgsTypeList, fcArgsValueList) createFunction(fcName, fcArgsTypeList, fcArgsValueList)
@ -263,7 +264,7 @@ def createFunction(fcName, fcArgsTypeList, fcArgsValueList):
elif value == 'short': elif value == 'short':
line = '\tgetShort(req, "' + key + '", &myreq.' + key + ');\n' line = '\tgetShort(req, "' + key + '", &myreq.' + key + ');\n'
elif value == 'float': elif value == 'float':
print line print(line)
line = '\tgetDouble(req, "' + key + '", &myreq.' + key + ');\n' line = '\tgetDouble(req, "' + key + '", &myreq.' + key + ');\n'
ffunction.write(line) ffunction.write(line)
@ -294,10 +295,10 @@ define_count = 1
for line in fcpp: for line in fcpp:
if " virtual void On" in line: if " virtual void On" in line:
print 'callback' print('callback')
processCallBack(line) processCallBack(line)
elif " virtual int" in line: elif " virtual int" in line:
print 'function' print('function')
processFunction(line) processFunction(line)
fcpp.close() fcpp.close()

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY' __author__ = 'CHENXY'
# C++和python类型的映射字典 # C++和python类型的映射字典
@ -48,7 +49,7 @@ def process_typedef(line):
else: else:
keyword = content[-1] keyword = content[-1]
keyword = keyword.replace(';\n', '') keyword = keyword.replace(';\n', '')
print content, keyword print(content, keyword)
if '[' in keyword: if '[' in keyword:
i = keyword.index('[') i = keyword.index('[')
@ -91,15 +92,15 @@ def main():
py_line = process_line(line) py_line = process_line(line)
if py_line: if py_line:
fpy.write(py_line.decode('gbk').encode('utf-8')) fpy.write(py_line.decode('gbk').encode('utf-8'))
print n print(n)
fcpp.close() fcpp.close()
fpy.close() fpy.close()
print u'data_type.py生成过程完成' print(u'data_type.py生成过程完成')
except Exception, e: except Exception as e:
print u'data_type.py生成过程出错' print(u'data_type.py生成过程出错')
print e print(e)
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 ksgold_data_type import * from ksgold_data_type import *
@ -47,7 +48,7 @@ def main():
n = line.index('//') n = line.index('//')
line = line[:n] line = line[:n]
print no, ':', line print(no, ':', line)
content = line.split('\t') content = line.split('\t')

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import sys import sys
from time import sleep from time import sleep
import datetime import datetime
@ -13,7 +14,7 @@ from vnxspeedmd import *
def print_dict(d): def print_dict(d):
"""按照键值打印一个字典""" """按照键值打印一个字典"""
for key,value in d.items(): for key,value in d.items():
print key + ':' + str(value) print(key + ':' + str(value))
def parseDateTime(date,time,milli): def parseDateTime(date,time,milli):
@ -32,8 +33,8 @@ def parseDateTime(date,time,milli):
def simple_log(func): def simple_log(func):
"""简单装饰器用于输出函数名""" """简单装饰器用于输出函数名"""
def wrapper(*args, **kw): def wrapper(*args, **kw):
print "" print("")
print str(func.__name__) print(str(func.__name__))
return func(*args, **kw) return func(*args, **kw)
return wrapper return wrapper
@ -57,7 +58,7 @@ class TestMdApi(MdApi):
@simple_log @simple_log
def onFrontDisconnected(self, n): def onFrontDisconnected(self, n):
"""服务器断开""" """服务器断开"""
print n print(n)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import sys import sys
from time import sleep from time import sleep
@ -12,15 +13,15 @@ from vnxspeedtd import *
def print_dict(d): def print_dict(d):
"""按照键值打印一个字典""" """按照键值打印一个字典"""
for key,value in d.items(): for key,value in d.items():
print key + ':' + str(value) print(key + ':' + str(value))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def simple_log(func): def simple_log(func):
"""简单装饰器用于输出函数名""" """简单装饰器用于输出函数名"""
def wrapper(*args, **kw): def wrapper(*args, **kw):
print "" print("")
print str(func.__name__) print(str(func.__name__))
return func(*args, **kw) return func(*args, **kw)
return wrapper return wrapper
@ -43,7 +44,7 @@ class TestTdApi(TdApi):
@simple_log @simple_log
def onFrontDisconnected(self, n): def onFrontDisconnected(self, n):
"""服务器断开""" """服务器断开"""
print n print(n)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -82,7 +83,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -90,7 +91,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -105,7 +106,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -113,7 +114,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -145,7 +146,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -153,7 +154,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -161,7 +162,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -188,7 +189,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -203,7 +204,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -217,7 +218,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -225,7 +226,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@simple_log @simple_log
@ -233,7 +234,7 @@ class TestTdApi(TdApi):
"""查询持仓""" """查询持仓"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------