Skip to content

Commit

Permalink
binance: add order rate limiter for binance
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Nov 4, 2021
1 parent 7eb91cc commit 1a861c9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/exchange/binance/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/adshao/go-binance/v2/futures"
"golang.org/x/time/rate"
"os"
"strconv"
"strings"
Expand All @@ -22,6 +23,8 @@ import (

const BNB = "BNB"

var orderLimiter = rate.NewLimiter(rate.Every(10 * time.Second), 50)

var log = logrus.WithFields(logrus.Fields{
"exchange": "binance",
})
Expand Down Expand Up @@ -732,8 +735,11 @@ func (e *Exchange) submitSpotOrder(ctx context.Context, order types.SubmitOrder)

func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (createdOrders types.OrderSlice, err error) {
for _, order := range orders {
var createdOrder *types.Order
if err := orderLimiter.Wait(ctx) ; err != nil {
log.WithError(err).Errorf("order rate limiter wait error")
}

var createdOrder *types.Order
if e.IsMargin {
createdOrder, err = e.submitMarginOrder(ctx, order)
} else {
Expand Down

0 comments on commit 1a861c9

Please sign in to comment.