mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-10 22:36:58 +08:00
fix: prevent panics from unsafe type assertions in trading code + add request body limit
Security & Reliability: - Add requestBodyLimitMiddleware (1MB) to prevent OOM from oversized API payloads - Fix defer resp.Body.Close() inside loop in getPublicIPFromAPI (connection leak) - Add posFloat64/posString safe helpers for position map access Panic Prevention (critical for trading): - Convert 30+ unsafe type assertions (pos["key"].(type)) to safe comma-ok pattern across all exchange traders: OKX, Hyperliquid, Aster, Bybit, KuCoin, Gate, Bitget, Binance - Fix auto_trader_risk.go: drawdown monitor could panic and silently stop monitoring, leaving positions unprotected - Fix auto_trader_decision.go & auto_trader_loop.go: core trading loop position parsing now crash-proof - All trader/ code now has zero unsafe type assertions Frontend: - Fix config.ts: rejected promise cached forever on network error (never retries)
This commit is contained in:
@@ -165,9 +165,10 @@ func (t *GateTrader) CloseLong(symbol string, quantity float64) (map[string]inte
|
||||
return nil, err
|
||||
}
|
||||
for _, pos := range positions {
|
||||
posSymbol := t.convertSymbol(pos["symbol"].(string))
|
||||
rawSymbol, _ := pos["symbol"].(string)
|
||||
posSymbol := t.convertSymbol(rawSymbol)
|
||||
if posSymbol == symbol && pos["side"] == "long" {
|
||||
quantity = pos["positionAmt"].(float64)
|
||||
quantity, _ = pos["positionAmt"].(float64)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -233,9 +234,10 @@ func (t *GateTrader) CloseShort(symbol string, quantity float64) (map[string]int
|
||||
return nil, err
|
||||
}
|
||||
for _, pos := range positions {
|
||||
posSymbol := t.convertSymbol(pos["symbol"].(string))
|
||||
rawSymbol, _ := pos["symbol"].(string)
|
||||
posSymbol := t.convertSymbol(rawSymbol)
|
||||
if posSymbol == symbol && pos["side"] == "short" {
|
||||
quantity = pos["positionAmt"].(float64)
|
||||
quantity, _ = pos["positionAmt"].(float64)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user