#!/usr/bin/env python3
"""Quick check of Binance balances for positions that should have been sold"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from binance.client import Client
import config as cfg

c = Client(cfg.BINANCE_API_KEY, cfg.BINANCE_API_SECRET, testnet=cfg.TESTNET_MODE)
acct = c.get_account()
tickers = {t['symbol']: float(t['price']) for t in c.get_all_tickers()}

# Check all open orders too
open_orders = c.get_open_orders()
if open_orders:
    print(f"=== {len(open_orders)} OPEN ORDERS ===")
    for o in open_orders:
        print(f"  {o['symbol']} {o['side']} qty={o['origQty']} price={o['price']} status={o['status']}")
else:
    print("=== 0 OPEN ORDERS ===")

targets = ['ENSO','ATOM','TRX','LTC']
print(f"\n=== TARGET POSITIONS ===")
for b in acct['balances']:
    if b['asset'] in targets:
        free = float(b['free'])
        locked = float(b['locked'])
        total = free + locked
        sym = b['asset'] + 'USDT'
        price = tickers.get(sym, 0)
        val = total * price
        if total > 0:
            print(f"  {b['asset']:6} free={free:.8f} locked={locked:.8f} total={total:.8f} price={price:.6f} val={val:.2f}$")

# Also show ALL significant positions
print(f"\n=== ALL POSITIONS >= 5$ ===")
ignore = {'USDT','BUSD','USDC','DAI','USD','EUR','BNB','LDBNB','ETHW','BETH','WBTC','WBETH','BNSOL'}
for b in acct['balances']:
    if b['asset'] in ignore:
        continue
    free = float(b['free'])
    locked = float(b['locked'])
    total = free + locked
    if total > 0:
        sym = b['asset'] + 'USDT'
        price = tickers.get(sym, 0)
        if price > 0:
            val = total * price
            if val >= 5:
                lock_str = f" (LOCKED={locked:.8f})" if locked > 0 else ""
                print(f"  {b['asset']:6} free={free:.8f} total={total:.8f} val={val:.2f}${lock_str}")
