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

Added All Coins' Information #342

Merged
merged 1 commit into from Jan 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions v2/asset_detail_service.go
Expand Up @@ -42,6 +42,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 @@ -50,3 +74,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 @@ -681,6 +681,11 @@ func (c *Client) NewUserUniversalTransferService() *CreateUserUniversalTransferS
return &CreateUserUniversalTransferService{c: c}
}

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

// NewDustTransferService init Get All Margin Assets service
func (c *Client) NewGetAllMarginAssetsService() *GetAllMarginAssetsService {
return &GetAllMarginAssetsService{c: c}
Expand Down