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:
David Ackroyd
2020-04-17 08:59:06 +10:00
committed by GitHub
parent 70cba38fa3
commit c0d2ac5e51
5 changed files with 67154 additions and 44303 deletions

View File

@@ -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"

View File

@@ -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"`
}

View File

@@ -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
}

View File

@@ -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) {

File diff suppressed because it is too large Load Diff