gpt4 book ai didi

c# - Coinspot REST API - C#

转载 作者:行者123 更新时间:2023-11-30 20:28:28 26 4
gpt4 key购买 nike

我正在尝试访问 Coinspot REST API,但返回错误。我在与 Bittrex 和 Independent Reserve 交谈时没有问题,但 Coinspot 有点不同。这是我的代码:

    protected override RESTClient RESTClient { get; } = new RESTClient(new NewtonsoftSerializationAdapter(), new Uri("https://www.coinspot.com.au/api"));

public class postdata
{
public string nonce { get; set; }
}

public string CalculateMD5Hash(string input)
{
//step 1, calculate MD5 hash from input

MD5 md5 = MD5.Create();
var inputBytes = Encoding.ASCII.GetBytes(input);
var hash = md5.ComputeHash(inputBytes);

// step 2, convert byte array to hex string
var sb = new StringBuilder();

for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}

return sb.ToString();
}

/// <summary>
/// Private IR Call: GetAccounts
/// </summary>
/// <returns></returns>
private async Task<List<AccountHolding>> Balances()
{

//https://github.com/geekpete/py-coinspot-api/blob/master/coinspot/coinspot.py

//var nonce = new Date().getTime();

//var postdata = postdata || { };
//postdata.nonce = nonce;

//var stringmessage = JSON.stringify(postdata);
//var signedMessage = new hmac("sha512", self.secret);

//signedMessage.update(stringmessage);

// 'sign': sign,
//'key': self.key

var nonce = APIHelpers.GetNonce();

var postdata = new postdata { nonce = nonce };
var json = JsonConvert.SerializeObject(postdata);

System.Diagnostics.Debug.WriteLine(json);

var sign = APIHelpers.GetHMACSHAHash(ApiSecret, json, APIHelpers.HMACSHAType.NineBit);

//Do we do this?
//The JavaScript samples seem to hash with MD5 afterwards for double encryption?
sign = CalculateMD5Hash(sign);

RESTClient.Headers.Clear();
RESTClient.Headers.Add("sign", sign);
RESTClient.Headers.Add("key", ApiKey);

try
{
var retVal = await RESTClient.PostAsync<string, postdata>(postdata, "/my/balances");

System.Diagnostics.Debug.WriteLine(retVal);
}
catch (Exception ex)
{

}

throw new NotImplementedException();
}

doco 非常少!我卡住了。 https://www.coinspot.com.au/api

我现在手边没有错误,但这是一个完全无法描述的错误,包含有关出错原因的信息。这有点像“无效调用”。但是,我知道它在某种程度上被接受了我发布的数据,因为如果我将属性“nonce”的名称更改为“noncey”,我会收到一个有意义的错误消息“no nonce”。

最佳答案

您有没有设法让这个 API 正常工作? CoinSpot 对此不是很支持。我只能让 3 个硬币 API 工作,这没什么帮助

关于c# - Coinspot REST API - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47363129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com