mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-20 15:10:10 +00:00
Binance: update orderbook and ticker rate limits (#1697)
* updates some rate limits * WOAH FRIDAY FAILURES * remove secret code, DONT LOOK * types.Number, rv ob num, fr changes * ever so slight neaten * Remove FundingRateInfo for CMF only * revert to using the funding rate intervals
This commit is contained in:
@@ -135,7 +135,6 @@ func (b *Binance) GetOrderBook(ctx context.Context, obd OrderBookDataRequestPara
|
||||
}
|
||||
params.Set("symbol", symbol)
|
||||
params.Set("limit", strconv.Itoa(obd.Limit))
|
||||
|
||||
var resp OrderBookData
|
||||
if err := b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
@@ -491,29 +490,53 @@ func (b *Binance) GetAveragePrice(ctx context.Context, symbol currency.Pair) (Av
|
||||
// GetPriceChangeStats returns price change statistics for the last 24 hours
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
func (b *Binance) GetPriceChangeStats(ctx context.Context, symbol currency.Pair) (PriceChangeStats, error) {
|
||||
func (b *Binance) GetPriceChangeStats(ctx context.Context, symbol currency.Pair) (*PriceChangeStats, error) {
|
||||
resp := PriceChangeStats{}
|
||||
params := url.Values{}
|
||||
rateLimit := spotPriceChangeAllRate
|
||||
rateLimit := spotTickerAllRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = spotDefaultRate
|
||||
rateLimit = spotTicker1Rate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
path := priceChange + "?" + params.Encode()
|
||||
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
return &resp, b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetTickers returns the ticker data for the last 24 hrs
|
||||
func (b *Binance) GetTickers(ctx context.Context) ([]PriceChangeStats, error) {
|
||||
func (b *Binance) GetTickers(ctx context.Context, symbols ...currency.Pair) ([]PriceChangeStats, error) {
|
||||
var resp []PriceChangeStats
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, priceChange, spotPriceChangeAllRate, &resp)
|
||||
symbolLength := len(symbols)
|
||||
params := url.Values{}
|
||||
var rl request.EndpointLimit
|
||||
switch {
|
||||
case symbolLength == 1:
|
||||
rl = spotTicker1Rate
|
||||
case symbolLength > 1 && symbolLength <= 20:
|
||||
rl = spotTicker20Rate
|
||||
case symbolLength > 20 && symbolLength <= 100:
|
||||
rl = spotTicker100Rate
|
||||
case symbolLength > 100, symbolLength == 0:
|
||||
rl = spotTickerAllRate
|
||||
}
|
||||
path := priceChange
|
||||
if symbolLength > 0 {
|
||||
symbolValues := make([]string, symbolLength)
|
||||
for i := range symbols {
|
||||
symbolValue, err := b.FormatSymbol(symbols[i], asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
symbolValues[i] = "\"" + symbolValue + "\""
|
||||
}
|
||||
params.Set("symbols", "["+strings.Join(symbolValues, ",")+"]")
|
||||
path += "?" + params.Encode()
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rl, &resp)
|
||||
}
|
||||
|
||||
// GetLatestSpotPrice returns latest spot price of symbol
|
||||
@@ -522,7 +545,7 @@ func (b *Binance) GetTickers(ctx context.Context) ([]PriceChangeStats, error) {
|
||||
func (b *Binance) GetLatestSpotPrice(ctx context.Context, symbol currency.Pair) (SymbolPrice, error) {
|
||||
resp := SymbolPrice{}
|
||||
params := url.Values{}
|
||||
rateLimit := spotSymbolPriceAllRate
|
||||
rateLimit := spotTickerAllRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = spotDefaultRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
|
||||
@@ -94,16 +94,14 @@ func (b *Binance) GetFuturesOrderbook(ctx context.Context, symbol currency.Pair,
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
|
||||
rateBudget := cFuturesDefaultRate
|
||||
rateBudget := cFuturesOrderbook1000Rate
|
||||
switch {
|
||||
case limit == 5, limit == 10, limit == 20, limit == 50:
|
||||
rateBudget = cFuturesOrderbook50Rate
|
||||
case limit >= 100 && limit < 500:
|
||||
rateBudget = cFuturesOrderbook100Rate
|
||||
case limit >= 500 && limit < 1000:
|
||||
case limit == 0, limit >= 500 && limit < 1000:
|
||||
rateBudget = cFuturesOrderbook500Rate
|
||||
case limit == 1000:
|
||||
rateBudget = cFuturesOrderbook1000Rate
|
||||
}
|
||||
|
||||
var data OrderbookData
|
||||
|
||||
@@ -1192,11 +1192,14 @@ func TestGetPriceChangeStats(t *testing.T) {
|
||||
|
||||
func TestGetTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetTickers(context.Background())
|
||||
if err != nil {
|
||||
t.Error("Binance TestGetTickers error", err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := b.GetTickers(context.Background(),
|
||||
currency.NewPair(currency.BTC, currency.USDT),
|
||||
currency.NewPair(currency.ETH, currency.USDT))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestGetLatestSpotPrice(t *testing.T) {
|
||||
@@ -2819,7 +2822,7 @@ func TestUpdateOrderExecutionLimits(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFundingRates(t *testing.T) {
|
||||
func TestGetHistoricalFundingRates(t *testing.T) {
|
||||
t.Parallel()
|
||||
s, e := getTime()
|
||||
_, err := b.GetHistoricalFundingRates(context.Background(), &fundingrate.HistoricalRatesRequest{
|
||||
|
||||
@@ -300,8 +300,8 @@ type IndexMarkPrice struct {
|
||||
IndexPrice types.Number `json:"indexPrice"`
|
||||
EstimatedSettlePrice types.Number `json:"estimatedSettlePrice"`
|
||||
LastFundingRate types.Number `json:"lastFundingRate"`
|
||||
NextFundingTime int64 `json:"nextFundingTime"`
|
||||
Time int64 `json:"time"`
|
||||
NextFundingTime types.Time `json:"nextFundingTime"`
|
||||
Time types.Time `json:"time"`
|
||||
}
|
||||
|
||||
// CandleStick holds kline data
|
||||
@@ -327,25 +327,27 @@ type AveragePrice struct {
|
||||
|
||||
// PriceChangeStats contains statistics for the last 24 hours trade
|
||||
type PriceChangeStats struct {
|
||||
Symbol string `json:"symbol"`
|
||||
PriceChange float64 `json:"priceChange,string"`
|
||||
PriceChangePercent float64 `json:"priceChangePercent,string"`
|
||||
WeightedAvgPrice float64 `json:"weightedAvgPrice,string"`
|
||||
PrevClosePrice float64 `json:"prevClosePrice,string"`
|
||||
LastPrice float64 `json:"lastPrice,string"`
|
||||
LastQty float64 `json:"lastQty,string"`
|
||||
BidPrice float64 `json:"bidPrice,string"`
|
||||
AskPrice float64 `json:"askPrice,string"`
|
||||
OpenPrice float64 `json:"openPrice,string"`
|
||||
HighPrice float64 `json:"highPrice,string"`
|
||||
LowPrice float64 `json:"lowPrice,string"`
|
||||
Volume float64 `json:"volume,string"`
|
||||
QuoteVolume float64 `json:"quoteVolume,string"`
|
||||
OpenTime time.Time `json:"openTime"`
|
||||
CloseTime time.Time `json:"closeTime"`
|
||||
FirstID int64 `json:"firstId"`
|
||||
LastID int64 `json:"lastId"`
|
||||
Count int64 `json:"count"`
|
||||
Symbol string `json:"symbol"`
|
||||
PriceChange types.Number `json:"priceChange"`
|
||||
PriceChangePercent types.Number `json:"priceChangePercent"`
|
||||
WeightedAvgPrice types.Number `json:"weightedAvgPrice"`
|
||||
PrevClosePrice types.Number `json:"prevClosePrice"`
|
||||
LastPrice types.Number `json:"lastPrice"`
|
||||
LastQty types.Number `json:"lastQty"`
|
||||
BidPrice types.Number `json:"bidPrice"`
|
||||
AskPrice types.Number `json:"askPrice"`
|
||||
BidQuantity types.Number `json:"bidQty"`
|
||||
AskQuantity types.Number `json:"askQty"`
|
||||
OpenPrice types.Number `json:"openPrice"`
|
||||
HighPrice types.Number `json:"highPrice"`
|
||||
LowPrice types.Number `json:"lowPrice"`
|
||||
Volume types.Number `json:"volume"`
|
||||
QuoteVolume types.Number `json:"quoteVolume"`
|
||||
OpenTime time.Time `json:"openTime"`
|
||||
CloseTime time.Time `json:"closeTime"`
|
||||
FirstID int64 `json:"firstId"`
|
||||
LastID int64 `json:"lastId"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
// SymbolPrice holds basic symbol price
|
||||
|
||||
@@ -102,16 +102,14 @@ func (b *Binance) UFuturesOrderbook(ctx context.Context, symbol currency.Pair, l
|
||||
params.Set("limit", strLimit)
|
||||
}
|
||||
|
||||
rateBudget := uFuturesDefaultRate
|
||||
rateBudget := uFuturesOrderbook1000Rate
|
||||
switch {
|
||||
case limit == 5, limit == 10, limit == 20, limit == 50:
|
||||
rateBudget = uFuturesOrderbook50Rate
|
||||
case limit >= 100 && limit < 500:
|
||||
rateBudget = uFuturesOrderbook100Rate
|
||||
case limit >= 500 && limit < 1000:
|
||||
case limit == 0, limit >= 500 && limit < 1000:
|
||||
rateBudget = uFuturesOrderbook500Rate
|
||||
case limit == 1000:
|
||||
rateBudget = uFuturesOrderbook1000Rate
|
||||
}
|
||||
|
||||
var data OrderbookData
|
||||
|
||||
@@ -378,15 +378,15 @@ func (b *Binance) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
}
|
||||
|
||||
err = ticker.ProcessTicker(&ticker.Price{
|
||||
Last: tick[y].LastPrice,
|
||||
High: tick[y].HighPrice,
|
||||
Low: tick[y].LowPrice,
|
||||
Bid: tick[y].BidPrice,
|
||||
Ask: tick[y].AskPrice,
|
||||
Volume: tick[y].Volume,
|
||||
QuoteVolume: tick[y].QuoteVolume,
|
||||
Open: tick[y].OpenPrice,
|
||||
Close: tick[y].PrevClosePrice,
|
||||
Last: tick[y].LastPrice.Float64(),
|
||||
High: tick[y].HighPrice.Float64(),
|
||||
Low: tick[y].LowPrice.Float64(),
|
||||
Bid: tick[y].BidPrice.Float64(),
|
||||
Ask: tick[y].AskPrice.Float64(),
|
||||
Volume: tick[y].Volume.Float64(),
|
||||
QuoteVolume: tick[y].QuoteVolume.Float64(),
|
||||
Open: tick[y].OpenPrice.Float64(),
|
||||
Close: tick[y].PrevClosePrice.Float64(),
|
||||
Pair: pairFmt,
|
||||
ExchangeName: b.Name,
|
||||
AssetType: a,
|
||||
@@ -435,13 +435,13 @@ func (b *Binance) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
return err
|
||||
}
|
||||
err = ticker.ProcessTicker(&ticker.Price{
|
||||
Last: tick[y].LastPrice,
|
||||
High: tick[y].HighPrice,
|
||||
Low: tick[y].LowPrice,
|
||||
Volume: tick[y].Volume,
|
||||
QuoteVolume: tick[y].QuoteVolume,
|
||||
Open: tick[y].OpenPrice,
|
||||
Close: tick[y].PrevClosePrice,
|
||||
Last: tick[y].LastPrice.Float64(),
|
||||
High: tick[y].HighPrice.Float64(),
|
||||
Low: tick[y].LowPrice.Float64(),
|
||||
Volume: tick[y].Volume.Float64(),
|
||||
QuoteVolume: tick[y].QuoteVolume.Float64(),
|
||||
Open: tick[y].OpenPrice.Float64(),
|
||||
Close: tick[y].PrevClosePrice.Float64(),
|
||||
Pair: cp,
|
||||
ExchangeName: b.Name,
|
||||
AssetType: a,
|
||||
@@ -468,15 +468,15 @@ func (b *Binance) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Ite
|
||||
return nil, err
|
||||
}
|
||||
err = ticker.ProcessTicker(&ticker.Price{
|
||||
Last: tick.LastPrice,
|
||||
High: tick.HighPrice,
|
||||
Low: tick.LowPrice,
|
||||
Bid: tick.BidPrice,
|
||||
Ask: tick.AskPrice,
|
||||
Volume: tick.Volume,
|
||||
QuoteVolume: tick.QuoteVolume,
|
||||
Open: tick.OpenPrice,
|
||||
Close: tick.PrevClosePrice,
|
||||
Last: tick.LastPrice.Float64(),
|
||||
High: tick.HighPrice.Float64(),
|
||||
Low: tick.LowPrice.Float64(),
|
||||
Bid: tick.BidPrice.Float64(),
|
||||
Ask: tick.AskPrice.Float64(),
|
||||
Volume: tick.Volume.Float64(),
|
||||
QuoteVolume: tick.QuoteVolume.Float64(),
|
||||
Open: tick.OpenPrice.Float64(),
|
||||
Close: tick.PrevClosePrice.Float64(),
|
||||
Pair: p,
|
||||
ExchangeName: b.Name,
|
||||
AssetType: a,
|
||||
@@ -510,13 +510,13 @@ func (b *Binance) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Ite
|
||||
return nil, err
|
||||
}
|
||||
err = ticker.ProcessTicker(&ticker.Price{
|
||||
Last: tick[0].LastPrice,
|
||||
High: tick[0].HighPrice,
|
||||
Low: tick[0].LowPrice,
|
||||
Volume: tick[0].Volume,
|
||||
QuoteVolume: tick[0].QuoteVolume,
|
||||
Open: tick[0].OpenPrice,
|
||||
Close: tick[0].PrevClosePrice,
|
||||
Last: tick[0].LastPrice.Float64(),
|
||||
High: tick[0].HighPrice.Float64(),
|
||||
Low: tick[0].LowPrice.Float64(),
|
||||
Volume: tick[0].Volume.Float64(),
|
||||
QuoteVolume: tick[0].QuoteVolume.Float64(),
|
||||
Open: tick[0].OpenPrice.Float64(),
|
||||
Close: tick[0].PrevClosePrice.Float64(),
|
||||
Pair: p,
|
||||
ExchangeName: b.Name,
|
||||
AssetType: a,
|
||||
@@ -2002,7 +2002,6 @@ func (b *Binance) GetLatestFundingRates(ctx context.Context, r *fundingrate.Late
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mp, err = b.UGetMarkPrice(ctx, fPair)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -2026,7 +2025,7 @@ func (b *Binance) GetLatestFundingRates(ctx context.Context, r *fundingrate.Late
|
||||
if !isPerp {
|
||||
continue
|
||||
}
|
||||
var fundingRateFrequency int64
|
||||
var fundingRateFrequency int64 = 8
|
||||
for x := range fri {
|
||||
if fri[x].Symbol != mp[i].Symbol {
|
||||
continue
|
||||
@@ -2034,14 +2033,15 @@ func (b *Binance) GetLatestFundingRates(ctx context.Context, r *fundingrate.Late
|
||||
fundingRateFrequency = fri[x].FundingIntervalHours
|
||||
break
|
||||
}
|
||||
nft := time.UnixMilli(mp[i].NextFundingTime)
|
||||
nft := mp[i].NextFundingTime.Time()
|
||||
cft := nft.Add(-time.Hour * time.Duration(fundingRateFrequency))
|
||||
rate := fundingrate.LatestRateResponse{
|
||||
TimeChecked: time.Now(),
|
||||
Exchange: b.Name,
|
||||
Asset: r.Asset,
|
||||
Pair: cp,
|
||||
LatestRate: fundingrate.Rate{
|
||||
Time: time.UnixMilli(mp[i].Time).Truncate(time.Hour * time.Duration(fundingRateFrequency)),
|
||||
Time: cft,
|
||||
Rate: decimal.NewFromFloat(mp[i].LastFundingRate),
|
||||
},
|
||||
}
|
||||
@@ -2055,17 +2055,16 @@ func (b *Binance) GetLatestFundingRates(ctx context.Context, r *fundingrate.Late
|
||||
}
|
||||
return resp, nil
|
||||
case asset.CoinMarginedFutures:
|
||||
var mp []IndexMarkPrice
|
||||
mp, err = b.GetIndexAndMarkPrice(ctx, fPair.String(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var fri []FundingRateInfoResponse
|
||||
fri, err = b.GetFundingRateInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var mp []IndexMarkPrice
|
||||
mp, err = b.GetIndexAndMarkPrice(ctx, fPair.String(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := make([]fundingrate.LatestRateResponse, 0, len(mp))
|
||||
for i := range mp {
|
||||
var cp currency.Pair
|
||||
@@ -2081,7 +2080,7 @@ func (b *Binance) GetLatestFundingRates(ctx context.Context, r *fundingrate.Late
|
||||
if !isPerp {
|
||||
continue
|
||||
}
|
||||
var fundingRateFrequency int64
|
||||
var fundingRateFrequency int64 = 8
|
||||
for x := range fri {
|
||||
if fri[x].Symbol != mp[i].Symbol {
|
||||
continue
|
||||
@@ -2089,14 +2088,15 @@ func (b *Binance) GetLatestFundingRates(ctx context.Context, r *fundingrate.Late
|
||||
fundingRateFrequency = fri[x].FundingIntervalHours
|
||||
break
|
||||
}
|
||||
nft := time.UnixMilli(mp[i].NextFundingTime)
|
||||
nft := mp[i].NextFundingTime.Time()
|
||||
cft := nft.Add(-time.Hour * time.Duration(fundingRateFrequency))
|
||||
rate := fundingrate.LatestRateResponse{
|
||||
TimeChecked: time.Now(),
|
||||
Exchange: b.Name,
|
||||
Asset: r.Asset,
|
||||
Pair: cp,
|
||||
LatestRate: fundingrate.Rate{
|
||||
Time: time.UnixMilli(mp[i].Time).Truncate(time.Duration(fundingRateFrequency) * time.Hour),
|
||||
Time: cft,
|
||||
Rate: mp[i].LastFundingRate.Decimal(),
|
||||
},
|
||||
}
|
||||
@@ -2148,7 +2148,7 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var fundingRateFrequency int64
|
||||
var fundingRateFrequency int64 = 8
|
||||
fps := fPair.String()
|
||||
for x := range fri {
|
||||
if fri[x].Symbol != fps {
|
||||
@@ -2180,10 +2180,10 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
|
||||
return nil, err
|
||||
}
|
||||
pairRate.LatestRate = fundingrate.Rate{
|
||||
Time: time.UnixMilli(mp[len(mp)-1].Time).Truncate(time.Duration(fundingRateFrequency) * time.Hour),
|
||||
Time: mp[len(mp)-1].Time.Time().Truncate(time.Duration(fundingRateFrequency) * time.Hour),
|
||||
Rate: decimal.NewFromFloat(mp[len(mp)-1].LastFundingRate),
|
||||
}
|
||||
pairRate.TimeOfNextRate = time.UnixMilli(mp[len(mp)-1].NextFundingTime)
|
||||
pairRate.TimeOfNextRate = mp[len(mp)-1].NextFundingTime.Time()
|
||||
if r.IncludePayments {
|
||||
var income []UAccountIncomeHistory
|
||||
income, err = b.UAccountIncomeHistory(ctx, fPair, "FUNDING_FEE", int64(requestLimit), r.StartDate, r.EndDate)
|
||||
@@ -2214,7 +2214,7 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var fundingRateFrequency int64
|
||||
var fundingRateFrequency int64 = 8
|
||||
fps := fPair.String()
|
||||
for x := range fri {
|
||||
if fri[x].Symbol != fps {
|
||||
@@ -2246,10 +2246,10 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
|
||||
return nil, err
|
||||
}
|
||||
pairRate.LatestRate = fundingrate.Rate{
|
||||
Time: time.UnixMilli(mp[len(mp)-1].Time).Truncate(time.Duration(fundingRateFrequency) * time.Hour),
|
||||
Time: mp[len(mp)-1].NextFundingTime.Time().Add(-time.Hour * time.Duration(fundingRateFrequency)),
|
||||
Rate: mp[len(mp)-1].LastFundingRate.Decimal(),
|
||||
}
|
||||
pairRate.TimeOfNextRate = time.UnixMilli(mp[len(mp)-1].NextFundingTime)
|
||||
pairRate.TimeOfNextRate = mp[len(mp)-1].NextFundingTime.Time()
|
||||
if r.IncludePayments {
|
||||
var income []FuturesIncomeHistoryData
|
||||
income, err = b.FuturesIncomeHistory(ctx, fPair, "FUNDING_FEE", r.StartDate, r.EndDate, int64(requestLimit))
|
||||
@@ -2259,7 +2259,7 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
|
||||
for j := range income {
|
||||
for x := range pairRate.FundingRates {
|
||||
tt := time.UnixMilli(income[j].Timestamp)
|
||||
tt = tt.Truncate(time.Duration(fundingRateFrequency) * time.Hour)
|
||||
tt = tt.Truncate(8 * time.Hour)
|
||||
if !tt.Equal(pairRate.FundingRates[x].Time) {
|
||||
continue
|
||||
}
|
||||
@@ -2897,7 +2897,6 @@ func (b *Binance) GetFuturesContractDetails(ctx context.Context, item asset.Item
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ei, err := b.UExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -11,19 +11,19 @@ const (
|
||||
// Global dictates the max rate limit for general request items which is
|
||||
// 1200 requests per minute
|
||||
spotInterval = time.Minute
|
||||
spotRequestRate = 1200
|
||||
spotRequestRate = 6000
|
||||
// Order related limits which are segregated from the global rate limits
|
||||
// 100 requests per 10 seconds and max 100000 requests per day.
|
||||
spotOrderInterval = 10 * time.Second
|
||||
spotOrderRequestRate = 100
|
||||
cFuturesInterval = time.Minute
|
||||
cFuturesRequestRate = 6000
|
||||
cFuturesRequestRate = 2400
|
||||
cFuturesOrderInterval = time.Minute
|
||||
cFuturesOrderRequestRate = 1200
|
||||
uFuturesInterval = time.Minute
|
||||
uFuturesRequestRate = 2400
|
||||
uFuturesOrderInterval = time.Minute
|
||||
uFuturesOrderRequestRate = 1200
|
||||
uFuturesOrderInterval = time.Second * 10
|
||||
uFuturesOrderRequestRate = 300
|
||||
)
|
||||
|
||||
// Binance Spot rate limits
|
||||
@@ -32,11 +32,14 @@ const (
|
||||
spotExchangeInfo
|
||||
spotHistoricalTradesRate
|
||||
spotOrderbookDepth500Rate
|
||||
spotOrderbookDepth100Rate
|
||||
spotOrderbookDepth1000Rate
|
||||
spotOrderbookDepth5000Rate
|
||||
spotOrderbookTickerAllRate
|
||||
spotPriceChangeAllRate
|
||||
spotSymbolPriceAllRate
|
||||
spotTicker1Rate
|
||||
spotTicker20Rate
|
||||
spotTicker100Rate
|
||||
spotTickerAllRate
|
||||
spotOpenOrdersAllRate
|
||||
spotOpenOrdersSpecificRate
|
||||
spotOrderRate
|
||||
@@ -104,14 +107,17 @@ func GetRateLimits() request.RateLimitDefinitions {
|
||||
return request.RateLimitDefinitions{
|
||||
spotDefaultRate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 1),
|
||||
spotOrderbookTickerAllRate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 2),
|
||||
spotSymbolPriceAllRate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 2),
|
||||
spotHistoricalTradesRate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 5),
|
||||
spotOrderbookDepth500Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 5),
|
||||
spotOrderbookDepth1000Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 10),
|
||||
spotOrderbookDepth100Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 5),
|
||||
spotOrderbookDepth500Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 25),
|
||||
spotOrderbookDepth1000Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 50),
|
||||
spotOrderbookDepth5000Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 250),
|
||||
spotAccountInformationRate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 10),
|
||||
spotExchangeInfo: request.GetRateLimiterWithWeight(spotDefaultLimiter, 10),
|
||||
spotPriceChangeAllRate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 40),
|
||||
spotOrderbookDepth5000Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 50),
|
||||
spotTicker1Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 2),
|
||||
spotTicker20Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 2),
|
||||
spotTicker100Rate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 40),
|
||||
spotTickerAllRate: request.GetRateLimiterWithWeight(spotDefaultLimiter, 80),
|
||||
spotOrderRate: request.GetRateLimiterWithWeight(spotOrderLimiter, 1),
|
||||
spotOrderQueryRate: request.GetRateLimiterWithWeight(spotOrderLimiter, 2),
|
||||
spotOpenOrdersSpecificRate: request.GetRateLimiterWithWeight(spotOrderLimiter, 3),
|
||||
@@ -120,14 +126,14 @@ func GetRateLimits() request.RateLimitDefinitions {
|
||||
uFuturesDefaultRate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 1),
|
||||
uFuturesKline100Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 1),
|
||||
uFuturesOrderbook50Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 2),
|
||||
uFuturesOrderbook100Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 5),
|
||||
uFuturesOrderbook500Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 10),
|
||||
uFuturesOrderbook1000Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 20),
|
||||
uFuturesKline500Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 2),
|
||||
uFuturesOrderbookTickerAllRate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 2),
|
||||
uFuturesOrderbook100Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 5),
|
||||
uFuturesKline1000Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 5),
|
||||
uFuturesAccountInformationRate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 5),
|
||||
uFuturesOrderbook500Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 10),
|
||||
uFuturesKlineMaxRate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 10),
|
||||
uFuturesOrderbook1000Rate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 20),
|
||||
uFuturesHistoricalTradesRate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 20),
|
||||
uFuturesTickerPriceHistoryRate: request.GetRateLimiterWithWeight(usdMarginedFuturesLimiter, 40),
|
||||
uFuturesOrdersDefaultRate: request.GetRateLimiterWithWeight(usdMarginedFuturesOrdersLimiter, 1),
|
||||
@@ -178,7 +184,7 @@ func openOrdersLimit(symbol string) request.EndpointLimit {
|
||||
func orderbookLimit(depth int) request.EndpointLimit {
|
||||
switch {
|
||||
case depth <= 100:
|
||||
return spotDefaultRate
|
||||
return spotOrderbookDepth100Rate
|
||||
case depth <= 500:
|
||||
return spotOrderbookDepth500Rate
|
||||
case depth <= 1000:
|
||||
|
||||
@@ -21,11 +21,11 @@ func TestRateLimit_Limit(t *testing.T) {
|
||||
Deadline time.Time
|
||||
}{
|
||||
"Open Orders": {Expected: spotOpenOrdersSpecificRate, Limit: openOrdersLimit(symbol)},
|
||||
"Orderbook Depth 5": {Expected: spotDefaultRate, Limit: orderbookLimit(5)},
|
||||
"Orderbook Depth 10": {Expected: spotDefaultRate, Limit: orderbookLimit(10)},
|
||||
"Orderbook Depth 20": {Expected: spotDefaultRate, Limit: orderbookLimit(20)},
|
||||
"Orderbook Depth 50": {Expected: spotDefaultRate, Limit: orderbookLimit(50)},
|
||||
"Orderbook Depth 100": {Expected: spotDefaultRate, Limit: orderbookLimit(100)},
|
||||
"Orderbook Depth 5": {Expected: spotOrderbookDepth100Rate, Limit: orderbookLimit(5)},
|
||||
"Orderbook Depth 10": {Expected: spotOrderbookDepth100Rate, Limit: orderbookLimit(10)},
|
||||
"Orderbook Depth 20": {Expected: spotOrderbookDepth100Rate, Limit: orderbookLimit(20)},
|
||||
"Orderbook Depth 50": {Expected: spotOrderbookDepth100Rate, Limit: orderbookLimit(50)},
|
||||
"Orderbook Depth 100": {Expected: spotOrderbookDepth100Rate, Limit: orderbookLimit(100)},
|
||||
"Orderbook Depth 500": {Expected: spotOrderbookDepth500Rate, Limit: orderbookLimit(500)},
|
||||
"Orderbook Depth 1000": {Expected: spotOrderbookDepth1000Rate, Limit: orderbookLimit(1000)},
|
||||
"Orderbook Depth 5000": {Expected: spotOrderbookDepth5000Rate, Limit: orderbookLimit(5000)},
|
||||
@@ -63,7 +63,7 @@ func TestRateLimit_LimitStatic(t *testing.T) {
|
||||
testTable := map[string]request.EndpointLimit{
|
||||
"Default": spotDefaultRate,
|
||||
"Historical Trades": spotHistoricalTradesRate,
|
||||
"All Price Changes": spotPriceChangeAllRate,
|
||||
"All Price Changes": spotTickerAllRate,
|
||||
"All Orders": spotAllOrdersRate,
|
||||
}
|
||||
|
||||
|
||||
95291
exchanges/binance/testdata/http.json
vendored
95291
exchanges/binance/testdata/http.json
vendored
File diff suppressed because it is too large
Load Diff
@@ -73,13 +73,13 @@ type UCompressedTradeData struct {
|
||||
|
||||
// UMarkPrice stores mark price data
|
||||
type UMarkPrice struct {
|
||||
Symbol string `json:"symbol"`
|
||||
MarkPrice float64 `json:"markPrice,string"`
|
||||
IndexPrice float64 `json:"indexPrice,string"`
|
||||
LastFundingRate float64 `json:"lastFundingRate,string"`
|
||||
EstimatedSettlePrice float64 `json:"estimatedSettlePrice,string"`
|
||||
NextFundingTime int64 `json:"nextFundingTime"`
|
||||
Time int64 `json:"time"`
|
||||
Symbol string `json:"symbol"`
|
||||
MarkPrice float64 `json:"markPrice,string"`
|
||||
IndexPrice float64 `json:"indexPrice,string"`
|
||||
LastFundingRate float64 `json:"lastFundingRate,string"`
|
||||
EstimatedSettlePrice float64 `json:"estimatedSettlePrice,string"`
|
||||
NextFundingTime types.Time `json:"nextFundingTime"`
|
||||
Time types.Time `json:"time"`
|
||||
}
|
||||
|
||||
// FundingRateInfoResponse stores funding rate info
|
||||
|
||||
Reference in New Issue
Block a user