R/fiat_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 Fiat operations
#' @description binanceRapi.Fiat
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ SapiV1FiatOrdersGet } \emph{ Fiat Deposit/Withdraw History (USER_DATA) }
#' - If beginTime and endTime are not sent, the recent 30-day data will be returned.  Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } transaction.type Enum < [0, 1] >
#' \item \emph{ @param } begin.time integer
#' \item \emph{ @param } end.time integer
#' \item \emph{ @param } page integer
#' \item \emph{ @param } rows integer
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } \link{InlineResponse20082} \cr
#'
#'
#' \item status code : 200 | History of deposit/withdraw orders
#'
#' \item return type : InlineResponse20082 
#' \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{ SapiV1FiatPaymentsGet } \emph{ Fiat Payments History (USER_DATA) }
#' - If beginTime and endTime are not sent, the recent 30-day data will be returned.  Weight(IP): 1
#'
#' \itemize{
#' \item \emph{ @param } transaction.type Enum < [0, 1] >
#' \item \emph{ @param } begin.time integer
#' \item \emph{ @param } end.time integer
#' \item \emph{ @param } page integer
#' \item \emph{ @param } rows integer
#' \item \emph{ @param } recv.window integer
#' \item \emph{ @returnType } \link{InlineResponse200783 \cr
#'
#'
#' \item status code : 200 | History of fiat payments
#'
#' \item return type : InlineResponse20083 
#' \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{
#' ####################  SapiV1FiatOrdersGet  ####################
#'
#' library(binanceRapi)
#' var.transaction.type <- '0' # character | * `0` - deposit * `1` - withdraw
#' var.begin.time <- 1626144956000 # integer | 
#' var.end.time <- 56 # integer | UTC timestamp in ms
#' var.page <- 1 # integer | Default 1
#' var.rows <- 300 # integer | Default 100, max 500
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Fiat Deposit/Withdraw History (USER_DATA)
#' api.instance <- FiatApi$new()
#'
#' result <- api.instance$SapiV1FiatOrdersGet(var.transaction.type, var.timestamp, var.signature, begin.time=var.begin.time, end.time=var.end.time, page=var.page, rows=var.rows, recv.window=var.recv.window)
#'
#'
#' ####################  SapiV1FiatPaymentsGet  ####################
#'
#' library(binanceRapi)
#' var.transaction.type <- '0' # character | * `0` - deposit * `1` - withdraw
#' var.begin.time <- 1626144956000 # integer | 
#' var.end.time <- 56 # integer | UTC timestamp in ms
#' var.page <- 1 # integer | Default 1
#' var.rows <- 300 # integer | Default 100, max 500
#' var.recv.window <- 5000 # integer | The value cannot be greater than 60000
#'
#' #Fiat Payments History (USER_DATA)
#' api.instance <- FiatApi$new()
#'
#' result <- api.instance$SapiV1FiatPaymentsGet(var.transaction.type, var.timestamp, var.signature, begin.time=var.begin.time, end.time=var.end.time, page=var.page, rows=var.rows, recv.window=var.recv.window)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
FiatApi <- R6::R6Class(
  'FiatApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    SapiV1FiatOrdersGet = function(transaction.type, begin.time=NULL, end.time=NULL, page=NULL, rows=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1FiatOrdersGetWithHttpInfo(transaction.type, begin.time, end.time, page, rows, 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
      }
    },

    SapiV1FiatOrdersGetWithHttpInfo = function(transaction.type, begin.time=NULL, end.time=NULL, page=NULL, rows=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

      queryParams['transactionType'] <- transaction.type

      queryParams['beginTime'] <- begin.time

      queryParams['endTime'] <- end.time

      queryParams['page'] <- page

      queryParams['rows'] <- rows

      queryParams['recvWindow'] <- recv.window

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

      body <- NULL
      urlPath <- "/sapi/v1/fiat/orders"
      # 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, "InlineResponse20082", 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)
      }
    },
    SapiV1FiatPaymentsGet = function(transaction.type, begin.time=NULL, end.time=NULL, page=NULL, rows=NULL, recv.window=NULL, ...){
      apiResponse <- self$SapiV1FiatPaymentsGetWithHttpInfo(transaction.type, begin.time, end.time, page, rows, 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
      }
    },

    SapiV1FiatPaymentsGetWithHttpInfo = function(transaction.type, begin.time=NULL, end.time=NULL, page=NULL, rows=NULL, recv.window=NULL, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

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

      queryParams['transactionType'] <- transaction.type

      queryParams['beginTime'] <- begin.time

      queryParams['endTime'] <- end.time

      queryParams['page'] <- page

      queryParams['rows'] <- rows

      queryParams['recvWindow'] <- recv.window

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

      body <- NULL
      urlPath <- "/sapi/v1/fiat/payments"
      # 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, "InlineResponse20083", 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.