mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
binance: add order rate limiter for binance
This commit is contained in:
parent
7eb91cc7cc
commit
1a861c98a1
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"github.com/adshao/go-binance/v2/futures"
|
||||
"golang.org/x/time/rate"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -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",
|
||||
})
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user