Skip to content

Commit

Permalink
feat: v5 get sub deposit records (#123)
Browse files Browse the repository at this point in the history
* feat: implement

* test: integration

* test: unit

* docs: update
  • Loading branch information
hirokisan authored Apr 19, 2023
1 parent 1d0d373 commit c939fa0
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ The following API endpoints have been implemented

- [`/v5/asset/transfer/query-inter-transfer-list` Get Internal Transfer Records](https://bybit-exchange.github.io/docs/v5/asset/inter-transfer-list)
- [`/v5/asset/deposit/query-record` Get Deposit Records](https://bybit-exchange.github.io/docs/v5/asset/deposit-record)
- [`/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)

#### User
Expand Down
15 changes: 15 additions & 0 deletions integrationtest/v5/asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ func TestGetDepositRecords(t *testing.T) {
}
}

func TestGetSubDepositRecords(t *testing.T) {
client := bybit.NewTestClient().WithAuthFromEnv()
limit := 1
res, err := client.V5().Asset().GetSubDepositRecords(bybit.V5GetSubDepositRecordsParam{
SubMemberID: "1462488",
Limit: &limit,
})
require.NoError(t, err)
{
goldenFilename := "./testdata/v5-asset-get-sub-deposit-records.json"
testhelper.Compare(t, goldenFilename, testhelper.ConvertToJSON(res.Result))
testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result))
}
}

func TestGetInternalDepositRecords(t *testing.T) {
client := bybit.NewTestClient().WithAuthFromEnv()
limit := 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rows": [],
"nextPageCursor": ""
}
59 changes: 59 additions & 0 deletions v5_asset_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "github.com/google/go-querystring/query"
type V5AssetServiceI interface {
GetInternalTransferRecords(V5GetInternalTransferRecordsParam) (*V5GetInternalTransferRecordsResponse, error)
GetDepositRecords(V5GetDepositRecordsParam) (*V5GetDepositRecordsResponse, error)
GetSubDepositRecords(V5GetSubDepositRecordsParam) (*V5GetSubDepositRecordsResponse, error)
GetInternalDepositRecords(V5GetInternalDepositRecordsParam) (*V5GetInternalDepositRecordsResponse, error)
}

Expand Down Expand Up @@ -123,6 +124,64 @@ func (s *V5AssetService) GetDepositRecords(param V5GetDepositRecordsParam) (*V5G
return &res, nil
}

// V5GetSubDepositRecordsParam :
type V5GetSubDepositRecordsParam struct {
SubMemberID string `url:"subMemberId"`

Coin *Coin `url:"coin,omitempty"`
StartTime *int64 `url:"startTime,omitempty"` // Start time (ms). Default value: 30 days before the current time
EndTime *int64 `url:"endTime,omitempty"` // The start timestamp (ms)
Limit *int `url:"limit,omitempty"` // Limit for data size per page. [1, 50]. Default: 50
Cursor *string `url:"cursor,omitempty"`
}

// V5GetSubDepositRecordsResponse :
type V5GetSubDepositRecordsResponse struct {
CommonV5Response `json:",inline"`
Result V5GetSubDepositRecordsResult `json:"result"`
}

// V5GetSubDepositRecordsResult :
type V5GetSubDepositRecordsResult struct {
Rows V5GetSubDepositRecordsRows `json:"rows"`
NextPageCursor string `json:"nextPageCursor"`
}

// V5GetSubDepositRecordsRows :
type V5GetSubDepositRecordsRows []V5GetSubDepositRecordsRow

// V5GetSubDepositRecordsRow :
type V5GetSubDepositRecordsRow struct {
Coin Coin `json:"coin"`
Chain string `json:"chain"`
Amount string `json:"amount"`
TxID string `json:"txID"`
Status DepositStatusV5 `json:"status"`
ToAddress string `json:"toAddress"`
Tag string `json:"tag"`
DepositFee string `json:"depositFee"`
SuccessAt string `json:"successAt"`
Confirmations string `json:"confirmations"`
TxIndex string `json:"txIndex"`
BlockHash string `json:"blockHash"`
}

// GetSubDepositRecords :
func (s *V5AssetService) GetSubDepositRecords(param V5GetSubDepositRecordsParam) (*V5GetSubDepositRecordsResponse, error) {
var res V5GetSubDepositRecordsResponse

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

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

return &res, nil
}

// V5GetInternalDepositRecordsParam :
type V5GetInternalDepositRecordsParam struct {
StartTime *int64 `url:"startTime,omitempty"` // Start time (ms). Default value: 30 days before the current time
Expand Down
59 changes: 59 additions & 0 deletions v5_asset_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,65 @@ func GetDepositRecords(t *testing.T) {
})
}

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

path := "/v5/asset/deposit/query-sub-member-record"
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().GetSubDepositRecords(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 := V5GetSubDepositRecordsParam{}

path := "/v5/asset/deposit/query-sub-member-record"
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().GetSubDepositRecords(param)
assert.Error(t, err)
})
}

func GetInternalDepositRecords(t *testing.T) {
t.Run("success", func(t *testing.T) {
param := V5GetInternalDepositRecordsParam{}
Expand Down

0 comments on commit c939fa0

Please sign in to comment.