Skip to content

Commit

Permalink
Add getIsolatedMarginAllPairs endpoint (#350)
Browse files Browse the repository at this point in the history
Co-authored-by: adshao <tjusgj@gmail.com>
  • Loading branch information
quserinn and adshao committed Mar 14, 2022
1 parent 84448eb commit 5c415dd
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
5 changes: 5 additions & 0 deletions v2/client.go
Expand Up @@ -733,6 +733,11 @@ func (c *Client) NewConvertTradeHistoryService() *ConvertTradeHistoryService {
return &ConvertTradeHistoryService{c: c}
}

// NewGetIsolatedMarginAllPairsService init get isolated margin all pairs service
func (c *Client) NewGetIsolatedMarginAllPairsService() *GetIsolatedMarginAllPairsService {
return &GetIsolatedMarginAllPairsService{c: c}
}

// NewInterestHistoryService init the interest history service
func (c *Client) NewInterestHistoryService() *InterestHistoryService {
return &InterestHistoryService{c: c}
Expand Down
34 changes: 34 additions & 0 deletions v2/margin_service.go
Expand Up @@ -1011,3 +1011,37 @@ func (s *GetAllMarginAssetsService) Do(ctx context.Context, opts ...RequestOptio
}
return res, nil
}

// GetIsolatedMarginAllPairsService get isolated margin pair info
type GetIsolatedMarginAllPairsService struct {
c *Client
}

// Do send request
func (s *GetIsolatedMarginAllPairsService) Do(ctx context.Context, opts ...RequestOption) (res []*IsolatedMarginAllPair, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/margin/isolated/allPairs",
secType: secTypeAPIKey,
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return []*IsolatedMarginAllPair{}, err
}
res = make([]*IsolatedMarginAllPair, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*IsolatedMarginAllPair{}, err
}
return res, nil
}

// IsolatedMarginAllPair define isolated margin pair info
type IsolatedMarginAllPair struct {
Symbol string `json:"symbol"`
Base string `json:"base"`
Quote string `json:"quote"`
IsMarginTrade bool `json:"isMarginTrade"`
IsBuyAllowed bool `json:"isBuyAllowed"`
IsSellAllowed bool `json:"isSellAllowed"`
}
62 changes: 62 additions & 0 deletions v2/margin_service_test.go
Expand Up @@ -811,3 +811,65 @@ func (s *marginTestSuite) TestCloseMarginUserStream() {
err := s.client.NewCloseMarginUserStreamService().ListenKey(listenKey).Do(newContext())
s.r().NoError(err)
}

func (s *marginTestSuite) TestGetIsolatedMarginAllPairs() {
data := []byte(`[{
"base": "BNB",
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "BNBBTC"
},
{
"base": "TRX",
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "TRXBTC"
}]`)
s.mockDo(data, nil)
defer s.assertDo()

s.assertReq(func(r *request) {
e := newRequest()
s.assertRequestEqual(e, r)
})
res, err := s.client.NewGetIsolatedMarginAllPairsService().
Do(newContext())
r := s.r()
r.NoError(err)
r.Len(res, 2)
e := []*IsolatedMarginAllPair{
{
Symbol: "BNBBTC",
Base: "BNB",
Quote: "BTC",
IsMarginTrade: true,
IsBuyAllowed: true,
IsSellAllowed: true,
}, {
Symbol: "TRXBTC",
Base: "TRX",
Quote: "BTC",
IsMarginTrade: true,
IsBuyAllowed: true,
IsSellAllowed: true,
},
}

for i := 0; i < len(res); i++ {
s.assertIsolatedMarginAllPairsEqual(e[i], res[i])
}
}

func (s *marginTestSuite) assertIsolatedMarginAllPairsEqual(e, a *IsolatedMarginAllPair) {
r := s.r()
r.Equal(e.Symbol, a.Symbol, "Symbol")
r.Equal(e.Base, a.Base, "Base")
r.Equal(e.Quote, a.Quote, "Quote")
r.Equal(e.IsMarginTrade, a.IsMarginTrade, "IsMarginTrade")
r.Equal(e.IsBuyAllowed, a.IsBuyAllowed, "IsBuyAllowed")
r.Equal(e.IsSellAllowed, a.IsSellAllowed, "IsSellAllowed")
}

0 comments on commit 5c415dd

Please sign in to comment.