[Mod] auto subscribe market data when add new legs
This commit is contained in:
parent
6279ab4ddf
commit
c02b37bde2
@ -8,7 +8,7 @@
|
|||||||
<img src ="https://img.shields.io/badge/version-2.0.7-blueviolet.svg"/>
|
<img src ="https://img.shields.io/badge/version-2.0.7-blueviolet.svg"/>
|
||||||
<img src ="https://img.shields.io/badge/platform-windows|linux|macos-yellow.svg"/>
|
<img src ="https://img.shields.io/badge/platform-windows|linux|macos-yellow.svg"/>
|
||||||
<img src ="https://img.shields.io/badge/python-3.7-blue.svg" />
|
<img src ="https://img.shields.io/badge/python-3.7-blue.svg" />
|
||||||
<img src ="https://img.shields.io/travis/com/vnpy/vnpy/master.svg"/>
|
<img src ="https://img.shields.io/circleci/build/github/vnpy/vnpy?token=4d11df68295c8cc02a2bede46094991364190bbc"/>
|
||||||
<img src ="https://img.shields.io/github/license/vnpy/vnpy.svg?color=orange"/>
|
<img src ="https://img.shields.io/github/license/vnpy/vnpy.svg?color=orange"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -211,6 +211,24 @@ class SpreadDataEngine:
|
|||||||
event = Event(EVENT_SPREAD_POS, spread)
|
event = Event(EVENT_SPREAD_POS, spread)
|
||||||
self.event_engine.put(event)
|
self.event_engine.put(event)
|
||||||
|
|
||||||
|
def get_leg(self, vt_symbol: str) -> LegData:
|
||||||
|
""""""
|
||||||
|
leg = self.legs.get(vt_symbol, None)
|
||||||
|
|
||||||
|
if not leg:
|
||||||
|
leg = LegData(vt_symbol)
|
||||||
|
self.legs[vt_symbol] = leg
|
||||||
|
|
||||||
|
# Subscribe market data
|
||||||
|
contract = self.main_engine.get_contract(vt_symbol)
|
||||||
|
req = SubscribeRequest(
|
||||||
|
contract.symbol,
|
||||||
|
contract.exchange
|
||||||
|
)
|
||||||
|
self.main_engine.subscribe(req, contract.gateway_name)
|
||||||
|
|
||||||
|
return leg
|
||||||
|
|
||||||
def add_spread(
|
def add_spread(
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
@ -229,11 +247,7 @@ class SpreadDataEngine:
|
|||||||
|
|
||||||
for leg_setting in leg_settings:
|
for leg_setting in leg_settings:
|
||||||
vt_symbol = leg_setting["vt_symbol"]
|
vt_symbol = leg_setting["vt_symbol"]
|
||||||
|
leg = self.get_leg(vt_symbol)
|
||||||
leg = self.legs.get(vt_symbol, None)
|
|
||||||
if not leg:
|
|
||||||
leg = LegData(vt_symbol)
|
|
||||||
self.legs[vt_symbol] = leg
|
|
||||||
|
|
||||||
legs.append(leg)
|
legs.append(leg)
|
||||||
price_multipliers[vt_symbol] = leg_setting["price_multiplier"]
|
price_multipliers[vt_symbol] = leg_setting["price_multiplier"]
|
||||||
|
Loading…
Reference in New Issue
Block a user