mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
binance: add order rate limiter for binance
This commit is contained in:
parent
7eb91cc7cc
commit
1a861c98a1
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/adshao/go-binance/v2/futures"
|
"github.com/adshao/go-binance/v2/futures"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -22,6 +23,8 @@ import (
|
||||||
|
|
||||||
const BNB = "BNB"
|
const BNB = "BNB"
|
||||||
|
|
||||||
|
var orderLimiter = rate.NewLimiter(rate.Every(10 * time.Second), 50)
|
||||||
|
|
||||||
var log = logrus.WithFields(logrus.Fields{
|
var log = logrus.WithFields(logrus.Fields{
|
||||||
"exchange": "binance",
|
"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) {
|
func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (createdOrders types.OrderSlice, err error) {
|
||||||
for _, order := range orders {
|
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 {
|
if e.IsMargin {
|
||||||
createdOrder, err = e.submitMarginOrder(ctx, order)
|
createdOrder, err = e.submitMarginOrder(ctx, order)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user