public void UpdateCurrencyValue(DataLayer.TrnLunoValue.TrnLunoValueDataTable newTable) { TrnLunoValueTableAdapter.Update(newTable); }
private void GetData() { WebClient webClient = new WebClient(); webClient.Headers.Add("user-agent", "Only a test!"); string js5on = webClient.DownloadString("https://api.mybitx.com/api/1/tickers"); //deserialse the object Dictionary <string, object> values = JsonConvert.DeserializeObject <Dictionary <string, object> >(js5on); BusLayer.Currency currencyHelper = new BusLayer.Currency(); //loop through each of the values and save the data DataLayer.TrnLunoValue.TrnLunoValueDataTable currencyTable = new DataLayer.TrnLunoValue.TrnLunoValueDataTable(); foreach (var item in values) { List <Dictionary <string, string> > itemList = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(item.Value.ToString()); int totalBids = 0; int maxTotal = 10; foreach (Dictionary <string, string> thisItem in itemList) { //get the current list item for the code //if the code exists it means we want to add the data, else we just continue to the next try { string searchCode = thisItem["pair"]; if (searchCode == "XBTZAR") { searchCode = "BTC"; } DataLayer.MstCurrencyList.MstCurrencyListRow currentListRow = currencyHelper.GetCurrentListRowForCode(searchCode); decimal thisBid = Convert.ToDecimal(thisItem["bid"]); int currentBid = Convert.ToInt32(thisBid); totalBids += currentBid; //if(totalBids >= maxTotal) //{ //stop the counter now // break; //} //order data only - must take the ["Bid"] element and save the price and volume up to a max of 10 BTC coints //add a new row and save the data DataLayer.TrnLunoValue.TrnLunoValueRow newRow = currencyTable.NewTrnLunoValueRow(); newRow.TrnLunoValueGuid = Guid.NewGuid(); newRow.MstCurrencyListGuid = currentListRow.MstCurrencyListGuid; newRow.timestamp = thisItem["timestamp"]; newRow.bid = decimal.Parse(thisItem["bid"]); newRow.ask = decimal.Parse(thisItem["ask"]); newRow.last_trade = decimal.Parse(thisItem["last_trade"]); newRow.rolling_24_hour_volume = decimal.Parse(thisItem["rolling_24_hour_volume"]); newRow.pair = thisItem["pair"]; newRow.CreateDate = DateTime.Now; newRow.PrmCurrencySourceId = (int)BusLayer.Handler.CurrencySource.Sources.Luno; currencyTable.AddTrnLunoValueRow(newRow); } catch (Exception ex) { } } } //update the table currencyHelper.UpdateCurrencyValue(currencyTable); }