R/staking_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 Staking operations
#' @description binanceRapi.Staking
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ SapiV1StakingPersonalLeftQuotaGet } \emph{ Get Personal Left Quota of Staking Product (USER_DATA) }
#' Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } product character
#' \item \emph{ @param } product.id character
#' \item \emph{ @param } timestamp integer
#' \item \emph{ @param } signature character
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } list( \link{inline_response_200_100} ) \cr
#'
#'
#' \item status code : 200 | Quota.
#'
#' \item return type : array[InlineResponse200100] 
#' \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}{
#' }
#' }
#'
#' \strong{ SapiV1StakingPositionGet } \emph{ Get Staking Product Position (USER_DATA) }
#' Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } product character
#' \item \emph{ @param } timestamp integer
#' \item \emph{ @param } signature character
#' \item \emph{ @param } product.id character
#' \item \emph{ @param } asset character
#' \item \emph{ @param } current integer
#' \item \emph{ @param } size integer
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } list( \link{inline_response_200_98} ) \cr
#'
#'
#' \item status code : 200 | Position.
#'
#' \item return type : array[InlineResponse20098] 
#' \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}{
#' }
#' }
#'
#' \strong{ SapiV1StakingProductListGet } \emph{ Get Staking Product List (USER_DATA) }
#' Get available Staking product list.  Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } product character
#' \item \emph{ @param } timestamp integer
#' \item \emph{ @param } signature character
#' \item \emph{ @param } asset character
#' \item \emph{ @param } current integer
#' \item \emph{ @param } size integer
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } list( \link{inline_response_200_95} ) \cr
#'
#'
#' \item status code : 200 | Product list.
#'
#' \item return type : array[InlineResponse20095] 
#' \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}{
#' }
#' }
#'
#' \strong{ SapiV1StakingPurchasePost } \emph{ Purchase Staking Product (USER_DATA) }
#' Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } product character
#' \item \emph{ @param } product.id character
#' \item \emph{ @param } amount numeric
#' \item \emph{ @param } timestamp integer
#' \item \emph{ @param } signature character
#' \item \emph{ @param } renewable character
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } \link{InlineResponse20096} \cr
#'
#'
#' \item status code : 200 | Position Id.
#'
#' \item return type : InlineResponse20096 
#' \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}{
#' }
#' }
#'
#' \strong{ SapiV1StakingRedeemPost } \emph{ Redeem Staking Product (USER_DATA) }
#' Redeem Staking product. Locked staking and Locked DeFI staking belong to early redemption, redeeming in advance will result in loss of interest that you have earned.  Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } product character
#' \item \emph{ @param } product.id character
#' \item \emph{ @param } timestamp integer
#' \item \emph{ @param } signature character
#' \item \emph{ @param } position.id character
#' \item \emph{ @param } amount numeric
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } \link{InlineResponse20097} \cr
#'
#'
#' \item status code : 200 | Success.
#'
#' \item return type : InlineResponse20097 
#' \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}{
#' }
#' }
#'
#' \strong{ SapiV1StakingSetAutoStakingPost } \emph{ Set Auto Staking (USER_DATA) }
#' Set auto staking on Locked Staking or Locked DeFi Staking  Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } product character
#' \item \emph{ @param } position.id character
#' \item \emph{ @param } renewable character
#' \item \emph{ @param } timestamp integer
#' \item \emph{ @param } signature character
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } \link{InlineResponse20097} \cr
#'
#'
#' \item status code : 200 | Success.
#'
#' \item return type : InlineResponse20097 
#' \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}{
#' }
#' }
#'
#' \strong{ SapiV1StakingStakingRecordGet } \emph{ Get Staking History (USER_DATA) }
#' Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } product character
#' \item \emph{ @param } txn.type character
#' \item \emph{ @param } timestamp integer
#' \item \emph{ @param } signature character
#' \item \emph{ @param } asset character
#' \item \emph{ @param } start.time integer
#' \item \emph{ @param } end.time integer
#' \item \emph{ @param } current integer
#' \item \emph{ @param } size integer
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } list( \link{inline_response_200_99} ) \cr
#'
#'
#' \item status code : 200 | Staking History.
#'
#' \item return type : array[InlineResponse20099] 
#' \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{
#' ####################  SapiV1StakingPersonalLeftQuotaGet  ####################
#'
#' library(binanceRapi)
#' var.product <- 'product_example' # character | * `STAKING` - for Locked Staking * `F_DEFI` - for flexible DeFi Staking * `L_DEFI` - for locked DeFi Staking
#' var.product.id <- 'product.id_example' # character | 
#' var.timestamp <- 56 # integer | UTC timestamp in ms
#' var.signature <- 'signature_example' # character | Signature
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Get Personal Left Quota of Staking Product (USER_DATA)
#' api.instance <- StakingApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-MBX-APIKEY'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$SapiV1StakingPersonalLeftQuotaGet(var.product, var.product.id, var.timestamp, var.signature, recv.window=var.recv.window)
#'
#'
#' ####################  SapiV1StakingPositionGet  ####################
#'
#' library(binanceRapi)
#' var.product <- 'product_example' # character | * `STAKING` - for Locked Staking * `F_DEFI` - for flexible DeFi Staking * `L_DEFI` - for locked DeFi Staking
#' var.timestamp <- 56 # integer | UTC timestamp in ms
#' var.signature <- 'signature_example' # character | Signature
#' var.product.id <- 'product.id_example' # character | 
#' var.asset <- 'BNB' # character | 
#' var.current <- 1 # integer | Current querying page. Start from 1. Default:1
#' var.size <- 100 # integer | Default:10 Max:100
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Get Staking Product Position (USER_DATA)
#' api.instance <- StakingApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-MBX-APIKEY'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$SapiV1StakingPositionGet(var.product, var.timestamp, var.signature, product.id=var.product.id, asset=var.asset, current=var.current, size=var.size, recv.window=var.recv.window)
#'
#'
#' ####################  SapiV1StakingProductListGet  ####################
#'
#' library(binanceRapi)
#' var.product <- 'product_example' # character | * `STAKING` - for Locked Staking * `F_DEFI` - for flexible DeFi Staking * `L_DEFI` - for locked DeFi Staking
#' var.timestamp <- 56 # integer | UTC timestamp in ms
#' var.signature <- 'signature_example' # character | Signature
#' var.asset <- 'BNB' # character | 
#' var.current <- 1 # integer | Current querying page. Start from 1. Default:1
#' var.size <- 100 # integer | Default:10 Max:100
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Get Staking Product List (USER_DATA)
#' api.instance <- StakingApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-MBX-APIKEY'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$SapiV1StakingProductListGet(var.product, var.timestamp, var.signature, asset=var.asset, current=var.current, size=var.size, recv.window=var.recv.window)
#'
#'
#' ####################  SapiV1StakingPurchasePost  ####################
#'
#' library(binanceRapi)
#' var.product <- 'product_example' # character | * `STAKING` - for Locked Staking * `F_DEFI` - for flexible DeFi Staking * `L_DEFI` - for locked DeFi Staking
#' var.product.id <- 'product.id_example' # character | 
#' var.amount <- 1.01 # numeric | 
#' var.timestamp <- 56 # integer | UTC timestamp in ms
#' var.signature <- 'signature_example' # character | Signature
#' var.renewable <- 'renewable_example' # character | true or false, default false. Active if product is `STAKING` or `L_DEFI`
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Purchase Staking Product (USER_DATA)
#' api.instance <- StakingApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-MBX-APIKEY'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$SapiV1StakingPurchasePost(var.product, var.product.id, var.amount, var.timestamp, var.signature, renewable=var.renewable, recv.window=var.recv.window)
#'
#'
#' ####################  SapiV1StakingRedeemPost  ####################
#'
#' library(binanceRapi)
#' var.product <- 'product_example' # character | * `STAKING` - for Locked Staking * `F_DEFI` - for flexible DeFi Staking * `L_DEFI` - for locked DeFi Staking
#' var.product.id <- 'product.id_example' # character | 
#' var.timestamp <- 56 # integer | UTC timestamp in ms
#' var.signature <- 'signature_example' # character | Signature
#' var.position.id <- 'position.id_example' # character | Mandatory if product is `STAKING` or `L_DEFI`
#' var.amount <- 3.4 # numeric | Mandatory if product is `F_DEFI`
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Redeem Staking Product (USER_DATA)
#' api.instance <- StakingApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-MBX-APIKEY'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$SapiV1StakingRedeemPost(var.product, var.product.id, var.timestamp, var.signature, position.id=var.position.id, amount=var.amount, recv.window=var.recv.window)
#'
#'
#' ####################  SapiV1StakingSetAutoStakingPost  ####################
#'
#' library(binanceRapi)
#' var.product <- 'product_example' # character | * `STAKING` - for Locked Staking * `L_DEFI` - for locked DeFi Staking
#' var.position.id <- 'position.id_example' # character | 
#' var.renewable <- 'renewable_example' # character | true or false
#' var.timestamp <- 56 # integer | UTC timestamp in ms
#' var.signature <- 'signature_example' # character | Signature
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Set Auto Staking (USER_DATA)
#' api.instance <- StakingApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-MBX-APIKEY'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$SapiV1StakingSetAutoStakingPost(var.product, var.position.id, var.renewable, var.timestamp, var.signature, recv.window=var.recv.window)
#'
#'
#' ####################  SapiV1StakingStakingRecordGet  ####################
#'
#' library(binanceRapi)
#' var.product <- 'product_example' # character | * `STAKING` - for Locked Staking * `F_DEFI` - for flexible DeFi Staking * `L_DEFI` - for locked DeFi Staking
#' var.txn.type <- 'txn.type_example' # character | `SUBSCRIPTION`, `REDEMPTION`, `INTEREST`
#' var.timestamp <- 56 # integer | UTC timestamp in ms
#' var.signature <- 'signature_example' # character | Signature
#' var.asset <- 'BNB' # character | 
#' var.start.time <- 56 # integer | UTC timestamp in ms
#' var.end.time <- 56 # integer | UTC timestamp in ms
#' var.current <- 1 # integer | Current querying page. Start from 1. Default:1
#' var.size <- 100 # integer | Default:10 Max:100
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Get Staking History (USER_DATA)
#' api.instance <- StakingApi$new()
#'
#' #Configure API key authorization: ApiKeyAuth
#' api.instance$apiClient$apiKeys['X-MBX-APIKEY'] <- 'TODO_YOUR_API_KEY';
#'
#' result <- api.instance$SapiV1StakingStakingRecordGet(var.product, var.txn.type, var.timestamp, var.signature, asset=var.asset, start.time=var.start.time, end.time=var.end.time, current=var.current, size=var.size, recv.window=var.recv.window)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
StakingApi <- R6::R6Class(
  'StakingApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    SapiV1StakingPersonalLeftQuotaGet = function(product, product.id, timestamp, signature, recv.window=NULL, ...){
      apiResponse <- self$SapiV1StakingPersonalLeftQuotaGetWithHttpInfo(product, product.id, timestamp, signature, 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
      }
    },

    SapiV1StakingPersonalLeftQuotaGetWithHttpInfo = function(product, product.id, timestamp, signature, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

      queryParams['product'] <- product

      queryParams['productId'] <- product.id

      queryParams['recvWindow'] <- recv.window

      queryParams['timestamp'] <- timestamp

      queryParams['signature'] <- signature

      body <- NULL
      urlPath <- "/sapi/v1/staking/personalLeftQuota"
      # API key authentication
      if ("X-MBX-APIKEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-MBX-APIKEY"]) > 0) {
        headerParams['X-MBX-APIKEY'] <- paste(unlist(self$apiClient$apiKeys["X-MBX-APIKEY"]), collapse='')
      }

      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[InlineResponse200100]", 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)
      }
    },
    SapiV1StakingPositionGet = function(product, timestamp, signature, product.id=NULL, asset=NULL, current=NULL, size=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1StakingPositionGetWithHttpInfo(product, timestamp, signature, product.id, asset, current, size, 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
      }
    },

    SapiV1StakingPositionGetWithHttpInfo = function(product, timestamp, signature, product.id=NULL, asset=NULL, current=NULL, size=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

      queryParams['product'] <- product

      queryParams['productId'] <- product.id

      queryParams['asset'] <- asset

      queryParams['current'] <- current

      queryParams['size'] <- size

      queryParams['recvWindow'] <- recv.window

      queryParams['timestamp'] <- timestamp

      queryParams['signature'] <- signature

      body <- NULL
      urlPath <- "/sapi/v1/staking/position"
      # API key authentication
      if ("X-MBX-APIKEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-MBX-APIKEY"]) > 0) {
        headerParams['X-MBX-APIKEY'] <- paste(unlist(self$apiClient$apiKeys["X-MBX-APIKEY"]), collapse='')
      }

      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[InlineResponse20098]", 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)
      }
    },
    SapiV1StakingProductListGet = function(product, timestamp, signature, asset=NULL, current=NULL, size=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1StakingProductListGetWithHttpInfo(product, timestamp, signature, asset, current, size, 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
      }
    },

    SapiV1StakingProductListGetWithHttpInfo = function(product, timestamp, signature, asset=NULL, current=NULL, size=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

      queryParams['product'] <- product

      queryParams['asset'] <- asset

      queryParams['current'] <- current

      queryParams['size'] <- size

      queryParams['recvWindow'] <- recv.window

      queryParams['timestamp'] <- timestamp

      queryParams['signature'] <- signature

      body <- NULL
      urlPath <- "/sapi/v1/staking/productList"
      # API key authentication
      if ("X-MBX-APIKEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-MBX-APIKEY"]) > 0) {
        headerParams['X-MBX-APIKEY'] <- paste(unlist(self$apiClient$apiKeys["X-MBX-APIKEY"]), collapse='')
      }

      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[InlineResponse20095]", 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)
      }
    },
    SapiV1StakingPurchasePost = function(product, product.id, amount, timestamp, signature, renewable=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1StakingPurchasePostWithHttpInfo(product, product.id, amount, timestamp, signature, renewable, 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
      }
    },

    SapiV1StakingPurchasePostWithHttpInfo = function(product, product.id, amount, timestamp, signature, renewable=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

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

      queryParams['product'] <- product

      queryParams['productId'] <- product.id

      queryParams['amount'] <- amount

      queryParams['renewable'] <- renewable

      queryParams['recvWindow'] <- recv.window

      queryParams['timestamp'] <- timestamp

      queryParams['signature'] <- signature

      body <- NULL
      urlPath <- "/sapi/v1/staking/purchase"
      # API key authentication
      if ("X-MBX-APIKEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-MBX-APIKEY"]) > 0) {
        headerParams['X-MBX-APIKEY'] <- paste(unlist(self$apiClient$apiKeys["X-MBX-APIKEY"]), collapse='')
      }

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

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "InlineResponse20096", 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)
      }
    },
    SapiV1StakingRedeemPost = function(product, product.id, timestamp, signature, position.id=NULL, amount=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1StakingRedeemPostWithHttpInfo(product, product.id, timestamp, signature, position.id, amount, 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
      }
    },

    SapiV1StakingRedeemPostWithHttpInfo = function(product, product.id, timestamp, signature, position.id=NULL, amount=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

      queryParams['product'] <- product

      queryParams['positionId'] <- position.id

      queryParams['productId'] <- product.id

      queryParams['amount'] <- amount

      queryParams['recvWindow'] <- recv.window

      queryParams['timestamp'] <- timestamp

      queryParams['signature'] <- signature

      body <- NULL
      urlPath <- "/sapi/v1/staking/redeem"
      # API key authentication
      if ("X-MBX-APIKEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-MBX-APIKEY"]) > 0) {
        headerParams['X-MBX-APIKEY'] <- paste(unlist(self$apiClient$apiKeys["X-MBX-APIKEY"]), collapse='')
      }

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

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "InlineResponse20097", 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)
      }
    },
    SapiV1StakingSetAutoStakingPost = function(product, position.id, renewable, timestamp, signature, recv.window=NULL, ...){
      apiResponse <- self$SapiV1StakingSetAutoStakingPostWithHttpInfo(product, position.id, renewable, timestamp, signature, 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
      }
    },

    SapiV1StakingSetAutoStakingPostWithHttpInfo = function(product, position.id, renewable, timestamp, signature, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

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

      queryParams['product'] <- product

      queryParams['positionId'] <- position.id

      queryParams['renewable'] <- renewable

      queryParams['recvWindow'] <- recv.window

      queryParams['timestamp'] <- timestamp

      queryParams['signature'] <- signature

      body <- NULL
      urlPath <- "/sapi/v1/staking/setAutoStaking"
      # API key authentication
      if ("X-MBX-APIKEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-MBX-APIKEY"]) > 0) {
        headerParams['X-MBX-APIKEY'] <- paste(unlist(self$apiClient$apiKeys["X-MBX-APIKEY"]), collapse='')
      }

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

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "InlineResponse20097", 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)
      }
    },
    SapiV1StakingStakingRecordGet = function(product, txn.type, timestamp, signature, asset=NULL, start.time=NULL, end.time=NULL, current=NULL, size=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1StakingStakingRecordGetWithHttpInfo(product, txn.type, timestamp, signature, asset, start.time, end.time, current, size, 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
      }
    },

    SapiV1StakingStakingRecordGetWithHttpInfo = function(product, txn.type, timestamp, signature, asset=NULL, start.time=NULL, end.time=NULL, current=NULL, size=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

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

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

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

      queryParams['product'] <- product

      queryParams['txnType'] <- txn.type

      queryParams['asset'] <- asset

      queryParams['startTime'] <- start.time

      queryParams['endTime'] <- end.time

      queryParams['current'] <- current

      queryParams['size'] <- size

      queryParams['recvWindow'] <- recv.window

      queryParams['timestamp'] <- timestamp

      queryParams['signature'] <- signature

      body <- NULL
      urlPath <- "/sapi/v1/staking/stakingRecord"
      # API key authentication
      if ("X-MBX-APIKEY" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["X-MBX-APIKEY"]) > 0) {
        headerParams['X-MBX-APIKEY'] <- paste(unlist(self$apiClient$apiKeys["X-MBX-APIKEY"]), collapse='')
      }

      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[InlineResponse20099]", 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.