diff --git a/v2/client.go b/v2/client.go index aba78acf..4a66fb4f 100644 --- a/v2/client.go +++ b/v2/client.go @@ -1027,8 +1027,8 @@ func (c *Client) NewVipLoanService() *VipLoanService { return &VipLoanService{c: c} } -func (c *Client) NewFlexibleLoanService() *FlexibleLoanService { - return &FlexibleLoanService{c: c} +func (c *Client) NewGetFlexibleLoanAssetsDataService() *GetFlexibleLoanAssetsDataService { + return &GetFlexibleLoanAssetsDataService{c: c} } func (c *Client) NewIsolatedMarginDataService() *IsolatedMarginDataService { @@ -1038,3 +1038,15 @@ func (c *Client) NewIsolatedMarginDataService() *IsolatedMarginDataService { func (c *Client) NewCrossMarginDataService() *CrossMarginDataService { return &CrossMarginDataService{c: c} } + +func (c *Client) NewFlexibleLoanBorrowService() *FlexibleLoanBorrowService { + return &FlexibleLoanBorrowService{c: c} +} + +func (c *Client) NewGetFlexibleLoanOngoingOrdersService() *GetFlexibleLoanOngoingOrdersService { + return &GetFlexibleLoanOngoingOrdersService{c: c} +} + +func (c *Client) NewFlexibleLoanRepayService() *FlexibleLoanRepayService { + return &FlexibleLoanRepayService{c: c} +} diff --git a/v2/flexible_loan_repay.go b/v2/flexible_loan_repay.go new file mode 100644 index 00000000..f2c13ddc --- /dev/null +++ b/v2/flexible_loan_repay.go @@ -0,0 +1,96 @@ +package binance + +import ( + "context" + "net/http" +) + +type FlexibleLoanRepayService struct { + c *Client + loanCoin string + collateralCoin string + repayAmount float64 + collateralReturn *bool + fullRepayment *bool +} + +type FlexibleLoanRepayStatus string + +const ( + FlexibleLoanRepaid FlexibleBorrowStatus = "Repaid" + FlexibleLoanRepaying FlexibleBorrowStatus = "Repaying" + FlexibleLoanFailed FlexibleBorrowStatus = "Failed" +) + +type FlexibleLoanRepayResp struct { + LoanCoin string `json:"loanCoin"` + CollateralCoin string `json:"collateralCoin"` + RemainingDebt string `json:"remainingDebt"` + RemainingCollateral string `json:"remainingCollateral"` + FullRepayment bool `json:"fullRepayment"` + CurrentLTV string `json:"currentLTV"` + RepayStatus FlexibleLoanRepayStatus `json:"repayStatus"` +} + +// LoanCoin set loanCoin +func (s *FlexibleLoanRepayService) LoanCoin(loanCoin string) *FlexibleLoanRepayService { + s.loanCoin = loanCoin + return s +} + +// CollateralCoin set collateralCoin +func (s *FlexibleLoanRepayService) CollateralCoin(coll string) *FlexibleLoanRepayService { + s.collateralCoin = coll + return s +} + +// RepayAmount set repayAmount +func (s *FlexibleLoanRepayService) RepayAmount(amt float64) *FlexibleLoanRepayService { + s.repayAmount = amt + return s +} + +// CollateralReturn set collateralReturn +func (s *FlexibleLoanRepayService) CollateralReturn(collReturn bool) *FlexibleLoanRepayService { + s.collateralReturn = &collReturn + return s +} + +// FullRepayment set fullRepayment +func (s *FlexibleLoanRepayService) FullRepayment(fullRepayment bool) *FlexibleLoanRepayService { + s.fullRepayment = &fullRepayment + return s +} + +// Do send request +func (s *FlexibleLoanRepayService) Do(ctx context.Context, opts ...RequestOption) (res *FlexibleLoanRepayResp, err error) { + r := &request{ + method: http.MethodPost, + endpoint: "/sapi/v1/loan/flexible/repay", + secType: secTypeSigned, + } + + r.setParam("loanCoin", s.loanCoin) + r.setParam("collateralCoin", s.collateralCoin) + r.setParam("repayAmount", s.repayAmount) + + if s.collateralReturn != nil { + r.setParam("collateralReturn", *s.collateralReturn) + } + + if s.fullRepayment != nil { + r.setParam("fullRepayment", *s.fullRepayment) + } + + data, err := s.c.callAPI(ctx, r, opts...) + if err != nil { + return nil, err + } + + res = new(FlexibleLoanRepayResp) + err = json.Unmarshal(data, res) + if err != nil { + return nil, err + } + return res, nil +} diff --git a/v2/get_flexible_loan_ongoing_orders.go b/v2/get_flexible_loan_ongoing_orders.go new file mode 100644 index 00000000..5ba2f9a5 --- /dev/null +++ b/v2/get_flexible_loan_ongoing_orders.go @@ -0,0 +1,88 @@ +package binance + +import ( + "context" + "net/http" +) + +type GetFlexibleLoanOngoingOrdersService struct { + c *Client + loanCoin *string + collateralCoin *string + current *int64 + limit *int64 +} + +type GetFlexibleLoanOngoingOrdersResp struct { + Rows []FlexibleLoanOngoingOrder `json:"rows"` + Total int64 `json:"total"` +} + +type FlexibleLoanOngoingOrder struct { + LoanCoin string `json:"loanCoin"` + TotalDebt string `json:"totalDebt"` + CollateralCoin string `json:"collateralCoin"` + CollateralAmount string `json:"collateralAmount"` + CurrentLTV string `json:"currentLTV"` +} + +// LoanCoin set loanCoin +func (s *GetFlexibleLoanOngoingOrdersService) LoanCoin(loanCoin string) *GetFlexibleLoanOngoingOrdersService { + s.loanCoin = &loanCoin + return s +} + +// CollateralCoin set collateralCoin +func (s *GetFlexibleLoanOngoingOrdersService) CollateralCoin(coll string) *GetFlexibleLoanOngoingOrdersService { + s.collateralCoin = &coll + return s +} + +// Current set current +func (s *GetFlexibleLoanOngoingOrdersService) Current(current int64) *GetFlexibleLoanOngoingOrdersService { + s.current = ¤t + return s +} + +// Limit set limit +func (s *GetFlexibleLoanOngoingOrdersService) Limit(limit int64) *GetFlexibleLoanOngoingOrdersService { + s.limit = &limit + return s +} + +// Do send request +func (s *GetFlexibleLoanOngoingOrdersService) Do(ctx context.Context, opts ...RequestOption) (res *GetFlexibleLoanOngoingOrdersResp, err error) { + r := &request{ + method: http.MethodGet, + endpoint: "/sapi/v1/loan/flexible/ongoing/orders", + secType: secTypeSigned, + } + + if s.loanCoin != nil { + r.setParam("loanCoin", *s.loanCoin) + } + + if s.collateralCoin != nil { + r.setParam("collateralCoin", *s.collateralCoin) + } + + if s.current != nil { + r.setParam("current", *s.current) + } + + if s.limit != nil { + r.setParam("limit", *s.limit) + } + + data, err := s.c.callAPI(ctx, r, opts...) + if err != nil { + return nil, err + } + + res = new(GetFlexibleLoanOngoingOrdersResp) + err = json.Unmarshal(data, res) + if err != nil { + return nil, err + } + return res, nil +} diff --git a/v2/loan_service.go b/v2/loan_service.go index d2949dfd..d382ef91 100644 --- a/v2/loan_service.go +++ b/v2/loan_service.go @@ -105,12 +105,12 @@ type FlexibleLoanableAssets struct { Total int64 `json:"total"` } -type FlexibleLoanService struct { +type GetFlexibleLoanAssetsDataService struct { c *Client } // Do send request -func (s *FlexibleLoanService) Do(ctx context.Context, opts ...RequestOption) (res *FlexibleLoanableAssets, err error) { +func (s *GetFlexibleLoanAssetsDataService) Do(ctx context.Context, opts ...RequestOption) (res *FlexibleLoanableAssets, err error) { r := &request{ method: http.MethodGet, endpoint: "/sapi/v1/loan/flexible/loanable/data", @@ -129,3 +129,79 @@ func (s *FlexibleLoanService) Do(ctx context.Context, opts ...RequestOption) (re } return res, nil } + +type FlexibleLoanBorrowService struct { + c *Client + loanCoin string + loanAmount float64 + collateralCoin string + collateralAmount *float64 +} + +type FlexibleBorrowStatus string + +const ( + FlexibleBorrowStatusSucceeds FlexibleBorrowStatus = "Succeeds" + FlexibleBorrowStatusFailed FlexibleBorrowStatus = "Failed" + FlexibleBorrowStatusProcessing FlexibleBorrowStatus = "Processing" +) + +type FlexibleLoanBorrowResp struct { + LoanCoin string `json:"loanCoin"` + LoanAmount string `json:"loanAmount"` + CollateralCoin string `json:"collateralCoin"` + CollateralAmount string `json:"collateralAmount"` + Status FlexibleBorrowStatus `json:"status"` +} + +// LoanCoin set loanCoin +func (s *FlexibleLoanBorrowService) LoanCoin(loanCoin string) *FlexibleLoanBorrowService { + s.loanCoin = loanCoin + return s +} + +// LoanAmount set loanAmount +func (s *FlexibleLoanBorrowService) LoanAmount(loanAmount float64) *FlexibleLoanBorrowService { + s.loanAmount = loanAmount + return s +} + +// CollateralCoin set collateralCoin +func (s *FlexibleLoanBorrowService) CollateralCoin(coll string) *FlexibleLoanBorrowService { + s.collateralCoin = coll + return s +} + +// CollateralAmount set collateralAmount +func (s *FlexibleLoanBorrowService) CollateralAmount(collAmt float64) *FlexibleLoanBorrowService { + s.collateralAmount = &collAmt + return s +} + +// Do send request +func (s *FlexibleLoanBorrowService) Do(ctx context.Context, opts ...RequestOption) (res *FlexibleLoanBorrowResp, err error) { + r := &request{ + method: http.MethodPost, + endpoint: "/sapi/v1/loan/flexible/borrow", + secType: secTypeSigned, + } + + r.setParam("loanCoin", s.loanCoin) + r.setParam("loanAmount", s.loanAmount) + r.setParam("collateralCoin", s.collateralCoin) + if s.collateralAmount != nil { + r.setParam("collateralAmount", *s.collateralAmount) + } + + data, err := s.c.callAPI(ctx, r, opts...) + if err != nil { + return nil, err + } + + res = new(FlexibleLoanBorrowResp) + err = json.Unmarshal(data, res) + if err != nil { + return nil, err + } + return res, nil +}