[Mod] fix algo control bugs in BasicSpreadStrategy

This commit is contained in:
vn.py 2019-10-28 22:14:25 +08:00
parent 877c703e0f
commit 766d705e7a

View File

@ -87,6 +87,8 @@ class BasicSpreadStrategy(SpreadStrategyTemplate):
# No position # No position
if not self.spread_pos: if not self.spread_pos:
self.stop_close_algos()
# Start open algos # Start open algos
if not self.buy_algoid: if not self.buy_algoid:
self.buy_algoid = self.start_long_algo( self.buy_algoid = self.start_long_algo(
@ -98,27 +100,20 @@ class BasicSpreadStrategy(SpreadStrategyTemplate):
self.short_price, self.max_pos, self.payup, self.interval self.short_price, self.max_pos, self.payup, self.interval
) )
# Stop close algos
if self.sell_algoid:
self.stop_algo(self.sell_algoid)
if self.cover_algoid:
self.stop_algo(self.cover_algoid)
# Long position # Long position
elif self.spread_pos > 0: elif self.spread_pos > 0:
self.stop_open_algos()
# Start sell close algo # Start sell close algo
if not self.sell_algoid: if not self.sell_algoid:
self.sell_algoid = self.start_short_algo( self.sell_algoid = self.start_short_algo(
self.sell_price, self.spread_pos, self.payup, self.interval self.sell_price, self.spread_pos, self.payup, self.interval
) )
# Stop buy open algo
if self.buy_algoid:
self.stop_algo(self.buy_algoid)
# Short position # Short position
elif self.spread_pos < 0: elif self.spread_pos < 0:
self.stop_open_algos()
# Start cover close algo # Start cover close algo
if not self.cover_algoid: if not self.cover_algoid:
self.cover_algoid = self.start_long_algo( self.cover_algoid = self.start_long_algo(
@ -126,10 +121,6 @@ class BasicSpreadStrategy(SpreadStrategyTemplate):
self.spread_pos), self.payup, self.interval self.spread_pos), self.payup, self.interval
) )
# Stop short open algo
if self.short_algoid:
self.stop_algo(self.short_algoid)
self.put_event() self.put_event()
def on_spread_pos(self): def on_spread_pos(self):
@ -166,3 +157,19 @@ class BasicSpreadStrategy(SpreadStrategyTemplate):
Callback when new trade data is received. Callback when new trade data is received.
""" """
pass pass
def stop_open_algos(self):
""""""
if self.buy_algoid:
self.stop_algo(self.buy_algoid)
if self.short_algoid:
self.stop_algo(self.short_algoid)
def stop_close_algos(self):
""""""
if self.sell_algoid:
self.stop_algo(self.sell_algoid)
if self.cover_algoid:
self.stop_algo(self.cover_algoid)