Skip to content

Commit

Permalink
added max-loan on account methods
Browse files Browse the repository at this point in the history
  • Loading branch information
amaioli committed May 5, 2022
1 parent 5b08558 commit 039d0f0
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
66 changes: 66 additions & 0 deletions account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,69 @@ type LeverageDetail struct {
PosSide string `json:"posSide"`
Lever string `json:"lever"`
}

// GetMaximumLoanService get account balance
type GetMaximumLoanService struct {
c *Client
instId string
mgnMode string
mgnCcy string
}

// Set currency instId
func (s *GetMaximumLoanService) InstrumentId(instId string) *GetMaximumLoanService {
s.instId = instId
return s
}

// Set currency mgnMode
func (s *GetMaximumLoanService) ManagementMode(mgnMode string) *GetMaximumLoanService {
s.mgnMode = mgnMode
return s
}

// Set currency mgnMode
func (s *GetMaximumLoanService) ManagementCurrency(mgnCcy string) *GetMaximumLoanService {
s.mgnCcy = mgnCcy
return s
}

// Do send request
func (s *GetMaximumLoanService) Do(ctx context.Context, opts ...RequestOption) (res *GetMaximumLoanServiceResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/api/v5/account/max-loan",
secType: secTypeSigned,
}

r.setParam("instId", s.instId)
r.setParam("mgnMode", s.mgnMode)
r.setParam("mgnCcy", s.mgnCcy)

data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(GetMaximumLoanServiceResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}

// Get the maximum loan of instrument response
type GetMaximumLoanServiceResponse struct {
Code string `json:"code"`
Data []*MaxLoan `json:"data"`
Msg string `json:"msg"`
}

type MaxLoan struct {
InstId string `json:"instId"`
MgnMode string `json:"mgnMode"`
MgnCcy string `json:"mgnCcy"`
MaxLoan string `json:"maxLoan"`
Ccy string `json:"ccy"`
Side string `json:"side"`
}
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,8 @@ func (c *Client) NewGetDeliveryExerciseHistoryService() *GetDeliveryExerciseHist
func (c *Client) NewFundTransferService() *FundTransferService {
return &FundTransferService{c: c}
}

// NewFundTransferService
func (c *Client) NewMaximumLoanService() *GetMaximumLoanService {
return &GetMaximumLoanService{c: c}
}

0 comments on commit 039d0f0

Please sign in to comment.