gateio: add ConvertSmallBalances, GetAccountDetails and GetUserTransactionRateLimitInfo API endpoints (#1889)

* gateio: add function ConvertSmallBalances

* glorious/Thrasher: nits/additions

* file standard

* glorious: nit

* AI: nit

* boss king: nit

* refactor: rename account detail functions and types for consistency

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2025-04-22 12:46:54 +10:00
committed by GitHub
parent 1bf3433d61
commit 977fecab19
4 changed files with 85 additions and 0 deletions

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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"`
}

View File

@@ -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(),