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:
tinkle-community
2026-06-11 00:30:34 +08:00
parent 094ab45476
commit 9ea9bd705f
15 changed files with 206 additions and 50 deletions

View File

@@ -36,14 +36,21 @@ func (t *AsterTrader) GetBalance() (map[string]interface{}, error) {
foundUSDT = true
// Parse Aster fields (reference: https://github.com/asterdex/api-docs)
var parseErr error
if avail, ok := bal["availableBalance"].(string); ok {
availableBalance, _ = strconv.ParseFloat(avail, 64)
if availableBalance, parseErr = types.ParseFloatField("availableBalance", avail); parseErr != nil {
return nil, parseErr
}
}
if unpnl, ok := bal["crossUnPnl"].(string); ok {
crossUnPnl, _ = strconv.ParseFloat(unpnl, 64)
if crossUnPnl, parseErr = types.ParseFloatField("crossUnPnl", unpnl); parseErr != nil {
return nil, parseErr
}
}
if cwb, ok := bal["crossWalletBalance"].(string); ok {
crossWalletBalance, _ = strconv.ParseFloat(cwb, 64)
if crossWalletBalance, parseErr = types.ParseFloatField("crossWalletBalance", cwb); parseErr != nil {
return nil, parseErr
}
}
break
}