mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-16 01:06:59 +08:00
feat(agent): add market hours check for stock trades
- 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
This commit is contained in:
@@ -322,6 +322,9 @@ func (at *AutoTrader) executeCloseLongWithRecord(decision *kernel.Decision, acti
|
||||
logger.Infof(" 🗑️ Cancelled stop/TP orders for %s", decision.Symbol)
|
||||
}
|
||||
|
||||
// Record quantity in action record (was missing — close decisions showed 0 quantity in history)
|
||||
actionRecord.Quantity = quantity
|
||||
|
||||
// Close position
|
||||
order, err := at.trader.CloseLong(decision.Symbol, 0) // 0 = close all
|
||||
if err != nil {
|
||||
@@ -387,6 +390,9 @@ func (at *AutoTrader) executeCloseShortWithRecord(decision *kernel.Decision, act
|
||||
logger.Infof(" 📊 Using exchange position data: qty=%.8f, entry=%.2f", quantity, entryPrice)
|
||||
}
|
||||
|
||||
// Record quantity in action record (was missing — close decisions showed 0 quantity in history)
|
||||
actionRecord.Quantity = quantity
|
||||
|
||||
// Cancel existing stop-loss and take-profit orders BEFORE closing position
|
||||
// Critical: orphaned SL/TP orders could trigger after position is closed and create unintended positions
|
||||
if err := at.trader.CancelStopOrders(decision.Symbol); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user