Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v5 get deposit records #122

Merged
merged 4 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions integrationtest/v5/asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
57 changes: 57 additions & 0 deletions v5_asset_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions v5_asset_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
11 changes: 11 additions & 0 deletions v5_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)