From f65f24b2a4844434b8e869cb6618b2fa2575a97e Mon Sep 17 00:00:00 2001 From: hirokisan Date: Tue, 18 Apr 2023 21:46:38 +0900 Subject: [PATCH] feat: v5 get deposit records (#122) * feat: implement * test: integration * test: unit * docs: update --- README.md | 1 + integrationtest/v5/asset/asset_test.go | 14 +++ .../v5-asset-get-deposit-records.json | 19 ++++ v5_asset_service.go | 57 ++++++++++++ v5_asset_service_test.go | 89 +++++++++++++++++++ v5_enum.go | 11 +++ 6 files changed, 191 insertions(+) create mode 100644 integrationtest/v5/asset/testdata/v5-asset-get-deposit-records.json diff --git a/README.md b/README.md index cfdd042..9de0982 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-record` Get Deposit Records](https://bybit-exchange.github.io/docs/v5/asset/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 d7961b7..16ad93c 100644 --- a/integrationtest/v5/asset/asset_test.go +++ b/integrationtest/v5/asset/asset_test.go @@ -24,6 +24,20 @@ func TestGetInternalTransferRecords(t *testing.T) { } } +func TestGetDepositRecords(t *testing.T) { + client := bybit.NewTestClient().WithAuthFromEnv() + limit := 1 + res, err := client.V5().Asset().GetDepositRecords(bybit.V5GetDepositRecordsParam{ + Limit: &limit, + }) + require.NoError(t, err) + { + goldenFilename := "./testdata/v5-asset-get-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-deposit-records.json b/integrationtest/v5/asset/testdata/v5-asset-get-deposit-records.json new file mode 100644 index 0000000..06abd83 --- /dev/null +++ b/integrationtest/v5/asset/testdata/v5-asset-get-deposit-records.json @@ -0,0 +1,19 @@ +{ + "rows": [ + { + "coin": "USDT", + "chain": "ETH", + "amount": "10000", + "txID": "skip-notification-scene-test-amount-202304160106-146940-USDT", + "status": 3, + "toAddress": "test-amount-address", + "tag": "", + "depositFee": "", + "successAt": "1681607166000", + "confirmations": "10000", + "txIndex": "", + "blockHash": "" + } + ], + "nextPageCursor": "eyJtaW5JRCI6MTEzMzUzNSwibWF4SUQiOjExMzM1MzV9" +} \ No newline at end of file diff --git a/v5_asset_service.go b/v5_asset_service.go index 6da54b9..7c30ef8 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) + GetDepositRecords(V5GetDepositRecordsParam) (*V5GetDepositRecordsResponse, error) GetInternalDepositRecords(V5GetInternalDepositRecordsParam) (*V5GetInternalDepositRecordsResponse, error) } @@ -66,6 +67,62 @@ func (s *V5AssetService) GetInternalTransferRecords(param V5GetInternalTransferR return &res, nil } +// V5GetDepositRecordsParam : +type V5GetDepositRecordsParam struct { + 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"` // End time (ms). Default value: current time + Limit *int `url:"limit,omitempty"` // Number of items per page, [1, 50]. Default value: 50 + Cursor *string `url:"cursor,omitempty"` +} + +// V5GetDepositRecordsResponse : +type V5GetDepositRecordsResponse struct { + CommonV5Response `json:",inline"` + Result V5GetDepositRecordsResult `json:"result"` +} + +// V5GetDepositRecordsResult : +type V5GetDepositRecordsResult struct { + Rows V5GetTransferRecordsRows `json:"rows"` + NextPageCursor string `json:"nextPageCursor"` +} + +// V5GetTransferRecordsRows : +type V5GetTransferRecordsRows []V5GetTransferRecordsRow + +// V5GetTransferRecordsRow : +type V5GetTransferRecordsRow 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"` +} + +// GetDepositRecords : +func (s *V5AssetService) GetDepositRecords(param V5GetDepositRecordsParam) (*V5GetDepositRecordsResponse, error) { + var res V5GetDepositRecordsResponse + + queryString, err := query.Values(param) + if err != nil { + return nil, err + } + + if err := s.client.getV5Privately("/v5/asset/deposit/query-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 fd69d5c..8289117 100644 --- a/v5_asset_service_test.go +++ b/v5_asset_service_test.go @@ -89,6 +89,95 @@ func TestV5Asset_GetInternalTransferRecords(t *testing.T) { }) } +func GetDepositRecords(t *testing.T) { + t.Run("success", func(t *testing.T) { + param := V5GetDepositRecordsParam{} + + path := "/v5/asset/deposit/query-record" + method := http.MethodGet + status := http.StatusOK + respBody := map[string]interface{}{ + "result": map[string]interface{}{ + "rows": []map[string]interface{}{ + { + "coin": "USDT", + "chain": "ETH", + "amount": "10000", + "txID": "skip-notification-scene-test-amount-202304160106-146940-USDT", + "status": 3, + "toAddress": "test-amount-address", + "tag": "", + "depositFee": "", + "successAt": "1681607166000", + "confirmations": "10000", + "txIndex": "", + "blockHash": "", + }, + }, + "nextPageCursor": "eyJtaW5JRCI6MTEzMzUzNSwibWF4SUQiOjExMzM1MzV9", + }, + } + 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().GetDepositRecords(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 := V5GetDepositRecordsParam{} + + path := "/v5/asset/deposit/query-record" + method := http.MethodGet + status := http.StatusOK + respBody := map[string]interface{}{ + "result": map[string]interface{}{ + "rows": []map[string]interface{}{ + { + "coin": "USDT", + "chain": "ETH", + "amount": "10000", + "txID": "skip-notification-scene-test-amount-202304160106-146940-USDT", + "status": 3, + "toAddress": "test-amount-address", + "tag": "", + "depositFee": "", + "successAt": "1681607166000", + "confirmations": "10000", + "txIndex": "", + "blockHash": "", + }, + }, + "nextPageCursor": "eyJtaW5JRCI6MTEzMzUzNSwibWF4SUQiOjExMzM1MzV9", + }, + } + 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().GetDepositRecords(param) + assert.Error(t, err) + }) +} + func GetInternalDepositRecords(t *testing.T) { t.Run("success", func(t *testing.T) { param := V5GetInternalDepositRecordsParam{} diff --git a/v5_enum.go b/v5_enum.go index e0998f9..ac3abd2 100644 --- a/v5_enum.go +++ b/v5_enum.go @@ -253,3 +253,14 @@ const ( InternalDepositStatusV5Success = InternalDepositStatusV5(2) InternalDepositStatusV5Failed = InternalDepositStatusV5(3) ) + +// DepositStatusV5 : +type DepositStatusV5 int + +const ( + DepositStatusV5Unknown = DepositStatusV5(0) + DepositStatusV5ToBeConfirmed = DepositStatusV5(1) + DepositStatusV5Processing = DepositStatusV5(2) + DepositStatusV5Success = DepositStatusV5(3) + DepositStatusV5Failed = DepositStatusV5(4) +)