0

I try to recover information in C# about crypto currency on the bittrex exchange plateform.

For that I have this website: https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC. With Chrome i have this result:

{"success":true,"message":"","result":"Bid":0.01678600,"Ask":0.01680095,"Last":0.01678600}}

And I want to recover that. So in my form i set :

public variable :

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

Public button event :

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

When i run then program I get an error with an authentification issue, but, I just when to read information with public key.

Does Anyone knows where am I wrong? and how can I bypass this authentification issue ?

UPDATE : Thanks Dieter B, I still have the authentification error, i'm not sure about encoding and the time format needed. Have you any clue ?

 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;

        }

Thank you

twenty94470
  • 105
  • 2
  • 12

0 Answers0