Merge pull request #869 from cclauss/modernize-vnpy_api_c_and_f

Modernize vnpy/api/c* and vnpy/api/f*
This commit is contained in:
vn.py 2018-05-17 09:43:04 +08:00 committed by GitHub
commit 92377715af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 116 additions and 99 deletions

View File

@ -1,3 +1,4 @@
# encoding: UTF-8
from vncshshlp import CsHsHlp
from __future__ import absolute_import
from .vncshshlp import CsHsHlp

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
import sys
from time import sleep
@ -14,21 +15,21 @@ branch_no = ''
def print_list(l):
""""""
for d in l:
print d
print(d)
#----------------------------------------------------------------------
def print_dict(d):
"""按照键值打印一个字典"""
for key,value in d.items():
print key + ':' + str(value)
print(key + ':' + str(value))
#----------------------------------------------------------------------
def simple_log(func):
"""简单装饰器用于输出函数名"""
def wrapper(*args, **kw):
print '-' * 20
print str(func.__name__)
print('-' * 20)
print(str(func.__name__))
return func(*args, **kw)
return wrapper
@ -59,18 +60,18 @@ class TestHlp(CsHsHlp):
@simple_log
def onMsg(self, type_, data, reqNo, errorNo, errorInfo):
""""""
print 'type:', type_
print('type:', type_)
# print_list(data)
print 'reqNo:', reqNo
print 'errorNo:', errorNo
print 'errorInfo:', errorInfo
print('reqNo:', reqNo)
print('errorNo:', errorNo)
print('errorInfo:', errorInfo)
'''
for i in data[0].keys():
print "key=%s,value=%s"%(i,data[0][i])
'''
for dd in data:
print dd
print(dd)
self.data = data
@ -101,23 +102,23 @@ class TestHlp(CsHsHlp):
'''
i = self.loadConfig("Hsconfig.ini")
if i:
print u'加载配置失败:', i
print(u'加载配置失败:', i)
return i
print u'加载配置成功'
print(u'加载配置成功')
# 初始化
i = self.init()
if i:
print u'初始化失败:', i
print(u'初始化失败:', i)
return i
print u'初始化成功'
print(u'初始化成功')
# 连接服务器
i = self.connectServer()
if i:
print u'服务器连接失败:', i
print(u'服务器连接失败:', i)
return i
print u'服务器连接成功'
print(u'服务器连接成功')
return int(0)
@ -135,10 +136,10 @@ def test():
# 初始化端口
i = api.init_api()
if i:
print u'初始化端口失败请检查clog文件', i
print(u'初始化端口失败请检查clog文件', i)
return
# 登录
print u'尝试登录'
print(u'尝试登录')
i = api.beginParam()
api.setValue("identity_type", "2")
api.setValue("password_type", "2")
@ -150,7 +151,7 @@ def test():
api.setValue('option_fund_account', account['id'])
api.setValue('op_station', '<yangxs><vnpy><test>')
i = api.bizCallAndCommit(331100)
print u'尝试登录返回', i
print(u'尝试登录返回', i)
sleep(3)
#---------------------------------------------------------
# 配置self的变量
@ -170,34 +171,34 @@ def test():
api.request_num = '500'
api.op_station = '<yangxs><vnpy><test>'
else:
print 'error in set the value'
print('error in set the value')
#------------------------------------------
# 订阅 620001 成交回报 33011
# 订阅 620001 委托回写 33012
# api.setNessaryParam()
print u'订阅 33011'
print(u'订阅 33011')
api.beginParam()
acc_info = '~' .join([api.branch_no, api.fund_account])
api.setValue('issue_type', "33011")
api.setValue('acc_info', acc_info)
i = api.subscribeData(620001)
print i
print(i)
sleep(1)
print u'订阅 33012'
print(u'订阅 33012')
api.beginParam()
acc_info = '~' .join([api.branch_no, api.fund_account])
api.setValue('issue_type', "33012")
api.setValue('acc_info', acc_info)
i = api.subscribeData(620001)
print i
print(i)
sleep(1)
print u'配置参数,进行下单'
print(u'配置参数,进行下单')
# 配置
api.setNessaryParam()
# 下单参数 338011
@ -211,22 +212,22 @@ def test():
api.setValue('entrust_prop', '0')
api.setValue('covered_flag', '')
i = api.bizCallAndCommit(338011)
print u'尝试下单返回', i
print(u'尝试下单返回', i)
sleep(3)
print u'查询持仓'
print(u'查询持仓')
# 查询持仓
# api.beginParam()
api.setNessaryParam()
i = api.bizCallAndCommit(338023)
sleep(3)
print u'查询持仓返回',i
print(u'查询持仓返回',i)
if(len(api.data)):
for dd in api.data:
print "-----------------------"
print("-----------------------")
for i in dd.keys():
print "key=%s,value=%s"%(i,api.data[0][i])
print("key=%s,value=%s"%(i,api.data[0][i]))
# --------------------------------------------------------------------------
# 测试撤单 338012,先下单,间隔后撤单
@ -241,7 +242,7 @@ def test():
api.setValue('entrust_prop', '0')
api.setValue('covered_flag', '')
i = api.bizCallAndCommit(338011)
print u'尝试下单返回', i
print(u'尝试下单返回', i)
sleep(3)
# print api.data
@ -251,16 +252,16 @@ def test():
e_no = tt['entrust_no']
api.order[e_no] = tt
print api.order
print(api.order)
api.setNessaryParam()
api.setValue('exchange_type','1')
for kk in api.order.keys():
api.setValue('entrust_no', kk)
i = api.bizCallAndCommit(338012)
print u'尝试撤单', kk
print(u'尝试撤单', kk)
sleep(1)
#pop or del
print api.data
print(api.data)
#-----------------------------------
@ -271,15 +272,15 @@ def test():
api.setValue('locate_entrust_no', kk)
i = api.bizCallAndCommit(338020)
print u'查询指定订单', kk
print(u'查询指定订单', kk)
sleep(1)
print api.data
print(api.data)
api.setNessaryParam()
api.setValue('query_kind', '1')
i = api.bizCallAndCommit(338020)
sleep(1)
print api.data
print(api.data)

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from vnctpmd import MdApi
from vnctptd import TdApi
from ctp_data_type import defineDict
from __future__ import absolute_import
from .vnctpmd import MdApi
from .vnctptd import TdApi
from .ctp_data_type import defineDict

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY'
# C++和python类型的映射字典
@ -92,9 +93,9 @@ def main():
fcpp.close()
fpy.close()
print u'data_type.py生成过程完成'
print(u'data_type.py生成过程完成')
except:
print u'data_type.py生成过程出错'
print(u'data_type.py生成过程出错')
if __name__ == '__main__':

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY'
from ctp_struct import structDict
@ -257,7 +258,7 @@ def createFunction(fcName, fcArgsTypeList, fcArgsValueList):
ffunction.write(line)
if type_ == 'CThostFtdcInputOrderField':
print(key, value)
print((key, value))
print(line)
ffunction.write('\tint i = this->api->' + fcName + '(&myreq, nRequestID);\n')

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY'
# C++和python类型的映射字典
@ -92,9 +93,9 @@ def main():
fcpp.close()
fpy.close()
print u'data_type.py生成过程完成'
print(u'data_type.py生成过程完成')
except:
print u'data_type.py生成过程出错'
print(u'data_type.py生成过程出错')
if __name__ == '__main__':

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY'
from string import join
@ -250,8 +251,8 @@ def createFunction(fcName, fcArgsTypeList, fcArgsValueList):
ffunction.write(line)
if type_ == 'CThostFtdcInputOrderField':
print key, value
print line
print(key, value)
print(line)
ffunction.write('\tint i = this->api->' + fcName + '(&myreq, nRequestID);\n')
ffunction.write('\treturn i;\n')

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
import sys
from time import sleep
@ -12,15 +13,15 @@ from vnctpmd import *
def print_dict(d):
"""按照键值打印一个字典"""
for key,value in d.items():
print key + ':' + str(value)
print(key + ':' + str(value))
#----------------------------------------------------------------------
def simple_log(func):
"""简单装饰器用于输出函数名"""
def wrapper(*args, **kw):
print ""
print str(func.__name__)
print("")
print(str(func.__name__))
return func(*args, **kw)
return wrapper
@ -44,13 +45,13 @@ class TestMdApi(MdApi):
@simple_log
def onFrontDisconnected(self, n):
"""服务器断开"""
print n
print(n)
#----------------------------------------------------------------------
@simple_log
def onHeartBeatWarning(self, n):
"""心跳报警"""
print n
print(n)
#----------------------------------------------------------------------
@simple_log

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
import sys
from time import sleep
@ -11,15 +12,15 @@ from vnctptd import *
def print_dict(d):
"""按照键值打印一个字典"""
for key,value in d.items():
print key + ':' + str(value)
print(key + ':' + str(value))
#----------------------------------------------------------------------
def simple_log(func):
"""简单装饰器用于输出函数名"""
def wrapper(*args, **kw):
print ""
print str(func.__name__)
print("")
print(str(func.__name__))
return func(*args, **kw)
return wrapper
@ -43,13 +44,13 @@ class TestTdApi(TdApi):
@simple_log
def onFrontDisconnected(self, n):
"""服务器断开"""
print n
print(n)
#----------------------------------------------------------------------
@simple_log
def onHeartBeatWarning(self, n):
"""心跳报警"""
print n
print(n)
#----------------------------------------------------------------------
@simple_log
@ -95,8 +96,8 @@ class TestTdApi(TdApi):
"""查询合约回报"""
print_dict(data)
print_dict(error)
print n
print last
print(n)
print(last)
#----------------------------------------------------------------------

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from vnfemasmd import MdApi
from vnfemastd import TdApi
from femas_data_type import defineDict
from __future__ import absolute_import
from .vnfemasmd import MdApi
from .vnfemastd import TdApi
from .femas_data_type import defineDict

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
__author__ = 'CHENXY'
# C++和python类型的映射字典
@ -88,9 +89,9 @@ def main():
fcpp.close()
fpy.close()
print u'data_type.py生成过程完成'
print(u'data_type.py生成过程完成')
except:
print u'data_type.py生成过程出错'
print(u'data_type.py生成过程出错')
if __name__ == '__main__':

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
import sys
from time import sleep
@ -12,15 +13,15 @@ from vnfemasmd import *
def print_dict(d):
"""按照键值打印一个字典"""
for key,value in d.items():
print key + ':' + str(value)
print(key + ':' + str(value))
#----------------------------------------------------------------------
def simple_log(func):
"""简单装饰器用于输出函数名"""
def wrapper(*args, **kw):
print ""
print str(func.__name__)
print("")
print(str(func.__name__))
return func(*args, **kw)
return wrapper
@ -44,13 +45,13 @@ class TestMdApi(MdApi):
@simple_log
def onFrontDisconnected(self, n):
"""服务器断开"""
print n
print(n)
#----------------------------------------------------------------------
@simple_log
def onHeartBeatWarning(self, n):
"""心跳报警"""
print n
print(n)
#----------------------------------------------------------------------
@simple_log

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
import sys
from time import sleep
@ -11,15 +12,15 @@ from vnfemastd import *
def print_dict(d):
"""按照键值打印一个字典"""
for key,value in d.items():
print key + ':' + str(value)
print(key + ':' + str(value))
#----------------------------------------------------------------------
def simple_log(func):
"""简单装饰器用于输出函数名"""
def wrapper(*args, **kw):
print ""
print str(func.__name__)
print("")
print(str(func.__name__))
return func(*args, **kw)
return wrapper
@ -43,13 +44,13 @@ class TestTdApi(TdApi):
@simple_log
def onFrontDisconnected(self, n):
"""服务器断开"""
print n
print(n)
#----------------------------------------------------------------------
@simple_log
def onHeartBeatWarning(self, n):
"""心跳报警"""
print n
print(n)
#----------------------------------------------------------------------
@simple_log
@ -95,8 +96,8 @@ class TestTdApi(TdApi):
"""查询合约回报"""
print_dict(data)
print_dict(error)
print n
print last
print(n)
print(last)
#----------------------------------------------------------------------

View File

@ -1,3 +1,4 @@
# encoding: UTF-8
from vnfxcm import FxcmApi
from __future__ import absolute_import
from .vnfxcm import FxcmApi

View File

@ -1,8 +1,10 @@
# encoding: UTF-8
from __future__ import print_function
from __future__ import absolute_import
from time import sleep
from vnfxcm import FxcmApi
from .vnfxcm import FxcmApi
url = 'https://api-demo.fxcm.com:443'
port = 443
@ -10,10 +12,10 @@ token = '48055b5d9afac0a300143ac067ce04cd2430a434'
proxy = 'https://localhost:1080'
api = FxcmApi()
print 'api created'
print('api created')
api.connect(url, port, token, proxy)
print api.bearer
print(api.bearer)
sleep(20)
#api.getInstruments()

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
import json
import requests
from socketIO_client import SocketIO
@ -334,32 +335,32 @@ class FxcmApi(object):
#----------------------------------------------------------------------
def onConnect(self):
"""连接回调"""
print 'onConnect'
print('onConnect')
#----------------------------------------------------------------------
def onDisconnect(self):
"""断开回调"""
print 'onClose'
print('onClose')
#----------------------------------------------------------------------
def onError(self, error, reqid):
"""错误回调"""
print 'onError', error
print('onError', error)
#----------------------------------------------------------------------
def onGetInstruments(self, data, reqid):
"""查询合约代码回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onGetModel(self, data, reqid):
"""查询表回调"""
print '*' * 30
print data
print('*' * 30)
print(data)
for d in data['offers']:
#if str(d['currency']) == 'EUR/USD':
# print d
print d['currency']#, d['visible']
print(d['currency'])#, d['visible']
#print len(data['summary'])
#print data
@ -367,47 +368,47 @@ class FxcmApi(object):
#----------------------------------------------------------------------
def onSubscribe(self, data, reqid):
"""订阅行情回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onUnsubscribe(self, data, reqid):
"""退订行情回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onSubscribeModel(self, data, reqid):
"""订阅表回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onUnsubscribeModel(self, data, reqid):
"""退订表回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onUpdateSubscriptions(self, data, reqid):
"""订阅报价表回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onOpenTrade(self, data, reqid):
"""开仓回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onCloseTrade(self, data, reqid):
"""平仓回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onChangeOrder(self, data, reqid):
"""改单回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onDeleteOrder(self, data, reqid):
"""撤单回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def processPriceUpdate(self, msg):
@ -418,19 +419,19 @@ class FxcmApi(object):
#----------------------------------------------------------------------
def processModelUpdate(self, msg):
"""表推送"""
print msg
print(msg)
data = json.loads(msg)
self.onModelUpdate(data)
#----------------------------------------------------------------------
def onPriceUpdate(self, data):
"""行情推送"""
print data
print(data)
#----------------------------------------------------------------------
def onModelUpdate(self, data):
"""表推送"""
print data
print(data)
#print '*' * 30
#fsubscribeModel
#print len(data), data.get('isTotal', None), data