mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 01:48:22 +08:00
fix: fallback to Binance kline when coinank returns empty data for non-Binance exchanges
CoinAnk recently stopped providing free kline data for OKX/Bitget/Gate exchanges (returns success but empty array). This caused '3-minute k-line data is empty' errors for all users on those exchanges. Fix: detect empty kline response and automatically fallback to Binance kline data, which is always available.
This commit is contained in:
@@ -78,15 +78,19 @@ func getKlinesFromCoinAnk(symbol, interval, exchange string, limit int) ([]Kline
|
|||||||
ts := time.Now().UnixMilli()
|
ts := time.Now().UnixMilli()
|
||||||
// Use "To" side to search backward from current time (get historical klines)
|
// Use "To" side to search backward from current time (get historical klines)
|
||||||
coinankKlines, err := coinank_api.Kline(ctx, symbol, coinankExchange, ts, coinank_enum.To, limit, coinankInterval)
|
coinankKlines, err := coinank_api.Kline(ctx, symbol, coinankExchange, ts, coinank_enum.To, limit, coinankInterval)
|
||||||
if err != nil {
|
if err != nil || len(coinankKlines) == 0 {
|
||||||
// If exchange-specific data fails, fallback to Binance
|
// If exchange-specific data fails or returns empty, fallback to Binance
|
||||||
if coinankExchange != coinank_enum.Binance {
|
if coinankExchange != coinank_enum.Binance {
|
||||||
logger.Warnf("⚠️ CoinAnk %s data failed, falling back to Binance: %v", exchange, err)
|
if err != nil {
|
||||||
|
logger.Warnf("⚠️ CoinAnk %s data failed, falling back to Binance: %v", exchange, err)
|
||||||
|
} else {
|
||||||
|
logger.Warnf("⚠️ CoinAnk %s %s data empty for %s, falling back to Binance", exchange, interval, symbol)
|
||||||
|
}
|
||||||
coinankKlines, err = coinank_api.Kline(ctx, symbol, coinank_enum.Binance, ts, coinank_enum.To, limit, coinankInterval)
|
coinankKlines, err = coinank_api.Kline(ctx, symbol, coinank_enum.Binance, ts, coinank_enum.To, limit, coinankInterval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("CoinAnk API error (fallback): %w", err)
|
return nil, fmt.Errorf("CoinAnk API error (fallback): %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else if err != nil {
|
||||||
return nil, fmt.Errorf("CoinAnk API error: %w", err)
|
return nil, fmt.Errorf("CoinAnk API error: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user