diff --git a/examples/WebTrader/run.py b/examples/WebTrader/run.py index 37ca9859..ed582095 100644 --- a/examples/WebTrader/run.py +++ b/examples/WebTrader/run.py @@ -12,6 +12,7 @@ from vnpy.trader.vtEvent import (EVENT_TICK, EVENT_ORDER, EVENT_TRADE, EVENT_ERROR, EVENT_CONTRACT) from vnpy.trader.vtObject import VtSubscribeReq, VtOrderReq, VtCancelOrderReq 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' subAddress = 'tcp://localhost:8866' @@ -608,7 +609,8 @@ ee.register(EVENT_POSITION, handleEvent) ee.register(EVENT_CONTRACT, handleEvent) ee.register(EVENT_LOG, handleEvent) ee.register(EVENT_ERROR, handleEvent) - +ee.register(EVENT_CTA_LOG, handleEvent) +ee.register(EVENT_CTA_STRATEGY, handleEvent) diff --git a/vnpy/trader/app/ctaStrategy/ctaEngine.py b/vnpy/trader/app/ctaStrategy/ctaEngine.py index ef53b3e0..7c1e4584 100644 --- a/vnpy/trader/app/ctaStrategy/ctaEngine.py +++ b/vnpy/trader/app/ctaStrategy/ctaEngine.py @@ -566,10 +566,15 @@ class CtaEngine(object): """触发策略状态变化事件(通常用于通知GUI更新)""" strategy = self.strategyDict[name] d = {k:strategy.__getattribute__(k) for k in strategy.varList} + event = Event(EVENT_CTA_STRATEGY+name) event.dict_['data'] = d self.eventEngine.put(event) + event2 = Event(EVENT_CTA_STRATEGY) + event2.dict_['data'] = d + self.eventEngine.put(event2) + #---------------------------------------------------------------------- def callStrategyFunc(self, strategy, func, params=None): """调用策略的函数,若触发异常则捕捉""" diff --git a/vnpy/trader/app/optionMaster/etf_portfolio.json b/vnpy/trader/app/optionMaster/etf_portfolio.json index 59b19cd5..626f29cc 100644 --- a/vnpy/trader/app/optionMaster/etf_portfolio.json +++ b/vnpy/trader/app/optionMaster/etf_portfolio.json @@ -9,7 +9,9 @@ "underlyingSymbol": "510050", "chainSymbol": "510050-1802", "r": 0.03 - }, + } + ], + "other": [ { "underlyingSymbol": "510050", "chainSymbol": "510050-1803", diff --git a/vnpy/trader/gateway/ctpGateway/ctpGateway.py b/vnpy/trader/gateway/ctpGateway/ctpGateway.py index 21f8c118..33e26540 100644 --- a/vnpy/trader/gateway/ctpGateway/ctpGateway.py +++ b/vnpy/trader/gateway/ctpGateway/ctpGateway.py @@ -335,8 +335,12 @@ class CtpMdApi(MdApi): #---------------------------------------------------------------------- def onRspSubMarketData(self, data, error, n, last): """订阅合约回报""" - # 通常不在乎订阅错误,选择忽略 - pass + if 'ErrorID' in error and error['ErrorID']: + 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): @@ -844,10 +848,12 @@ class CtpTdApi(TdApi): contract.size = data['VolumeMultiple'] contract.priceTick = data['PriceTick'] contract.strikePrice = data['StrikePrice'] - contract.underlyingSymbol = data['UnderlyingInstrID'] contract.productClass = productClassMapReverse.get(data['ProductClass'], PRODUCT_UNKNOWN) 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 data['OptionsType'] == '1':