Skip to content

Commit aa4704d

Browse files
committed
[TradingModes] add get_is_using_trading_mode_on_exchange
1 parent 09dbe79 commit aa4704d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

octobot_trading/exchanges/exchange_builder.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ async def _build_exchange_manager(self):
7979
await self._build_trader()
8080

8181
# create trading modes
82-
await self._build_trading_modes_if_required(trading_mode_class)
82+
await self._build_trading_modes_if_required(
83+
trading_mode_class, self.exchange_manager.tentacles_setup_config
84+
)
8385

8486
# add to global exchanges
8587
self.exchange_manager.update_debug_info()
@@ -126,17 +128,22 @@ async def _register_trading_modes_requirements(self, trading_mode_class, tentacl
126128
not trading_mode_class.is_ignoring_cancelled_orders_trades()
127129
)
128130

129-
async def _build_trading_modes_if_required(self, trading_mode_class):
131+
async def _build_trading_modes_if_required(self, trading_mode_class, tentacles_setup_config):
130132
if self._is_using_trading_modes:
131133
# self.exchange_manager.trader can be None if neither simulator or real trader has be set
132-
if self.exchange_manager.is_trading:
134+
if self.exchange_manager.is_trading and (
135+
trading_mode_class.get_is_using_trading_mode_on_exchange(
136+
self.exchange_name, tentacles_setup_config
137+
)
138+
):
133139
if self.exchange_manager.trader is None:
134140
self.logger.warning(f"There wont be any order created on {self.exchange_name}: neither "
135141
f"simulated nor real trader has been activated.")
136142
else:
137143
self.exchange_manager.trading_modes = await self.build_trading_modes(trading_mode_class)
138144
else:
139-
self.logger.info(f"{self.exchange_name} exchange is online and won't be trading")
145+
no_action = "trading without using direct trading mode" if self.exchange_manager.is_trading else "trading"
146+
self.logger.info(f"{self.exchange_name} exchange is online and won't be {no_action}")
140147

141148
async def build_trading_modes(self, trading_mode_class):
142149
try:

octobot_trading/modes/abstract_trading_mode.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,25 @@ def is_following_trading_signals(self) -> bool:
183183
return False
184184

185185
@classmethod
186-
def get_is_trading_on_exchange(cls, exchange_name,
187-
tentacles_setup_config: tm_configuration.TentaclesSetupConfiguration) -> bool:
186+
def get_is_trading_on_exchange(
187+
cls, exchange_name, tentacles_setup_config: tm_configuration.TentaclesSetupConfiguration
188+
) -> bool:
188189
"""
189190
:return: When returning false, the associated exchange_manager.is_trading will be set to false, which will
190191
prevent the initialization of trade related elements. Default is True
191192
"""
192193
return True
193194

195+
@classmethod
196+
def get_is_using_trading_mode_on_exchange(
197+
cls, exchange_name, tentacles_setup_config: tm_configuration.TentaclesSetupConfiguration
198+
) -> bool:
199+
"""
200+
:return: When returning false, no trading mode will be created on this exchange, even if
201+
get_is_trading_on_exchange() returns True. Default is falling back to get_is_trading_on_exchange()
202+
"""
203+
return cls.get_is_trading_on_exchange(exchange_name, tentacles_setup_config)
204+
194205
@classmethod
195206
def is_ignoring_cancelled_orders_trades(cls) -> bool:
196207
"""

0 commit comments

Comments
 (0)