【问题标题】:Yobit API POST request (R)Yobit API POST 请求 (R)
【发布时间】:2018-08-08 23:15:06
【问题描述】:

我尝试通过 R 向yobit API 请求。 要访问一些您需要完成身份验证的方法:

每个 Trade API 请求都应通过身份验证。 通过发送以下 HTTP 标题来完成身份验证:

Key - API-key,例如:FAF816D16FFDFBD1D46EEF5D5B10D8A2

签名 - 数字签名、POST 参数 (?param0=val0 & ...& nonce=1) 由密钥通过 HMAC-SHA512 签名

后续请求中的参数nonce(最小1到最大2147483646)应该超过前一个。要使 nonce 为空,需要生成新的密钥。

我的代码:

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

来自服务器的响应:

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

感谢您的帮助!

【问题讨论】:

    标签: r api httr


    【解决方案1】:

    这是我在节点 js 中完成的及其工作。

    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);
    });
    

    【讨论】:

    • OP 在 R 语言中寻求帮助,因此虽然您的回答很受赞赏,但它并不能帮助人们寻找 OP 问题的答案(即如何在 R 中解决这个问题)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 2018-08-04
    • 2020-03-06
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多