mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-12 07:16:56 +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 {
|
||||
|
||||
@@ -276,7 +276,7 @@ func (t *HyperliquidTrader) GetMarketPrice(symbol string) (float64, error) {
|
||||
if err == nil {
|
||||
return priceFloat, nil
|
||||
}
|
||||
return 0, fmt.Errorf("price format error: %v", err)
|
||||
return 0, fmt.Errorf("price format error: %w", err)
|
||||
}
|
||||
|
||||
return 0, fmt.Errorf("price not found for %s", symbol)
|
||||
@@ -335,7 +335,7 @@ func (t *HyperliquidTrader) getXyzMarketPrice(coin string) (float64, error) {
|
||||
if err == nil {
|
||||
return priceFloat, nil
|
||||
}
|
||||
return 0, fmt.Errorf("price format error: %v", err)
|
||||
return 0, fmt.Errorf("price format error: %w", err)
|
||||
}
|
||||
|
||||
return 0, fmt.Errorf("xyz dex price not found for %s (lookup key: %s)", coin, lookupKey)
|
||||
|
||||
Reference in New Issue
Block a user