diff --git a/exchanges/gateio/gateio.go b/exchanges/gateio/gateio.go index b3abf8c7..00517675 100644 --- a/exchanges/gateio/gateio.go +++ b/exchanges/gateio/gateio.go @@ -1345,6 +1345,28 @@ func (g *Gateio) GetUsersTotalBalance(ctx context.Context, ccy currency.Code) (* return response, g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, walletTotalBalanceEPL, http.MethodGet, walletTotalBalance, params, nil, &response) } +// ConvertSmallBalances converts small balances of provided currencies into GT. +// If no currencies are provided, all supported currencies will be converted +// See [this documentation](https://www.gate.io/help/guide/functional_guidelines/22367) for details and restrictions. +func (g *Gateio) ConvertSmallBalances(ctx context.Context, currs ...currency.Code) error { + currencyList := make([]string, len(currs)) + for i := range currs { + if currs[i].IsEmpty() { + return currency.ErrCurrencyCodeEmpty + } + currencyList[i] = currs[i].Upper().String() + } + + payload := struct { + Currency []string `json:"currency"` + IsAll bool `json:"is_all"` + }{ + Currency: currencyList, + IsAll: len(currs) == 0, + } + return g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, walletConvertSmallBalancesEPL, http.MethodPost, "wallet/small_balance", nil, payload, nil) +} + // ********************************* Margin ******************************************* // GetMarginSupportedCurrencyPairs retrieves margin supported currency pairs. @@ -3686,3 +3708,15 @@ func getSettlementFromCurrency(currencyPair currency.Pair) (settlement currency. return currency.EMPTYCODE, fmt.Errorf("%w %v", errCannotParseSettlementCurrency, currencyPair) } } + +// GetAccountDetails retrieves account details +func (g *Gateio) GetAccountDetails(ctx context.Context) (*AccountDetails, error) { + var resp *AccountDetails + return resp, g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, spotAccountsEPL, http.MethodGet, "account/detail", nil, nil, &resp) +} + +// GetUserTransactionRateLimitInfo retrieves user transaction rate limit info +func (g *Gateio) GetUserTransactionRateLimitInfo(ctx context.Context) ([]UserTransactionRateLimitInfo, error) { + var resp []UserTransactionRateLimitInfo + return resp, g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, spotAccountsEPL, http.MethodGet, "account/rate_limit", nil, nil, &resp) +} diff --git a/exchanges/gateio/gateio_test.go b/exchanges/gateio/gateio_test.go index 5ef7980d..be56e3e9 100644 --- a/exchanges/gateio/gateio_test.go +++ b/exchanges/gateio/gateio_test.go @@ -3887,3 +3887,30 @@ func TestDeriveFuturesWebsocketOrderResponses(t *testing.T) { }) } } + +func TestConvertSmallBalances(t *testing.T) { + t.Parallel() + err := g.ConvertSmallBalances(t.Context(), currency.EMPTYCODE) + require.ErrorIs(t, err, currency.ErrCurrencyCodeEmpty) + + sharedtestvalues.SkipTestIfCredentialsUnset(t, g, canManipulateRealOrders) + + err = g.ConvertSmallBalances(t.Context(), currency.F16) + require.NoError(t, err) +} + +func TestGetAccountDetails(t *testing.T) { + t.Parallel() + sharedtestvalues.SkipTestIfCredentialsUnset(t, g) + got, err := g.GetAccountDetails(t.Context()) + require.NoError(t, err) + require.NotEmpty(t, got) +} + +func TestGetUserTransactionRateLimitInfo(t *testing.T) { + t.Parallel() + sharedtestvalues.SkipTestIfCredentialsUnset(t, g) + got, err := g.GetUserTransactionRateLimitInfo(t.Context()) + require.NoError(t, err) + require.NotEmpty(t, got) +} diff --git a/exchanges/gateio/gateio_types.go b/exchanges/gateio/gateio_types.go index 663b1830..1c0d174d 100644 --- a/exchanges/gateio/gateio_types.go +++ b/exchanges/gateio/gateio_types.go @@ -2690,3 +2690,25 @@ type UnifiedUserAccount struct { UseFunding bool `json:"use_funding"` RefreshTime types.Time `json:"refresh_time"` } + +// AccountDetails represents account detail information +type AccountDetails struct { + IPWhitelist []string `json:"ip_whitelist"` + CurrencyPairs []string `json:"currency_pairs"` + UserID int64 `json:"user_id"` + VIPTier int64 `json:"tier"` + VIPTierExpireTime time.Time `json:"tier_expire_time"` + Key struct { + Mode int64 `json:"mode"` // mode: 1 - classic account 2 - portfolio margin account + } `json:"key"` + CopyTradingRole int64 `json:"copy_trading_role"` // User role: 0 - Ordinary user 1 - Order leader 2 - Follower 3 - Order leader and follower +} + +// UserTransactionRateLimitInfo represents user transaction rate limit information +type UserTransactionRateLimitInfo struct { + Type string `json:"type"` + Tier types.Number `json:"tier"` + Ratio types.Number `json:"ratio"` + MainRatio types.Number `json:"main_ratio"` + UpdatedAt types.Time `json:"updated_at"` +} diff --git a/exchanges/gateio/ratelimiter.go b/exchanges/gateio/ratelimiter.go index 870b4d9b..5e77b2d8 100644 --- a/exchanges/gateio/ratelimiter.go +++ b/exchanges/gateio/ratelimiter.go @@ -68,6 +68,7 @@ const ( walletSavedAddressesEPL walletTradingFeeEPL walletTotalBalanceEPL + walletConvertSmallBalancesEPL walletWithdrawEPL walletCancelWithdrawEPL @@ -256,6 +257,7 @@ var packageRateLimits = request.RateLimitDefinitions{ walletSavedAddressesEPL: standardRateLimit(), walletTradingFeeEPL: standardRateLimit(), walletTotalBalanceEPL: personalAccountRateLimit(), + walletConvertSmallBalancesEPL: personalAccountRateLimit(), walletWithdrawEPL: withdrawFromWalletRateLimit(), walletCancelWithdrawEPL: standardRateLimit(),