Gateio: Add unified account API endpoint support (#1573)

* gateio: Add unified account fetching

* Add test change name add commentary

* glorious: nits

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2024-07-23 13:21:13 +10:00
committed by GitHub
parent 34d9920c78
commit 45ef2b1445
3 changed files with 58 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ const (
gateioSpotCandlesticks = "spot/candlesticks"
gateioSpotFeeRate = "spot/fee"
gateioSpotAccounts = "spot/accounts"
gateioUnifiedAccounts = "unified/accounts"
gateioSpotBatchOrders = "spot/batch_orders"
gateioSpotOpenOrders = "spot/open_orders"
gateioSpotClosePositionWhenCrossCurrencyDisabledPath = "spot/cross_liquidate_orders"
@@ -552,6 +553,16 @@ func (g *Gateio) GetSpotAccounts(ctx context.Context, ccy currency.Code) ([]Spot
exchange.RestSpot, spotPrivateEPL, http.MethodGet, gateioSpotAccounts, params, nil, &response)
}
// GetUnifiedAccount retrieves unified account.
func (g *Gateio) GetUnifiedAccount(ctx context.Context, ccy currency.Code) (*UnifiedUserAccount, error) {
params := url.Values{}
if !ccy.IsEmpty() {
params.Set("currency", ccy.String())
}
var response UnifiedUserAccount
return &response, g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, spotPrivateEPL, http.MethodGet, gateioUnifiedAccounts, params, nil, &response)
}
// CreateBatchOrders Create a batch of orders Batch orders requirements: custom order field text is required At most 4 currency pairs,
// maximum 10 orders each, are allowed in one request No mixture of spot orders and margin orders, i.e. account must be identical for all orders
func (g *Gateio) CreateBatchOrders(ctx context.Context, args []CreateOrderRequestData) ([]SpotOrder, error) {

View File

@@ -3598,3 +3598,12 @@ func TestGetCurrencyTradeURL(t *testing.T) {
}
}
}
func TestGetUnifiedAccount(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, g)
// Requires unified account to be enabled for this to function.
payload, err := g.GetUnifiedAccount(context.Background(), currency.EMPTYCODE)
require.NoError(t, err)
require.NotEmpty(t, payload)
}

View File

@@ -2689,3 +2689,41 @@ type PriceAndAmount struct {
Amount types.Number `json:"amount,omitempty"`
Price types.Number `json:"price,omitempty"`
}
// BalanceDetails represents a user's balance details
type BalanceDetails struct {
Available types.Number `json:"available"`
Freeze types.Number `json:"freeze"`
Borrowed types.Number `json:"borrowed"`
NegativeLiabilities types.Number `json:"negative_liab"`
FuturesPosLiabilities types.Number `json:"futures_pos_liab"`
Equity types.Number `json:"equity"`
TotalFreeze types.Number `json:"total_freeze"`
TotalLiabilities types.Number `json:"total_liab"`
SpotInUse types.Number `json:"spot_in_use"`
Funding types.Number `json:"funding"`
FundingVersion types.Number `json:"funding_version"`
}
// UnifiedUserAccount represents a unified user account
type UnifiedUserAccount struct {
UserID int64 `json:"user_id"`
Locked bool `json:"locked"`
Balances map[currency.Code]BalanceDetails `json:"balances"`
Total types.Number `json:"total"`
Borrowed types.Number `json:"borrowed"`
TotalInitialMargin types.Number `json:"total_initial_margin"`
TotalMarginBalance types.Number `json:"total_margin_balance"`
TotalMaintenanceMargin types.Number `json:"total_maintenance_margin"`
TotalInitialMarginRate types.Number `json:"total_initial_margin_rate"`
TotalMaintenanceMarginRate types.Number `json:"total_maintenance_margin_rate"`
TotalAvailableMargin types.Number `json:"total_available_margin"`
UnifiedAccountTotal types.Number `json:"unified_account_total"`
UnifiedAccountTotalLiabilities types.Number `json:"unified_account_total_liab"`
UnifiedAccountTotalEquity types.Number `json:"unified_account_total_equity"`
Leverage types.Number `json:"leverage"`
SpotOrderLoss types.Number `json:"spot_order_loss"`
SpotHedge bool `json:"spot_hedge"`
UseFunding bool `json:"use_funding"`
RefreshTime Time `json:"refresh_time"`
}