Skip to content

Commit

Permalink
Add /v2/private/account/api-key endpoint (#71)
Browse files Browse the repository at this point in the history
* feat(futuresV2): add `/v2/private/account/api-key` endpoint

* fix: from CR
  • Loading branch information
rtunazzz authored Jan 23, 2023
1 parent 9cfe1ae commit dd40aec
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
38 changes: 38 additions & 0 deletions future_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bybit
import (
"encoding/json"
"net/url"
"time"

"github.com/google/go-querystring/query"
)
Expand All @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions future_inverse_future.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions future_inverse_perpetual.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions future_usdt_perpetual.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit dd40aec

Please sign in to comment.