Key fixes:
- Add price validation to detect/correct doubled filled_price from broker
- Emit position_closed socket event to refresh UI after closing positions
- Fix statistics not updating when positions are closed
- Filter out zero-size positions from display
- Add USD/USDT toggle for balance display (click to switch)
Trade system improvements:
- Refactor Trade class P/L calculation with realized/unrealized tracking
- Add settle() method for proper position closing
- Improve trade_filled() to use current filled qty for averaging
- Add fallback to exchange balances when broker balance unavailable
Paper broker enhancements:
- Add exchange-qualified price storage for multi-exchange support
- Add price_source tracking for positions
- Improve state persistence
Tests:
- Add comprehensive tests for trade P/L calculations
- Add tests for paper broker price source tracking
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add KuCoin-specific balance fetching with type='trade' parameter
- Reinitialize ccxt client in refresh_balances() to fix pickle corruption
- Force reconnection when exchange is restored from database cache
- Add balance refresh button and socket handler in frontend
- Fix template null check for balances display
- Clean up DataCache and candles imports
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
EDM Integration:
- Add edm_client module for REST/WebSocket communication with exchange-data-manager
- Refactor candles.py to fetch data exclusively from EDM
- Add EDM session management for authenticated exchange access
- Update backtesting to use EDM for historical data
- Pass edm_client through to all strategy instances
- Add /api/edm-config, /api/chart-view, /health/edm endpoints
- Remove legacy candle-fetching code from DataCache_v3 and Exchange
UI Improvements:
- Make all popup dialogs draggable and resizable (exchange config, indicator, signal, trade)
- Add default trading source (exchange, symbol, timeframe) to strategy dialog
- Convert symbol fields to dropdowns with smart prioritization (popular pairs first)
- Fix signal dialog property dropdown initialization
Bug Fixes:
- Fix PythonGenerator regex to handle symbols starting with numbers (e.g., 0G/USDT)
- Fix EDM client date format (use Unix timestamps instead of ISO strings)
- Fix strategy default_source database migration
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Exchange.py:
- Add get_trading_fees(symbol) - fetches fees from market data
- Tries user-specific fees for authenticated users (fetch_trading_fees)
- Falls back to market data (public)
- Returns maker/taker rates with source indicator
- Add get_margin_info(symbol) - returns margin trading availability
ExchangeInterface.py:
- Add get_trading_fees() - routes to appropriate exchange
- Add get_margin_info() - routes to appropriate exchange
- Both methods handle user/exchange lookup with fallback to defaults
trade.py:
- Update new_trade() to fetch actual fees from exchange
- Uses taker fee for market orders, maker fee for limit orders
- Falls back to exchange_fees defaults if fetch fails
Fees now come from actual exchange data (0.1% for Binance spot)
instead of hardcoded defaults.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Check if exchange supports fetchPositions before calling it
- Handle PermissionDenied (error -2015) gracefully with debug log instead of error
- Handle NotSupported exception for exchanges that don't support positions
- Use ccxt standard field names (contracts, entryPrice) with fallbacks
- Skip positions with zero size
- Add documentation noting this is a futures/derivatives feature
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Key fixes:
- ExchangeInterface: Remove stale entries before creating new exchange connections
- LiveBroker: Optimize get_total_equity() to price only top 10 assets (was hanging on 462 testnet assets)
- LiveBroker: Add fiat currency skip list to avoid failed price lookups
- PythonGenerator: Fix market symbol regex to handle 2-5 char symbols (BTC/USDT)
New features:
- LiveStrategyInstance: Full live trading strategy execution
- Circuit breaker and position limits for live trading safety
- Restart-safe order reconciliation via client order IDs
Verified working:
- Live strategy starts on Binance testnet
- Orders placed and filled successfully
- Execution loop runs with active strategies
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>