fix: Telegram command handler errors (/status and /positions) #74

Closed
opened 2026-02-05 18:54:24 +09:00 by agentson · 0 comments
Collaborator

Problem

Telegram commands /status and /positions are failing with AttributeError:

  1. Line 630: 'RiskManager' object has no attribute 'calculate_pnl'
  2. Line 645: 'RiskManager' object has no attribute 'circuit_breaker_threshold'
  3. Line 662/673: 'dict' object has no attribute 'stocks'

Root Cause

  • RiskManager doesn't have calculate_pnl() method (P&L calc is in main.py)
  • RiskManager uses private _cb_threshold attribute, not public circuit_breaker_threshold
  • broker.get_balance() returns dict, not object with .stocks attribute

Solution

/status Command

  • Remove invalid risk.calculate_pnl(balance) call
  • Inline P&L calculation from balance dict (output2)
  • Fix risk.circuit_breaker_thresholdrisk._cb_threshold

/positions Command

  • Remove balance.stocks references
  • Show account summary instead of individual positions:
    • Total evaluation, cash, purchase total, P&L%
  • Add note about API enhancement needed for individual positions

Testing

  • All unit tests pass (27/27 telegram tests)
  • Live bot testing shows no errors
  • Commands execute successfully
## Problem Telegram commands `/status` and `/positions` are failing with AttributeError: 1. **Line 630**: `'RiskManager' object has no attribute 'calculate_pnl'` 2. **Line 645**: `'RiskManager' object has no attribute 'circuit_breaker_threshold'` 3. **Line 662/673**: `'dict' object has no attribute 'stocks'` ## Root Cause - RiskManager doesn't have `calculate_pnl()` method (P&L calc is in main.py) - RiskManager uses private `_cb_threshold` attribute, not public `circuit_breaker_threshold` - `broker.get_balance()` returns dict, not object with `.stocks` attribute ## Solution ### /status Command - Remove invalid `risk.calculate_pnl(balance)` call - Inline P&L calculation from balance dict (`output2`) - Fix `risk.circuit_breaker_threshold` → `risk._cb_threshold` ### /positions Command - Remove `balance.stocks` references - Show account summary instead of individual positions: - Total evaluation, cash, purchase total, P&L% - Add note about API enhancement needed for individual positions ## Testing - All unit tests pass (27/27 telegram tests) - Live bot testing shows no errors - Commands execute successfully
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#74