protected void OnMensaje(string p, CDataPrice moneyp) { if (Mensaje != null) { Mensaje(p, moneyp); } }
public CDataPrice consultaCoins(string sMoneda, ListView lvObj) { string sTexto = string.Empty; CDataPrice dPrice = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://bitso.com/api/v2/ticker?book=" + sMoneda); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { var json = reader.ReadToEnd(); dPrice = JsonConvert.DeserializeObject <CDataPrice>(json); lvObj.Items[sMoneda].SubItems[1].Text = dPrice.ask; lvObj.Items[sMoneda].SubItems[2].Text = dPrice.high; lvObj.Items[sMoneda].SubItems[3].Text = dPrice.low; lvObj.Items[sMoneda].SubItems[4].Text = dPrice.last; } } catch (Exception ex) { MessageBox.Show("Ocurrio un error al Consultar monedas[1]: " + ex.Message); } return(dPrice); }
public void MostrarMensaje(string sMensaje, CDataPrice moneyp) { if (sMensaje != "" || Convert.ToDouble(moneyp.ask) > 0.0) { OnMensaje(sMensaje, moneyp); } }
public void consultaCoins2(string sMoneda, ListView lvObj, ref string sTServ) { string sTexto = string.Empty; CDataPrice dPrice = null; MoneyData2 md = null; try { string sURL = @"https://bitso.com/api/v3/ticker?book=" + sMoneda; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL); request.Timeout = 4000; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { var json = reader.ReadToEnd(); //dPrice = JsonConvert.DeserializeObject<CDataPrice>(json); md = JsonConvert.DeserializeObject <MoneyData2>(json); /*"volume": "22.31349615", "high": "5750.00","last": "5633.98","low": "5450.00","vwap": "5393.45","ask": "5632.24", * "bid": "5520.01","timestamp": "1447348096*/ dPrice = md.payload; if (sMoneda == "btc_mxn" || sMoneda == "xrp_mxn") { lvObj.Items[sMoneda].SubItems[1].Text = string.Format("{0,14:N2}", Convert.ToDouble(dPrice.ask)); lvObj.Items[sMoneda].SubItems[2].Text = string.Format("{0,14:N2}", Convert.ToDouble(dPrice.high)); lvObj.Items[sMoneda].SubItems[3].Text = string.Format("{0,14:N2}", Convert.ToDouble(dPrice.low)); lvObj.Items[sMoneda].SubItems[4].Text = string.Format("{0,14:N2}", Convert.ToDouble(dPrice.last)); } else { lvObj.Items[sMoneda].SubItems[1].Text = dPrice.ask; lvObj.Items[sMoneda].SubItems[2].Text = dPrice.high; lvObj.Items[sMoneda].SubItems[3].Text = dPrice.low; lvObj.Items[sMoneda].SubItems[4].Text = dPrice.last; } dPrice.book = sMoneda; MostrarMensaje("", dPrice); request = null; response.Close(); sTServ = dPrice.created_at.ToShortTimeString(); } } catch (WebException ex) { //string sMsge = string.Empty; //using (WebResponse responsex = ex.Response) //{ // HttpWebResponse httpResponsex2 = (HttpWebResponse)responsex; // //Console.WriteLine("Error code: {0}", httpResponse.StatusCode); // using (Stream dataex = responsex.GetResponseStream()) // using (var readerex = new StreamReader(dataex)) // { // sMsge = readerex.ReadToEnd() + "Error:" + httpResponsex2.StatusCode.ToString(); // //MessageBox.Show(text + " : " + httpResponse.StatusCode); // dataex.Close(); // dataex.Dispose(); // } // httpResponsex2 = null; //} sMensajeError = string.Format("stauts: {0}, Error:{1}, moneda[{2}][#2] ,d |h[{3}]\n", ex.Status.ToString(), ex.Message, sMoneda, getTime()); MostrarMensaje(sMensajeError, dPrice); // MostrarMensaje(sMsge, dPrice); } catch (Exception ex) { //MessageBox.Show("Ocurrio un error: " + ex.Message); sMensajeError = string.Format("Error:{0} ,Moneda[{1}][#2], d |h[{2}]\n", ex.Message, sMoneda, getTime()); MostrarMensaje(sMensajeError, dPrice); //MessageBox.Show(sMensajeError); } }