gateio: update rate limit definitions (#1733)

* gateio: update rate limit definitions (cherry-pick)

* Add test and missing

* Shared REST rate limit definitions with Websocket service, set lookup item to nil for systems that do not require rate limiting; add glorious nit

* gateio: fix race

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2024-12-12 15:08:24 +11:00
committed by GitHub
parent 2a4c2d24a7
commit 068a4535ed
6 changed files with 621 additions and 374 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -333,7 +333,7 @@ func TestCreateBatchOrders(t *testing.T) {
func TestGetSpotOpenOrders(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
if _, err := g.GateioSpotOpenOrders(context.Background(), 0, 0, false); err != nil {
if _, err := g.GetSpotOpenOrders(context.Background(), 0, 0, false); err != nil {
t.Errorf("%s GetSpotOpenOrders() error %v", g.Name, err)
}
}
@@ -3014,11 +3014,11 @@ func TestGetSettlementFromCurrency(t *testing.T) {
for _, assetType := range []asset.Item{asset.Futures, asset.DeliveryFutures, asset.Options} {
availPairs, err := g.GetAvailablePairs(assetType)
require.NoErrorf(t, err, "GetAvailablePairs for asset %s must not error", assetType)
for x := range availPairs {
t.Run(strconv.Itoa(x), func(t *testing.T) {
for i, pair := range availPairs {
t.Run(strconv.Itoa(i)+":"+assetType.String(), func(t *testing.T) {
t.Parallel()
_, err = getSettlementFromCurrency(availPairs[x])
assert.NoErrorf(t, err, "getSettlementFromCurrency should not error for pair %s and asset %s", availPairs[x], assetType)
_, err := getSettlementFromCurrency(pair)
assert.NoErrorf(t, err, "getSettlementFromCurrency should not error for pair %s and asset %s", pair, assetType)
})
}
}

View File

@@ -24,7 +24,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
@@ -32,8 +31,7 @@ import (
)
const (
gateioWebsocketEndpoint = "wss://api.gateio.ws/ws/v4/"
gateioWebsocketRateLimit = 120 * time.Millisecond
gateioWebsocketEndpoint = "wss://api.gateio.ws/ws/v4/"
spotPingChannel = "spot.ping"
spotPongChannel = "spot.pong"
@@ -90,7 +88,7 @@ func (g *Gateio) WsConnectSpot(ctx context.Context, conn stream.Connection) erro
if err != nil {
return err
}
conn.SetupPingHandler(request.Unset, stream.PingHandler{
conn.SetupPingHandler(websocketRateLimitNotNeededEPL, stream.PingHandler{
Websocket: true,
Delay: time.Second * 15,
Message: pingMessage,
@@ -587,7 +585,7 @@ func (g *Gateio) manageSubs(ctx context.Context, event string, conn stream.Conne
if err != nil {
return err
}
result, err := conn.SendMessageReturnResponse(ctx, request.Unset, msg.ID, msg)
result, err := conn.SendMessageReturnResponse(ctx, websocketRateLimitNotNeededEPL, msg.ID, msg)
if err != nil {
return err
}
@@ -698,7 +696,7 @@ func (g *Gateio) handleSubscription(ctx context.Context, conn stream.Connection,
}
var errs error
for k := range payloads {
result, err := conn.SendMessageReturnResponse(ctx, request.Unset, payloads[k].ID, payloads[k])
result, err := conn.SendMessageReturnResponse(ctx, websocketRateLimitNotNeededEPL, payloads[k].ID, payloads[k])
if err != nil {
errs = common.AppendError(errs, err)
continue

View File

@@ -151,7 +151,7 @@ func (g *Gateio) SetDefaults() {
}
g.Requester, err = request.New(g.Name,
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
request.WithLimiter(GetRateLimit()),
request.WithLimiter(packageRateLimits),
)
if err != nil {
log.Errorln(log.ExchangeSys, err)
@@ -203,6 +203,7 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
FillsFeed: g.Features.Enabled.FillsFeed,
TradeFeed: g.Features.Enabled.TradeFeed,
UseMultiConnectionManagement: true,
RateLimitDefinitions: packageRateLimits,
})
if err != nil {
return err
@@ -210,7 +211,6 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
// Spot connection
err = g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
URL: gateioWebsocketEndpoint,
RateLimit: request.NewWeightedRateLimitByDuration(gateioWebsocketRateLimit),
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
Handler: g.WsHandleSpotData,
@@ -226,7 +226,6 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
// Futures connection - USDT margined
err = g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
URL: futuresWebsocketUsdtURL,
RateLimit: request.NewWeightedRateLimitByDuration(gateioWebsocketRateLimit),
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
Handler: func(ctx context.Context, incoming []byte) error {
@@ -245,7 +244,6 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
// Futures connection - BTC margined
err = g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
URL: futuresWebsocketBtcURL,
RateLimit: request.NewWeightedRateLimitByDuration(gateioWebsocketRateLimit),
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
Handler: func(ctx context.Context, incoming []byte) error {
@@ -265,7 +263,6 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
// Futures connection - Delivery - USDT margined
err = g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
URL: deliveryRealUSDTTradingURL,
RateLimit: request.NewWeightedRateLimitByDuration(gateioWebsocketRateLimit),
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
Handler: func(ctx context.Context, incoming []byte) error {
@@ -284,7 +281,6 @@ func (g *Gateio) Setup(exch *config.Exchange) error {
// Futures connection - Options
return g.Websocket.SetupNewConnection(&stream.ConnectionSetup{
URL: optionsWebsocketURL,
RateLimit: request.NewWeightedRateLimitByDuration(gateioWebsocketRateLimit),
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
Handler: g.WsHandleOptionsData,
@@ -1658,7 +1654,7 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.MultiOrderReque
switch req.AssetType {
case asset.Spot, asset.Margin, asset.CrossMargin:
var spotOrders []SpotOrdersDetail
spotOrders, err = g.GateioSpotOpenOrders(ctx, 0, 0, req.AssetType == asset.CrossMargin)
spotOrders, err = g.GetSpotOpenOrders(ctx, 0, 0, req.AssetType == asset.CrossMargin)
if err != nil {
return nil, err
}

View File

@@ -6,49 +6,414 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
)
// GateIO endpoints limits.
// GateIO endpoints limits. See: https://www.gate.io/docs/developers/apiv4/en/#frequency-limit-rule
const (
spotDefaultEPL request.EndpointLimit = iota
spotPrivateEPL
spotPlaceOrdersEPL
spotCancelOrdersEPL
perpetualSwapDefaultEPL
perpetualSwapPlaceOrdersEPL
perpetualSwapPrivateEPL
perpetualSwapCancelOrdersEPL
walletEPL
withdrawalEPL
publicTickersSpotEPL request.EndpointLimit = iota + 1
publicOrderbookSpotEPL
publicMarketTradesSpotEPL
publicCandleStickSpotEPL
publicCurrencyPairDetailSpotEPL
publicListCurrencyPairsSpotEPL
publicCurrenciesSpotEPL
// Request rates per interval
publicCurrencyPairsMarginEPL
publicOrderbookMarginEPL
spotPublicRate = 900
spotPrivateRate = 900
spotPlaceOrdersRate = 10
spotCancelOrdersRate = 500
perpetualSwapPublicRate = 300
perpetualSwapPlaceOrdersRate = 100
perpetualSwapPrivateRate = 400
perpetualSwapCancelOrdersRate = 400
walletRate = 200
withdrawalRate = 1
publicInsuranceDeliveryEPL
publicDeliveryContractsEPL
publicOrderbookDeliveryEPL
publicTradingHistoryDeliveryEPL
publicCandleSticksDeliveryEPL
publicTickersDeliveryEPL
// interval
oneSecondInterval = time.Second
threeSecondsInterval = time.Second * 3
publicFuturesContractsEPL
publicOrderbookFuturesEPL
publicTradingHistoryFuturesEPL
publicCandleSticksFuturesEPL
publicPremiumIndexEPL
publicTickersFuturesEPL
publicFundingRatesEPL
publicInsuranceFuturesEPL
publicStatsFuturesEPL
publicIndexConstituentsEPL
publicLiquidationHistoryEPL
publicUnderlyingOptionsEPL
publicExpirationOptionsEPL
publicContractsOptionsEPL
publicSettlementOptionsEPL
publicOrderbookOptionsEPL
publicTickerOptionsEPL
publicUnderlyingTickerOptionsEPL
publicCandleSticksOptionsEPL
publicMarkpriceCandleSticksOptionsEPL
publicTradeHistoryOptionsEPL
publicGetServerTimeEPL
publicFlashSwapEPL
publicListCurrencyChainEPL
walletDepositAddressEPL
walletWithdrawalRecordsEPL
walletDepositRecordsEPL
walletTransferCurrencyEPL
walletSubAccountTransferEPL
walletSubAccountTransferHistoryEPL
walletSubAccountToSubAccountTransferEPL
walletWithdrawStatusEPL
walletSubAccountBalancesEPL
walletSubAccountMarginBalancesEPL
walletSubAccountFuturesBalancesEPL
walletSubAccountCrossMarginBalancesEPL
walletSavedAddressesEPL
walletTradingFeeEPL
walletTotalBalanceEPL
walletWithdrawEPL
walletCancelWithdrawEPL
subAccountEPL
spotTradingFeeEPL
spotAccountsEPL
spotGetOpenOrdersEPL
spotClosePositionEPL
spotBatchOrdersEPL
spotPlaceOrderEPL
spotGetOrdersEPL
spotCancelAllOpenOrdersEPL
spotCancelBatchOrdersEPL
spotGetOrderEPL
spotAmendOrderEPL
spotCancelSingleOrderEPL
spotTradingHistoryEPL
spotCountdownCancelEPL
spotCreateTriggerOrderEPL
spotGetTriggerOrderListEPL
spotCancelTriggerOrdersEPL
spotGetTriggerOrderEPL
spotCancelTriggerOrderEPL
marginAccountListEPL
marginAccountBalanceEPL
marginFundingAccountListEPL
marginLendBorrowEPL
marginAllLoansEPL
marginMergeLendingLoansEPL
marginGetLoanEPL
marginModifyLoanEPL
marginCancelLoanEPL
marginRepayLoanEPL
marginListLoansEPL
marginRepaymentRecordEPL
marginSingleRecordEPL
marginModifyLoanRecordEPL
marginAutoRepayEPL
marginGetAutoRepaySettingsEPL
marginGetMaxTransferEPL
marginGetMaxBorrowEPL
marginSupportedCurrencyCrossListEPL
marginSupportedCurrencyCrossEPL
marginAccountsEPL
marginAccountHistoryEPL
marginCreateCrossBorrowLoanEPL
marginExecuteRepaymentsEPL
marginGetCrossMarginRepaymentsEPL
marginGetMaxTransferCrossEPL
marginGetMaxBorrowCrossEPL
marginGetCrossBorrowHistoryEPL
marginGetBorrowEPL
flashSwapOrderEPL
flashGetOrdersEPL
flashGetOrderEPL
flashOrderReviewEPL
privateUnifiedSpotEPL
perpetualAccountEPL
perpetualAccountBooksEPL
perpetualPositionsEPL
perpetualPositionEPL
perpetualUpdateMarginEPL
perpetualUpdateLeverageEPL
perpetualUpdateRiskEPL
perpetualToggleDualModeEPL
perpetualPositionsDualModeEPL
perpetualUpdateMarginDualModeEPL
perpetualUpdateLeverageDualModeEPL
perpetualUpdateRiskDualModeEPL
perpetualSubmitOrderEPL
perpetualGetOrdersEPL
perpetualSubmitBatchOrdersEPL
perpetualFetchOrderEPL
perpetualCancelOrderEPL
perpetualAmendOrderEPL
perpetualTradingHistoryEPL
perpetualClosePositionEPL
perpetualLiquidationHistoryEPL
perpetualCancelTriggerOrdersEPL
perpetualSubmitTriggerOrderEPL
perpetualListOpenOrdersEPL
perpetualCancelOpenOrdersEPL
perpetualGetTriggerOrderEPL
perpetualCancelTriggerOrderEPL
deliveryAccountEPL
deliveryAccountBooksEPL
deliveryPositionsEPL
deliveryUpdateMarginEPL
deliveryUpdateLeverageEPL
deliveryUpdateRiskLimitEPL
deliverySubmitOrderEPL
deliveryGetOrdersEPL
deliveryCancelOrdersEPL
deliveryGetOrderEPL
deliveryCancelOrderEPL
deliveryTradingHistoryEPL
deliveryCloseHistoryEPL
deliveryLiquidationHistoryEPL
deliverySettlementHistoryEPL
deliveryGetTriggerOrdersEPL
deliveryAutoOrdersEPL
deliveryCancelTriggerOrdersEPL
deliveryGetTriggerOrderEPL
deliveryCancelTriggerOrderEPL
optionsSettlementsEPL
optionsAccountsEPL
optionsAccountBooksEPL
optionsPositions
optionsLiquidationHistoryEPL
optionsSubmitOrderEPL
optionsOrdersEPL
optionsCancelOrdersEPL
optionsOrderEPL
optionsCancelOrderEPL
optionsTradingHistoryEPL
websocketRateLimitNotNeededEPL
)
// GetRateLimit returns the rate limiter for the exchange
func GetRateLimit() request.RateLimitDefinitions {
return request.RateLimitDefinitions{
spotDefaultEPL: request.NewRateLimitWithWeight(oneSecondInterval, spotPublicRate, 1),
spotPrivateEPL: request.NewRateLimitWithWeight(oneSecondInterval, spotPrivateRate, 1),
spotPlaceOrdersEPL: request.NewRateLimitWithWeight(oneSecondInterval, spotPlaceOrdersRate, 1),
spotCancelOrdersEPL: request.NewRateLimitWithWeight(oneSecondInterval, spotCancelOrdersRate, 1),
perpetualSwapDefaultEPL: request.NewRateLimitWithWeight(oneSecondInterval, perpetualSwapPublicRate, 1),
perpetualSwapPlaceOrdersEPL: request.NewRateLimitWithWeight(oneSecondInterval, perpetualSwapPlaceOrdersRate, 1),
perpetualSwapPrivateEPL: request.NewRateLimitWithWeight(oneSecondInterval, perpetualSwapPrivateRate, 1),
perpetualSwapCancelOrdersEPL: request.NewRateLimitWithWeight(oneSecondInterval, perpetualSwapCancelOrdersRate, 1),
walletEPL: request.NewRateLimitWithWeight(oneSecondInterval, walletRate, 1),
withdrawalEPL: request.NewRateLimitWithWeight(threeSecondsInterval, withdrawalRate, 1),
}
// package level rate limits for REST API
var packageRateLimits = request.RateLimitDefinitions{
publicOrderbookSpotEPL: standardRateLimit(),
publicMarketTradesSpotEPL: standardRateLimit(),
publicCandleStickSpotEPL: standardRateLimit(),
publicTickersSpotEPL: standardRateLimit(),
publicCurrencyPairDetailSpotEPL: standardRateLimit(),
publicListCurrencyPairsSpotEPL: standardRateLimit(),
publicCurrenciesSpotEPL: standardRateLimit(),
publicCurrencyPairsMarginEPL: standardRateLimit(),
publicOrderbookMarginEPL: standardRateLimit(),
publicInsuranceDeliveryEPL: standardRateLimit(),
publicDeliveryContractsEPL: standardRateLimit(),
publicOrderbookDeliveryEPL: standardRateLimit(),
publicTradingHistoryDeliveryEPL: standardRateLimit(),
publicCandleSticksDeliveryEPL: standardRateLimit(),
publicTickersDeliveryEPL: standardRateLimit(),
publicFuturesContractsEPL: standardRateLimit(),
publicOrderbookFuturesEPL: standardRateLimit(),
publicTradingHistoryFuturesEPL: standardRateLimit(),
publicCandleSticksFuturesEPL: standardRateLimit(),
publicPremiumIndexEPL: standardRateLimit(),
publicTickersFuturesEPL: standardRateLimit(),
publicFundingRatesEPL: standardRateLimit(),
publicInsuranceFuturesEPL: standardRateLimit(),
publicStatsFuturesEPL: standardRateLimit(),
publicIndexConstituentsEPL: standardRateLimit(),
publicLiquidationHistoryEPL: standardRateLimit(),
publicUnderlyingOptionsEPL: standardRateLimit(),
publicExpirationOptionsEPL: standardRateLimit(),
publicContractsOptionsEPL: standardRateLimit(),
publicSettlementOptionsEPL: standardRateLimit(),
publicOrderbookOptionsEPL: standardRateLimit(),
publicTickerOptionsEPL: standardRateLimit(),
publicUnderlyingTickerOptionsEPL: standardRateLimit(),
publicCandleSticksOptionsEPL: standardRateLimit(),
publicMarkpriceCandleSticksOptionsEPL: standardRateLimit(),
publicTradeHistoryOptionsEPL: standardRateLimit(),
publicGetServerTimeEPL: standardRateLimit(),
publicFlashSwapEPL: standardRateLimit(),
publicListCurrencyChainEPL: standardRateLimit(),
walletDepositAddressEPL: standardRateLimit(),
walletWithdrawalRecordsEPL: standardRateLimit(),
walletDepositRecordsEPL: standardRateLimit(),
walletTransferCurrencyEPL: personalAccountRateLimit(),
walletSubAccountTransferEPL: personalAccountRateLimit(),
walletSubAccountTransferHistoryEPL: standardRateLimit(),
walletSubAccountToSubAccountTransferEPL: personalAccountRateLimit(),
walletWithdrawStatusEPL: standardRateLimit(),
walletSubAccountBalancesEPL: personalAccountRateLimit(),
walletSubAccountMarginBalancesEPL: personalAccountRateLimit(),
walletSubAccountFuturesBalancesEPL: personalAccountRateLimit(),
walletSubAccountCrossMarginBalancesEPL: personalAccountRateLimit(),
walletSavedAddressesEPL: standardRateLimit(),
walletTradingFeeEPL: standardRateLimit(),
walletTotalBalanceEPL: personalAccountRateLimit(),
walletWithdrawEPL: withdrawFromWalletRateLimit(),
walletCancelWithdrawEPL: standardRateLimit(),
subAccountEPL: personalAccountRateLimit(),
spotTradingFeeEPL: standardRateLimit(),
spotAccountsEPL: standardRateLimit(),
spotGetOpenOrdersEPL: standardRateLimit(),
spotClosePositionEPL: orderCloseRateLimit(),
spotBatchOrdersEPL: spotOrderPlacementRateLimit(),
spotPlaceOrderEPL: spotOrderPlacementRateLimit(),
spotGetOrdersEPL: standardRateLimit(),
spotCancelAllOpenOrdersEPL: orderCloseRateLimit(),
spotCancelBatchOrdersEPL: orderCloseRateLimit(),
spotGetOrderEPL: standardRateLimit(),
spotAmendOrderEPL: spotOrderPlacementRateLimit(),
spotCancelSingleOrderEPL: orderCloseRateLimit(),
spotTradingHistoryEPL: standardRateLimit(),
spotCountdownCancelEPL: orderCloseRateLimit(),
spotCreateTriggerOrderEPL: spotOrderPlacementRateLimit(),
spotGetTriggerOrderListEPL: standardRateLimit(),
spotCancelTriggerOrdersEPL: orderCloseRateLimit(),
spotGetTriggerOrderEPL: standardRateLimit(),
spotCancelTriggerOrderEPL: orderCloseRateLimit(),
marginAccountListEPL: otherPrivateEndpointRateLimit(),
marginAccountBalanceEPL: otherPrivateEndpointRateLimit(),
marginFundingAccountListEPL: otherPrivateEndpointRateLimit(),
marginLendBorrowEPL: otherPrivateEndpointRateLimit(),
marginAllLoansEPL: otherPrivateEndpointRateLimit(),
marginMergeLendingLoansEPL: otherPrivateEndpointRateLimit(),
marginGetLoanEPL: otherPrivateEndpointRateLimit(),
marginModifyLoanEPL: otherPrivateEndpointRateLimit(),
marginCancelLoanEPL: otherPrivateEndpointRateLimit(),
marginRepayLoanEPL: otherPrivateEndpointRateLimit(),
marginListLoansEPL: otherPrivateEndpointRateLimit(),
marginRepaymentRecordEPL: otherPrivateEndpointRateLimit(),
marginSingleRecordEPL: otherPrivateEndpointRateLimit(),
marginModifyLoanRecordEPL: otherPrivateEndpointRateLimit(),
marginAutoRepayEPL: otherPrivateEndpointRateLimit(),
marginGetAutoRepaySettingsEPL: otherPrivateEndpointRateLimit(),
marginGetMaxTransferEPL: otherPrivateEndpointRateLimit(),
marginGetMaxBorrowEPL: otherPrivateEndpointRateLimit(),
marginSupportedCurrencyCrossListEPL: otherPrivateEndpointRateLimit(),
marginSupportedCurrencyCrossEPL: otherPrivateEndpointRateLimit(),
marginAccountsEPL: otherPrivateEndpointRateLimit(),
marginAccountHistoryEPL: otherPrivateEndpointRateLimit(),
marginCreateCrossBorrowLoanEPL: otherPrivateEndpointRateLimit(),
marginExecuteRepaymentsEPL: otherPrivateEndpointRateLimit(),
marginGetCrossMarginRepaymentsEPL: otherPrivateEndpointRateLimit(),
marginGetMaxTransferCrossEPL: otherPrivateEndpointRateLimit(),
marginGetMaxBorrowCrossEPL: otherPrivateEndpointRateLimit(),
marginGetCrossBorrowHistoryEPL: otherPrivateEndpointRateLimit(),
marginGetBorrowEPL: otherPrivateEndpointRateLimit(),
flashSwapOrderEPL: otherPrivateEndpointRateLimit(),
flashGetOrdersEPL: otherPrivateEndpointRateLimit(),
flashGetOrderEPL: otherPrivateEndpointRateLimit(),
flashOrderReviewEPL: otherPrivateEndpointRateLimit(),
perpetualAccountEPL: standardRateLimit(),
perpetualAccountBooksEPL: standardRateLimit(),
perpetualPositionsEPL: standardRateLimit(),
perpetualPositionEPL: standardRateLimit(),
perpetualUpdateMarginEPL: standardRateLimit(),
perpetualUpdateLeverageEPL: standardRateLimit(),
perpetualUpdateRiskEPL: standardRateLimit(),
perpetualToggleDualModeEPL: standardRateLimit(),
perpetualPositionsDualModeEPL: standardRateLimit(),
perpetualUpdateMarginDualModeEPL: standardRateLimit(),
perpetualUpdateLeverageDualModeEPL: standardRateLimit(),
perpetualUpdateRiskDualModeEPL: standardRateLimit(),
perpetualSubmitOrderEPL: perpetualOrderplacementRateLimit(),
perpetualGetOrdersEPL: standardRateLimit(),
perpetualSubmitBatchOrdersEPL: perpetualOrderplacementRateLimit(),
perpetualFetchOrderEPL: standardRateLimit(),
perpetualCancelOrderEPL: orderCloseRateLimit(),
perpetualAmendOrderEPL: perpetualOrderplacementRateLimit(),
perpetualTradingHistoryEPL: standardRateLimit(),
perpetualClosePositionEPL: orderCloseRateLimit(),
perpetualLiquidationHistoryEPL: standardRateLimit(),
perpetualCancelTriggerOrdersEPL: orderCloseRateLimit(),
perpetualSubmitTriggerOrderEPL: perpetualOrderplacementRateLimit(),
perpetualListOpenOrdersEPL: standardRateLimit(),
perpetualCancelOpenOrdersEPL: orderCloseRateLimit(),
perpetualGetTriggerOrderEPL: standardRateLimit(),
perpetualCancelTriggerOrderEPL: orderCloseRateLimit(),
deliveryAccountEPL: standardRateLimit(),
deliveryAccountBooksEPL: standardRateLimit(),
deliveryPositionsEPL: standardRateLimit(),
deliveryUpdateMarginEPL: standardRateLimit(),
deliveryUpdateLeverageEPL: standardRateLimit(),
deliveryUpdateRiskLimitEPL: standardRateLimit(),
deliverySubmitOrderEPL: deliverySubmitCancelAmendRateLimit(),
deliveryGetOrdersEPL: standardRateLimit(),
deliveryCancelOrdersEPL: deliverySubmitCancelAmendRateLimit(),
deliveryGetOrderEPL: standardRateLimit(),
deliveryCancelOrderEPL: deliverySubmitCancelAmendRateLimit(),
deliveryTradingHistoryEPL: standardRateLimit(),
deliveryCloseHistoryEPL: standardRateLimit(),
deliveryLiquidationHistoryEPL: standardRateLimit(),
deliverySettlementHistoryEPL: standardRateLimit(),
deliveryGetTriggerOrdersEPL: standardRateLimit(),
deliveryAutoOrdersEPL: standardRateLimit(),
deliveryCancelTriggerOrdersEPL: deliverySubmitCancelAmendRateLimit(),
deliveryGetTriggerOrderEPL: standardRateLimit(),
deliveryCancelTriggerOrderEPL: deliverySubmitCancelAmendRateLimit(),
optionsSettlementsEPL: standardRateLimit(),
optionsAccountsEPL: standardRateLimit(),
optionsAccountBooksEPL: standardRateLimit(),
optionsPositions: standardRateLimit(),
optionsLiquidationHistoryEPL: standardRateLimit(),
optionsSubmitOrderEPL: optionsSubmitCancelAmendRateLimit(),
optionsOrdersEPL: standardRateLimit(),
optionsCancelOrdersEPL: optionsSubmitCancelAmendRateLimit(),
optionsOrderEPL: standardRateLimit(),
optionsCancelOrderEPL: optionsSubmitCancelAmendRateLimit(),
optionsTradingHistoryEPL: standardRateLimit(),
privateUnifiedSpotEPL: standardRateLimit(),
websocketRateLimitNotNeededEPL: nil, // no rate limit for certain websocket functions
}
func standardRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second*10, 200, 1)
}
func personalAccountRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second*10, 80, 1)
}
func orderCloseRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second, 200, 1)
}
func spotOrderPlacementRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second, 10, 1)
}
func otherPrivateEndpointRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second*10, 150, 1)
}
func perpetualOrderplacementRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second, 100, 1)
}
func deliverySubmitCancelAmendRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second*10, 500, 1)
}
func optionsSubmitCancelAmendRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second, 200, 1)
}
func withdrawFromWalletRateLimit() *request.RateLimiterWithWeight {
return request.NewRateLimitWithWeight(time.Second*3, 1, 1)
}

View File

@@ -0,0 +1,16 @@
package gateio
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRateLimits(t *testing.T) {
for epl := range optionsTradingHistoryEPL {
if epl == 0 {
continue
}
assert.NotEmptyf(t, packageRateLimits[epl], "Empty rate limit not found for const %v", epl)
}
}