Domysee / BittrexSharp

C# Api Wrapper for Bittrex
MIT License
30 stars 16 forks source link

Cant get it to work #6

Closed jjziets closed 6 years ago

jjziets commented 7 years ago

When i try to use your code I get an exception.

I have a forum with a button that does the following.

Any ideas what could be the problem? I have tried this from my work and home network. I thought it could be the home ISP but work network gives the same issue.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using BittrexSharp;

namespace WindowsFormsApp1 { public partial class MainForm1 : Form { public MainForm1() { InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {

            var apiKey = "......"; //removed for securty
            var apiSecret = "....."; //removed for securty 
            var BittrexAPI = new Bittrex(apiKey, apiSecret);

            toolStripStatusLabel1.Text = "Balance:" + BittrexAPI.GetBalance("BTC").ToString();
        }
        catch
        {
            toolStripStatusLabel1.Text = "Diconnected to BittrexAPI";
        }
    }
}

}

capture

jjziets commented 7 years ago

I have tried 3 keys. Also tried to run this the main loop.

jjziets commented 7 years ago

image

jjziets commented 7 years ago

It sees the construct Bittrex is not called when this.httpClient = new HttpClient(); is in it. Clearly I have something set wrong in my project. My windows form is targeting DotNet 4.6.1 as that is the only one that seems to support DotNet 1.4 Standard frame work

    public Bittrex(string apiKey, string apiSecret)
    {
        this.apiKey = apiKey;
        this.apiSecret = apiSecret;
        this.apiSecretBytes = encoding.GetBytes(apiSecret);
        // this.httpClient = new HttpClient();
    }
Domysee commented 7 years ago

What do you mean it is not called? Is there an exception?

Also please keep in mind that Bittrex has only async methods, so

"Balance:" + BittrexAPI.GetBalance("BTC").ToString();

won't work. You have to await the method calls, like this

"Balance:" + (await BittrexAPI.GetBalance("BTC").ToString());
InTheta commented 7 years ago

If you don't want an sync method/ task you can leave the await and use .Result

Domysee commented 6 years ago

Closed because of inactivity.