2017-11-18 161 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()。