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

⚡ update cex_exchange_plugin.py and dex_exchange_plugin.py #1434

Merged
merged 3 commits into from
Apr 8, 2024
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ ping3 = "^4.0.4"
talkytrend = "2.0.8"
iamlistening = "5.1.5"
findmyorder = "1.9.19"
dxsp = "10.0.1"
cefi = "4.4.11"
dxsp = "10.0.2"
cefi = "4.4.12"
myllm = "4.8.1"


Expand Down
15 changes: 7 additions & 8 deletions tt/plugins/default_plugins/cex_exchange_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ async def handle_message(self, msg):
"""
if not self.should_handle(msg):
return
if (settings.bot_ignore not in msg or settings.bot_prefix not in msg) and (
await self.fmo.search(msg) and self.should_handle_timeframe()
):
order = await self.fmo.get_order(msg)
if order and settings.trading_enabled:
trade = await self.exchange.submit_order(order)
if trade:
await send_notification(trade)
if settings.bot_ignore not in msg or settings.bot_prefix not in msg:
if await self.fmo.search(msg) and self.should_handle_timeframe():
order = await self.fmo.get_order(msg)
if order and settings.trading_enabled:
trade = await self.exchange.submit_order(order)
if trade:
await send_notification(trade)
Comment on lines +55 to +61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Merge nested if conditions (merge-nested-ifs)

Suggested change
if settings.bot_ignore not in msg or settings.bot_prefix not in msg:
if await self.fmo.search(msg) and self.should_handle_timeframe():
order = await self.fmo.get_order(msg)
if order and settings.trading_enabled:
trade = await self.exchange.submit_order(order)
if trade:
await send_notification(trade)
if (settings.bot_ignore not in msg or settings.bot_prefix not in msg) and (await self.fmo.search(msg) and self.should_handle_timeframe()):
order = await self.fmo.get_order(msg)
if order and settings.trading_enabled:
trade = await self.exchange.submit_order(order)
if trade:
await send_notification(trade)


ExplanationToo much nesting can make code difficult to understand, and this is especially
true in Python, where there are no brackets to help out with the delineation of
different nesting levels.

Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if conditions can be combined using
and is an easy win.


if msg.startswith(settings.bot_prefix):
command, *args = msg.split(" ")
Expand Down
15 changes: 7 additions & 8 deletions tt/plugins/default_plugins/dex_exchange_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ async def handle_message(self, msg):
if not self.should_handle(msg):
return

if (settings.bot_ignore not in msg or settings.bot_prefix not in msg) and (
await self.fmo.search(msg) and self.should_handle_timeframe()
):
order = await self.fmo.get_order(msg)
if order and settings.trading_enabled:
trade = await self.exchange.submit_order(order)
if trade:
await send_notification(trade)
if settings.bot_ignore not in msg or settings.bot_prefix not in msg:
if await self.fmo.search(msg) and self.should_handle_timeframe():
order = await self.fmo.get_order(msg)
if order and settings.trading_enabled:
trade = await self.exchange.submit_order(order)
if trade:
await send_notification(trade)
Comment on lines +48 to +54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Merge nested if conditions (merge-nested-ifs)

Suggested change
if settings.bot_ignore not in msg or settings.bot_prefix not in msg:
if await self.fmo.search(msg) and self.should_handle_timeframe():
order = await self.fmo.get_order(msg)
if order and settings.trading_enabled:
trade = await self.exchange.submit_order(order)
if trade:
await send_notification(trade)
if (settings.bot_ignore not in msg or settings.bot_prefix not in msg) and (await self.fmo.search(msg) and self.should_handle_timeframe()):
order = await self.fmo.get_order(msg)
if order and settings.trading_enabled:
trade = await self.exchange.submit_order(order)
if trade:
await send_notification(trade)


ExplanationToo much nesting can make code difficult to understand, and this is especially
true in Python, where there are no brackets to help out with the delineation of
different nesting levels.

Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if conditions can be combined using
and is an easy win.


if msg.startswith(settings.bot_prefix):
command, *args = msg.split(" ")
Expand Down
2 changes: 1 addition & 1 deletion tt/talky_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ iamlistening_enabled = true
# Bot Prefix
bot_prefix = "/"
# Character to ignore
bot_ignore = "ℹ️ 🦄 ⚠️ 📊 🏦 📺 ⬆️ 💬 🐻"
bot_ignore = "ℹ️ ⚠️ 📊 🏦 📺 ⬆️ 💬 🐻"
# Command for help
bot_command_help = "help"
# Command for info
Expand Down
5 changes: 4 additions & 1 deletion tt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ async def send_notification(msg):
if not settings.apprise_url:
logger.warning("No Apprise URL set")
return
if msg is None:
logger.warning("No message to send")
return
aobj = Apprise(settings.apprise_url)
msg_format = settings.apprise_format or NotifyFormat.MARKDOWN
try:
await aobj.async_notify(body=msg, body_format=msg_format)
except Exception as error:
logger.error("Verify Apprise URL: ", error)
logger.error("Verify Apprise URL", error)


async def run_bot():
Expand Down
Loading