diff --git a/README.md b/README.md index 9de0982..111f33a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/integrationtest/v5/asset/asset_test.go b/integrationtest/v5/asset/asset_test.go index 16ad93c..03501e2 100644 --- a/integrationtest/v5/asset/asset_test.go +++ b/integrationtest/v5/asset/asset_test.go @@ -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 diff --git a/integrationtest/v5/asset/testdata/v5-asset-get-sub-deposit-records.json b/integrationtest/v5/asset/testdata/v5-asset-get-sub-deposit-records.json new file mode 100644 index 0000000..3d993bd --- /dev/null +++ b/integrationtest/v5/asset/testdata/v5-asset-get-sub-deposit-records.json @@ -0,0 +1,4 @@ +{ + "rows": [], + "nextPageCursor": "" +} \ No newline at end of file diff --git a/v5_asset_service.go b/v5_asset_service.go index 340c359..0f09626 100644 --- a/v5_asset_service.go +++ b/v5_asset_service.go @@ -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) } @@ -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 diff --git a/v5_asset_service_test.go b/v5_asset_service_test.go index 8289117..1384cfe 100644 --- a/v5_asset_service_test.go +++ b/v5_asset_service_test.go @@ -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{}