mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 06:46:59 +08:00
fix(trader): harden API calls with timeouts, strict balance parsing, error context
- binance/bybit/gate: SDK default http.DefaultClient has no timeout; use a dedicated 30s-timeout client so a hung connection cannot stall the loop - bybit: stop mutating http.DefaultClient.Transport, which leaked the referer header into every other HTTP request in the process - add types.ParseFloatField: empty exchange fields stay zero, but malformed numeric values now surface as errors instead of silently becoming zero balances (applied to GetBalance across 8 exchanges) - wrap order/market-data errors in auto_trader_orders and okx cancel paths with symbol context; log per-order cancel failures in okx CancelAllOrders
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"nofx/logger"
|
||||
"nofx/trader/types"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -43,9 +44,15 @@ func (t *BitgetTrader) GetBalance() (map[string]interface{}, error) {
|
||||
var totalEquity, availableBalance, unrealizedPnL float64
|
||||
for _, acc := range accounts {
|
||||
if acc.MarginCoin == "USDT" {
|
||||
totalEquity, _ = strconv.ParseFloat(acc.AccountEquity, 64)
|
||||
availableBalance, _ = strconv.ParseFloat(acc.Available, 64)
|
||||
unrealizedPnL, _ = strconv.ParseFloat(acc.UnrealizedPL, 64)
|
||||
if totalEquity, err = types.ParseFloatField("accountEquity", acc.AccountEquity); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if availableBalance, err = types.ParseFloatField("available", acc.Available); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if unrealizedPnL, err = types.ParseFloatField("unrealizedPL", acc.UnrealizedPL); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logger.Infof("✓ [Bitget] Balance: equity=%.2f, available=%.2f", totalEquity, availableBalance)
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user