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>
High priority fixes:
- Wire time_in_force, stop_loss, take_profit to broker.place_order()
* Pass time_in_force from received_new_trade() to new_trade()
* Pass SL/TP/TIF from new_trade() to broker.place_order()
- Reconcile Trade ledger when SL/TP triggers
* Find all matching paper trades for symbol
* Settle trades at trigger price
* Move from active_trades to settled_trades
* Save to database
- Fix fresh schema missing SL/TP columns
* Add stop_loss and take_profit to CREATE TABLE statement
* Ensures first-run trade persistence works
Medium priority fixes:
- Hide SL/TP fields for SELL orders (inventory-only model)
* SL/TP only makes sense for BUY (opening positions)
* SELL closes existing positions, no SL/TP needed
* Added _updateSltpVisibility() method
* Side change listener shows/hides SL/TP row
* Removed SELL-side SL/TP validation
Tests:
- Added 2 integration tests for manual trading SL/TP path
- 353 tests pass (4 pre-existing failures unrelated)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Hide exchange dropdown for paper trades (uses single synthetic market)
- Add _updateExchangeRowVisibility() to toggle exchange row visibility
- Call visibility update on target change and form open
- Remove stale 'binance' fallback in Trade constructor call
(Trade.__init__ now handles exchange normalization for paper trades)
Addresses codex feedback:
- Medium: UX mismatch where exchange choice appeared relevant for paper
- Low: Dead code passing 'binance' for paper trades
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 4: Advanced Order Management
- Add stop_loss and take_profit fields to Trade class with DB persistence
- Add SL/TP form fields in new trade popup with validation
- Implement SL/TP evaluation in PaperBroker.update()
- Auto-close positions when SL/TP thresholds are crossed
- Emit sltp_triggered events to frontend with notifications
- Add Time-in-Force dropdown (GTC, IOC, FOK) to trade form
- Add persistence for position_sltp tracking across state save/load
- Add unit tests for SL/TP functionality (5 new tests)
- Add Trade class SL/TP field tests (2 new tests)
Also includes Phase 3 manual trading broker hardening:
- Fix broker UI not wired on startup
- Fix cancelled orders vanishing from history
- Fix positions not live-updating P/L
- Fix paper pricing exchange-ambiguity
- Simplify paper trades to single synthetic market
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>
Auth/Login improvements:
- Add dedicated login page (login_page.html)
- Redirect to /app after successful login/signup instead of welcome
- Add flash message categories to prevent cross-page message pollution
- Filter flash messages by category in templates
Exchange configuration fixes:
- Fix JS discarding API keys for public exchanges (now optional, not cleared)
- Add explicit key/secret validation in backend before saving
- Properly update configured_exchanges when keys provided
Trade dialog enhancements:
- Add exchange selector populated from connected exchanges
- Add testnet checkbox with exchange support detection
- Add production trading confirmation dialog
- Show TESTNET/LIVE badges on trade cards
- Validate exchange is configured before creating live trades
Bug fixes:
- Add try/except around get_user_data in is_logged_in()
- Fix DataFrame index access for user data retrieval
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix default fee from 0.1 (10%) to 0.001 (0.1%) in Trade class
- Add real-time trade updates via WebSocket trade_update events
- Fetch current market price for market orders instead of using cached price
- Add trade persistence to database with proper schema
- Add execution loop to update trades even without active strategies
- Add frontend handler for trade_update events in communication.js
- Add handleTradeUpdate method in trade.js for live P/L updates
- Add debug file logging for trade update debugging
- Update statistics dashboard and trading HUD templates
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>