mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Binance: replace deprecated /v1 API calls (#482)
Several /v1 API calls have been deprecated, and will be removed shortly. Moving these across to their /v3 equivalents Capturing of the klines request via the recorder was failing, as it did not handle the structure where the klines response in an array of mixed primitive arrays. Excluding primitive values from the exclusion checks addresses this
This commit is contained in:
@@ -26,14 +26,14 @@ const (
|
||||
apiURL = "https://api.binance.com"
|
||||
|
||||
// Public endpoints
|
||||
exchangeInfo = "/api/v1/exchangeInfo"
|
||||
orderBookDepth = "/api/v1/depth"
|
||||
recentTrades = "/api/v1/trades"
|
||||
historicalTrades = "/api/v1/historicalTrades"
|
||||
aggregatedTrades = "/api/v1/aggTrades"
|
||||
candleStick = "/api/v1/klines"
|
||||
exchangeInfo = "/api/v3/exchangeInfo"
|
||||
orderBookDepth = "/api/v3/depth"
|
||||
recentTrades = "/api/v3/trades"
|
||||
historicalTrades = "/api/v3/historicalTrades"
|
||||
aggregatedTrades = "/api/v3/aggTrades"
|
||||
candleStick = "/api/v3/klines"
|
||||
averagePrice = "/api/v3/avgPrice"
|
||||
priceChange = "/api/v1/ticker/24hr"
|
||||
priceChange = "/api/v3/ticker/24hr"
|
||||
symbolPrice = "/api/v3/ticker/price"
|
||||
bestPrice = "/api/v3/ticker/bookTicker"
|
||||
accountInfo = "/api/v3/account"
|
||||
|
||||
@@ -107,8 +107,6 @@ type RecentTradeRequestParams struct {
|
||||
|
||||
// RecentTrade holds recent trade data
|
||||
type RecentTrade struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
ID int64 `json:"id"`
|
||||
Price float64 `json:"price,string"`
|
||||
Quantity float64 `json:"qty,string"`
|
||||
@@ -247,7 +245,7 @@ type PriceChangeStats struct {
|
||||
QuoteVolume float64 `json:"quoteVolume,string"`
|
||||
OpenTime int64 `json:"openTime"`
|
||||
CloseTime int64 `json:"closeTime"`
|
||||
FirstID int64 `json:"fristId"`
|
||||
FirstID int64 `json:"firstId"`
|
||||
LastID int64 `json:"lastId"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
@@ -288,12 +288,19 @@ func CheckJSON(data interface{}, excluded *Exclusion) (interface{}, error) {
|
||||
if reflect.TypeOf(data).String() == "[]interface {}" {
|
||||
var sData []interface{}
|
||||
for i := range data.([]interface{}) {
|
||||
checkedData, err := CheckJSON(data.([]interface{})[i], excluded)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v := data.([]interface{})[i]
|
||||
switch v.(type) {
|
||||
case map[string]interface{}, []interface{}:
|
||||
checkedData, err := CheckJSON(v, excluded)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sData = append(sData, checkedData)
|
||||
sData = append(sData, checkedData)
|
||||
default:
|
||||
// Primitive value doesn't need exclusions applied, e.g. float64 or string
|
||||
sData = append(sData, v)
|
||||
}
|
||||
}
|
||||
return sData, nil
|
||||
}
|
||||
|
||||
@@ -64,10 +64,11 @@ func TestCheckResponsePayload(t *testing.T) {
|
||||
}
|
||||
|
||||
type TestStructLevel0 struct {
|
||||
StringVal string `json:"stringVal"`
|
||||
FloatVal float64 `json:"floatVal"`
|
||||
IntVal int64 `json:"intVal"`
|
||||
StructVal TestStructLevel1 `json:"structVal"`
|
||||
StringVal string `json:"stringVal"`
|
||||
FloatVal float64 `json:"floatVal"`
|
||||
IntVal int64 `json:"intVal"`
|
||||
StructVal TestStructLevel1 `json:"structVal"`
|
||||
MixedSlice []interface{} `json:"mixedSlice"`
|
||||
}
|
||||
|
||||
type TestStructLevel1 struct {
|
||||
@@ -117,11 +118,17 @@ func TestCheckJSON(t *testing.T) {
|
||||
OtherData: level2,
|
||||
}
|
||||
|
||||
sliceOfPrimitives := []interface{}{
|
||||
[]interface{}{float64(1586994000000), "6615.23000000"},
|
||||
[]interface{}{float64(1586994300000), "6624.74000000"},
|
||||
}
|
||||
|
||||
testVal := TestStructLevel0{
|
||||
StringVal: "somestringstuff",
|
||||
FloatVal: 3.14,
|
||||
IntVal: 1337,
|
||||
StructVal: level1,
|
||||
StringVal: "somestringstuff",
|
||||
FloatVal: 3.14,
|
||||
IntVal: 1337,
|
||||
StructVal: level1,
|
||||
MixedSlice: sliceOfPrimitives,
|
||||
}
|
||||
|
||||
exclusionList, err := GetExcludedItems()
|
||||
@@ -168,6 +175,22 @@ func TestCheckJSON(t *testing.T) {
|
||||
if newStruct.StructVal.OtherData.OtherData.BadVal2 != "" {
|
||||
t.Error("Value not wiped correctly")
|
||||
}
|
||||
|
||||
vals, err = CheckJSON(sliceOfPrimitives, &exclusionList)
|
||||
if err != nil {
|
||||
t.Error("Check JSON error", err)
|
||||
}
|
||||
|
||||
payload, err = json.Marshal(vals)
|
||||
if err != nil {
|
||||
t.Fatal("json marshal error", err)
|
||||
}
|
||||
|
||||
var newSlice []interface{}
|
||||
err = json.Unmarshal(payload, &newSlice)
|
||||
if err != nil {
|
||||
t.Fatal("Unmarshal error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetExcludedItems(t *testing.T) {
|
||||
|
||||
111383
testdata/http_mock/binance/binance.json
vendored
111383
testdata/http_mock/binance/binance.json
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user