From d7d9dc5c42448b70ca91ddc9db4f755b17b51c6d Mon Sep 17 00:00:00 2001 From: tinkle-community Date: Wed, 14 Jan 2026 12:18:24 +0800 Subject: [PATCH] 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 --- trader/interface.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/trader/interface.go b/trader/interface.go index cb8f0ddd..741e6e31 100644 --- a/trader/interface.go +++ b/trader/interface.go @@ -1,6 +1,7 @@ package trader import ( + "fmt" "nofx/logger" "time" ) @@ -206,8 +207,20 @@ func (a *GridTraderAdapter) PlaceLimitOrder(req *LimitOrderRequest) (*LimitOrder // CancelOrder cancels a specific order func (a *GridTraderAdapter) CancelOrder(symbol, orderID string) error { - // Fallback: cancel all orders for the symbol - return a.Trader.CancelAllOrders(symbol) + // Try to use CancelOrder if trader supports it directly + 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)