mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-12 07:16:56 +08:00
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:
@@ -350,7 +350,7 @@ func (at *AutoTrader) buildTradingContext() (*kernel.Context, error) {
|
||||
|
||||
// Calculate margin used (estimated)
|
||||
leverage := 10 // Default value, should actually be fetched from position info
|
||||
if lev, ok := pos["leverage"].(float64); ok {
|
||||
if lev := posFloat64(pos, "leverage"); lev > 0 {
|
||||
leverage = int(lev)
|
||||
}
|
||||
marginUsed := (quantity * markPrice) / float64(leverage)
|
||||
@@ -374,7 +374,7 @@ func (at *AutoTrader) buildTradingContext() (*kernel.Context, error) {
|
||||
}
|
||||
// Priority 2: Get from exchange API (Bybit: createdTime, OKX: createdTime)
|
||||
if updateTime == 0 {
|
||||
if createdTime, ok := pos["createdTime"].(int64); ok && createdTime > 0 {
|
||||
if createdTime := posInt64(pos, "createdTime"); createdTime > 0 {
|
||||
updateTime = createdTime
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user