File size: 2,454 Bytes
fc115d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
"""
Check which bots are actually running and saving state
"""

import os
import sys
from pathlib import Path
from dotenv import load_dotenv
from pymongo import MongoClient
from decimal import Decimal

sys.path.insert(0, str(Path(__file__).parent))
load_dotenv()

MONGO_URI = os.getenv("MONGO_URI")
try:
    import certifi
    client = MongoClient(MONGO_URI, tlsCAFile=certifi.where())
except ImportError:
    client = MongoClient(MONGO_URI)

db = client["trading_system"]
trades_collection = db["trades"]

print("=" * 100)
print("πŸ€– CHECKING WHICH BOTS ARE ACTIVE")
print("=" * 100)

# Get unique symbols from trades
all_trades = list(trades_collection.find())
symbols = set(t.get('symbol') for t in all_trades)

print(f"\nπŸ“Š Symbols in trade database: {sorted(symbols)}")

# Calculate P&L per asset
print(f"\nπŸ’° P&L Per Asset (from trades):")
print("-" * 100)
for symbol in sorted(symbols):
    symbol_trades = [t for t in all_trades if t.get('symbol') == symbol]
    symbol_pnl = sum(Decimal(str(t.get('pnl', 0))) for t in symbol_trades)

    # Get last trade
    last_trade = max(symbol_trades, key=lambda t: t.get('timestamp', ''))
    last_action = last_trade.get('action', 'UNKNOWN')
    last_time = last_trade.get('timestamp', 'UNKNOWN')

    print(f"  {symbol:<12} P&L: ${float(symbol_pnl):>+10,.2f} | Last trade: {last_action:<20} @ {last_time[:19]}")

print("\n" + "=" * 100)
print("πŸ” ROOT CAUSE ANALYSIS")
print("=" * 100)

print(f"""
The state database shows ONLY BTCUSDT, but trades exist for all 4 assets:
  β€’ BTCUSDT βœ…
  β€’ ETHUSDT ❌ (missing from state)
  β€’ SOLUSDT ❌ (missing from state)
  β€’ XRPUSDT ❌ (missing from state)

This means:
  1. Either the orchestrator is only tracking BTCUSDT in self.bots
  2. Or save_state() is being called with partial bot data
  3. Or the other bots were closed/removed after their last trades

Expected behavior:
  - save_state() should loop through ALL bots in self.bots
  - Each bot should maintain its realized_pnl across the bot's lifetime
  - State should accumulate P&L even for FLAT positions

Actual behavior:
  - Only BTCUSDT is present in state['assets']
  - Other assets' P&L is lost
  - Total P&L is incomplete

FIX NEEDED:
  The orchestrator must ensure ALL bots are initialized and their P&L is preserved
  even when they are in FLAT positions. Currently, it appears bots are being
  removed or not tracked when they close positions.
""")