mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 16:26:57 +08:00
robustness: add HTTP status code checks to market data & provider APIs
- market/api_client.go: check StatusCode for exchangeInfo, klines, price endpoints + add truncateBody helper for safe error messages - market/data.go: check StatusCode for openInterest and premiumIndex - provider/coinank: check StatusCode for GET and POST requests - provider/twelvedata: check StatusCode for time series and quote APIs - Prevents confusing JSON unmarshal errors when APIs return 429/500/etc
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package market
|
||||
|
||||
import (
|
||||
"nofx/safe"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"nofx/logger"
|
||||
"nofx/safe"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -270,6 +271,9 @@ func getOpenInterestData(symbol string) (*OIData, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("Binance openInterest API error (status %d): %s", resp.StatusCode, truncateBody(body))
|
||||
}
|
||||
|
||||
var result struct {
|
||||
OpenInterest string `json:"openInterest"`
|
||||
@@ -315,6 +319,9 @@ func getFundingRate(symbol string) (float64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return 0, fmt.Errorf("Binance premiumIndex API error (status %d): %s", resp.StatusCode, truncateBody(body))
|
||||
}
|
||||
|
||||
var result struct {
|
||||
Symbol string `json:"symbol"`
|
||||
|
||||
Reference in New Issue
Block a user