Integrate TelegramClient into main trading loop #34

Closed
opened 2026-02-04 21:26:54 +09:00 by agentson · 0 comments
Collaborator

Goal

Integrate Telegram notifications into the main trading loop for real-time alerts.

Scope

Update src/main.py:

  • Import TelegramClient and FatFingerRejected
  • Import sys module for exception detection
  • Initialize TelegramClient in run() function
  • Add market state tracking dict (_market_states)
  • Add 8 notification points:
    1. System startup (after line 303)
    2. Market open (when market opens, first time)
    3. Market close (when no markets open)
    4. Trade execution (after successful order)
    5. Fat finger protection (wrap validate_order in try/except)
    6. Circuit breaker (in CircuitBreakerTripped except block)
    7. Connection errors (after retry exhaustion)
    8. System shutdown (in finally block)
  • Add telegram parameter to trading_cycle() function
  • Close telegram session in finally block

Implementation Notes

  • Wrap all notification calls in try/except (graceful degradation)
  • Never let notifications crash trading loop
  • Use sys.exc_info() to detect circuit breaker in finally block

Success Criteria

  • All 8 notification points working
  • Notifications don't crash trading if Telegram fails
  • System works without Telegram credentials

Dependencies

  • Requires issue #31 (TelegramClient core)
  • Requires issue #33 (configuration)

Part 4 of Telegram notification system implementation

## Goal Integrate Telegram notifications into the main trading loop for real-time alerts. ## Scope Update `src/main.py`: - Import TelegramClient and FatFingerRejected - Import sys module for exception detection - Initialize TelegramClient in run() function - Add market state tracking dict (_market_states) - Add 8 notification points: 1. System startup (after line 303) 2. Market open (when market opens, first time) 3. Market close (when no markets open) 4. Trade execution (after successful order) 5. Fat finger protection (wrap validate_order in try/except) 6. Circuit breaker (in CircuitBreakerTripped except block) 7. Connection errors (after retry exhaustion) 8. System shutdown (in finally block) - Add telegram parameter to trading_cycle() function - Close telegram session in finally block ## Implementation Notes - Wrap all notification calls in try/except (graceful degradation) - Never let notifications crash trading loop - Use sys.exc_info() to detect circuit breaker in finally block ## Success Criteria - All 8 notification points working - Notifications don't crash trading if Telegram fails - System works without Telegram credentials ## Dependencies - Requires issue #31 (TelegramClient core) - Requires issue #33 (configuration) ## Related Part 4 of Telegram notification system implementation
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#34