Skip to content

Commit

Permalink
Binance: Fix UKlineData func (thrasher-corp#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
phieudu241 authored Aug 30, 2021
1 parent 8020e1e commit 1e79384
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions exchanges/binance/binance_ufutures.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
Expand Down Expand Up @@ -218,7 +219,7 @@ func (b *Binance) UKlineData(symbol currency.Pair, interval string, limit int64,
return resp, err
}
params.Set("symbol", symbolValue)
if !common.StringDataCompare(uValidPeriods, interval) {
if !common.StringDataCompare(validFuturesIntervals, interval) {
return resp, errors.New("invalid interval")
}
params.Set("interval", interval)
Expand All @@ -229,8 +230,8 @@ func (b *Binance) UKlineData(symbol currency.Pair, interval string, limit int64,
if startTime.After(endTime) {
return resp, errors.New("startTime cannot be after endTime")
}
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
params.Set("startTime", timeString(startTime))
params.Set("endTime", timeString(endTime))
}
rateBudget := uFuturesDefaultRate
switch {
Expand All @@ -256,7 +257,10 @@ func (b *Binance) UKlineData(symbol currency.Pair, interval string, limit int64,
if !ok {
return resp, errors.New("type assertion failed for opentime")
}
tempData.OpenTime = time.Unix(int64(floatData), 0)
tempData.OpenTime, err = convert.TimeFromUnixTimestampFloat(floatData)
if err != nil {
return resp, err
}
strData, ok = data[x][1].(string)
if !ok {
return resp, errors.New("type assertion failed for open")
Expand Down Expand Up @@ -306,7 +310,10 @@ func (b *Binance) UKlineData(symbol currency.Pair, interval string, limit int64,
if !ok {
return resp, errors.New("type assertion failed for close time")
}
tempData.CloseTime = time.Unix(int64(floatData), 0)
tempData.CloseTime, err = convert.TimeFromUnixTimestampFloat(floatData)
if err != nil {
return resp, err
}
strData, ok = data[x][7].(string)
if !ok {
return resp, errors.New("type assertion failed base asset volume")
Expand Down
2 changes: 1 addition & 1 deletion testdata/http_mock/binance/binance.json
Original file line number Diff line number Diff line change
Expand Up @@ -253203,7 +253203,7 @@
"0"
]
],
"queryString": "end_time=1580515200\u0026interval=5m\u0026start_time=1577836800\u0026symbol=LTCUSDT",
"queryString": "endTime=1580515200000\u0026interval=5m\u0026startTime=1577836800000\u0026symbol=LTCUSDT",
"bodyParams": "",
"headers": {}
}
Expand Down

0 comments on commit 1e79384

Please sign in to comment.