fix(grid): prevent CancelOrder from canceling all orders

CRITICAL BUG FIX:
- CancelOrder no longer calls CancelAllOrders
- Try exchange-specific CancelOrder if available
- Return error if individual cancellation not supported
This commit is contained in:
tinkle-community
2026-01-14 12:18:24 +08:00
parent 90509ae783
commit d7d9dc5c42

View File

@@ -1,6 +1,7 @@
package trader package trader
import ( import (
"fmt"
"nofx/logger" "nofx/logger"
"time" "time"
) )
@@ -206,8 +207,20 @@ func (a *GridTraderAdapter) PlaceLimitOrder(req *LimitOrderRequest) (*LimitOrder
// CancelOrder cancels a specific order // CancelOrder cancels a specific order
func (a *GridTraderAdapter) CancelOrder(symbol, orderID string) error { func (a *GridTraderAdapter) CancelOrder(symbol, orderID string) error {
// Fallback: cancel all orders for the symbol // Try to use CancelOrder if trader supports it directly
return a.Trader.CancelAllOrders(symbol) if canceler, ok := a.Trader.(interface {
CancelOrder(symbol, orderID string) error
}); ok {
return canceler.CancelOrder(symbol, orderID)
}
// For traders that only support CancelAllOrders, log a warning
// This is a limitation - we cannot cancel individual orders
logger.Warnf("[Grid] Trader does not support individual order cancellation, "+
"cannot cancel order %s. Consider using exchange-specific GridTrader implementation.", orderID)
// Return error instead of canceling all orders
return fmt.Errorf("individual order cancellation not supported for this exchange")
} }
// GetOrderBook returns empty order book (not supported in basic Trader) // GetOrderBook returns empty order book (not supported in basic Trader)