fix(trader): separate stop-loss and take-profit order cancellation to prevent accidental deletions #434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When adjusting stop-loss or take-profit levels,
CancelStopOrders()deleted BOTH stop-loss AND take-profit orders simultaneously, causing:Root cause:
Solution
1. Added new interface methods (trader/interface.go)
2. Implemented for all 3 exchanges
Binance (trader/binance_futures.go):
CancelStopLossOrders: FiltersOrderTypeStopMarket | OrderTypeStopCancelTakeProfitOrders: FiltersOrderTypeTakeProfitMarket | OrderTypeTakeProfitHyperliquid (trader/hyperliquid_trader.go):
CancelStopOrders(cancels all pending orders)Aster (trader/aster_trader.go):
CancelStopLossOrders: FiltersSTOP_MARKET | STOPCancelTakeProfitOrders: FiltersTAKE_PROFIT_MARKET | TAKE_PROFIT3. Usage in auto_trader.go
When
update_stop_lossorupdate_take_profitactions are implemented, they will use:Impact
CancelStopOrdersstill exists (deprecated)Testing
Code Changes
📝 Description | 描述
English:
Fixed critical bug where adjusting stop-loss or take-profit levels would delete BOTH orders simultaneously, leaving positions unprotected or without exit plans.
中文:
修復關鍵 bug:調整止損或止盈價格時會同時刪除兩種訂單,導致持倉失去保護或沒有退出計劃。
🎯 Type of Change | 變更類型
🔗 Related Issues | 相關 Issue
update_stop_lossandupdate_take_profitactions📋 Changes Made | 具體變更
English:
1. Added new interface methods (
trader/interface.go)2. Implemented for all 3 exchanges
Binance (
trader/binance_futures.go):CancelStopLossOrders: FiltersOrderTypeStopMarket | OrderTypeStopCancelTakeProfitOrders: FiltersOrderTypeTakeProfitMarket | OrderTypeTakeProfitHyperliquid (
trader/hyperliquid_trader.go):CancelStopOrders(cancels all pending orders)Aster (
trader/aster_trader.go):CancelStopLossOrders: FiltersSTOP_MARKET | STOPCancelTakeProfitOrders: FiltersTAKE_PROFIT_MARKET | TAKE_PROFIT3. Usage in auto_trader.go
When
update_stop_lossorupdate_take_profitactions are implemented:中文:
1. 新增接口方法 (
trader/interface.go)2. 為所有 3 個交易所實現
Binance (
trader/binance_futures.go):CancelStopLossOrders: 過濾OrderTypeStopMarket | OrderTypeStopCancelTakeProfitOrders: 過濾OrderTypeTakeProfitMarket | OrderTypeTakeProfitHyperliquid (
trader/hyperliquid_trader.go):CancelStopOrders(取消所有掛單)Aster (
trader/aster_trader.go):CancelStopLossOrders: 過濾STOP_MARKET | STOPCancelTakeProfitOrders: 過濾TAKE_PROFIT_MARKET | TAKE_PROFIT3. 在 auto_trader.go 中使用
當實現
update_stop_loss或update_take_profit動作時:🧪 Testing | 測試
Test Scenarios | 測試場景
Before Fix:
After Fix:
Test Environment | 測試環境
Test Results | 測試結果
✅ Checklist | 檢查清單
Code Quality | 代碼質量
Testing | 測試
Git
fix(trader):)devbranch | 已 rebase 到dev📋 PR Size Estimate | PR 大小估計
🎯 Review Focus Areas | 審查重點
Please pay special attention to:
請特別注意:
Specific areas:
Hyperliquid:
CancelStopLossOrdersandCancelTakeProfitOrderscancel ALL pending ordersBy submitting this PR, I confirm that: