Dashboard V12: Fix Open Positions count
- PROBLEM: Dashboard showed 0 positions (read from empty trades.json) - SOLUTION: Count locked coins instead (BTC/ETH/SOL/BNB/XRP) - RESULT: Now shows 5 active positions correctly - API: Added active_positions field to /api/state
This commit is contained in:
parent
57beea0cc9
commit
a861127afc
|
|
@ -76,26 +76,34 @@ async def get_state():
|
||||||
portfolio_value += data['total'] * price
|
portfolio_value += data['total'] * price
|
||||||
|
|
||||||
usdt_free = balance.get('USDT', {}).get('free', 0)
|
usdt_free = balance.get('USDT', {}).get('free', 0)
|
||||||
|
|
||||||
|
# Count active positions = locked coins (NOT trades.json)
|
||||||
|
active_positions = 0
|
||||||
|
for asset in ['BTC', 'ETH', 'SOL', 'BNB', 'XRP']:
|
||||||
|
if asset in balance and balance[asset]['locked'] > 0.00001:
|
||||||
|
active_positions += 1
|
||||||
|
|
||||||
trades = load_bot_state()
|
trades = load_bot_state()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'balance': balance,
|
'balance': balance,
|
||||||
'portfolio_value': round(portfolio_value, 2),
|
'portfolio_value': round(portfolio_value, 2),
|
||||||
'usdt_free': round(usdt_free, 2),
|
'usdt_free': round(usdt_free, 2),
|
||||||
|
'active_positions': active_positions, # ← NEW: Real count!
|
||||||
'current_trades': trades.get('current', {}),
|
'current_trades': trades.get('current', {}),
|
||||||
'completed_trades': trades.get('completed', []),
|
'completed_trades': trades.get('completed', []),
|
||||||
'prices': prices,
|
'prices': prices,
|
||||||
'timestamp': datetime.now().isoformat()
|
'timestamp': datetime.now().isoformat()
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {'error': str(e), 'portfolio_value': 0, 'usdt_free': 0}
|
return {'error': str(e), 'portfolio_value': 0, 'usdt_free': 0, 'active_positions': 0}
|
||||||
|
|
||||||
@app.get('/')
|
@app.get('/')
|
||||||
async def root():
|
async def root():
|
||||||
state = await get_state()
|
state = await get_state()
|
||||||
portfolio_val = state.get('portfolio_value', 0)
|
portfolio_val = state.get('portfolio_value', 0)
|
||||||
usdt_free = state.get('usdt_free', 0)
|
usdt_free = state.get('usdt_free', 0)
|
||||||
trades_count = len(state.get('current_trades', {}))
|
trades_count = state.get('active_positions', 0) # ← FIXED: Use real count!
|
||||||
prices = state.get('prices', {})
|
prices = state.get('prices', {})
|
||||||
|
|
||||||
html = f'''<!DOCTYPE html>
|
html = f'''<!DOCTYPE html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue