Hello once again!
I fixed the last issue I had with this software without any help but now its telling me something that I have never occurd before.
Let me show you the code so it will be easier toe xplain the situation.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Net;
using RestSharp;
namespace BitCoin_Evolution
{
public partial class Form1 : Form
{
string con = "Connected";
string dc = "Disconnected";
private Timer timer1;
int togMove;
int MvalX;
int MvalY;
public Form1()
{
InitializeComponent();
timer1 = new Timer();
timer1.Tick += new EventHandler(Update_BTC_Ticker);
timer1.Tick += new EventHandler(Update_BTC_Trader);
timer1.Interval = 2000;
timer1.Start();
}
private void Update_BTC_Ticker(object sender, EventArgs e)
{
var client = new RestClient("https://btc-e.com/api");
var request = new RestRequest("2/btc_usd/ticker", Method.GET);
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
IRestResponse<BtcUsdTicker> response = client.Execute<BtcUsdTicker>(request);
sellLabel.Text = Convert.ToString(response.Data.ticker.sell);
buyLabelTrue.Text = Convert.ToString(response.Data.ticker.buy);
}
private void Update_BTC_Trader(object sender, EventArgs e)
{
var tradeClient = new RestClient("https://btc-e.com/api");
var tradeRequest = new RestRequest("2/btc_usd/trades", Method.GET);
tradeRequest.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
IRestResponse<BtcTradeTicker> response = tradeClient.Execute<BtcTradeTicker>(tradeRequest);
textBox1.Text = Convert.ToString(response.Data.tradeTicker.price);
}
public class BtcUsdTicker
{
public Ticker ticker { get; set; }
}
public class Ticker
{
public float high { get; set; }
public float low { get; set; }
public float avg { get; set; }
public float vol { get; set; }
public float vol_cur { get; set; }
public float last { get; set; }
public float buy { get; set; }
public float sell { get; set; }
public int updated { get; set; }
public int server_time { get; set; }
}
public class BtcTradeTicker
{
public tradeTicker tradeTicker { get; set; }
}
public class tradeTicker
{
public int date { get; set; }
public double price { get; set; }
public double amount { get; set; }
public int tid { get; set; }
public string price_currency { get; set; }
public string item { get; set; }
public string trade_type { get; set; }
}
let me explain what is going on.
I cam calling a webrequest to
var client = new RestClient("https://btc-e.com/api");
var request = new RestRequest("2/btc_usd/ticker", Method.GET);
Which is working perfectly, its connecting with the labels and printing out without any hassle.
sellLabel.Text = Convert.ToString(response.Data.ticker.sell);
buyLabelTrue.Text = Convert.ToString(response.Data.ticker.buy);
private void Update_BTC_Ticker(object sender, EventArgs e)
{
var client = new RestClient("https://btc-e.com/api");
var request = new RestRequest("2/btc_usd/ticker", Method.GET);
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
IRestResponse<BtcUsdTicker> response = client.Execute<BtcUsdTicker>(request);
sellLabel.Text = Convert.ToString(response.Data.ticker.sell);
buyLabelTrue.Text = Convert.ToString(response.Data.ticker.buy);
}
As you can see the 1 is the main website its pulling from and then I am giving it the extra information that it needs to be pulling from this exact APi (number 2)
(3)Then it desierializes the code to Json > C#
(4) its calling what it just deserialized to check if there is something there (as you can see in the code and the API there is Data there)
(5) its locating the sell one and returning the value to the label
public float sell { get; set; }
(6) It does the exact same thing as (5) but its pulling .buy instead of .sell
My question is..
How come its not pulling the data from the other json table I created
public class BtcTradeTicker
It has the
public double price { get; set; }
For it to grab and check with the API but instead its saying that .Data is null
textBox1.Text = Convert.ToString(response.Data.tradeTicker.price);
Sidenote, I am using a third party library called restSharp
RestSharp - Simple REST and HTTP Client for .NET[
^]
What I have tried:
The code didnt look like that in the beginning, I've looked over the API and my code multiple times I really cant find whats wrong, I am bascally trying to redo the exact same thing I did for the first webrequest but a second time for a different API but its not letting me get any Data.