Skip to content

Commit

Permalink
feat: v5 get withdrawal records (#124)
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 23, 2023
1 parent c939fa0 commit 3afc0c3
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ The following API endpoints have been implemented
- [`/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)
- [`/v5/asset/withdraw/query-record` Get Withdrawal Records](https://bybit-exchange.github.io/docs/v5/asset/withdraw-record)

#### User

Expand Down
16 changes: 16 additions & 0 deletions integrationtest/v5/asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,19 @@ func TestGetInternalDepositRecords(t *testing.T) {
testhelper.UpdateFile(t, goldenFilename, testhelper.ConvertToJSON(res.Result))
}
}

func TestGetWithdrawalRecords(t *testing.T) {
client := bybit.NewTestClient().WithAuthFromEnv()
limit := 1
typ := bybit.WithdrawTypeAll
res, err := client.V5().Asset().GetWithdrawalRecords(bybit.V5GetWithdrawalRecordsParam{
Limit: &limit,
WithdrawType: &typ,
})
require.NoError(t, err)
{
goldenFilename := "./testdata/v5-asset-get-withdrawal-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": ""
}
59 changes: 59 additions & 0 deletions v5_asset_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type V5AssetServiceI interface {
GetDepositRecords(V5GetDepositRecordsParam) (*V5GetDepositRecordsResponse, error)
GetSubDepositRecords(V5GetSubDepositRecordsParam) (*V5GetSubDepositRecordsResponse, error)
GetInternalDepositRecords(V5GetInternalDepositRecordsParam) (*V5GetInternalDepositRecordsResponse, error)
GetWithdrawalRecords(V5GetWithdrawalRecordsParam) (*V5GetWithdrawalRecordsResponse, error)
}

// V5AssetService :
Expand Down Expand Up @@ -232,3 +233,61 @@ func (s *V5AssetService) GetInternalDepositRecords(param V5GetInternalDepositRec

return &res, nil
}

// V5GetWithdrawalRecordsParam :
type V5GetWithdrawalRecordsParam struct {
WithdrawID *string `url:"withdrawId,omitempty"`
Coin *Coin `url:"coin,omitempty"`
WithdrawType *WithdrawTypeV5 `url:"withdrawType,omitempty"`
StartTime *int64 `url:"startTime,omitempty"` // The start timestamp (ms)
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"`
}

// V5GetWithdrawalRecordsResponse :
type V5GetWithdrawalRecordsResponse struct {
CommonV5Response `json:",inline"`
Result V5GetWithdrawalRecordsResult `json:"result"`
}

// V5GetWithdrawalRecordsResult :
type V5GetWithdrawalRecordsResult struct {
Rows V5GetWithdrawalRecordsRows `json:"rows"`
NextPageCursor string `json:"nextPageCursor"`
}

// V5GetWithdrawalRecordsRows :
type V5GetWithdrawalRecordsRows []V5GetWithdrawalRecordsRow

// V5GetWithdrawalRecordsRow :
type V5GetWithdrawalRecordsRow struct {
WithdrawId string `json:"withdrawId"`
TxID string `json:"txId"`
WithdrawType WithdrawTypeV5 `json:"withdrawType"`
Coin Coin `json:"coin"`
Chain string `json:"chain"`
Amount string `json:"amount"`
WithdrawFee string `json:"withdrawFee"`
Status WithdrawStatusV5 `json:"status"`
ToAddress string `json:"toAddress"`
Tag string `json:"tag"`
CreatedTime string `json:"createTime"`
UpdatedTime string `json:"updateTime"`
}

// GetWithdrawalRecords :
func (s *V5AssetService) GetWithdrawalRecords(param V5GetWithdrawalRecordsParam) (*V5GetWithdrawalRecordsResponse, error) {
var res V5GetWithdrawalRecordsResponse

queryString, err := query.Values(param)
if err != nil {
return nil, err
}

if err := s.client.getV5Privately("/v5/asset/withdraw/query-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 @@ -295,3 +295,62 @@ func GetInternalDepositRecords(t *testing.T) {
assert.Error(t, err)
})
}

func TestGetWithdrawalRecords(t *testing.T) {
t.Run("success", func(t *testing.T) {
param := V5GetWithdrawalRecordsParam{}

path := "/v5/asset/withdraw/query-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().GetWithdrawalRecords(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 := V5GetWithdrawalRecordsParam{}

path := "/v5/asset/withdraw/query-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().GetWithdrawalRecords(param)
assert.Error(t, err)
})
}
20 changes: 20 additions & 0 deletions v5_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,23 @@ const (
DepositStatusV5Success = DepositStatusV5(3)
DepositStatusV5Failed = DepositStatusV5(4)
)

type WithdrawTypeV5 int

const (
WithdrawTypeOnChain = WithdrawTypeV5(0)
WithdrawTypeOffChain = WithdrawTypeV5(1)
WithdrawTypeAll = WithdrawTypeV5(2)
)

type WithdrawStatusV5 string

const (
WithdrawStatusV5SecurityCheck = WithdrawStatusV5("SecurityCheck")
WithdrawStatusV5Pending = WithdrawStatusV5("Pending")
WithdrawStatusV5Success = WithdrawStatusV5("success")
WithdrawStatusV5CancelByUser = WithdrawStatusV5("CancelByUser")
WithdrawStatusV5Reject = WithdrawStatusV5("Reject")
WithdrawStatusV5Fail = WithdrawStatusV5("Fail")
WithdrawStatusV5BlockchainConfirmed = WithdrawStatusV5("BlockchainConfirmed")
)

0 comments on commit 3afc0c3

Please sign in to comment.