[Add]增加WebTrader中对于CTA事件的监听
This commit is contained in:
parent
28ede4011f
commit
28f35fd7d8
@ -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)
|
||||
|
||||
|
||||
|
||||
|
@ -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):
|
||||
"""调用策略的函数,若触发异常则捕捉"""
|
||||
|
@ -9,7 +9,9 @@
|
||||
"underlyingSymbol": "510050",
|
||||
"chainSymbol": "510050-1802",
|
||||
"r": 0.03
|
||||
},
|
||||
}
|
||||
],
|
||||
"other": [
|
||||
{
|
||||
"underlyingSymbol": "510050",
|
||||
"chainSymbol": "510050-1803",
|
||||
|
@ -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':
|
||||
|
Loading…
Reference in New Issue
Block a user