Skip to content

Commit

Permalink
feat: Add permissionSets field to exchange info response (#641)
Browse files Browse the repository at this point in the history
* add Symbol.PermissionSets

* add ExchangeInfoService.showPermissionSets

* add TestExchangeInfoWithPermissionSets
  • Loading branch information
felipeneuwald authored Dec 4, 2024
1 parent 4fd0ba3 commit 03a0e81
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
20 changes: 16 additions & 4 deletions v2/exchange_info_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (

// ExchangeInfoService exchange info service
type ExchangeInfoService struct {
c *Client
symbol string
symbols []string
permissions []string
c *Client
symbol string
symbols []string
permissions []string
showPermissionSets *bool
}

// Symbol set symbol
Expand All @@ -35,6 +36,13 @@ func (s *ExchangeInfoService) Permissions(permissions ...string) *ExchangeInfoSe
return s
}

// ShowPermissionSets set showPermissionSets
func (s *ExchangeInfoService) ShowPermissionSets(showPermissionSets *bool) *ExchangeInfoService {
s.showPermissionSets = showPermissionSets

return s
}

// Do send request
func (s *ExchangeInfoService) Do(ctx context.Context, opts ...RequestOption) (res *ExchangeInfo, err error) {
r := &request{
Expand All @@ -52,6 +60,9 @@ func (s *ExchangeInfoService) Do(ctx context.Context, opts ...RequestOption) (re
if len(s.permissions) != 0 {
m["permissions"] = s.permissions
}
if s.showPermissionSets != nil {
m["showPermissionSets"] = *s.showPermissionSets
}
r.setParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
Expand Down Expand Up @@ -102,6 +113,7 @@ type Symbol struct {
IsMarginTradingAllowed bool `json:"isMarginTradingAllowed"`
Filters []map[string]interface{} `json:"filters"`
Permissions []string `json:"permissions"`
PermissionSets [][]string `json:"permissionSets"`
}

// LotSizeFilter define lot size filter of symbol
Expand Down
53 changes: 53 additions & 0 deletions v2/exchange_info_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,59 @@ func (s *exchangeInfoServiceTestSuite) TestExchangeInfo() {
s.assertMaxNumAlgoOrdersFilterEqual(eMaxNumAlgoOrdersFilter, res.Symbols[0].MaxNumAlgoOrdersFilter())
}

func (s *exchangeInfoServiceTestSuite) TestExchangeInfoWithPermissionSets() {
data := []byte(`{
"timezone":"UTC",
"serverTime":1733252001653,
"rateLimits":[
{
"rateLimitType":"REQUEST_WEIGHT",
"interval":"MINUTE",
"intervalNum":1,
"limit":6000
}
],
"exchangeFilters":[],
"symbols":[
{
"symbol":"BTCUSDT",
"status":"TRADING",
"baseAsset":"BTC",
"baseAssetPrecision":8,
"quoteAsset":"USDT",
"quotePrecision":8,
"quoteAssetPrecision":8,
"baseCommissionPrecision":8,
"quoteCommissionPrecision":8,
"orderTypes":["LIMIT","LIMIT_MAKER","MARKET","STOP_LOSS","STOP_LOSS_LIMIT","TAKE_PROFIT","TAKE_PROFIT_LIMIT"],
"icebergAllowed":true,
"ocoAllowed":true,
"otoAllowed":true,
"quoteOrderQtyMarketAllowed":true,
"allowTrailingStop":true,
"cancelReplaceAllowed":true,
"isSpotTradingAllowed":true,
"isMarginTradingAllowed":true,
"filters":[
{
"filterType":"PRICE_FILTER",
"minPrice":"0.01000000",
"maxPrice":"1000000.00000000",
"tickSize":"0.01000000"
}
],
"permissions":[],
"permissionSets":[["SPOT","MARGIN"]]
}
]
}`)
s.mockDo(data, nil)
res, err := s.client.NewExchangeInfoService().Symbol("BTCUSDT").Do(newContext())
s.r().NoError(err)
s.r().Len(res.Symbols[0].PermissionSets, 1)
s.r().Equal([]string{"SPOT", "MARGIN"}, res.Symbols[0].PermissionSets[0])
}

func (s *exchangeInfoServiceTestSuite) assertExchangeInfoEqual(e, a *ExchangeInfo) {
r := s.r()

Expand Down

0 comments on commit 03a0e81

Please sign in to comment.