Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick makeover to restore package functionality. #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions R/accounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}
18 changes: 9 additions & 9 deletions R/add_order.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ 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") {
side <- "sell"
} else {
stop("Unrecognized sell or buy side. Please select either 'b' or 's'.")
}

#generate order----
if (is.null(stop)) {
order_attribs <- list(
Expand All @@ -77,9 +77,9 @@ add_order <- function(api.key,
stop_price = stop_price
)
}

order <- toJSON(order_attribs, auto_unbox = TRUE)

#fetch response----
response <-
auth(
Expand All @@ -90,10 +90,10 @@ add_order <- function(api.key,
passphrase = passphrase,
order = order
)

#transform----
response <- as.data.frame(response)

#return----
return(response)
}
}
49 changes: 23 additions & 26 deletions R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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----
Expand All @@ -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
Expand All @@ -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)

}
}

Expand Down