From f4a29f19b1bb52f9e880f54fbf8f11dca388811d Mon Sep 17 00:00:00 2001 From: Rostislav <43965646+lyro41@users.noreply.github.com> Date: Thu, 14 Dec 2023 03:11:04 +0300 Subject: [PATCH] Fix set-collateral-switch account endpoint for REST API V5 (#149) * fix v5 account set collateral coin * test(integration): v5 account set collateral coin --------- Co-authored-by: Rostislav Lyupa <> --- integrationtest/v5/account/account_test.go | 5 ++++- v5_account_service.go | 26 +++++++--------------- v5_account_service_test.go | 8 ++++--- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/integrationtest/v5/account/account_test.go b/integrationtest/v5/account/account_test.go index 23ed4c5..a15bdf2 100644 --- a/integrationtest/v5/account/account_test.go +++ b/integrationtest/v5/account/account_test.go @@ -63,7 +63,10 @@ func TestGetCollateralInfo(t *testing.T) { func TestSetCollateralCoin(t *testing.T) { client := bybit.NewTestClient().WithAuthFromEnv() coins := []bybit.Coin{bybit.CoinBTC} - res, err := client.V5().Account().SetCollateralCoin(coins, bybit.CollateralSwitchV5On) + res, err := client.V5().Account().SetCollateralCoin(bybit.V5SetCollateralCoinParam{ + Coin: bybit.CoinBTC, + CollateralSwitch: bybit.CollateralSwitchV5On, + }) require.NoError(t, err) { goldenFilename := "./testdata/v5-account-set-collateral-coin.json" diff --git a/v5_account_service.go b/v5_account_service.go index aca8e52..9e07056 100644 --- a/v5_account_service.go +++ b/v5_account_service.go @@ -11,7 +11,7 @@ import ( // V5AccountServiceI : type V5AccountServiceI interface { GetWalletBalance(AccountType, []Coin) (*V5GetWalletBalanceResponse, error) - SetCollateralCoin([]Coin, CollateralSwitchV5) (*V5SetCollateralCoinResponse, error) + SetCollateralCoin(V5SetCollateralCoinParam) (*V5SetCollateralCoinResponse, error) GetCollateralInfo(V5GetCollateralInfoParam) (*V5GetCollateralInfoResponse, error) GetAccountInfo() (*V5GetAccountInfoResponse, error) GetTransactionLog(V5GetTransactionLogParam) (*V5GetTransactionLogResponse, error) @@ -98,7 +98,12 @@ func (s *V5AccountService) GetWalletBalance(at AccountType, coins []Coin) (*V5Ge // V5SetCollateralCoinParam : type V5SetCollateralCoinParam struct { - Coin Coin `json:"coin"` + // Coin: + // You cannot pass multiple coins to query + // USDT,USDC cannot be switched off + Coin Coin `json:"coin"` + + // CollateralSwitch: CollateralSwitchV5On or CollateralSwitchV5Off CollateralSwitch CollateralSwitchV5 `json:"collateralSwitch"` } @@ -109,24 +114,9 @@ type V5SetCollateralCoinResponse struct { } // SetCollateralCoin : -// -// coins: USDT,USDC cannot be switched off -// cs: CollateralSwitchV5On or CollateralSwitchV5Off -func (s *V5AccountService) SetCollateralCoin(coins []Coin, cs CollateralSwitchV5) (*V5SetCollateralCoinResponse, error) { +func (s *V5AccountService) SetCollateralCoin(param V5SetCollateralCoinParam) (*V5SetCollateralCoinResponse, error) { var res V5SetCollateralCoinResponse - param := V5SetCollateralCoinParam{ - CollateralSwitch: cs, - } - - if len(coins) > 0 { - var coinsStr []string - for _, c := range coins { - coinsStr = append(coinsStr, string(c)) - } - param.Coin = Coin(strings.Join(coinsStr, ",")) - } - body, err := json.Marshal(param) if err != nil { return nil, err diff --git a/v5_account_service_test.go b/v5_account_service_test.go index 4283bd1..63c5ab5 100644 --- a/v5_account_service_test.go +++ b/v5_account_service_test.go @@ -75,8 +75,10 @@ func TestV5Account_GetWalletBalance(t *testing.T) { func TestV5Account_SetCollateralCoin(t *testing.T) { t.Run("success", func(t *testing.T) { - coins := make([]Coin, 1) - coins[0] = CoinBTC + param := V5SetCollateralCoinParam{ + Coin: CoinBTC, + CollateralSwitch: CollateralSwitchV5On, + } path := "/v5/account/set-collateral-switch" method := http.MethodPost @@ -97,7 +99,7 @@ func TestV5Account_SetCollateralCoin(t *testing.T) { WithBaseURL(server.URL). WithAuth("test", "test") - resp, err := client.V5().Account().SetCollateralCoin(coins, CollateralSwitchV5On) + resp, err := client.V5().Account().SetCollateralCoin(param) require.NoError(t, err) require.NotNil(t, resp)