Any ideas on implementing for R?
Closed this issue · 3 comments
Hi all,
I'm a newbie and the only language I know a little of is R.
I've managed to get a number of other APIs working under R using syntax like this:
# Account Stats
response <- httr::GET(
url = "https://API_URL_GOES_HERE",
)
I think I've got the gist of the syntax for R, but I'm having problems with hashing the Secret Key.
My API key / secret works with the "Try it out" link here.
But I get the usual invalid / 2000 error when passing my hashed secret key via the API.
Here's my code:
Here's how I'm trying to generate the hashed secret key:
input <- paste0(APIKey," ", XTime," ", XNonce," "," ", OrgID," ", " ", "GET"," ", "/main/api/v2/accounting/accounts2", " ")
# Needs hashed?
APISecret <- hmac(input, "My_Secret_Key", "sha256")
XAuth <- paste0(APIKey, ":", APISecret)
And here's my API call:
# Account Stats
response<- httr::GET(
url = "https://api2.nicehash.com/main/api/v2/accounting/accounts2",
httr::add_headers(
`X-Time` = XTime,
`X-Nonce` = XNonce,
`X-Organization-Id` = OrgID,
#`X-Request-Id` = XNonce,
`X-Auth`= XAuth,
`Content-Type` = "application/json; charset=utf-8"
)
)
My thoughts are:
- input is not correctly formatted
- hmac() isn't generating what NiceHash expects
- My GET() isn't structured quite right
Any ideas?
OK, pretty sure the problem is with the formatting of the input to hash the secret key.
I'm trying to get the same results as shown here
Here's my code for that bit:
APIKey <- "4ebd366d-76f4-4400-a3b6-e51515d054d6"
XTime <- "1543597115712"
XNonce <- "9675d0f8-1325-484b-9594-c9d6d3268890"
OrgID <- "da41b3bc-3d0b-4226-b7ea-aee73f94a518"
input <- paste0(APIKey, " ", XTime, " ", XNonce, " ", " ", OrgID, " ", " ", "GET", " ", "/main/api/v2/hashpower/orderBook", " ", "algorithm=X16R&page=0&size=100")
APISecret <- hmac(input, "fd8a1652-728b-42fe-82b8-f623e56da8850750f5bf-ce66-4ca7-8b84-93651abc723b", "sha256")
APISecret
What am I doing wrong?
I cannot get APISecret to output:
21e6a16f6eb34ac476d59f969f548b47fffe3fea318d9c99e77fc710d2fed798
As shown in that example. I'm sure it's something to do with the "zero bytes", shown as symbols on that page, but I can't find an equivalent in R.
Hi, see here https://github.com/nicehash/rest-clients-demo/blob/master/javascript/api.js the code is pretty much self-explanatory.
Thanks, but I've tried using
"\0"
previously and I just get this error:
Error: nul character not allowed (line 1)