Merge pull request #875 from cclauss/modernize-vnpy_api_k

Modernize vnpy/api/k*
This commit is contained in:
vn.py 2018-05-19 22:32:47 +08:00 committed by GitHub
commit 8569f7ddfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 27 deletions

View File

@ -1,4 +1,5 @@
# encoding: UTF-8 # encoding: UTF-8
from vnksgoldtd import TdApi from __future__ import absolute_import
from ksgold_data_type import defineDict from .vnksgoldtd import TdApi
from .ksgold_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('[')
@ -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 vnksotpmd import MdApi from __future__ import absolute_import
from vnksotptd import TdApi from .vnksotpmd import MdApi
from ksotp_data_type import defineDict from .vnksotptd import TdApi
from .ksotp_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类型的映射字典
@ -88,9 +89,9 @@ def main():
fcpp.close() fcpp.close()
fpy.close() fpy.close()
print u'data_type.py生成过程完成' print(u'data_type.py生成过程完成')
except: except:
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 ksotp_data_type import * from ksotp_data_type import *
@ -15,7 +16,7 @@ def main():
fpy.write('\n') fpy.write('\n')
for n, line in enumerate(fcpp): for n, line in enumerate(fcpp):
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:]
@ -38,8 +39,8 @@ def main():
try: try:
type_ = typedefDict[typedef] type_ = typedefDict[typedef]
except KeyError: except KeyError:
print content print(content)
print typedef print(typedef)
variable = content[2].replace(';\n', "") variable = content[2].replace(';\n', "")
py_line = '%s["%s"] = "%s"\n' % (name, variable, type_) py_line = '%s["%s"] = "%s"\n' % (name, variable, type_)

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 vnksotpmd 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
@ -44,7 +45,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
@ -11,15 +12,15 @@ from vnksotptd 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
@ -89,8 +90,8 @@ class TestTdApi(TdApi):
"""查询合约回报""" """查询合约回报"""
print_dict(data) print_dict(data)
print_dict(error) print_dict(error)
print n print(n)
print last print(last)
#---------------------------------------------------------------------- #----------------------------------------------------------------------