From 6ddd36e79ca28237430428e7cea3992c5ed80600 Mon Sep 17 00:00:00 2001 From: MarcoZanon Date: Sun, 14 Feb 2021 22:05:29 +0100 Subject: [PATCH] Quick makeover to restore package functionality. Various fixes addressing the error message "error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version" --- R/accounts.R | 12 ++++++------ R/add_order.R | 18 +++++++++--------- R/auth.R | 49 +++++++++++++++++++++++-------------------------- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/R/accounts.R b/R/accounts.R index 5f19141..2f186f1 100644 --- a/R/accounts.R +++ b/R/accounts.R @@ -21,11 +21,11 @@ accounts <- function(api.key, secret, passphrase) { #get url extension---- - req.url <- "/accounts/" - + req.url <- "/accounts" + #define method---- method <- "GET" - + #fetch response---- response <- auth( method = method, @@ -34,12 +34,12 @@ accounts <- function(api.key, secret = secret, passphrase = passphrase ) - + #transform---- response$balance <- as.numeric(response$balance) response$available <- as.numeric(response$available) response$hold <- as.numeric(response$hold) - + #return---- return(response) -} +} \ No newline at end of file diff --git a/R/add_order.R b/R/add_order.R index 932fc1e..b01b042 100644 --- a/R/add_order.R +++ b/R/add_order.R @@ -41,15 +41,15 @@ add_order <- function(api.key, size) { #get url extension---- req.url <- "/orders" - + #define method---- method <- "POST" - + #transform params---- product_id <- toupper(product_id) price <- as.character(price) size <- as.character(size) - + if (side == "b") { side <- "buy" } else if (side == "s") { @@ -57,7 +57,7 @@ add_order <- function(api.key, } else { stop("Unrecognized sell or buy side. Please select either 'b' or 's'.") } - + #generate order---- if (is.null(stop)) { order_attribs <- list( @@ -77,9 +77,9 @@ add_order <- function(api.key, stop_price = stop_price ) } - + order <- toJSON(order_attribs, auto_unbox = TRUE) - + #fetch response---- response <- auth( @@ -90,10 +90,10 @@ add_order <- function(api.key, passphrase = passphrase, order = order ) - + #transform---- response <- as.data.frame(response) - + #return---- return(response) -} +} \ No newline at end of file diff --git a/R/auth.R b/R/auth.R index 4380873..b32b211 100644 --- a/R/auth.R +++ b/R/auth.R @@ -47,14 +47,13 @@ auth <- function(method, sign <- base64Encode(hmac(key, what, algo = "sha256", raw = TRUE)) # hash - #define headers---- - httpheader <- list( - 'CB-ACCESS-KEY' = api.key, - 'CB-ACCESS-SIGN' = sign, - 'CB-ACCESS-TIMESTAMP' = timestamp, - 'CB-ACCESS-PASSPHRASE' = passphrase, - 'Content-Type' = 'application/json' - ) +#define headers---- + httpheader <- "'CB-ACCESS-KEY' = api.key, + 'CB-ACCESS-SIGN' = sign, + 'CB-ACCESS-TIMESTAMP' = timestamp, + 'CB-ACCESS-PASSPHRASE' = passphrase, + 'Content-Type' = 'application/json'" + #generating GET results---- if (method == "GET") { @@ -70,11 +69,11 @@ auth <- function(method, } #Get test windows---- else { - response <- fromJSON(getURLContent( - url = url, - curl = getCurlHandle(useragent = "R"), - httpheader = httpheader - )) + + response <-eval(parse(text = paste("GET(url=url, add_headers(", httpheader, "))"))) + response <- content(response, as = "text", encoding = "UTF-8") + response <- fromJSON(response, flatten = TRUE) + } } #generating POST results---- @@ -92,14 +91,12 @@ auth <- function(method, } #Post test windows---- else{ - response <- fromJSON( - getURLContent( - url = url, - curl = getCurlHandle(useragent = "R"), - httpheader = httpheader, - postfields = order - ) - ) + + response <-eval(parse(text = paste("POST(url=url, add_headers(", httpheader, "), body = order)"))) + response <- content(response, as = "text", encoding = "UTF-8") + response <- fromJSON(response, flatten = TRUE) + message(paste("method: ", method, sep="")) + message(paste("url: ", url, sep="")) } } #Generating DELETE results @@ -112,11 +109,11 @@ auth <- function(method, httpheader = httpheader )) } else { - response <- fromJSON(httpDELETE( - url = url, - curl = getCurlHandle(useragent = "R"), - httpheader = httpheader - )) + + response <-eval(parse(text = paste("DELETE(url=url, add_headers(", httpheader, "))"))) + response <- content(response, as = "text", encoding = "UTF-8") + response <- fromJSON(response, flatten = TRUE) + } }