Commit Graph

16 Commits

Author SHA1 Message Date
rob d3bbb36dc2 Fix live trade P/L bugs, improve UI refresh, add balance toggle
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>
2026-03-12 12:15:56 -03:00
rob 21d449d877 Fix KuCoin balance fetching and add balance refresh functionality
- 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>
2026-03-06 06:10:31 -04:00
rob 0e481e653e Integrate EDM for candle data and improve UI dialogs
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>
2026-03-04 11:42:06 -04:00
rob 45395c86c5 Implement fee fetching from exchange via ccxt
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>
2026-03-02 16:30:19 -04:00
rob dd8467468c Fix Binance API error -2015 when fetching positions on spot exchanges
- 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>
2026-03-01 18:03:55 -04:00
rob 639043b261 Live trading infrastructure functional on testnet
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>
2026-03-01 15:23:34 -04:00
rob f1a184b131 Fix chart loading and stabilize local runtime 2026-02-28 15:15:56 -04:00
Rob f1d0f2a4b1 Indicators are fixed after last update. 2024-09-18 13:47:07 -03:00
Rob b666ec22af Extended DataCache with indicator caching functionality. All DataCache tests pass. 2024-09-07 19:51:01 -03:00
Rob 439c852cf5 Fixed an issue where the client asked for too many records and was not receiving them. Also ensured that much of the code is dealing with timezones proactively. 2024-08-16 15:51:15 -03:00
Rob d288eebbec Re-wrote DataCache.py and Implemented tests and got them all passing. 2024-08-15 22:39:38 -03:00
Rob c398a423a3 implemented tests for Exchangeinterface.py 2024-08-04 02:06:23 -03:00
Rob 917ccedbaf Documented Exchange.py 2024-08-03 17:35:40 -03:00
Rob e601f8c23e Completed unittests for Exchange. 2024-08-02 15:51:25 -03:00
Rob 0b1ad39476 Fixed query_uptodate function and added comprehensive test cases 2024-08-02 01:36:45 -03:00
Rob b699bd950e Updated project structure and staged modified files 2024-07-25 08:21:15 -03:00