- execute_trade: warn user when US market is closed (order queued for next open)
- get_market_price: include market_open/market_status for stock quotes
- Uses Alpaca's /v2/clock endpoint via IsMarketOpen() interface
- Prevents surprise queued orders during off-hours
Critical bug: isStockSymbol('BTC') returned true because 'BTC' is 3
uppercase letters and the suffix check only catches 'BTCUSDT'-style pairs.
This caused crypto trade commands to be routed to Alpaca (stock trader)
instead of crypto exchanges.
Fix: add knownCryptoSymbols map with 60+ common crypto base symbols.
Check this map first before the heuristic letter-count check.
Also includes:
- Unit tests for isStockSymbol (crypto vs stock classification)
- Alpaca support in handleSyncBalance/handleClosePosition API handlers
- Cancel orphaned SL/TP orders before manual position close
- Clear peak PnL cache on position close (prevent stale data)
- Lighter FormatQuantity uses actual market precision instead of hardcoded 4
Critical bugs fixed:
- executeCloseLong/CloseShort: cancel stop-loss and take-profit orders BEFORE closing
position to prevent orphaned orders from triggering and creating unintended positions
- emergencyClosePosition: same fix for drawdown monitor's emergency close path
- Skip SetStopLoss/SetTakeProfit when AI returns price=0 (prevents exchange API errors)
Also includes:
- Add agent.Stop() to graceful shutdown sequence in main.go
- Remove unused variable suppression in Hyperliquid trader
- Replace all raw pos["key"].(type) assertions with posFloat64/posString/posInt64 helpers
across auto_trader_decision, auto_trader_grid, auto_trader_grid_orders,
auto_trader_grid_regime, auto_trader_loop, auto_trader_orders, auto_trader_risk
- Add posInt64 helper for int64 extraction (createdTime etc)
- Fix emergencyExit: log CloseLong/CloseShort errors instead of silently dropping
- Fix emergencyExit: log GetPositions error on failure
- Upgrade closeAllPositions log level from Infof to Warnf for close failures
- Zero raw type assertions remaining in auto_trader_* files