public async static Task <List <BTC_USD_DTO> > List_BTC_USD() { List <BTC_USD_DTO> ls = new List <BTC_USD_DTO>(); try { BTC_USD_DTO t = new BTC_USD_DTO(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri("https://www.bitstamp.net/api/v2/ticker"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync(client.BaseAddress + "/btcusd"); if (response.IsSuccessStatusCode) { var data = response.Content.ReadAsStringAsync().Result; BTC_USD_DTO u = JsonConvert.DeserializeObject <BTC_USD_DTO>(data); ls.Add(u); response.Dispose(); } client.Dispose(); } catch (Exception) { } return(ls); }
public bool Insert_BTC_BUS(BTC_USD_DTO dto) { string squery = string.Format("Insert into BTC_USD([Open],Last,Hight,Low,Volume,Time) values({0},{1},{2},{3},{4},GETDATE())", dto.open, dto.last, dto.high, dto.low, dto.volume); try { conn.Open(); SqlCommand cmd = new SqlCommand(squery, conn); var u = cmd.ExecuteNonQuery(); cmd.Dispose(); return(true); } catch (Exception) { throw; } finally { conn.Close(); } }
private void Insert_BTC_USD() { try { BTC_USD_DTO dto = new BTC_USD_DTO(); dto.open = double.Parse(dataGridView1.Rows[0].Cells[8].Value.ToString()); dto.last = double.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString()); dto.high = double.Parse(dataGridView1.Rows[0].Cells[0].Value.ToString()); dto.low = double.Parse(dataGridView1.Rows[0].Cells[5].Value.ToString()); dto.volume = double.Parse(dataGridView1.Rows[0].Cells[4].Value.ToString()); BTC_USD_BUS bus = new BTC_USD_BUS(); bus.Insert_BTC_USD(dto); } catch (Exception) { //timer1.Stop(); //MessageBox.Show("BTC/USD API connect has been stopped"); return; } finally { timer1.Start(); } }
public bool Insert_BTC_USD(BTC_USD_DTO dto) { BTC_USD_DAO dao = new BTC_USD_DAO(); return(dao.Insert_BTC_BUS(dto)); }