Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telegram] fix async commands #1131

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Services/Interfaces/telegram_bot_interface/telegram_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def command_pause_resume(self, update: telegram.Update, _: telegram.ext.Co
await TelegramBotInterface._send_message(
update, f"_Pausing..._{interfaces_bots.EOL}`I'm cancelling my orders.`"
)
self.set_command_pause()
await self.set_command_pause()

@staticmethod
async def command_ping(update: telegram.Update, _: telegram.ext.ContextTypes.DEFAULT_TYPE):
Expand All @@ -200,8 +200,9 @@ async def command_risk(update: telegram.Update, context: telegram.ext.ContextTyp
@staticmethod
async def command_profitability(update: telegram.Update, _: telegram.ext.ContextTypes.DEFAULT_TYPE):
if TelegramBotInterface._is_valid_user(update):
await TelegramBotInterface._send_message(update, interfaces_bots.AbstractBotInterface.get_command_profitability(
markdown=True))
await TelegramBotInterface._send_message(
update, interfaces_bots.AbstractBotInterface.get_command_profitability(markdown=True)
)

@staticmethod
async def command_fees(update: telegram.Update, _: telegram.ext.ContextTypes.DEFAULT_TYPE):
Expand All @@ -214,7 +215,7 @@ async def command_fees(update: telegram.Update, _: telegram.ext.ContextTypes.DEF
async def command_sell_all_currencies(update: telegram.Update, _: telegram.ext.ContextTypes.DEFAULT_TYPE):
if TelegramBotInterface._is_valid_user(update):
await TelegramBotInterface._send_message(
update, f"`{interfaces_bots.AbstractBotInterface.get_command_sell_all_currencies()}`"
update, f"`{await interfaces_bots.AbstractBotInterface.get_command_sell_all_currencies()}`"
)

@staticmethod
Expand All @@ -225,7 +226,7 @@ async def command_sell_all(update: telegram.Update, context: telegram.ext.Contex
await TelegramBotInterface._send_message(update, "`Require a currency in parameter of this command.`")
else:
await TelegramBotInterface._send_message(
update, f"`{interfaces_bots.AbstractBotInterface.get_command_sell_all(currency)}`"
update, f"`{await interfaces_bots.AbstractBotInterface.get_command_sell_all(currency)}`"
)

@staticmethod
Expand Down Expand Up @@ -254,7 +255,7 @@ async def command_portfolio_refresh(update: telegram.Update, _: telegram.ext.Con
if TelegramBotInterface._is_valid_user(update):
result = "Refresh"
try:
interfaces_bots.AbstractBotInterface.set_command_portfolios_refresh()
await interfaces_bots.AbstractBotInterface.set_command_portfolios_refresh()
await TelegramBotInterface._send_message(update, f"`{result} successful`")
except Exception as e:
await TelegramBotInterface._send_message(update, f"`{result} failure: {e}`")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ async def test_all_commands():
assert len(bot_interface.get_command_open_orders()) > 50
assert len(bot_interface.get_command_fees()) > 50
assert "Decimal" not in bot_interface.get_command_fees()
assert "Nothing to sell" in bot_interface.get_command_sell_all_currencies()
assert "Nothing to sell for BTC" in bot_interface.get_command_sell_all("BTC")
assert "Nothing to sell" in await bot_interface.get_command_sell_all_currencies()
assert "Nothing to sell for BTC" in await bot_interface.get_command_sell_all("BTC")
with pytest.raises(RuntimeError):
await bot_interface.set_command_portfolios_refresh()
assert len(bot_interface.get_command_portfolio()) > 50
assert "Decimal" not in bot_interface.get_command_portfolio()
assert len(bot_interface.get_command_profitability()) > 50
Expand All @@ -85,3 +87,4 @@ async def test_all_commands():
for elem in
[interfaces.AbstractInterface.project_name, interfaces.AbstractInterface.project_version])
assert "Hello, I'm OctoBot" in bot_interface.get_command_start()
assert await bot_interface.set_command_pause() is None