kucoin: add trades, orders rate limiter

This commit is contained in:
c9s 2022-03-18 17:33:10 +08:00
parent 71af9961a1
commit 9757ca290b

View File

@ -13,11 +13,13 @@ import (
"golang.org/x/time/rate" "golang.org/x/time/rate"
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi" "github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
) )
var marketDataLimiter = rate.NewLimiter(rate.Every(500*time.Millisecond), 1) var marketDataLimiter = rate.NewLimiter(rate.Every(500*time.Millisecond), 1)
var queryTradeLimiter = rate.NewLimiter(rate.Every(5*time.Second), 1)
var queryOrderLimiter = rate.NewLimiter(rate.Every(5*time.Second), 1)
var ErrMissingSequence = errors.New("sequence is missing") var ErrMissingSequence = errors.New("sequence is missing")
@ -314,6 +316,10 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
req.EndAt(until) req.EndAt(until)
} }
if err := queryOrderLimiter.Wait(ctx); err != nil {
return nil, err
}
orderList, err := req.Do(ctx) orderList, err := req.Do(ctx)
if err != nil { if err != nil {
return orders, err return orders, err
@ -354,6 +360,10 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
req.EndAt(*options.EndTime) req.EndAt(*options.EndTime)
} }
if err := queryTradeLimiter.Wait(ctx); err != nil {
return trades, err
}
response, err := req.Do(ctx) response, err := req.Do(ctx)
if err != nil { if err != nil {
return trades, err return trades, err