Skip to content

Commit

Permalink
added All Coins' Information (adshao#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
MJ23M authored and nikhilsaraf committed Oct 2, 2022
1 parent 315676e commit e8393f3
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
63 changes: 63 additions & 0 deletions v2/asset_detail_service.go
Expand Up @@ -41,6 +41,30 @@ func (s *GetAssetDetailService) Do(ctx context.Context) (res map[string]AssetDet
return res, nil
}

type GetAllCoinsInfoService struct {
c *Client
asset *string
}

// Do send request
func (s *GetAllCoinsInfoService) Do(ctx context.Context) (res []*CoinInfo, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/capital/config/getall",
secType: secTypeSigned,
}
data, err := s.c.callAPI(ctx, r)
if err != nil {
return []*CoinInfo{}, err
}
res = make([]*CoinInfo, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*CoinInfo{}, err
}
return res, nil
}

// AssetDetail represents the detail of an asset
type AssetDetail struct {
MinWithdrawAmount string `json:"minWithdrawAmount"`
Expand All @@ -49,3 +73,42 @@ type AssetDetail struct {
WithdrawStatus bool `json:"withdrawStatus"`
DepositTip string `json:"depositTip"`
}

type CoinInfo struct {
Coin string `json:"coin"`
DepositAllEnable bool `json:"depositAllEnable"`
Free string `json:"free"`
Freeze string `json:"freeze"`
Ipoable string `json:"ipoable"`
Ipoing string `json:"ipoing"`
IsLegalMoney bool `json:"isLegalMoney"`
Locked string `json:"locked"`
Name string `json:"name"`
NetworkList []Network `json:"networkList"`
Storage string `json:"storage"`
Trading bool `json:"trading"`
WithdrawAllEnable bool `json:"withdrawAllEnable"`
Withdrawing string `json:"withdrawing"`
}

type Network struct {
AddressRegex string `json:"addressRegex"`
Coin string `json:"coin"`
DepositDesc string `json:"depositDesc,omitempty"` // 仅在充值关闭时返回
DepositEnable bool `json:"depositEnable"`
IsDefault bool `json:"isDefault"`
MemoRegex string `json:"memoRegex"`
MinConfirm int `json:"minConfirm"` // 上账所需的最小确认数
Name string `json:"name"`
Network string `json:"network"`
ResetAddressStatus bool `json:"resetAddressStatus"`
SpecialTips string `json:"specialTips"`
UnLockConfirm int `json:"unLockConfirm"` // 解锁需要的确认数
WithdrawDesc string `json:"withdrawDesc,omitempty"` // 仅在提现关闭时返回
WithdrawEnable bool `json:"withdrawEnable"`
WithdrawFee string `json:"withdrawFee"`
WithdrawIntegerMultiple string `json:"withdrawIntegerMultiple"`
WithdrawMax string `json:"withdrawMax"`
WithdrawMin string `json:"withdrawMin"`
SameAddress bool `json:"sameAddress"` // 是否需要memo
}
76 changes: 76 additions & 0 deletions v2/asset_detail_service_test.go
Expand Up @@ -44,3 +44,79 @@ func (s *withdrawServiceTestSuite) TestGetAssetDetail() {
s.r().Equal(res["CTR"].DepositStatus, false, "depositStatus")
s.r().Equal(res["SKY"].DepositStatus, true, "depositStatus")
}
func (s *assetDetailServiceTestSuite) TestGetAllCoinsInfo() {
data := []byte(`
[
{
"coin": "BTC",
"depositAllEnable": true,
"free": "0.08074558",
"freeze": "0.00000000",
"ipoable": "0.00000000",
"ipoing": "0.00000000",
"isLegalMoney": false,
"locked": "0.00000000",
"name": "Bitcoin",
"networkList": [
{
"addressRegex": "^(bnb1)[0-9a-z]{38}$",
"coin": "BTC",
"depositDesc": "Wallet Maintenance, Deposit Suspended",
"depositEnable": false,
"isDefault": false,
"memoRegex": "^[0-9A-Za-z\\-_]{1,120}$",
"minConfirm": 1,
"name": "BEP2",
"network": "BNB",
"resetAddressStatus": false,
"specialTips": "Both a MEMO and an Address are required to successfully deposit your BEP2-BTCB tokens to Binance.",
"unLockConfirm": 0,
"withdrawDesc": "Wallet Maintenance, Withdrawal Suspended",
"withdrawEnable": false,
"withdrawFee": "0.00000220",
"withdrawIntegerMultiple": "0.00000001",
"withdrawMax": "9999999999.99999999",
"withdrawMin": "0.00000440",
"sameAddress": true
},
{
"addressRegex": "^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bc1)[0-9A-Za-z]{39,59}$",
"coin": "BTC",
"depositEnable": true,
"isDefault": true,
"memoRegex": "",
"minConfirm": 1,
"name": "BTC",
"network": "BTC",
"resetAddressStatus": false,
"specialTips": "",
"unLockConfirm": 0,
"withdrawEnable": true,
"withdrawFee": "0.00050000",
"withdrawIntegerMultiple": "0.00000001",
"withdrawMax": "750",
"withdrawMin": "0.00100000",
"sameAddress": false
}
],
"storage": "0.00000000",
"trading": true,
"withdrawAllEnable": true,
"withdrawing": "0.00000000"
}
]`)

s.mockDo(data, nil)
defer s.assertDo()

s.assertReq(func(r *request) {
e := newSignedRequest()
s.assertRequestEqual(e, r)
})

res, err := s.client.NewGetAllCoinsInfoService().Do(newContext())
s.r().NoError(err)
s.r().Equal(res[0].DepositAllEnable, true, "depositAllEnable")
s.r().Equal(res[0].NetworkList[0].WithdrawEnable, false, "withdrawEnable")
s.r().Equal(res[0].NetworkList[1].MinConfirm, 1, "minConfirm")
}
5 changes: 5 additions & 0 deletions v2/client.go
Expand Up @@ -624,3 +624,8 @@ func (c *Client) NewListDustLogService() *ListDustLogService {
func (c *Client) NewDustTransferService() *DustTransferService {
return &DustTransferService{c: c}
}

// NewAllCoinsInformation
func (c *Client) NewGetAllCoinsInfoService() *GetAllCoinsInfoService {
return &GetAllCoinsInfoService{c: c}
}

0 comments on commit e8393f3

Please sign in to comment.