mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
kucoin: add trades, orders rate limiter
This commit is contained in:
parent
71af9961a1
commit
9757ca290b
|
@ -13,11 +13,13 @@ import (
|
|||
"golang.org/x/time/rate"
|
||||
|
||||
"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/types"
|
||||
)
|
||||
|
||||
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")
|
||||
|
||||
|
@ -314,6 +316,10 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
|
|||
req.EndAt(until)
|
||||
}
|
||||
|
||||
if err := queryOrderLimiter.Wait(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orderList, err := req.Do(ctx)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
|
@ -354,6 +360,10 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
|
|||
req.EndAt(*options.EndTime)
|
||||
}
|
||||
|
||||
if err := queryTradeLimiter.Wait(ctx); err != nil {
|
||||
return trades, err
|
||||
}
|
||||
|
||||
response, err := req.Do(ctx)
|
||||
if err != nil {
|
||||
return trades, err
|
||||
|
|
Loading…
Reference in New Issue
Block a user