diff --git a/src/web_dashboard.py b/src/web_dashboard.py index a7c3bf1..396ce24 100644 --- a/src/web_dashboard.py +++ b/src/web_dashboard.py @@ -14,36 +14,28 @@ with open('/home/marc/bot-deploy/.env') as f: binance = Client(env.get('BINANCE_API_KEY_LIVE'), env.get('BINANCE_API_SECRET_LIVE')) -# CACHE for prices (update every 5 seconds) price_cache = {'prices': {}, 'timestamp': 0} def get_live_prices(): - """Get LIVE prices from Binance API with 5-second cache""" global price_cache - - # Return cached if less than 5 seconds old if time.time() - price_cache['timestamp'] < 5: return price_cache['prices'] prices = {'USDT': 1.0} - pairs = ['BTCUSDT', 'ETHUSDT', 'SOLUSDT', 'BNBUSDT', 'XRPUSDT'] for pair in pairs: try: ticker = binance.get_ticker(symbol=pair) asset = pair.replace('USDT', '') prices[asset] = float(ticker['lastPrice']) - except Exception as e: + except: pass - # Update cache price_cache['prices'] = prices price_cache['timestamp'] = time.time() - return prices def load_bot_state(): - """Load bot state from file""" state_file = '/home/marc/bot-deploy/trades.json' if os.path.exists(state_file): try: @@ -55,9 +47,7 @@ def load_bot_state(): @app.get('/api/state') async def get_state(): - """Return complete bot state with LIVE prices""" try: - # Get balance from Binance ONCE (not per asset) account = binance.get_account() balance = {} @@ -67,7 +57,6 @@ async def get_state(): locked = float(asset_data['locked']) total = free + locked - # Only include meaningful balances if total > 0.00001: balance[asset] = { 'free': free, @@ -75,11 +64,8 @@ async def get_state(): 'total': total } - # Get cached prices (5-second update) prices = get_live_prices() - # Calculate portfolio value with LIVE prices - # ONLY for known trading pairs (exclude junk tokens) portfolio_value = 0 tracked_assets = ['BTC', 'ETH', 'SOL', 'BNB', 'XRP', 'USDT', 'USDC'] @@ -89,10 +75,7 @@ async def get_state(): price = prices.get(asset, 0) portfolio_value += data['total'] * price - # Get USDT free specifically usdt_free = balance.get('USDT', {}).get('free', 0) - - # Load trade state trades = load_bot_state() return { @@ -102,8 +85,7 @@ async def get_state(): 'current_trades': trades.get('current', {}), 'completed_trades': trades.get('completed', []), 'prices': prices, - 'timestamp': datetime.now().isoformat(), - 'note': 'Portfolio calculated with LIVE Binance prices (tracked assets only, excludes junk tokens)' + 'timestamp': datetime.now().isoformat() } except Exception as e: return {'error': str(e), 'portfolio_value': 0, 'usdt_free': 0} @@ -121,76 +103,269 @@ async def root(): -Trading Bot Dashboard V6 +Trading Bot V7
-

💰 Trading Bot V6 Dashboard

+ -
-
-
PORTFOLIO VALUE
-
${portfolio_val:.2f}
-
-
-
USDT FREE
-
${usdt_free:.2f}
-
-
-
OPEN TRADES
-
{trades_count}
-
-
-
STATUS
-
🟢 LIVE
-
-
-
BOT VERSION
-
V6 ENHANCED
-
-
-
LAST UPDATE
-
REAL-TIME
-
-
+
+
+ +
V7 — Real-time Portfolio
+
-

📊 CURRENT PRICES (LIVE from Binance)

- - - - - ''' +
+
+
Portfolio Value
+
${portfolio_val:.2f}
+
+
+
USDT Available
+
${usdt_free:.2f}
+
+
+
Open Positions
+
{trades_count}
+
+
+ +
Live Prices
+
AssetPrice USD
+ + + + + + + ''' for asset, price in prices.items(): - html += f'' + html += f''' + + + ''' - html += '''
AssetPrice (USD)
{asset}${price:.2f}
{asset}${price:.2f}
+ html += ''' + -

💰 BALANCE BREAKDOWN

- - - - - - - - ''' +
Holdings
+
AssetFreeLockedTotalValue
+ + + + + + + + + + ''' tracked = ['BTC', 'ETH', 'SOL', 'BNB', 'XRP', 'USDT', 'USDC'] balance = state.get('balance', {}) @@ -201,26 +376,16 @@ tr:nth-child(even) {{ background: #0d0d0d; }} price = prices.get(asset, 0) value = data['total'] * price html += f''' - - - - - - ''' + + + + + + ''' - html += '''
AssetFreeLockedTotalUSD Value
{asset}{data['free']:.6f}{data['locked']:.6f}{data['total']:.6f}${value:.2f}
{asset}{data['free']:.6f}{data['locked']:.6f}{data['total']:.6f}${value:.2f}
- -
-✅ Portfolio: Calculated from LIVE Binance prices (tracked assets only)
-✅ Cache: Prices cached for 5 seconds (fast response)
-✅ Accuracy: Real Binance Spot balance
-
-Tracked assets: BTC, ETH, SOL, BNB, XRP, USDT, USDC
-(Excludes junk/dust tokens)
-
-V6: 2 decimal precision for all prices -
- + html += ''' + +
'''