R HMAC-SHA512 signing

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

R HMAC-SHA512 signing

I am currently trying to use a HMAC-SHA512 signing to get authentified on a website in order to request through the website api some personal details.

The website displays some code (but not in r!) for users :

$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
I have tried to reproduce the code in r :

The first step seems quite easy :

apikey = "2...XXX...3"
apisecret = "7...XXX...c"
First issue : I do not know how to enter the time, I assume that Sys.time() is not suitable here, nor as.numeric(Sys.time()) as it is not an integer (maybe I am already wrong ...)

nonce = floor(as.numeric(Sys.time()))
Then :

uri = paste0('https://bittrex.com/api/v1.1/market/getopenorders?`apikey=',apikey,'&nonce=',nonce)`
sign = hmac(apisecret,uri,"sha512")
For the two last steps, I have tried :

ch = binaryBuffer(uri)
curlSetOpt(ch, .forceHeaderNames = TRUE, sign)
execResult = GET(ch)
and got the following error message :

Error in as.character.default(url) :
  no method for coercing this S4 class to a vector
Does anyone noticed what was wrong with my code ? Any remark / question / suggestion will be highly appreciated !