Skip to content

Commit

Permalink
fix(AutoTrader): only try instantiate notifier if notify > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
kieran-mackle committed Mar 12, 2024
1 parent 1586fee commit 01cd614
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions autotrader/autotrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,34 +1005,35 @@ def run(self) -> Union[None, Broker]:
self._global_config_dict = global_config

# Create notifier instance
if "telegram" in self._notification_provider.lower():
# Use telegram
if "TELEGRAM" not in self._global_config_dict:
self.logger.error(
"Please configure your telegram bot in keys.yaml. At "
+ "a minimum, you must specify the api_key for your bot. You can "
+ "also specify your chat_id. If you do not know it, then send your "
+ "bot a message before starting AutoTrader again, and it will "
+ "be inferred."
)
sys.exit()

else:
# Check keys provided
required_keys = ["api_key"]
for key in required_keys:
if key not in self._global_config_dict["TELEGRAM"]:
self.logger.error(
f"Please define {key} under TELEGRAM in keys.yaml."
)
sys.exit()
if self._notify > 0:
if "telegram" in self._notification_provider.lower():
# Use telegram
if "TELEGRAM" not in self._global_config_dict:
self.logger.error(
"Please configure your telegram bot in keys.yaml. At "
+ "a minimum, you must specify the api_key for your bot. You can "
+ "also specify your chat_id. If you do not know it, then send your "
+ "bot a message before starting AutoTrader again, and it will "
+ "be inferred."
)
sys.exit()

# Instantiate notifier
self._notifier = Telegram(
api_token=self._global_config_dict["TELEGRAM"]["api_key"],
chat_id=self._global_config_dict["TELEGRAM"].get("chat_id"),
logger_kwargs=self._logger_kwargs,
)
else:
# Check keys provided
required_keys = ["api_key"]
for key in required_keys:
if key not in self._global_config_dict["TELEGRAM"]:
self.logger.error(
f"Please define {key} under TELEGRAM in keys.yaml."
)
sys.exit()

# Instantiate notifier
self._notifier = Telegram(
api_token=self._global_config_dict["TELEGRAM"]["api_key"],
chat_id=self._global_config_dict["TELEGRAM"].get("chat_id"),
logger_kwargs=self._logger_kwargs,
)

# Check data feed requirements
if self._feed is None:
Expand Down

0 comments on commit 01cd614

Please sign in to comment.