Skip to content

Commit

Permalink
feat: v5 get internal deposit records (#121)
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 16, 2023
1 parent b259999 commit 4075341
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 0 deletions.
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-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 @@ -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))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rows": [],
"nextPageCursor": ""
}
52 changes: 52 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)
GetInternalDepositRecords(V5GetInternalDepositRecordsParam) (*V5GetInternalDepositRecordsResponse, error)
}

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

0 comments on commit 4075341

Please sign in to comment.