[Add]增加WebTrader中对于CTA事件的监听

This commit is contained in:
vn.py 2018-02-07 10:12:47 +08:00
parent 28ede4011f
commit 28f35fd7d8
4 changed files with 20 additions and 5 deletions

View File

@ -12,6 +12,7 @@ from vnpy.trader.vtEvent import (EVENT_TICK, EVENT_ORDER, EVENT_TRADE,
EVENT_ERROR, EVENT_CONTRACT) EVENT_ERROR, EVENT_CONTRACT)
from vnpy.trader.vtObject import VtSubscribeReq, VtOrderReq, VtCancelOrderReq from vnpy.trader.vtObject import VtSubscribeReq, VtOrderReq, VtCancelOrderReq
from vnpy.trader.app.rpcService.rsClient import MainEngineProxy from vnpy.trader.app.rpcService.rsClient import MainEngineProxy
from vnpy.trader.app.ctaStrategy.ctaBase import EVENT_CTA_LOG, EVENT_CTA_STRATEGY
reqAddress = 'tcp://localhost:6688' reqAddress = 'tcp://localhost:6688'
subAddress = 'tcp://localhost:8866' subAddress = 'tcp://localhost:8866'
@ -608,7 +609,8 @@ ee.register(EVENT_POSITION, handleEvent)
ee.register(EVENT_CONTRACT, handleEvent) ee.register(EVENT_CONTRACT, handleEvent)
ee.register(EVENT_LOG, handleEvent) ee.register(EVENT_LOG, handleEvent)
ee.register(EVENT_ERROR, handleEvent) ee.register(EVENT_ERROR, handleEvent)
ee.register(EVENT_CTA_LOG, handleEvent)
ee.register(EVENT_CTA_STRATEGY, handleEvent)

View File

@ -566,10 +566,15 @@ class CtaEngine(object):
"""触发策略状态变化事件通常用于通知GUI更新""" """触发策略状态变化事件通常用于通知GUI更新"""
strategy = self.strategyDict[name] strategy = self.strategyDict[name]
d = {k:strategy.__getattribute__(k) for k in strategy.varList} d = {k:strategy.__getattribute__(k) for k in strategy.varList}
event = Event(EVENT_CTA_STRATEGY+name) event = Event(EVENT_CTA_STRATEGY+name)
event.dict_['data'] = d event.dict_['data'] = d
self.eventEngine.put(event) self.eventEngine.put(event)
event2 = Event(EVENT_CTA_STRATEGY)
event2.dict_['data'] = d
self.eventEngine.put(event2)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def callStrategyFunc(self, strategy, func, params=None): def callStrategyFunc(self, strategy, func, params=None):
"""调用策略的函数,若触发异常则捕捉""" """调用策略的函数,若触发异常则捕捉"""

View File

@ -9,7 +9,9 @@
"underlyingSymbol": "510050", "underlyingSymbol": "510050",
"chainSymbol": "510050-1802", "chainSymbol": "510050-1802",
"r": 0.03 "r": 0.03
}, }
],
"other": [
{ {
"underlyingSymbol": "510050", "underlyingSymbol": "510050",
"chainSymbol": "510050-1803", "chainSymbol": "510050-1803",

View File

@ -335,8 +335,12 @@ class CtpMdApi(MdApi):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onRspSubMarketData(self, data, error, n, last): def onRspSubMarketData(self, data, error, n, last):
"""订阅合约回报""" """订阅合约回报"""
# 通常不在乎订阅错误,选择忽略 if 'ErrorID' in error and error['ErrorID']:
pass err = VtErrorData()
err.gatewayName = self.gatewayName
err.errorID = error['ErrorID']
err.errorMsg = error['ErrorMsg'].decode('gbk')
self.gateway.onError(err)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onRspUnSubMarketData(self, data, error, n, last): def onRspUnSubMarketData(self, data, error, n, last):
@ -844,10 +848,12 @@ class CtpTdApi(TdApi):
contract.size = data['VolumeMultiple'] contract.size = data['VolumeMultiple']
contract.priceTick = data['PriceTick'] contract.priceTick = data['PriceTick']
contract.strikePrice = data['StrikePrice'] contract.strikePrice = data['StrikePrice']
contract.underlyingSymbol = data['UnderlyingInstrID']
contract.productClass = productClassMapReverse.get(data['ProductClass'], PRODUCT_UNKNOWN) contract.productClass = productClassMapReverse.get(data['ProductClass'], PRODUCT_UNKNOWN)
contract.expiryDate = data['ExpireDate'] contract.expiryDate = data['ExpireDate']
#contract.underlyingSymbol = data['UnderlyingInstrID'] # 针对商品期权
contract.underlyingSymbol = '-'.join([data['UnderlyingInstrID'], str(data['ExpireDate'])[2:-2]])
# 期权类型 # 期权类型
if contract.productClass is PRODUCT_OPTION: if contract.productClass is PRODUCT_OPTION:
if data['OptionsType'] == '1': if data['OptionsType'] == '1':