fix: consistent safe type helpers in auto_trader, log emergency exit errors

- Replace all raw pos["key"].(type) assertions with posFloat64/posString/posInt64 helpers
  across auto_trader_decision, auto_trader_grid, auto_trader_grid_orders,
  auto_trader_grid_regime, auto_trader_loop, auto_trader_orders, auto_trader_risk
- Add posInt64 helper for int64 extraction (createdTime etc)
- Fix emergencyExit: log CloseLong/CloseShort errors instead of silently dropping
- Fix emergencyExit: log GetPositions error on failure
- Upgrade closeAllPositions log level from Infof to Warnf for close failures
- Zero raw type assertions remaining in auto_trader_* files
This commit is contained in:
shinchan-zhai
2026-03-23 12:29:21 +08:00
parent ed9230d38b
commit 3c39d1efbe
8 changed files with 78 additions and 51 deletions

View File

@@ -41,11 +41,11 @@ func (at *AutoTrader) checkPositionDrawdown() {
}
for _, pos := range positions {
symbol, _ := pos["symbol"].(string)
side, _ := pos["side"].(string)
entryPrice, _ := pos["entryPrice"].(float64)
markPrice, _ := pos["markPrice"].(float64)
quantity, _ := pos["positionAmt"].(float64)
symbol := posString(pos, "symbol")
side := posString(pos, "side")
entryPrice := posFloat64(pos, "entryPrice")
markPrice := posFloat64(pos, "markPrice")
quantity := posFloat64(pos, "positionAmt")
if symbol == "" || side == "" || entryPrice == 0 {
continue // skip malformed position data
}
@@ -55,7 +55,7 @@ func (at *AutoTrader) checkPositionDrawdown() {
// Calculate current P&L percentage
leverage := 10 // Default value
if lev, ok := pos["leverage"].(float64); ok {
if lev := posFloat64(pos, "leverage"); lev > 0 {
leverage = int(lev)
}