mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Poloniex: Fix GetChartData error return value (#1819)
Signed-off-by: cangqiaoyuzhuo <850072022@qq.com>
This commit is contained in:
@@ -224,28 +224,27 @@ func (p *Poloniex) GetChartData(ctx context.Context, currencyPair string, start,
|
||||
}
|
||||
|
||||
var temp json.RawMessage
|
||||
var resp []ChartData
|
||||
path := "/public?command=returnChartData&" + vals.Encode()
|
||||
err := p.SendHTTPRequest(ctx, exchange.RestSpot, path, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tempUnmarshal := json.Unmarshal(temp, &resp)
|
||||
if tempUnmarshal != nil {
|
||||
var resp []ChartData
|
||||
err = json.Unmarshal(temp, &resp)
|
||||
if err != nil {
|
||||
var errResp struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
errRet := json.Unmarshal(temp, &errResp)
|
||||
if errRet != nil {
|
||||
return nil, err
|
||||
if errRet := json.Unmarshal(temp, &errResp); errRet != nil {
|
||||
return nil, errRet
|
||||
}
|
||||
if errResp.Error != "" {
|
||||
return nil, errors.New(errResp.Error)
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GetCurrencies returns information about currencies
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
"github.com/thrasher-corp/gocryptotrader/types"
|
||||
)
|
||||
|
||||
// Ticker holds ticker data
|
||||
@@ -102,15 +103,15 @@ type OrderTrade struct {
|
||||
|
||||
// ChartData holds kline data
|
||||
type ChartData struct {
|
||||
Date int64 `json:"date,string"`
|
||||
High float64 `json:"high,string"`
|
||||
Low float64 `json:"low,string"`
|
||||
Open float64 `json:"open,string"`
|
||||
Close float64 `json:"close,string"`
|
||||
Volume float64 `json:"volume,string"`
|
||||
QuoteVolume float64 `json:"quoteVolume,string"`
|
||||
WeightedAverage float64 `json:"weightedAverage,string"`
|
||||
Error string `json:"error"`
|
||||
Date types.Time `json:"date"`
|
||||
High types.Number `json:"high"`
|
||||
Low types.Number `json:"low"`
|
||||
Open types.Number `json:"open"`
|
||||
Close types.Number `json:"close"`
|
||||
Volume types.Number `json:"volume"`
|
||||
QuoteVolume types.Number `json:"quoteVolume"`
|
||||
WeightedAverage types.Number `json:"weightedAverage"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// Currencies contains currency information
|
||||
|
||||
@@ -959,12 +959,12 @@ func (p *Poloniex) GetHistoricCandles(ctx context.Context, pair currency.Pair, a
|
||||
timeSeries := make([]kline.Candle, len(resp))
|
||||
for x := range resp {
|
||||
timeSeries[x] = kline.Candle{
|
||||
Time: time.UnixMilli(resp[x].Date),
|
||||
Open: resp[x].Open,
|
||||
High: resp[x].High,
|
||||
Low: resp[x].Low,
|
||||
Close: resp[x].Close,
|
||||
Volume: resp[x].Volume,
|
||||
Time: resp[x].Date.Time(),
|
||||
Open: resp[x].Open.Float64(),
|
||||
High: resp[x].High.Float64(),
|
||||
Low: resp[x].Low.Float64(),
|
||||
Close: resp[x].Close.Float64(),
|
||||
Volume: resp[x].Volume.Float64(),
|
||||
}
|
||||
}
|
||||
return req.ProcessResponse(timeSeries)
|
||||
@@ -989,12 +989,12 @@ func (p *Poloniex) GetHistoricCandlesExtended(ctx context.Context, pair currency
|
||||
}
|
||||
for x := range resp {
|
||||
timeSeries = append(timeSeries, kline.Candle{
|
||||
Time: time.UnixMilli(resp[x].Date),
|
||||
Open: resp[x].Open,
|
||||
High: resp[x].High,
|
||||
Low: resp[x].Low,
|
||||
Close: resp[x].Close,
|
||||
Volume: resp[x].Volume,
|
||||
Time: resp[x].Date.Time(),
|
||||
Open: resp[x].Open.Float64(),
|
||||
High: resp[x].High.Float64(),
|
||||
Low: resp[x].Low.Float64(),
|
||||
Close: resp[x].Close.Float64(),
|
||||
Volume: resp[x].Volume.Float64(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user