Merge pull request #874 from cclauss/modernize-vnpy_api_h_and_i

Modernize vnpy/api/h* and i*
This commit is contained in:
vn.py 2018-05-31 15:26:00 +08:00 committed by GitHub
commit c28380a6ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 152 additions and 143 deletions

View File

@ -1,3 +1,4 @@
# encoding: UTF-8 # encoding: UTF-8
from vnhuobi import TradeApi, DataApi from __future__ import absolute_import
from .vnhuobi import TradeApi, DataApi

View File

@ -5,7 +5,8 @@
#import zlib #import zlib
#import time #import time
from vnhuobi import DataApi from __future__ import absolute_import
from .vnhuobi import DataApi
#if __name__ == '__main__': #if __name__ == '__main__':
#while(1): #while(1):

View File

@ -1,6 +1,8 @@
# encoding: utf-8 # encoding: utf-8
from vnhuobi import * from __future__ import print_function
from __future__ import absolute_import
from .vnhuobi import *
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def testTrade(): def testTrade():
@ -15,9 +17,9 @@ def testTrade():
api.start() api.start()
# 查询 # 查询
print api.getSymbols() print(api.getSymbols())
print api.getCurrencys() print(api.getCurrencys())
print api.getTimestamp() print(api.getTimestamp())
#accountid = '' #accountid = ''
@ -27,7 +29,7 @@ def testTrade():
#api.getAccountBalance(accountid) #api.getAccountBalance(accountid)
#api.getOrders(symbol, 'pre-submitted,submitted,partial-filled,partial-canceled,filled,canceled') #api.getOrders(symbol, 'pre-submitted,submitted,partial-filled,partial-canceled,filled,canceled')
#api.getOrders(symbol, 'filled') #api.getOrders(symbol, 'filled')
print api.getMatchResults(symbol) print(api.getMatchResults(symbol))
#api.getOrder('2440401255') #api.getOrder('2440401255')
#api.getMatchResult('2440401255') #api.getMatchResult('2440401255')

View File

@ -1,5 +1,6 @@
# encoding: utf-8 # encoding: utf-8
from __future__ import print_function
import urllib import urllib
import hmac import hmac
import base64 import base64
@ -419,71 +420,71 @@ class TradeApi(object):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onError(self, msg, reqid): def onError(self, msg, reqid):
"""错误回调""" """错误回调"""
print msg, reqid print(msg, reqid)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetSymbols(self, data, reqid): def onGetSymbols(self, data, reqid):
"""查询代码回调""" """查询代码回调"""
#print reqid, data #print reqid, data
for d in data: for d in data:
print d print(d)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetCurrencys(self, data, reqid): def onGetCurrencys(self, data, reqid):
"""查询货币回调""" """查询货币回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetTimestamp(self, data, reqid): def onGetTimestamp(self, data, reqid):
"""查询时间回调""" """查询时间回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetAccounts(self, data, reqid): def onGetAccounts(self, data, reqid):
"""查询账户回调""" """查询账户回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetAccountBalance(self, data, reqid): def onGetAccountBalance(self, data, reqid):
"""查询余额回调""" """查询余额回调"""
print reqid, data print(reqid, data)
for d in data['data']['list']: for d in data['data']['list']:
print d print(d)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetOrders(self, data, reqid): def onGetOrders(self, data, reqid):
"""查询委托回调""" """查询委托回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetMatchResults(self, data, reqid): def onGetMatchResults(self, data, reqid):
"""查询成交回调""" """查询成交回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetOrder(self, data, reqid): def onGetOrder(self, data, reqid):
"""查询单一委托回调""" """查询单一委托回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onGetMatchResult(self, data, reqid): def onGetMatchResult(self, data, reqid):
"""查询单一成交回调""" """查询单一成交回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onPlaceOrder(self, data, reqid): def onPlaceOrder(self, data, reqid):
"""委托回调""" """委托回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onCancelOrder(self, data, reqid): def onCancelOrder(self, data, reqid):
"""撤单回调""" """撤单回调"""
print reqid, data print(reqid, data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onBatchCancel(self, data, reqid): def onBatchCancel(self, data, reqid):
"""批量撤单回调""" """批量撤单回调"""
print reqid, data print(reqid, data)
######################################################################## ########################################################################
@ -644,7 +645,7 @@ class DataApi(object):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onError(self, msg): def onError(self, msg):
"""错误推送""" """错误推送"""
print msg print(msg)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onData(self, data): def onData(self, data):
@ -664,14 +665,14 @@ class DataApi(object):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onMarketDepth(self, data): def onMarketDepth(self, data):
"""行情深度推送 """ """行情深度推送 """
print data print(data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onTradeDetail(self, data): def onTradeDetail(self, data):
"""成交细节推送""" """成交细节推送"""
print data print(data)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onMarketDetail(self, data): def onMarketDetail(self, data):
"""市场细节推送""" """市场细节推送"""
print data print(data)

View File

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

View File

@ -1,15 +1,18 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import sys import sys
from time import sleep from time import sleep
from six.moves import input
from vnib import IbApi from vnib import IbApi
######################################################################## ########################################################################
class TestApi(IbApi): class TestApi(IbApi):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def __init__(self): def __init__(self):
@ -18,283 +21,283 @@ class TestApi(IbApi):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def nextValidId(self, orderId): def nextValidId(self, orderId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def currentTime(self, time): def currentTime(self, time):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def connectAck(self): def connectAck(self):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def error(self, id_, errorCode, errorString): def error(self, id_, errorCode, errorString):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def accountSummary(self, reqId, account, tag, value, curency): def accountSummary(self, reqId, account, tag, value, curency):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def accountSummaryEnd(self, reqId): def accountSummaryEnd(self, reqId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def tickPrice(self, tickerId, field, price, canAutoExecute): def tickPrice(self, tickerId, field, price, canAutoExecute):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def tickSize(self, tickerId, field, size): def tickSize(self, tickerId, field, size):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def tickOptionComputation(self, tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice): def tickOptionComputation(self, tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def tickGeneric(self, tickerId, tickType, value): def tickGeneric(self, tickerId, tickType, value):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def tickString(self, tickerId, tickType, value): def tickString(self, tickerId, tickType, value):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def tickEFP(self, tickerId, tickType, basisPoints, formattedBasisPoints, totalDividends, holdDays, futureLastTradeDate, dividendImpact, dividendsToLastTradeDate): def tickEFP(self, tickerId, tickType, basisPoints, formattedBasisPoints, totalDividends, holdDays, futureLastTradeDate, dividendImpact, dividendsToLastTradeDate):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def orderStatus(self, orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld): def orderStatus(self, orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def openOrder(self, orderId, contract, order, orderState): def openOrder(self, orderId, contract, order, orderState):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def openOrderEnd(self): def openOrderEnd(self):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def winError(self, str_, lastError): def winError(self, str_, lastError):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def connectionClosed(self): def connectionClosed(self):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def updateAccountValue(self, key, val, currency, accountName): def updateAccountValue(self, key, val, currency, accountName):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def updatePortfolio(self, contract, position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL, accountName): def updatePortfolio(self, contract, position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL, accountName):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def updateAccountTime(self, timeStamp): def updateAccountTime(self, timeStamp):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def accountDownloadEnd(self, accountName): def accountDownloadEnd(self, accountName):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def contractDetails(self, reqId, contractDetails): def contractDetails(self, reqId, contractDetails):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def bondContractDetails(self, reqId, contractDetails): def bondContractDetails(self, reqId, contractDetails):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def contractDetailsEnd(self, reqId): def contractDetailsEnd(self, reqId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def execDetails(self, reqId, contract, execution): def execDetails(self, reqId, contract, execution):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def execDetailsEnd(self, reqId): def execDetailsEnd(self, reqId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def updateMktDepth(self, id_, position, operation, side, price, size): def updateMktDepth(self, id_, position, operation, side, price, size):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def updateMktDepthL2(self, id_, position, marketMaker, operation, side, price, size): def updateMktDepthL2(self, id_, position, marketMaker, operation, side, price, size):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def updateNewsBulletin(self, msgId, msgType, newsMessage, originExch): def updateNewsBulletin(self, msgId, msgType, newsMessage, originExch):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def managedAccounts(self, accountsList): def managedAccounts(self, accountsList):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def receiveFA(self, pFaDataType, cxml): def receiveFA(self, pFaDataType, cxml):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def historicalData(self, reqId, date, open_, high, low, close, volume, barCount, WAP, hasGaps): def historicalData(self, reqId, date, open_, high, low, close, volume, barCount, WAP, hasGaps):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def scannerParameters(self, xml): def scannerParameters(self, xml):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def scannerData(self, reqId, rank, contractDetails, distance, benchmark, projection, legsStr): def scannerData(self, reqId, rank, contractDetails, distance, benchmark, projection, legsStr):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def scannerDataEnd(self, reqId): def scannerDataEnd(self, reqId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def realtimeBar(self, reqId, time, open_, high, low, close, volume, wap, count): def realtimeBar(self, reqId, time, open_, high, low, close, volume, wap, count):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def fundamentalData(self, reqId, data): def fundamentalData(self, reqId, data):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def deltaNeutralValidation(self, reqId, underComp): def deltaNeutralValidation(self, reqId, underComp):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def tickSnapshotEnd(self, reqId): def tickSnapshotEnd(self, reqId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def marketDataType(self, reqId, marketDataType): def marketDataType(self, reqId, marketDataType):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def commissionReport(self, commissionReport): def commissionReport(self, commissionReport):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def position(self, account, contract, position, avgCost): def position(self, account, contract, position, avgCost):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def positionEnd(self): def positionEnd(self):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def verifyMessageAPI(self, apiData): def verifyMessageAPI(self, apiData):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def verifyCompleted(self, isSuccessful, errorText): def verifyCompleted(self, isSuccessful, errorText):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def displayGroupList(self, reqId, groups): def displayGroupList(self, reqId, groups):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def displayGroupUpdated(self, reqId, contractInfo): def displayGroupUpdated(self, reqId, contractInfo):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def verifyAndAuthMessageAPI(self, apiData, xyzChallange): def verifyAndAuthMessageAPI(self, apiData, xyzChallange):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def verifyAndAuthCompleted(self, isSuccessful, errorText): def verifyAndAuthCompleted(self, isSuccessful, errorText):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def positionMulti(self, reqId, account, modelCode, contract, pos, avgCost): def positionMulti(self, reqId, account, modelCode, contract, pos, avgCost):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def positionMultiEnd(self, reqId): def positionMultiEnd(self, reqId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def accountUpdateMulti(self, reqId, account, modelCode, key, value, currency): def accountUpdateMulti(self, reqId, account, modelCode, key, value, currency):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def accountUpdateMultiEnd(self, reqId): def accountUpdateMultiEnd(self, reqId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def securityDefinitionOptionalParameter(self, reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes): def securityDefinitionOptionalParameter(self, reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def securityDefinitionOptionalParameterEnd(self, reqId): def securityDefinitionOptionalParameterEnd(self, reqId):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def softDollarTiers(self, reqId, tiers): def softDollarTiers(self, reqId, tiers):
print sys._getframe().f_code.co_name print(sys._getframe().f_code.co_name)
print locals() print(locals())
@ -302,14 +305,14 @@ if __name__ == '__main__':
api = TestApi() api = TestApi()
n = api.eConnect('127.0.0.1', 7497, 123, False) n = api.eConnect('127.0.0.1', 7497, 123, False)
print n print(n)
#t = api.TwsConnectionTime() #t = api.TwsConnectionTime()
#print t #print t
# #
sleep(1) sleep(1)
print 'req time' print('req time')
api.reqCurrentTime() api.reqCurrentTime()
# #
@ -319,6 +322,6 @@ if __name__ == '__main__':
#print 'disconnect' #print 'disconnect'
#api.eDisconnect() #api.eDisconnect()
raw_input() input()