R/pay_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 Pay operations
#' @description binanceRapi.Pay
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ SapiV1PayTransactionsGet } \emph{ Get Pay Trade History (USER_DATA) }
#' - If startTimestamp and endTimestamp are not sent, the recent 90 days' data will be returned. - The max interval between startTimestamp and endTimestamp is 90 days. - Support for querying orders within the last 18 months.  Weight(UID): 3000
#'
#' \itemize{
#' \item \emph{ @param } start.timestamp integer
#' \item \emph{ @param } end.timestamp integer
#' \item \emph{ @param } limit integer
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } \link{InlineResponse200134} \cr
#'
#'
#' \item status code : 200 | Pay History
#'
#' \item return type : InlineResponse200134 
#' \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{
#' ####################  SapiV1PayTransactionsGet  ####################
#'
#' library(binanceRapi)
#' var.start.timestamp <- 56 # integer | UTC timestamp in ms
#' var.end.timestamp <- 56 # integer | UTC timestamp in ms
#' var.limit <- 100 # integer | default 100, max 100
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Get Pay Trade History (USER_DATA)
#' api.instance <- PayApi$new()
#'
#' result <- api.instance$SapiV1PayTransactionsGet(start.timestamp=var.start.timestamp, end.timestamp=var.end.timestamp, limit=var.limit, recv.window=var.recv.window)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
PayApi <- R6::R6Class(
  'PayApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    SapiV1PayTransactionsGet = function(start.timestamp=NULL, end.timestamp=NULL, limit=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1PayTransactionsGetWithHttpInfo(start.timestamp, end.timestamp, 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
      }
    },

    SapiV1PayTransactionsGetWithHttpInfo = function(start.timestamp=NULL, end.timestamp=NULL, limit=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

      queryParams['startTimestamp'] <- start.timestamp

      queryParams['endTimestamp'] <- end.timestamp

      queryParams['limit'] <- limit

      queryParams['recvWindow'] <- recv.window

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

      body <- NULL
      urlPath <- "/sapi/v1/pay/transactions"
      # 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, "InlineResponse200134", 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.