diff --git a/exchanges/binance/binance.go b/exchanges/binance/binance.go index fb81633a..389535b3 100644 --- a/exchanges/binance/binance.go +++ b/exchanges/binance/binance.go @@ -37,6 +37,7 @@ const ( historicalTrades = "/api/v1/historicalTrades" aggregatedTrades = "/api/v1/aggTrades" candleStick = "/api/v1/klines" + averagePrice = "/api/v3/avgPrice" priceChange = "/api/v1/ticker/24hr" symbolPrice = "/api/v3/ticker/price" bestPrice = "/api/v3/ticker/bookTicker" @@ -339,6 +340,24 @@ func (b *Binance) GetSpotKline(arg KlinesRequestParams) ([]CandleStick, error) { return kline, nil } +// GetAveragePrice returns current average price for a symbol. +// +// symbol: string of currency pair +func (b *Binance) GetAveragePrice(symbol string) (AveragePrice, error) { + resp := AveragePrice{} + + if err := b.CheckSymbol(symbol); err != nil { + return resp, err + } + + params := url.Values{} + params.Set("symbol", common.StringToUpper(symbol)) + + path := fmt.Sprintf("%s%s?%s", b.APIUrl, averagePrice, params.Encode()) + + return resp, b.SendHTTPRequest(path, &resp) +} + // GetPriceChangeStats returns price change statistics for the last 24 hours // // symbol: string of currency pair diff --git a/exchanges/binance/binance_test.go b/exchanges/binance/binance_test.go index 9fc92141..6d687a0d 100644 --- a/exchanges/binance/binance_test.go +++ b/exchanges/binance/binance_test.go @@ -96,6 +96,14 @@ func TestGetSpotKline(t *testing.T) { } } +func TestGetAveragePrice(t *testing.T) { + t.Parallel() + _, err := b.GetAveragePrice("BTCUSDT") + if err != nil { + t.Error("Test Failed - Binance GetAveragePrice() error", err) + } +} + func TestGetPriceChangeStats(t *testing.T) { t.Parallel() _, err := b.GetPriceChangeStats("BTCUSDT") diff --git a/exchanges/binance/binance_types.go b/exchanges/binance/binance_types.go index 6e1e886b..92ab3365 100644 --- a/exchanges/binance/binance_types.go +++ b/exchanges/binance/binance_types.go @@ -34,14 +34,21 @@ type ExchangeInfo struct { OrderTypes []string `json:"orderTypes"` IcebergAllowed bool `json:"icebergAllowed"` Filters []struct { - FilterType string `json:"filterType"` - MinPrice float64 `json:"minPrice,string"` - MaxPrice float64 `json:"maxPrice,string"` - TickSize float64 `json:"tickSize,string"` - MinQty float64 `json:"minQty,string"` - MaxQty float64 `json:"maxQty,string"` - StepSize float64 `json:"stepSize,string"` - MinNotional float64 `json:"minNotional,string"` + FilterType string `json:"filterType"` + MinPrice float64 `json:"minPrice,string"` + MaxPrice float64 `json:"maxPrice,string"` + TickSize float64 `json:"tickSize,string"` + MultiplierUp float64 `json:"multiplierUp,string"` + MultiplierDown float64 `json:"multiplierDown,string"` + AvgPriceMins int64 `json:"avgPriceMins"` + MinQty float64 `json:"minQty,string"` + MaxQty float64 `json:"maxQty,string"` + StepSize float64 `json:"stepSize,string"` + MinNotional float64 `json:"minNotional,string"` + ApplyToMarket bool `json:"applyToMarket"` + Limit int64 `json:"limit"` + MaxNumAlgoOrders int64 `json:"maxNumAlgoOrders"` + MaxNumIcebergOrders int64 `json:"maxNumIcebergOrders"` } `json:"filters"` } `json:"symbols"` } @@ -224,6 +231,12 @@ type CandleStick struct { TakerBuyQuoteAssetVolume float64 } +// AvgPrice holds current average symbol price +type AveragePrice struct { + Mins int64 `json:"mins"` + Price float64 `json:"price,string"` +} + // PriceChangeStats contains statistics for the last 24 hours trade type PriceChangeStats struct { Symbol string `json:"symbol"`