mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user