如何验证Bitstamp HTTP API v2请求?

时间:2017-11-03 16:25:10

标签: c# api authentication httprequest

我尝试发出订单:https://www.bitstamp.net/api/v2/sell/btceur/?key=xxxxxxxx&signature=BA3CBF267C54965441207FAD25AD7C1C4B9110CE49BA7F2752F7DA79828BF5A1&nonce=1509725707&amount=0.002&price=6267.0

我正在获取403 Forbidden代码和此JSON消息:

{
    "status": "error", 
    "reason": "Missing key, signature and nonce parameters.", 
    "code"  : "API0000"
}

我在C#中开发,但也尝试使用Postman进行手动操作并获得相同的结果。

对于签名计算,我使用了与此类似的帖子中找到的代码:

#region Methods

private string GetSignature(string customerId, string publicApiKey, string privateApiKey, Int32 nonce)
{
    string msg = string.Format("{0}{1}{2}", nonce,
        customerId,
        publicApiKey);

    return ByteArrayToString(SignHMACSHA256(privateApiKey, StringToByteArray(msg))).ToUpper();
}

private static byte[] SignHMACSHA256(String key, byte[] data)
{
    HMACSHA256 hashMaker = new HMACSHA256(Encoding.ASCII.GetBytes(key));
    return hashMaker.ComputeHash(data);
}

private static byte[] StringToByteArray(string str)
{
    return System.Text.Encoding.ASCII.GetBytes(str);
}

private static string ByteArrayToString(byte[] hash)
{
    return BitConverter.ToString(hash).Replace("-", "").ToLower();
}

#endregion

如何成功验证请求?

更新: 我根据python代码交叉检查签名生成,这没关系。还有什么呢?

0 个答案:

没有答案