mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Add GetAveragePrice function to the binance API (#212)
* Add GetAveragePrice function to the binance API * Add new filters * Remove typo
This commit is contained in:
committed by
Adrian Gallagher
parent
b11c52ca07
commit
47f89d838b
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user