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:
shinchan-zhai
2026-03-23 19:51:03 +08:00
parent 812972c5e8
commit f94c9bc3c8
4 changed files with 43 additions and 12 deletions

View File

@@ -132,9 +132,6 @@ func (t *HyperliquidTrader) GetBalance() (map[string]interface{}, error) {
spotUSDCBalance, availableBalance)
}
// Suppress unused variable warning
_ = totalUnrealizedPnlAll
result["totalWalletBalance"] = totalWalletBalance // Total assets (Perp + Spot + xyz) - unrealized
result["totalEquity"] = totalEquityCalculated // Total equity = Perp AV + Spot + xyz AV
result["availableBalance"] = availableBalance // Available balance (Perp + Spot if unified)