fix: resolve Telegram command handler errors for /status and /positions (issue #74) #75

Merged
jihoson merged 1 commits from feature/issue-74-telegram-command-fix into main 2026-02-05 18:56:24 +09:00
Collaborator

Summary

Fixed AttributeError exceptions in Telegram /status and /positions commands that were causing handlers to crash.

Changes Made

/status Command (src/main.py:621-653)

  • Removed invalid risk.calculate_pnl(balance) call (method doesn't exist)
  • Implemented inline P&L calculation using balance dict output2 structure
  • Fixed risk.circuit_breaker_thresholdrisk._cb_threshold (correct private attribute)

/positions Command (src/main.py:655-692)

  • Removed balance.stocks references (balance is dict, not object)
  • Changed to display account summary instead:
    • Total Evaluation (portfolio value)
    • Available Cash
    • Purchase Total (cost basis)
    • P&L percentage
  • Added note about API enhancement needed for individual positions

Tests (tests/test_telegram_commands.py)

  • Updated mock responses to match new account summary format
  • Updated assertions to check correct fields
  • All 27 telegram command tests pass

Testing

Unit Tests:

tests/test_telegram_commands.py - 27/27 PASSED ✅

Live Bot Testing:

  • Started bot in paper mode
  • Executed /status and /positions commands via Telegram
  • No errors in logs
  • Commands respond correctly

Root Cause

  1. RiskManager doesn't have calculate_pnl() method - P&L calculation is in main.py
  2. RiskManager uses private _cb_threshold, not public circuit_breaker_threshold
  3. broker.get_balance() returns dict with nested structure, not object with .stocks attribute

Resolves

Closes #74

🤖 Generated with Claude Code

## Summary Fixed AttributeError exceptions in Telegram `/status` and `/positions` commands that were causing handlers to crash. ### Changes Made #### `/status` Command (src/main.py:621-653) - ✅ Removed invalid `risk.calculate_pnl(balance)` call (method doesn't exist) - ✅ Implemented inline P&L calculation using balance dict `output2` structure - ✅ Fixed `risk.circuit_breaker_threshold` → `risk._cb_threshold` (correct private attribute) #### `/positions` Command (src/main.py:655-692) - ✅ Removed `balance.stocks` references (balance is dict, not object) - ✅ Changed to display account summary instead: - Total Evaluation (portfolio value) - Available Cash - Purchase Total (cost basis) - P&L percentage - ✅ Added note about API enhancement needed for individual positions #### Tests (tests/test_telegram_commands.py) - ✅ Updated mock responses to match new account summary format - ✅ Updated assertions to check correct fields - ✅ All 27 telegram command tests pass ### Testing **Unit Tests:** ``` tests/test_telegram_commands.py - 27/27 PASSED ✅ ``` **Live Bot Testing:** - Started bot in paper mode - Executed `/status` and `/positions` commands via Telegram - No errors in logs - Commands respond correctly ### Root Cause 1. RiskManager doesn't have `calculate_pnl()` method - P&L calculation is in main.py 2. RiskManager uses private `_cb_threshold`, not public `circuit_breaker_threshold` 3. `broker.get_balance()` returns dict with nested structure, not object with `.stocks` attribute ### Resolves Closes #74 🤖 Generated with [Claude Code](https://claude.com/claude-code)
agentson added 1 commit 2026-02-05 18:55:03 +09:00
fix: resolve Telegram command handler errors for /status and /positions (issue #74)
Some checks failed
CI / test (pull_request) Has been cancelled
18a098d9a6
Fixed AttributeError exceptions in /status and /positions commands:
- Replaced invalid risk.calculate_pnl() with inline P&L calculation from balance dict
- Changed risk.circuit_breaker_threshold to risk._cb_threshold
- Replaced balance.stocks access with account summary from output2 dict
- Updated tests to match new account summary format

All 27 telegram command tests pass. Live bot testing confirms no errors.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
jihoson merged commit 27f581f17d into main 2026-02-05 18:56:24 +09:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#75