R/crypto_loans_api.R

# Binance Public Spot API
#
# OpenAPI Specifications for the Binance Public Spot API  API documents:   - [https://github.com/binance/binance-spot-api-docs](https://github.com/binance/binance-spot-api-docs)   - [https://binance-docs.github.io/apidocs/spot/en](https://binance-docs.github.io/apidocs/spot/en)
#
# The version of the OpenAPI document: 1.0
# 
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title CryptoLoans operations
#' @description binanceRapi.CryptoLoans
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ SapiV1LoanIncomeGet } \emph{ Get Crypto Loans Income History (USER_DATA) }
#' - If startTime and endTime are not sent, the recent 7-day data will be returned. - The max interval between startTime and endTime is 30 days.  Weight(UID): 6000
#'
#' \itemize{
#' \item \emph{ @param } asset character
#' \item \emph{ @param } type Enum < [borrowIn, collateralSpent, repayAmount, collateralReturn, addCollateral, removeCollateral, collateralReturnAfterLiquidation] >
#' \item \emph{ @param } start.time integer
#' \item \emph{ @param } end.time integer
#' \item \emph{ @param } limit integer
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } list( \link{inline_response_200_133} ) \cr
#'
#'
#' \item status code : 200 | Loan History
#'
#' \item return type : array[InlineResponse200133] 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 400 | Bad Request
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 401 | Unauthorized Request
#'
#' \item return type : Error 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  SapiV1LoanIncomeGet  ####################
#'
#' library(binanceRapi)
#' var.asset <- 'BTC' # character | 
#' var.type <- 'type_example' # character | All types will be returned by default. * `borrowIn` * `collateralSpent` * `repayAmount` * `collateralReturn` - Collateral return after repayment * `addCollateral` * `removeCollateral` * `collateralReturnAfterLiquidation`
#' var.start.time <- 56 # integer | UTC timestamp in ms
#' var.end.time <- 56 # integer | UTC timestamp in ms
#' var.limit <- 20 # integer | default 20, max 100
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Get Crypto Loans Income History (USER_DATA)
#' api.instance <- CryptoLoansApi$new()
#'
#' result <- api.instance$SapiV1LoanIncomeGet(var.asset, type=var.type, start.time=var.start.time, end.time=var.end.time, limit=var.limit, recv.window=var.recv.window)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
CryptoLoansApi <- R6::R6Class(
  'CryptoLoansApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    SapiV1LoanIncomeGet = function(asset, type=NULL, start.time=NULL, end.time=NULL, limit=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1LoanIncomeGetWithHttpInfo(asset, type, start.time, end.time, limit, recv.window, ...)
      resp <- apiResponse$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        apiResponse$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        apiResponse
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        apiResponse
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        apiResponse
      }
    },

    SapiV1LoanIncomeGetWithHttpInfo = function(asset, type=NULL, start.time=NULL, end.time=NULL, limit=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

      if (missing(`asset`)) {
        stop("Missing required parameter `asset`.")
      }

      queryParams['asset'] <- asset

      queryParams['type'] <- type

      queryParams['startTime'] <- start.time

      queryParams['endTime'] <- end.time

      queryParams['limit'] <- limit

      queryParams['recvWindow'] <- recv.window

      queryParams['timestamp'] <- self$apiClient$Timestamp
      
      queryParams['signature'] <- self$apiClient$credentials$sign(queryParams)

      body <- NULL
      urlPath <- "/sapi/v1/loan/income"
      # API key authentication
      if (nchar(self$apiClient$credentials$key) > 0) {
        headerParams['X-MBX-APIKEY'] <- self$apiClient$credentials$key
      }

      resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "array[InlineResponse200133]", loadNamespace("binanceRapi")),
          error = function(e){
             stop("Failed to deserialize response")
          }
        )
        ApiResponse$new(deserializedRespObj, resp)
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        ApiResponse$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        ApiResponse$new("API server error", resp)
      }
    }
  )
)
grahamjwhite/binanceRapi documentation built on Nov. 22, 2022, 9:37 p.m.