Skip to content

Commit

Permalink
Update list withdraws service to sapi
Browse files Browse the repository at this point in the history
  • Loading branch information
kislikjeka committed Jun 11, 2021
1 parent 07e664d commit 15fb07e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 76 deletions.
64 changes: 41 additions & 23 deletions v2/withdraw_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ type CreateWithdrawResponse struct {
// See https://binance-docs.github.io/apidocs/spot/en/#withdraw-history-supporting-network-user_data
type ListWithdrawsService struct {
c *Client
asset *string
coin *string
status *int
offset *int
limit *int
startTime *int64
endTime *int64
}

// Asset sets the asset parameter.
func (s *ListWithdrawsService) Asset(asset string) *ListWithdrawsService {
s.asset = &asset
// Coin sets the asset parameter.
func (s *ListWithdrawsService) Coin(coin string) *ListWithdrawsService {
s.coin = &coin
return s
}

Expand All @@ -137,6 +139,18 @@ func (s *ListWithdrawsService) Status(status int) *ListWithdrawsService {
return s
}

// Offset sets the offset parameter
func (s *ListWithdrawsService) Offset(offset int) *ListWithdrawsService {
s.offset = &offset
return s
}

// Limit sets the limit parameter
func (s *ListWithdrawsService) Limit(limit int) *ListWithdrawsService {
s.limit = &limit
return s
}

// StartTime sets the startTime parameter.
// If present, EndTime MUST be specified. The difference between EndTime - StartTime MUST be between 0-90 days.
func (s *ListWithdrawsService) StartTime(startTime int64) *ListWithdrawsService {
Expand All @@ -155,11 +169,11 @@ func (s *ListWithdrawsService) EndTime(endTime int64) *ListWithdrawsService {
func (s *ListWithdrawsService) Do(ctx context.Context) (withdraws []*Withdraw, err error) {
r := &request{
method: "GET",
endpoint: "/wapi/v3/withdrawHistory.html",
endpoint: "/sapi/v1/capital/withdraw/history",
secType: secTypeSigned,
}
if s.asset != nil {
r.setParam("asset", *s.asset)
if s.coin != nil {
r.setParam("coin", *s.coin)
}
if s.status != nil {
r.setParam("status", *s.status)
Expand All @@ -170,6 +184,12 @@ func (s *ListWithdrawsService) Do(ctx context.Context) (withdraws []*Withdraw, e
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.offset != nil {
r.setParam("offset", *s.offset)
}
if s.limit != nil {
r.setParam("limit", *s.limit)
}
data, err := s.c.callAPI(ctx, r)
if err != nil {
return
Expand All @@ -179,26 +199,24 @@ func (s *ListWithdrawsService) Do(ctx context.Context) (withdraws []*Withdraw, e
if err != nil {
return
}
return res.Withdraws, nil
withdraws = *res
return withdraws, nil
}

// WithdrawHistoryResponse represents a response from ListWithdrawsService.
type WithdrawHistoryResponse struct {
Withdraws []*Withdraw `json:"withdrawList"`
Success bool `json:"success"`
}
type WithdrawHistoryResponse []*Withdraw

// Withdraw represents a single withdraw entry.
type Withdraw struct {
ID string `json:"id"`
WithdrawOrderID string `json:"withdrawOrderID"`
Amount float64 `json:"amount"`
TransactionFee float64 `json:"transactionFee"`
Address string `json:"address"`
AddressTag string `json:"addressTag"`
TxID string `json:"txId"`
Asset string `json:"asset"`
ApplyTime int64 `json:"applyTime"`
Network string `json:"network"`
Status int `json:"status"`
Address string `json:"address"`
Amount string `json:"amount"`
ApplyTime string `json:"applyTime"`
Coin string `json:"coin"`
ID string `json:"id"`
WithdrawOrderID string `json:"withdrawOrderId"`
Network string `json:"network"`
TransferType int `json:"transferType"`
Status int `json:"status"`
TransactionFee string `json:"transactionFee"`
TxId string `json:"txId"`
}
105 changes: 52 additions & 53 deletions v2/withdraw_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,33 @@ func (s *withdrawServiceTestSuite) TestCreateWithdraw() {

func (s *withdrawServiceTestSuite) TestListWithdraws() {
data := []byte(`
{
"withdrawList": [
{
"id":"7213fea8e94b4a5593d507237e5a555b",
"withdrawOrderID": "",
"amount": 0.99,
"transactionFee": 0.01,
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
"asset": "USDT",
"txId": "0xdf33b22bdb2b28b1f75ccd201a4a4m6e7g83jy5fc5d5a9d1340961598cfcb0a1",
"applyTime": 1508198532000,
"network": "ETH",
"status": 4
},
{
"id":"7213fea8e94b4a5534ggsd237e5a555b",
"withdrawOrderID": "withdrawtest",
"amount": 999.9999,
"transactionFee": 0.0001,
"address": "463tWEBn5XZJSxLU34r6g7h8jtxuNcDbjLSjkn3XAXHCbLrTTErJrBWYgHJQyrCwkNgYvyV3z8zctJLPCZy24jvb3NiTcTJ",
"addressTag": "342341222",
"txId": "b3c6219639c8ae3f9cf010cdc24fw7f7yt8j1e063f9b4bd1a05cb44c4b6e2509",
"asset": "XMR",
"applyTime": 1508198532000,
"status": 4
}
],
"success": true
}
[
{
"address": "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
"amount": "8.91000000",
"applyTime": "2019-10-12 11:12:02",
"coin": "USDT",
"id": "b6ae22b3aa844210a7041aee7589627c",
"withdrawOrderId": "WITHDRAWtest123",
"network": "ETH",
"transferType": 0,
"status": 6,
"transactionFee": "0.004",
"txId": "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268"
},
{
"address": "1FZdVHtiBqMrWdjPyRPULCUceZPJ2WLCsB",
"amount": "0.00150000",
"applyTime": "2019-09-24 12:43:45",
"coin": "BTC",
"id": "156ec387f49b41df8724fa744fa82719",
"network": "BTC",
"status": 6,
"transactionFee": "0.004",
"transferType": 0,
"txId": "60fd9007ebfddc753455f95fafa808c4302c836e4d1eebc5a132c36c1d8ac354"
}
]
`)
s.mockDo(data, nil)
defer s.assertDo()
Expand All @@ -106,7 +104,7 @@ func (s *withdrawServiceTestSuite) TestListWithdraws() {
endTime := int64(1508198532001)
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"asset": asset,
"coin": asset,
"status": status,
"startTime": startTime,
"endTime": endTime,
Expand All @@ -115,7 +113,7 @@ func (s *withdrawServiceTestSuite) TestListWithdraws() {
})

withdraws, err := s.client.NewListWithdrawsService().
Asset(asset).
Coin(asset).
Status(status).
StartTime(startTime).
EndTime(endTime).
Expand All @@ -125,37 +123,38 @@ func (s *withdrawServiceTestSuite) TestListWithdraws() {

s.Len(withdraws, 2)
s.assertWithdrawEqual(&Withdraw{
ID: "7213fea8e94b4a5593d507237e5a555b",
WithdrawOrderID: "",
Amount: 0.99,
TransactionFee: 0.01,
Address: "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
AddressTag: "",
Asset: "USDT",
TxID: "0xdf33b22bdb2b28b1f75ccd201a4a4m6e7g83jy5fc5d5a9d1340961598cfcb0a1",
ApplyTime: 1508198532000,
Address: "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
Amount: "8.91000000",
ApplyTime: "2019-10-12 11:12:02",
Coin: "USDT",
ID: "b6ae22b3aa844210a7041aee7589627c",
WithdrawOrderID: "WITHDRAWtest123",
Network: "ETH",
Status: 4,
TransferType: 0,
Status: 6,
TransactionFee: "0.004",
TxId: "60fd9007ebfddc753455f95fafa808c4302c836e4d1eebc5a132c36c1d8ac354",
}, withdraws[0])
s.assertWithdrawEqual(&Withdraw{
ID: "7213fea8e94b4a5534ggsd237e5a555b",
WithdrawOrderID: "withdrawOrderID",
Amount: 999.9999,
TransactionFee: 0.0001,
Address: "463tWEBn5XZJSxLU34r6g7h8jtxuNcDbjLSjkn3XAXHCbLrTTErJrBWYgHJQyrCwkNgYvyV3z8zctJLPCZy24jvb3NiTcTJ",
AddressTag: "342341222",
TxID: "b3c6219639c8ae3f9cf010cdc24fw7f7yt8j1e063f9b4bd1a05cb44c4b6e2509",
Asset: "XMR",
ApplyTime: 1508198532000,
Status: 4,
Address: "1FZdVHtiBqMrWdjPyRPULCUceZPJ2WLCsB",
Amount: "0.00150000",
ApplyTime: "2019-09-24 12:43:45",
Coin: "BTC",
ID: "156ec387f49b41df8724fa744fa82719",
WithdrawOrderID: "",
Network: "BTC",
TransferType: 0,
Status: 6,
TransactionFee: "0.004",
TxId: "60fd9007ebfddc753455f95fafa808c4302c836e4d1eebc5a132c36c1d8ac354",
}, withdraws[1])
}

func (s *withdrawServiceTestSuite) assertWithdrawEqual(e, a *Withdraw) {
r := s.r()
r.InDelta(e.Amount, a.Amount, 0.0000001, "Amount")
r.Equal(e.Amount, a.Amount, "Amount")
r.Equal(e.Address, a.Address, "Address")
r.Equal(e.Asset, a.Asset, "Asset")
r.Equal(e.Coin, a.Coin, "Coin")
r.Equal(e.ApplyTime, a.ApplyTime, "ApplyTime")
r.Equal(e.Status, a.Status, "Status")
}

0 comments on commit 15fb07e

Please sign in to comment.