0
votes

I try to request to yobit API wthin R. To get access to some of the methods you need to complete authentication:

Each Trade API request should pass authentication. Authentication is fulfilled by sending the following HTTP-titles:

Key - API-key, example: FAF816D16FFDFBD1D46EEF5D5B10D8A2

Sign - digital signature, POST-parameters (?param0=val0 & ...& nonce=1) signed by secret key through HMAC-SHA512

Parameter nonce (1 minimum to 2147483646 maximum) in succeeding request should exceed that in the previous one. To null nonce it is necessary to generate new key.

My code :

nonce=1   

API_KEY = "0B02AD5AF57854184D68D3D1D4D980F9"
API_SECRET = "89b20f882220b5dc6feeb33253c25ba3"
Body=paste('method=getInfo&nonce=',nonce, sep="")
sign = hmac(API_SECRET, Body, algo="sha512")
title=add_headers('Content-type'='application/x-www-form-urlencoded', Key = API_KEY, Sign = sign)
rep=POST('https://yobit.net/tapi', body=Body, headers=title,  encode='form')
nonce=nonce+1

Response from server:

"{\"success\":0,\"error\":\"invalid key, sign, method or nonce\"}"

Thanks for help!

1

1 Answers

0
votes

this i have done in node js And its working.

const crypto = require("crypto");
var apikey = 'apikey';
var secret = 'secret';

var signature = "method=getInfo&nonce="+ nonce;

console.log(signature);

var hmacsignature = crypto.createHmac('sha512', secret).update( signature ).digest('hex');

var headers = { 
    'Content-Type': 'application/x-www-form-urlencoded',
    'Key': apikey,
    'Sign': hmacsignature
};

var options = {
    url: 'https://yobit.net/tapi',
    method: 'POST',
    body: signature,
    headers: headers
}

console.log(options);

request1(options, function (error, response, body) {
    res.send(body);
});