pkg/exchange: rename tradeRateLimiter to queryOrderTradeRateLimiter

This commit is contained in:
Edwin 2023-10-25 21:36:26 +08:00
parent c611cfe73b
commit 881db49b70

View File

@ -26,14 +26,14 @@ const (
) )
// https://bybit-exchange.github.io/docs/zh-TW/v5/rate-limit // https://bybit-exchange.github.io/docs/zh-TW/v5/rate-limit
// GET/POST method (shared): 120 requests per second for 5 consecutive seconds
var (
// sharedRateLimiter indicates that the API belongs to the public API. // sharedRateLimiter indicates that the API belongs to the public API.
//
// The default order limiter apply 5 requests per second and a 5 initial bucket // The default order limiter apply 5 requests per second and a 5 initial bucket
// this includes QueryMarkets, QueryTicker, QueryAccountBalances, GetFeeRates // this includes QueryMarkets, QueryTicker, QueryAccountBalances, GetFeeRates
var (
sharedRateLimiter = rate.NewLimiter(rate.Every(time.Second/5), 5) sharedRateLimiter = rate.NewLimiter(rate.Every(time.Second/5), 5)
tradeRateLimiter = rate.NewLimiter(rate.Every(time.Second/5), 5) queryOrderTradeRateLimiter = rate.NewLimiter(rate.Every(time.Second/5), 5)
orderRateLimiter = rate.NewLimiter(rate.Every(100*time.Millisecond), 10) orderRateLimiter = rate.NewLimiter(rate.Every(time.Second/10), 10)
closedOrderQueryLimiter = rate.NewLimiter(rate.Every(time.Second), 1) closedOrderQueryLimiter = rate.NewLimiter(rate.Every(time.Second), 1)
log = logrus.WithFields(logrus.Fields{ log = logrus.WithFields(logrus.Fields{
@ -159,7 +159,7 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [
req = req.Cursor(cursor) req = req.Cursor(cursor)
} }
if err = tradeRateLimiter.Wait(ctx); err != nil { if err = queryOrderTradeRateLimiter.Wait(ctx); err != nil {
return nil, fmt.Errorf("place order rate limiter wait error: %w", err) return nil, fmt.Errorf("place order rate limiter wait error: %w", err)
} }
res, err := req.Do(ctx) res, err := req.Do(ctx)
@ -232,7 +232,7 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) (tr
req.Symbol(q.Symbol) req.Symbol(q.Symbol)
} }
if err := tradeRateLimiter.Wait(ctx); err != nil { if err := queryOrderTradeRateLimiter.Wait(ctx); err != nil {
return nil, fmt.Errorf("trade rate limiter wait error: %w", err) return nil, fmt.Errorf("trade rate limiter wait error: %w", err)
} }
response, err := req.Do(ctx) response, err := req.Do(ctx)
@ -463,7 +463,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
} }
req.Limit(limit) req.Limit(limit)
if err := tradeRateLimiter.Wait(ctx); err != nil { if err := queryOrderTradeRateLimiter.Wait(ctx); err != nil {
return nil, fmt.Errorf("trade rate limiter wait error: %w", err) return nil, fmt.Errorf("trade rate limiter wait error: %w", err)
} }
response, err := req.Do(ctx) response, err := req.Do(ctx)