2017-11-18 159 views
2

我试图点击Coinspot REST API,但我收到一个错误返回。我在与Bittrex和独立保留区谈话时毫无困难,但Coinspot有点不同。这是我的代码:Coinspot REST API - C#

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”,我会收到一个有意义的错误,指出“不是随机数”。

+2

你想告诉我们错误吗? – CodingYoshi

+1

对不起,我的意思是包括它,但我现在远离我的电脑。这是非常不明确的。这就像“无效”,没有任何解释。 –

+1

可以确认,错误(在json中)看起来像 '{ 'status':'invalid' }' – wislon

回答

1

你有没有设法让这个API工作。 CoinSpot不是很支持这一点。我只能得到3个硬币API工作,这是没有太大的帮助

+0

没有。它看起来像一半工作,但我永远无法连接。如果你联系他们,他们回复你,我想听到它。同时我已经要求他们通过API密钥禁用,他们甚至没有管理。 –

1

tl:dr它没有记录,但你需要使用端口443,我通过挖掘他们的节点SDK找到它。

我遇到了同样的问题,得到非描述性的{status:invalid}响应,在我的情况下使用Elixir而不是C#。我通过偷看他们的节点SDK来工作 - 我的细节使用他们的SDK,所以我知道它必须是我做得不好的东西(尽管他们的文档非常令人震惊)。他们使用443端口,一旦我设置它的工作。

我试过2件东西,我90%确定它是端口号,但是通过我的工作获得它的一半我打印由他们的节点sdk创建的sha512标志,并将其与我使用Cryptex生成的标志进行比较看到他们正在生成相同的sha512签名,但我的一个是大写字母,而节点一个是小写的 - 这可能会也可能不会结束,但我最终还是使用了String.downcase()。