Skip to content

Commit

Permalink
Added new asset endpoint - coin-info for REST API V5 (#145)
Browse files Browse the repository at this point in the history
Co-authored-by: Oleksandr Demidov <ot.demidov@gmail.com>
  • Loading branch information
OleksandrDemidov and ot-demidov authored Oct 31, 2023
1 parent ceddd98 commit 1d80106
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ The following API endpoints have been implemented
- [`/v5/asset/deposit/query-sub-member-record` Get Sub Deposit Records](https://bybit-exchange.github.io/docs/v5/asset/sub-deposit-record)
- [`/v5/asset/deposit/query-internal-record` Get Internal Deposit Records](https://bybit-exchange.github.io/docs/v5/asset/internal-deposit-record)
- [`/v5/asset/withdraw/query-record` Get Withdrawal Records](https://bybit-exchange.github.io/docs/v5/asset/withdraw-record)
- [`/v5/asset/coin/query-info` Get Coin Info](https://bybit-exchange.github.io/docs/v5/asset/coin-info)

#### User

Expand Down
7 changes: 7 additions & 0 deletions integrationtest/v5/asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ func TestGetWithdrawalRecords(t *testing.T) {
testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result))
}
}

func TestGetCoinInfo(t *testing.T) {
client := bybit.NewTestClient().WithAuthFromEnv()
res, err := client.V5().Asset().GetCoinInfo(bybit.V5GetCoinInfoParam{})
require.NoError(t, err)
// Fees may be changed, skipped comparison with golden file
}
62 changes: 62 additions & 0 deletions v5_asset_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type V5AssetServiceI interface {
GetSubDepositRecords(V5GetSubDepositRecordsParam) (*V5GetSubDepositRecordsResponse, error)
GetInternalDepositRecords(V5GetInternalDepositRecordsParam) (*V5GetInternalDepositRecordsResponse, error)
GetWithdrawalRecords(V5GetWithdrawalRecordsParam) (*V5GetWithdrawalRecordsResponse, error)
GetCoinInfo(V5GetCoinInfoParam) (*V5GetCoinInfoResponse, error)
}

// V5AssetService :
Expand Down Expand Up @@ -291,3 +292,64 @@ func (s *V5AssetService) GetWithdrawalRecords(param V5GetWithdrawalRecordsParam)

return &res, nil
}

// V5GetCoinInfoParam :
type V5GetCoinInfoParam struct {
Coin *Coin `url:"coin,omitempty"`
}

// V5GetCoinInfoResponse :
type V5GetCoinInfoResponse struct {
CommonV5Response `json:",inline"`
Result V5GetCoinInfoResult `json:"result"`
}

// V5GetCoinInfoResult :
type V5GetCoinInfoResult struct {
Rows V5GetCoinInfoRows `json:"rows"`
NextPageCursor string `json:"nextPageCursor"`
}

// V5GetCoinInfoRows :
type V5GetCoinInfoRows []V5GetCoinInfoRow

// V5GetCoinInfoRow :
type V5GetCoinInfoRow struct {
Name string `json:"name"`
Coin Coin `json:"coin"`
RemainAmount string `json:"remainAmount"`
Chains V5GetCoinInfoChains `json:"chains"`
}

// V5GetCoinInfoChains :
type V5GetCoinInfoChains []V5GetCoinInfoChain

// V5GetCoinInfoChain :
type V5GetCoinInfoChain struct {
Chain string `json:"chain"`
ChainType string `json:"chainType"`
Confirmation string `json:"confirmation"`
WithdrawFee string `json:"withdrawFee"`
DepositMin string `json:"depositMin"`
WithdrawMin string `json:"withdrawMin"`
MinAccuracy string `json:"minAccuracy"`
ChainDeposit string `json:"chainDeposit"`
ChainWithdraw string `json:"chainWithdraw"`
WithdrawPercentageFee string `json:"withdrawPercentageFee"`
}

// GetCoinInfo :
func (s *V5AssetService) GetCoinInfo(param V5GetCoinInfoParam) (*V5GetCoinInfoResponse, error) {
var res V5GetCoinInfoResponse

queryString, err := query.Values(param)
if err != nil {
return nil, err
}

if err := s.client.getV5Privately("/v5/asset/coin/query-info", queryString, &res); err != nil {
return nil, err
}

return &res, nil
}
59 changes: 59 additions & 0 deletions v5_asset_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,62 @@ func TestGetWithdrawalRecords(t *testing.T) {
assert.Error(t, err)
})
}

func TestGetCoinInfo(t *testing.T) {
t.Run("success", func(t *testing.T) {
param := V5GetCoinInfoParam{}

path := "/v5/asset/coin/query-info"
method := http.MethodGet
status := http.StatusOK
respBody := map[string]interface{}{
"result": map[string]interface{}{
"rows": []map[string]interface{}{},
"nextPageCursor": "",
},
}
bytesBody, err := json.Marshal(respBody)
require.NoError(t, err)

server, teardown := testhelper.NewServer(
testhelper.WithHandlerOption(path, method, status, bytesBody),
)
defer teardown()

client := NewTestClient().
WithBaseURL(server.URL).
WithAuth("test", "test")

resp, err := client.V5().Asset().GetCoinInfo(param)
require.NoError(t, err)

require.NotNil(t, resp)
testhelper.Compare(t, respBody["result"], resp.Result)
})
t.Run("authentication required", func(t *testing.T) {
param := V5GetCoinInfoParam{}

path := "/v5/asset/coin/query-info"
method := http.MethodGet
status := http.StatusOK
respBody := map[string]interface{}{
"result": map[string]interface{}{
"rows": []map[string]interface{}{},
"nextPageCursor": "",
},
}
bytesBody, err := json.Marshal(respBody)
require.NoError(t, err)

server, teardown := testhelper.NewServer(
testhelper.WithHandlerOption(path, method, status, bytesBody),
)
defer teardown()

client := NewTestClient().
WithBaseURL(server.URL)

_, err = client.V5().Asset().GetCoinInfo(param)
assert.Error(t, err)
})
}

0 comments on commit 1d80106

Please sign in to comment.