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

Add getIsolatedMarginAllPairs endpoint #350

Merged
merged 2 commits into from Mar 14, 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
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")
}