-
-
Save gsee/b20b3b9893cd74e462a8 to your computer and use it in GitHub Desktop.
library(RCurl) # for base64Decode(), base64Encode(), getURLContent(), and getCurlHandle() | |
library(digest) # for hmac() | |
library(RJSONIO) # for toJSON() and fromJSON() | |
api.key <- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
secret <- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
passphrase <- "your passphrase" | |
api.url <- "https://api.gdax.com" | |
req.url <- "/orders" | |
method <- "POST" | |
timestamp <- format(as.numeric(Sys.time()), digits=13) | |
key <- base64Decode(secret, mode="raw") | |
order <- list(price="1.0", size="0.01", side="buy", product_id="BTC-USD") | |
body <- toJSON(order, collapse="") | |
what <- paste0(timestamp, toupper(method), req.url, body) | |
sign <- base64Encode(hmac(key, what, algo="sha256", raw=TRUE)) | |
# set headers | |
httpheader <- list('CB-ACCESS-KEY'=api.key, | |
'CB-ACCESS-SIGN'=sign, | |
'CB-ACCESS-TIMESTAMP'=timestamp, | |
'CB-ACCESS-PASSPHRASE'=passphrase, | |
'Content-Type'='application/json') | |
# place an order | |
(order <- fromJSON(getURLContent(url=paste0(api.url, req.url), | |
curl=getCurlHandle(useragent="R"), | |
httpheader=httpheader, | |
postfields=body))) |
@DheerajAgarwal I am having a 400 error as well, comes up as an invalid signature. Could you post the code that successfully connected? Thanks
@tsulgrove Here is the link to my repo which is released under MIT. Please use at your own risk. I am currently testing it for CRAN release and hopefully CRAN will accept it without much issues. https://github.com/DheerajAgarwal/rgdax
rgdax
is now available on cran. library(rgdax)
should give you all the common functions needed.
@DheerajAgarwal thanks for making the effort to put together this code. But the bad request error does not seem to go away. Can you please share the exact code you got working, without burying the message in details about rgdax?
hey @prateekji2016, my complete code with examples is available on CRAN as well as my repo. https://github.com/DheerajAgarwal/rgdax for some time. I believe posting code is only going to make it more confusing as the actual code continues to evolve. Hope you will find what you are looking for.
@Bombax1864 I was just able to place the order successfully using a very similar approach but using
jsonlite
and notRJSONIO
. Let me know if you need any help and I can share my code with you.