Skip to content

Commit

Permalink
Update Deposit Address Service and broker TransferHistory methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kislikjeka committed Jun 10, 2021
1 parent 8be4536 commit 07e664d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 68 deletions.
8 changes: 4 additions & 4 deletions v2/borker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (c *Client) SubAccountTransfer(ctx context.Context, req SubAccountTransferR
}

// TransferHistory makes request
func (c *Client) TransferHistory(ctx context.Context, req SubAccountTransferHistoryRequest, opts ...RequestOption) (res *TransferHistoryResponse, err error) {
func (c *Client) TransferHistory(ctx context.Context, req SubAccountTransferHistoryRequest, opts ...RequestOption) (transfers []*Transfer, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/broker/transfer",
Expand Down Expand Up @@ -314,13 +314,13 @@ func (c *Client) TransferHistory(ctx context.Context, req SubAccountTransferHist
return nil, err
}

res = new(TransferHistoryResponse)
res := new(TransferHistoryResponse)
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}

return res, nil
transfers = *res
return transfers, nil
}

// callAPI makes API call
Expand Down
37 changes: 19 additions & 18 deletions v2/deposit_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,39 @@ func (s *ListDepositsService) Do(ctx context.Context) (deposits []*Deposit, err
if err != nil {
return
}
return res.Deposits, nil
deposits = *res
return deposits, nil
}

// DepositHistoryResponse represents a response from ListDepositsService.
type DepositHistoryResponse struct {
Success bool `json:"success"`
Deposits []*Deposit `json:"depositList"`
}
type DepositHistoryResponse []*Deposit

// Deposit represents a single deposit entry.
type Deposit struct {
InsertTime int64 `json:"insertTime"`
Amount float64 `json:"amount"`
Asset string `json:"asset"`
Address string `json:"address"`
AddressTag string `json:"addressTag"`
TxID string `json:"txId"`
Status int `json:"status"`
Amount string `json:"amount"`
Coin string `json:"coin"`
Network string `json:"network"`
Status int `json:"status"`
Address string `json:"address"`
AddressTag string `json:"addressTag"`
TxID string `json:"txId"`
InsertTime int64 `json:"insertTime"`
TransferType int `json:"transferType"`
ConfirmTimes string `json:"confirmTimes"`
}

// GetDepositsAddressService retrieves the details of a deposit address.
//
// See https://binance-docs.github.io/apidocs/spot/en/#deposit-address-supporting-network-user_data
type GetDepositsAddressService struct {
c *Client
asset string
coin string
network string
}

// Asset sets the asset parameter (MANDATORY).
func (s *GetDepositsAddressService) Asset(v string) *GetDepositsAddressService {
s.asset = v
// Coin sets the coin parameter (MANDATORY).
func (s *GetDepositsAddressService) Coin(v string) *GetDepositsAddressService {
s.coin = v
return s
}

Expand All @@ -140,7 +141,7 @@ func (s *GetDepositsAddressService) Do(ctx context.Context) (*GetDepositAddressR
endpoint: "/sapi/v1/capital/deposit/address",
secType: secTypeSigned,
}
r.setParam("coin", s.asset)
r.setParam("coin", s.coin)
if s.network != "" {
r.setParam("network", s.network)
}
Expand All @@ -163,5 +164,5 @@ type GetDepositAddressResponse struct {
Address string `json:"address"`
Coin string `json:"coin"`
Tag string `json:"tag"`
Url string `json:"url"`
URL string `json:"url"`
}
92 changes: 46 additions & 46 deletions v2/deposit_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,38 @@ func TestDepositService(t *testing.T) {

func (s *depositServiceTestSuite) TestListDeposits() {
data := []byte(`
{
"depositList": [
{
"insertTime": 1508198532000,
"amount": 0.04670582,
"asset": "ETH",
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
"txId": "0xdf33b22bdb2b28b1f75ccd201a4a4m6e7g83jy5fc5d5a9d1340961598cfcb0a1",
"status": 1
},
{
"insertTime": 1508298532000,
"amount": 1000,
"asset": "XMR",
"address": "463tWEBn5XZJSxLU34r6g7h8jtxuNcDbjLSjkn3XAXHCbLrTTErJrBWYgHJQyrCwkNgYvyV3z8zctJLPCZy24jvb3NiTcTJ",
"addressTag": "342341222",
"txId": "b3c6219639c8ae3f9cf010cdc24fw7f7yt8j1e063f9b4bd1a05cb44c4b6e2509",
"status": 1
}
],
"success": true
}
[
{
"amount":"0.00999800",
"coin":"PAXG",
"network":"ETH",
"status":1,
"address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
"addressTag":"",
"txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
"insertTime":1599621997000,
"transferType":0,
"confirmTimes":"12/12"
},
{
"amount":"0.50000000",
"coin":"IOTA",
"network":"IOTA",
"status":1,
"address":"SIZ9VLMHWATXKV99LH99CIGFJFUMLEHGWVZVNNZXRJJVWBPHYWPPBOSDORZ9EQSHCZAMPVAPGFYQAUUV9DROOXJLNW",
"addressTag":"342341222",
"txId":"ESBFVQUTPIWQNJSPXFNHNYHSQNTGKRVKPRABQWTAXCDWOAKDKYWPTVG9BGXNVNKTLEJGESAVXIKIZ9999",
"insertTime":1599620082000,
"transferType":0,
"confirmTimes":"1/1"
}
]
`)
s.mockDo(data, nil)
defer s.assertDo()
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"asset": "BTC",
"coin": "BTC",
"status": 1,
"startTime": 1508198532000,
"endTime": 1508198532001,
Expand All @@ -52,7 +56,7 @@ func (s *depositServiceTestSuite) TestListDeposits() {
})

deposits, err := s.client.NewListDepositsService().
Asset("BTC").
Coin("BTC").
Status(1).
StartTime(1508198532000).
EndTime(1508198532001).
Expand All @@ -62,30 +66,30 @@ func (s *depositServiceTestSuite) TestListDeposits() {

r.Len(deposits, 2)
s.assertDepositEqual(&Deposit{
InsertTime: 1508198532000,
Amount: 0.04670582,
Asset: "ETH",
Address: "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
InsertTime: 1599621997000,
Amount: "0.00999800",
Coin: "PAXG",
Address: "0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
AddressTag: "",
TxID: "0xdf33b22bdb2b28b1f75ccd201a4a4m6e7g83jy5fc5d5a9d1340961598cfcb0a1",
TxID: "0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
Status: 1,
}, deposits[0])
s.assertDepositEqual(&Deposit{
InsertTime: 1508298532000,
Amount: 1000.0,
Asset: "XMR",
Address: "463tWEBn5XZJSxLU34r6g7h8jtxuNcDbjLSjkn3XAXHCbLrTTErJrBWYgHJQyrCwkNgYvyV3z8zctJLPCZy24jvb3NiTcTJ",
InsertTime: 1599620082000,
Amount: "0.50000000",
Coin: "IOTA",
Address: "SIZ9VLMHWATXKV99LH99CIGFJFUMLEHGWVZVNNZXRJJVWBPHYWPPBOSDORZ9EQSHCZAMPVAPGFYQAUUV9DROOXJLNW",
AddressTag: "342341222",
TxID: "b3c6219639c8ae3f9cf010cdc24fw7f7yt8j1e063f9b4bd1a05cb44c4b6e2509",
TxID: "ESBFVQUTPIWQNJSPXFNHNYHSQNTGKRVKPRABQWTAXCDWOAKDKYWPTVG9BGXNVNKTLEJGESAVXIKIZ9999",
Status: 1,
}, deposits[1])
}

func (s *depositServiceTestSuite) assertDepositEqual(e, a *Deposit) {
r := s.r()
r.Equal(e.InsertTime, a.InsertTime, "InsertTime")
r.Equal(e.Asset, a.Asset, "Asset")
r.InDelta(e.Amount, a.Amount, 0.0000000001, "Amount")
r.Equal(e.Coin, a.Coin, "Coin")
r.Equal(e.Amount, a.Amount, "Amount")
r.Equal(e.Status, a.Status, "Status")
r.Equal(e.TxID, a.TxID, "TxID")
}
Expand All @@ -95,34 +99,30 @@ func (s *depositServiceTestSuite) TestGetDepositAddress() {
{
"address": "0xbf1f86b3c8ff4f8cbfc195e9713b6f0000000000",
"success": true,
"addressTag": "1231212",
"asset": "ETH",
"tag": "1231212",
"coin": "ETH",
"url": "https://etherscan.io/address/0xbf1f86b3c8ff4f8cbfc195e9713b6f0000000000"
}
`)
s.mockDo(data, nil)
defer s.assertDo()

asset := "ETH"
status := true
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"asset": asset,
"status": status,
"coin": asset,
})
s.assertRequestEqual(e, r)
})

res, err := s.client.NewGetDepositAddressService().
Asset(asset).
Status(status).
Coin(asset).
Do(newContext())

r := s.r()
r.NoError(err)
r.True(res.Success)
r.Equal("0xbf1f86b3c8ff4f8cbfc195e9713b6f0000000000", res.Address)
r.Equal("1231212", res.AddressTag)
r.Equal("ETH", res.Asset)
r.Equal("1231212", res.Tag)
r.Equal("ETH", res.Coin)
r.Equal("https://etherscan.io/address/0xbf1f86b3c8ff4f8cbfc195e9713b6f0000000000", res.URL)
}
1 change: 1 addition & 0 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTM
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand Down

0 comments on commit 07e664d

Please sign in to comment.