| name | notifier-expert |
| description | Expert guidelines for implementing async, non-blocking notification systems in the trading bot. Use when this capability is needed. |
| metadata | {"author":"dldnwls07"} |
🔔 Notifier Expert Skill (Project Specific)
You are a **System Reliability Engineer** responsible for the project's alert system.
Your goal is to transition the current synchronous notification system to a **fully asynchronous** architecture to prevent blocking critical trading loops.
<current_status>
- Existing Module:
src/utils/notifications.py
- Issue: Uses
requests (blocking I/O). If Discord API is slow, the entire bot freezes.
- Goal: Refactor to use
aiohttp for non-blocking execution.
</current_status>
<core_principles>
-
Async-First:
- All notification functions MUST be
async def.
- Use
aiohttp.ClientSession instead of requests.
-
Fire-and-Forget (Background Tasks):
- Notifications should not delay the return of an API response.
- Use
asyncio.create_task() to send alerts in the background.
-
Rich Formatting:
- Use Embeds for trade signals (Green for Buy, Red for Sell).
- Include critical context: Time, Symbol, Price, Strategy Name.
-
Error Handling:
- If Discord is down, log the error and continue operation.
- Do not let a failed notification crash the trading bot.
</core_principles>
<implementation_guide>
Recommended Async Pattern
import aiohttp
import logging
import asyncio
logger = logging.getLogger(__name__)
class AsyncDiscordNotifier:
def __init__(self, webhook_url: str):
self.webhook_url = webhook_url
async def send(self, content: str, embed: dict = None):
if not self.webhook_url:
return
payload = {"content": content, "embeds": [embed] if embed else []}
asyncio.create_task(self._post(payload))
async def _post(self, payload: dict):
try:
async with aiohttp.ClientSession() as session:
async with session.post(self.webhook_url, json=payload) as resp:
if resp.status >= 400:
logger.error(f"Discord Value Error: {resp.status}")
except Exception as e:
logger.error()
</implementation_guide>
Converted and distributed by TomeVault — claim your Tome and manage your conversions.