GetResponse Bittrex C#

时间:2018-01-08 13:37:23

标签: c# currency-exchange-rates

我尝试在bittrex交换平台上恢复C#中关于加密货币的信息。

为此,我有这个网站:https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC。 使用Chrome我有这样的结果:

  

{ “成功”:真, “消息”: “:,0.01678600” 问: “”, “结果”, “出价”:0.01680095, “上次”:0.01678600}}

我想恢复那个。所以在我的表格中我设置:

公共变量:

public const string BaseUrl = "https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC";

公开按钮事件:

var webreq = WebRequest.Create(BaseUrl);
var webresp = webreq.GetResponse();
MessageBox.Show("" + webresp);

当我运行然后程序时出现验证错误,但是,我只是在用公钥读取信息时。

有谁知道我哪里错了?以及如何绕过这个身份验证问题?

更新:感谢Dieter B,我仍然有身份验证错误,我不确定编码和所需的时间格式。你有什么线索吗?

 public static string time = DateTime.Now.ToString();
    public static string apisecret = "f**********************************d";
    public static string BaseUrl = "https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC?apikey=56************************61a&nonce="+time;
    public static readonly Encoding encoding = Encoding.UTF8;
    public static string sbinary;
    /// <summary>
    /// Point d'entrée principal de l'application.
    /// </summary>
    [STAThread]



    static void Main()
    {

        var keyByte = encoding.GetBytes(BaseUrl);
        using (var hmacsha256 = new HMACSHA256(keyByte))
        {
            hmacsha256.ComputeHash(encoding.GetBytes(apisecret));
            sbinary = ByteToString(hmacsha256.Hash);
        }

        HttpWebRequest GETRequest = (HttpWebRequest)WebRequest.Create(BaseUrl);
        GETRequest.Headers.Add("apisign", sbinary);
        GETRequest.Method = "GET";
        MessageBox.Show(sbinary);

            HttpWebResponse GETResponse = (HttpWebResponse)GETRequest.GetResponse();
            Stream GETResponseStream = GETResponse.GetResponseStream();
            StreamReader sr = new StreamReader(GETResponseStream);
            MessageBox.Show(sr.ReadToEnd());

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }


        static string ByteToString(byte[] buff)
        {
            string sbinary = "";
            for (int i = 0; i < buff.Length; i++)
                sbinary += buff[i].ToString("X2"); /* hex format */
            return sbinary;

        }

谢谢

0 个答案:

没有答案