mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-18 09:54:35 +08:00
fix: cancel orphaned stop/TP orders on position close + guard zero SL/TP prices
Critical bugs fixed: - executeCloseLong/CloseShort: cancel stop-loss and take-profit orders BEFORE closing position to prevent orphaned orders from triggering and creating unintended positions - emergencyClosePosition: same fix for drawdown monitor's emergency close path - Skip SetStopLoss/SetTakeProfit when AI returns price=0 (prevents exchange API errors) Also includes: - Add agent.Stop() to graceful shutdown sequence in main.go - Remove unused variable suppression in Hyperliquid trader
This commit is contained in:
@@ -112,6 +112,12 @@ func (at *AutoTrader) checkPositionDrawdown() {
|
||||
|
||||
// emergencyClosePosition emergency close position function
|
||||
func (at *AutoTrader) emergencyClosePosition(symbol, side string) error {
|
||||
// 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(symbol); err != nil {
|
||||
logger.Warnf(" ⚠️ Emergency close: failed to cancel stop orders for %s: %v", symbol, err)
|
||||
}
|
||||
|
||||
switch side {
|
||||
case "long":
|
||||
order, err := at.trader.CloseLong(symbol, 0) // 0 = close all
|
||||
|
||||
Reference in New Issue
Block a user