Skip to content

Commit

Permalink
Add_some_flexible_loan_endpoints (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Haiss2 authored Oct 13, 2023
1 parent a45823f commit 4d5d914
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 4 deletions.
16 changes: 14 additions & 2 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}
}
96 changes: 96 additions & 0 deletions v2/flexible_loan_repay.go
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
}
88 changes: 88 additions & 0 deletions v2/get_flexible_loan_ongoing_orders.go
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 = &current
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
}
80 changes: 78 additions & 2 deletions v2/loan_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}

0 comments on commit 4d5d914

Please sign in to comment.