forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add_some_flexible_loan_endpoints (#6)
- Loading branch information
Showing
4 changed files
with
276 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters