Skip to content

Commit e897fbf

Browse files
authored
add MarginGetAvailableInventoryService (#33)
1 parent a7296c3 commit e897fbf

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

v2/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,3 +1068,7 @@ func (c *Client) NewGetDelistService() *GetDelistService {
10681068
func (c *Client) NewMarginGetDelistService() *MarginGetDelistService {
10691069
return &MarginGetDelistService{c: c}
10701070
}
1071+
1072+
func (c *Client) NewMarginGetAvailableInventoryService() *MarginGetAvailableInventoryService {
1073+
return &MarginGetAvailableInventoryService{c: c}
1074+
}

v2/margin_service.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,3 +1346,44 @@ func (s *IsolatedMarginTransferService) Do(ctx context.Context, opts ...RequestO
13461346
}
13471347
return res, nil
13481348
}
1349+
1350+
type MarginGetAvailableInventoryService struct {
1351+
c *Client
1352+
isIsolated bool
1353+
}
1354+
1355+
// IsIsolated is for isolated margin or not, "TRUE", "FALSE",default "FALSE"
1356+
func (s *MarginGetAvailableInventoryService) IsIsolated(isIsolated bool) *MarginGetAvailableInventoryService {
1357+
s.isIsolated = isIsolated
1358+
return s
1359+
}
1360+
1361+
type AvailableInventory struct {
1362+
Assets map[string]string `json:"assets"`
1363+
UpdateTime int64 `json:"updateTime"`
1364+
}
1365+
1366+
// Do send request
1367+
func (s *MarginGetAvailableInventoryService) Do(ctx context.Context, opts ...RequestOption) (*AvailableInventory, error) {
1368+
r := &request{
1369+
method: http.MethodGet,
1370+
endpoint: "/sapi/v1/margin/available-inventory",
1371+
secType: secTypeSigned,
1372+
}
1373+
if s.isIsolated {
1374+
r.setParam("type", "ISOLATED")
1375+
} else {
1376+
r.setParam("type", "MARGIN")
1377+
}
1378+
1379+
data, err := s.c.callAPI(ctx, r, opts...)
1380+
if err != nil {
1381+
return nil, err
1382+
}
1383+
1384+
var res AvailableInventory
1385+
if err := json.Unmarshal(data, &res); err != nil {
1386+
return nil, err
1387+
}
1388+
return &res, nil
1389+
}

0 commit comments

Comments
 (0)