#!/usr/bin/env python3
"""Vérification silencieuse des trades en cours"""

import json
import time
from datetime import datetime

try:
    # Positions
    with open('positions.json', 'r') as f:
        positions = json.load(f)
    
    if not positions or len(positions) == 0:
        print("Aucune position ouverte")
    else:
        print(f"\n{len(positions)} position(s):")
        
        for symbol, pos in positions.items():
            pattern = pos.get('pattern', 'UNKNOWN')
            entry = pos.get('entry_price', 0)
            qty = pos.get('quantity', 0)
            sl = pos.get('stop_loss', 0)
            tp = pos.get('take_profit', 0)
            max_price = pos.get('max_price', entry)
            max_pnl = pos.get('max_pnl', 0)
            
            # Calculer P&L actuel (approximatif - besoin prix actuel)
            invested = entry * qty
            
            print(f"\n{symbol}:")
            print(f"  Pattern: {pattern}")
            print(f"  Entry: {entry} | Qty: {qty} | Investi: {invested:.2f} USDT")
            print(f"  SL: {sl} ({((sl-entry)/entry*100):+.2f}%) | TP: {tp} ({((tp-entry)/entry*100):+.2f}%)")
            print(f"  Max: {max_price} ({max_pnl:+.2f}%)")
        
        # Stats patterns
        patterns = {}
        total_invested = 0
        for sym, pos in positions.items():
            p = pos.get('pattern', 'UNKNOWN')
            patterns[p] = patterns.get(p, 0) + 1
            total_invested += pos.get('entry_price', 0) * pos.get('quantity', 0)
        
        print(f"\nPatterns: {', '.join([f'{p}={c}' for p, c in patterns.items()])}")
        print(f"Total investi: {total_invested:.2f} USDT")

except Exception as e:
    print(f"Erreur: {e}")
