From 17e0b79e62ab8cf924c3e8c248510136edf723db Mon Sep 17 00:00:00 2001 From: Haiss2 Date: Thu, 19 Oct 2023 18:12:15 +0700 Subject: [PATCH] Add sapi/v1/loan/flexible/borrow/history --- v2/get_flexible_loan_ borrow_history.go | 111 ++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 v2/get_flexible_loan_ borrow_history.go diff --git a/v2/get_flexible_loan_ borrow_history.go b/v2/get_flexible_loan_ borrow_history.go new file mode 100644 index 00000000..b24ae50b --- /dev/null +++ b/v2/get_flexible_loan_ borrow_history.go @@ -0,0 +1,111 @@ +package binance + +import ( + "context" + "net/http" +) + +type GetFlexibleLoanBorrowHistoryService struct { + c *Client + loanCoin *string + collateralCoin *string + startTime *int64 + endTime *int64 + current *int64 + limit *int64 +} + +type GetFlexibleLoanBorrowHistoryResp struct { + Rows []FlexibleLoanBorrowHistory `json:"rows"` + Total int64 `json:"total"` +} + +type FlexibleLoanBorrowHistory struct { + LoanCoin string `json:"loanCoin"` + InitialLoanAmount string `json:"initialLoanAmount"` + CollateralCoin string `json:"collateralCoin"` + InitialCollateralAmount string `json:"initialCollateralAmount"` + BorrowTime int64 `json:"borrowTime"` + Status FlexibleBorrowStatus `json:"status"` +} + +// LoanCoin set loanCoin +func (s *GetFlexibleLoanBorrowHistoryService) LoanCoin(loanCoin string) *GetFlexibleLoanBorrowHistoryService { + s.loanCoin = &loanCoin + return s +} + +// CollateralCoin set collateralCoin +func (s *GetFlexibleLoanBorrowHistoryService) CollateralCoin(coll string) *GetFlexibleLoanBorrowHistoryService { + s.collateralCoin = &coll + return s +} + +// Current set current +func (s *GetFlexibleLoanBorrowHistoryService) Current(current int64) *GetFlexibleLoanBorrowHistoryService { + s.current = ¤t + return s +} + +// Limit set limit +func (s *GetFlexibleLoanBorrowHistoryService) Limit(limit int64) *GetFlexibleLoanBorrowHistoryService { + s.limit = &limit + return s +} + +// StartTime set startTime +func (s *GetFlexibleLoanBorrowHistoryService) StartTime(startTime int64) *GetFlexibleLoanBorrowHistoryService { + s.startTime = &startTime + return s +} + +// EndTime set endTime +func (s *GetFlexibleLoanBorrowHistoryService) EndTime(endTime int64) *GetFlexibleLoanBorrowHistoryService { + s.endTime = &endTime + return s +} + +// Do send request +func (s *GetFlexibleLoanBorrowHistoryService) Do(ctx context.Context, opts ...RequestOption) (res *GetFlexibleLoanBorrowHistoryResp, err error) { + r := &request{ + method: http.MethodGet, + endpoint: "/sapi/v1/loan/flexible/borrow/history", + 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) + } + + if s.startTime != nil { + r.setParam("startTime", *s.startTime) + } + + if s.endTime != nil { + r.setParam("endTime", *s.endTime) + } + + data, err := s.c.callAPI(ctx, r, opts...) + if err != nil { + return nil, err + } + + res = new(GetFlexibleLoanBorrowHistoryResp) + err = json.Unmarshal(data, res) + if err != nil { + return nil, err + } + return res, nil +}