From 40753410b771c444c78df332afcd8b7845d19f18 Mon Sep 17 00:00:00 2001 From: hirokisan Date: Sun, 16 Apr 2023 10:44:17 +0900 Subject: [PATCH] feat: v5 get internal deposit records (#121) * feat: implement * test: integration * test: unit * docs: update --- README.md | 1 + integrationtest/v5/asset/asset_test.go | 14 +++++ ...v5-asset-get-internal-deposit-records.json | 4 ++ v5_asset_service.go | 52 ++++++++++++++++ v5_asset_service_test.go | 59 +++++++++++++++++++ v5_enum.go | 9 +++ 6 files changed, 139 insertions(+) create mode 100644 integrationtest/v5/asset/testdata/v5-asset-get-internal-deposit-records.json diff --git a/README.md b/README.md index ee2691a..cfdd042 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ The following API endpoints have been implemented #### Asset - [`/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-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 21e71b6..d7961b7 100644 --- a/integrationtest/v5/asset/asset_test.go +++ b/integrationtest/v5/asset/asset_test.go @@ -23,3 +23,17 @@ func TestGetInternalTransferRecords(t *testing.T) { testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) } } + +func TestGetInternalDepositRecords(t *testing.T) { + client := bybit.NewTestClient().WithAuthFromEnv() + limit := 1 + res, err := client.V5().Asset().GetInternalDepositRecords(bybit.V5GetInternalDepositRecordsParam{ + Limit: &limit, + }) + require.NoError(t, err) + { + goldenFilename := "./testdata/v5-asset-get-internal-deposit-records.json" + testhelper.Compare(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result)) + } +} diff --git a/integrationtest/v5/asset/testdata/v5-asset-get-internal-deposit-records.json b/integrationtest/v5/asset/testdata/v5-asset-get-internal-deposit-records.json new file mode 100644 index 0000000..3d993bd --- /dev/null +++ b/integrationtest/v5/asset/testdata/v5-asset-get-internal-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 4813a9a..6da54b9 100644 --- a/v5_asset_service.go +++ b/v5_asset_service.go @@ -5,6 +5,7 @@ import "github.com/google/go-querystring/query" // V5AssetServiceI : type V5AssetServiceI interface { GetInternalTransferRecords(V5GetInternalTransferRecordsParam) (*V5GetInternalTransferRecordsResponse, error) + GetInternalDepositRecords(V5GetInternalDepositRecordsParam) (*V5GetInternalDepositRecordsResponse, error) } // V5AssetService : @@ -64,3 +65,54 @@ func (s *V5AssetService) GetInternalTransferRecords(param V5GetInternalTransferR return &res, nil } + +// V5GetInternalDepositRecordsParam : +type V5GetInternalDepositRecordsParam struct { + StartTime *int64 `url:"startTime,omitempty"` // Start time (ms). Default value: 30 days before the current time + EndTime *int64 `url:"endTime,omitempty"` // End time (ms). Default value: current time + Coin *Coin `url:"coin,omitempty"` + Cursor *string `url:"cursor,omitempty"` + Limit *int `url:"limit,omitempty"` // Number of items per page, [1, 50]. Default value: 50 +} + +// V5GetInternalDepositRecordsResponse : +type V5GetInternalDepositRecordsResponse struct { + CommonV5Response `json:",inline"` + Result V5GetInternalDepositRecordsResult `json:"result"` +} + +// V5GetInternalDepositRecordsResult : +type V5GetInternalDepositRecordsResult struct { + Rows V5GetInternalTransferRecordsRows `json:"rows"` + NextPageCursor string `json:"nextPageCursor"` +} + +// V5GetInternalTransferRecordsRows : +type V5GetInternalTransferRecordsRows []V5GetInternalTransferRecordsRow + +// V5GetInternalTransferRecordsRow : +type V5GetInternalTransferRecordsRow struct { + ID string `json:"id"` + Type string `json:"type"` + Coin Coin `json:"coin"` + Amount string `json:"amount"` + Status InternalDepositStatusV5 `json:"status"` + Address string `json:"address"` // Email address or phone number + CreatedTime string `json:"createdTime"` +} + +// GetInternalDepositRecords : +func (s *V5AssetService) GetInternalDepositRecords(param V5GetInternalDepositRecordsParam) (*V5GetInternalDepositRecordsResponse, error) { + var res V5GetInternalDepositRecordsResponse + + queryString, err := query.Values(param) + if err != nil { + return nil, err + } + + if err := s.client.getV5Privately("/v5/asset/deposit/query-internal-record", queryString, &res); err != nil { + return nil, err + } + + return &res, nil +} diff --git a/v5_asset_service_test.go b/v5_asset_service_test.go index ff7ad9f..fd69d5c 100644 --- a/v5_asset_service_test.go +++ b/v5_asset_service_test.go @@ -88,3 +88,62 @@ func TestV5Asset_GetInternalTransferRecords(t *testing.T) { assert.Error(t, err) }) } + +func GetInternalDepositRecords(t *testing.T) { + t.Run("success", func(t *testing.T) { + param := V5GetInternalDepositRecordsParam{} + + path := "/v5/asset/deposit/query-internal-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().GetInternalDepositRecords(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 := V5GetInternalDepositRecordsParam{} + + path := "/v5/asset/deposit/query-internal-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().GetInternalDepositRecords(param) + assert.Error(t, err) + }) +} diff --git a/v5_enum.go b/v5_enum.go index 6ae01cf..e0998f9 100644 --- a/v5_enum.go +++ b/v5_enum.go @@ -244,3 +244,12 @@ const ( TransactionLogTypeV5CURRENCYBUY = TransactionLogTypeV5("CURRENCY_BUY") TransactionLogTypeV5CURRENCYSELL = TransactionLogTypeV5("CURRENCY_SELL") ) + +// InternalDepositStatusV5 : +type InternalDepositStatusV5 int + +const ( + InternalDepositStatusV5Processing = InternalDepositStatusV5(1) + InternalDepositStatusV5Success = InternalDepositStatusV5(2) + InternalDepositStatusV5Failed = InternalDepositStatusV5(3) +)