From dd40aeca79aab3764e4d11675ca59a8488307097 Mon Sep 17 00:00:00 2001 From: rtuna <38296319+rtunazzz@users.noreply.github.com> Date: Tue, 24 Jan 2023 00:48:59 +0100 Subject: [PATCH] Add `/v2/private/account/api-key` endpoint (#71) * feat(futuresV2): add `/v2/private/account/api-key` endpoint * fix: from CR --- README.md | 3 ++ future_common.go | 38 +++++++++++++++++++ future_inverse_future.go | 1 + future_inverse_perpetual.go | 1 + future_usdt_perpetual.go | 1 + .../future_inverse_future_test.go | 19 ++++++++++ .../testdata/v2-private-api-key-info.json | 1 + .../future_inverse_perpetual_test.go | 19 ++++++++++ .../testdata/v2-private-api-key-info.json | 1 + .../future_usdt_perpetual_test.go | 19 ++++++++++ .../testdata/v2-private-api-key-info.json | 1 + 11 files changed, 104 insertions(+) create mode 100644 integrationtest/future-inverse-future/testdata/v2-private-api-key-info.json create mode 100644 integrationtest/future-inverse-perpetual/testdata/v2-private-api-key-info.json create mode 100644 integrationtest/future-usdt-perpetual/testdata/v2-private-api-key-info.json diff --git a/README.md b/README.md index 616b192..6d44490 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ The following API endpoints have been implemented - `/v2/private/position/list` My Position - `/v2/private/position/trading-stop` Set Trading-Stop - `/v2/private/position/leverage/save` Set Leverage +- `/v2/private/account/api-key` API Key info ##### Wallet Data Endpoints @@ -170,6 +171,7 @@ The following API endpoints have been implemented - `/private/linear/position/set-leverage` Set Leverage - `/private/linear/position/trading-stop` Set Trading-Stop - `/private/linear/trade/execution/list` User Trade Records +- `/v2/private/account/api-key` API Key info ##### Wallet Data Endpoints @@ -205,6 +207,7 @@ The following API endpoints have been implemented - `/futures/private/position/list` My Position - `/futures/private/position/trading-stop` Set Trading-Stop - `/futures/private/position/leverage/save` Set Leverage +- `/v2/private/account/api-key` API Key info ##### Wallet Data Endpoints diff --git a/future_common.go b/future_common.go index 3a851c5..4e5dc39 100644 --- a/future_common.go +++ b/future_common.go @@ -3,6 +3,7 @@ package bybit import ( "encoding/json" "net/url" + "time" "github.com/google/go-querystring/query" ) @@ -12,6 +13,43 @@ type FutureCommonService struct { client *Client } +// APIKeyInfoResult : +type APIKeyInfoResult struct { + APIKey string `json:"api_key"` + Type string `json:"type"` + UserID int `json:"user_id"` + InviterID int `json:"inviter_id"` + Ips []string `json:"ips"` + Note string `json:"note"` + Permissions []string `json:"permissions"` + CreatedAt time.Time `json:"created_at"` + ExpiredAt time.Time `json:"expired_at"` + ReadOnly bool `json:"read_only"` + VipLevel string `json:"vip_level"` + MktMakerLevel string `json:"mkt_maker_level"` + AffiliateID int `json:"affiliate_id"` +} + +// APIKeyInfoResponse : +type APIKeyInfoResponse struct { + CommonResponse `json:",inline"` + Result []APIKeyInfoResult `json:"result"` +} + +// APIKeyInfo : +func (s *FutureCommonService) APIKeyInfo() (*APIKeyInfoResponse, error) { + var ( + res APIKeyInfoResponse + query url.Values + ) + + if err := s.client.getPrivately("v2/private/account/api-key", query, &res); err != nil { + return nil, err + } + + return &res, nil +} + // BalanceResponse : type BalanceResponse struct { CommonResponse `json:",inline"` diff --git a/future_inverse_future.go b/future_inverse_future.go index 3328081..80859fb 100644 --- a/future_inverse_future.go +++ b/future_inverse_future.go @@ -36,6 +36,7 @@ type FutureInverseFutureServiceI interface { ListFuturesPositions(SymbolFuture) (*ListFuturesPositionsResponse, error) FuturesTradingStop(FuturesTradingStopParam) (*FuturesTradingStopResponse, error) FuturesSaveLeverage(FuturesSaveLeverageParam) (*FuturesSaveLeverageResponse, error) + APIKeyInfo() (*APIKeyInfoResponse, error) // Wallet Data Endpoints Balance(Coin) (*BalanceResponse, error) diff --git a/future_inverse_perpetual.go b/future_inverse_perpetual.go index 881c826..4915338 100644 --- a/future_inverse_perpetual.go +++ b/future_inverse_perpetual.go @@ -38,6 +38,7 @@ type FutureInversePerpetualServiceI interface { ListPositions() (*ListPositionsResponse, error) TradingStop(TradingStopParam) (*TradingStopResponse, error) SaveLeverage(SaveLeverageParam) (*SaveLeverageResponse, error) + APIKeyInfo() (*APIKeyInfoResponse, error) // Wallet Data Endpoints Balance(Coin) (*BalanceResponse, error) diff --git a/future_usdt_perpetual.go b/future_usdt_perpetual.go index ae2a4a0..b03f274 100644 --- a/future_usdt_perpetual.go +++ b/future_usdt_perpetual.go @@ -36,6 +36,7 @@ type FutureUSDTPerpetualServiceI interface { SaveLinearLeverage(SaveLinearLeverageParam) (*SaveLinearLeverageResponse, error) LinearTradingStop(LinearTradingStopParam) (*LinearTradingStopResponse, error) LinearExecutionList(LinearExecutionListParam) (*LinearExecutionListResponse, error) + APIKeyInfo() (*APIKeyInfoResponse, error) // Wallet Data Endpoints Balance(Coin) (*BalanceResponse, error) diff --git a/integrationtest/future-inverse-future/future_inverse_future_test.go b/integrationtest/future-inverse-future/future_inverse_future_test.go index 1e88bab..9ff5e03 100644 --- a/integrationtest/future-inverse-future/future_inverse_future_test.go +++ b/integrationtest/future-inverse-future/future_inverse_future_test.go @@ -11,6 +11,25 @@ import ( "github.com/stretchr/testify/require" ) +func TestAPIKeyInfo(t *testing.T) { + t.Run("ok", func(t *testing.T) { + client := bybit.NewTestClient().WithAuthFromEnv() + res, err := client.Future().InverseFuture().APIKeyInfo() + require.NoError(t, err) + { + goldenFilename := "./testdata/v2-private-api-key-info.json" + testhelper.Compare(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + } + }) + + t.Run("auth error", func(t *testing.T) { + client := bybit.NewTestClient() + _, err := client.Future().InverseFuture().APIKeyInfo() + require.Error(t, err) + }) +} + func TestBalance(t *testing.T) { t.Run("ok", func(t *testing.T) { client := bybit.NewTestClient().WithAuthFromEnv() diff --git a/integrationtest/future-inverse-future/testdata/v2-private-api-key-info.json b/integrationtest/future-inverse-future/testdata/v2-private-api-key-info.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/integrationtest/future-inverse-future/testdata/v2-private-api-key-info.json @@ -0,0 +1 @@ +{} diff --git a/integrationtest/future-inverse-perpetual/future_inverse_perpetual_test.go b/integrationtest/future-inverse-perpetual/future_inverse_perpetual_test.go index 1b9076e..2b44ceb 100644 --- a/integrationtest/future-inverse-perpetual/future_inverse_perpetual_test.go +++ b/integrationtest/future-inverse-perpetual/future_inverse_perpetual_test.go @@ -11,6 +11,25 @@ import ( "github.com/stretchr/testify/require" ) +func TestAPIKeyInfo(t *testing.T) { + t.Run("ok", func(t *testing.T) { + client := bybit.NewTestClient().WithAuthFromEnv() + res, err := client.Future().InversePerpetual().APIKeyInfo() + require.NoError(t, err) + { + goldenFilename := "./testdata/v2-private-api-key-info.json" + testhelper.Compare(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + } + }) + + t.Run("auth error", func(t *testing.T) { + client := bybit.NewTestClient() + _, err := client.Future().InversePerpetual().APIKeyInfo() + require.Error(t, err) + }) +} + func TestBalance(t *testing.T) { t.Run("ok", func(t *testing.T) { client := bybit.NewTestClient().WithAuthFromEnv() diff --git a/integrationtest/future-inverse-perpetual/testdata/v2-private-api-key-info.json b/integrationtest/future-inverse-perpetual/testdata/v2-private-api-key-info.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/integrationtest/future-inverse-perpetual/testdata/v2-private-api-key-info.json @@ -0,0 +1 @@ +{} diff --git a/integrationtest/future-usdt-perpetual/future_usdt_perpetual_test.go b/integrationtest/future-usdt-perpetual/future_usdt_perpetual_test.go index af4ae96..5124f17 100644 --- a/integrationtest/future-usdt-perpetual/future_usdt_perpetual_test.go +++ b/integrationtest/future-usdt-perpetual/future_usdt_perpetual_test.go @@ -11,6 +11,25 @@ import ( "github.com/stretchr/testify/require" ) +func TestAPIKeyInfo(t *testing.T) { + t.Run("ok", func(t *testing.T) { + client := bybit.NewTestClient().WithAuthFromEnv() + res, err := client.Future().USDTPerpetual().APIKeyInfo() + require.NoError(t, err) + { + goldenFilename := "./testdata/v2-private-api-key-info.json" + testhelper.Compare(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + } + }) + + t.Run("auth error", func(t *testing.T) { + client := bybit.NewTestClient() + _, err := client.Future().USDTPerpetual().APIKeyInfo() + require.Error(t, err) + }) +} + func TestBalance(t *testing.T) { t.Run("ok", func(t *testing.T) { client := bybit.NewTestClient().WithAuthFromEnv() diff --git a/integrationtest/future-usdt-perpetual/testdata/v2-private-api-key-info.json b/integrationtest/future-usdt-perpetual/testdata/v2-private-api-key-info.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/integrationtest/future-usdt-perpetual/testdata/v2-private-api-key-info.json @@ -0,0 +1 @@ +{}