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 withdrawal records #124

Merged
merged 4 commits into from
Apr 23, 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 @@ -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")
)