private static BitcoinPriceInfos JSON2Info(String j) { BitcoinPriceInfos ret = new BitcoinPriceInfos(); XmlDictionaryReader jsonReader = JsonReaderWriterFactory.CreateJsonReader( Encoding.UTF8.GetBytes(j), new System.Xml.XmlDictionaryReaderQuotas()); XElement root = XElement.Load(jsonReader); foreach (XElement x1 in root.Nodes()) { string strSymbol = x1.Element("symbol").Value; BitcoinPriceInfo update = null; if (strSymbol == "btc") { ret.btc = update = new BitcoinPriceInfo(); } else if (strSymbol == "bch") { ret.bch = update = new BitcoinPriceInfo(); } if (update != null) { update.LastUpdate = x1.Element("last_updated").Value; update.PriceInUSD = Decimal.Parse(x1.Element("market_data").Element("current_price").Element("usd").Value); update.Symbol = strSymbol; } } root = null; return(ret); }
public static async Task <BitcoinPriceInfo> Run([QueueTrigger(nameof(BitcoinPriceUpdatedEvent), Connection = "AzureWebJobsStorage")] BitcoinPriceUpdatedEvent bitcoinPriceUpdatedEvent, ILogger log) { log.LogInformation($"Consuming price: {bitcoinPriceUpdatedEvent.RateUsd}@{bitcoinPriceUpdatedEvent.Timestamp}"); var usdToPlnRate = await GetCurrentNbpRate(); var bitcoinPlnPrice = Decimal.Round(usdToPlnRate * bitcoinPriceUpdatedEvent.RateUsd, 2); log.LogInformation($"Saving 1BTC = {bitcoinPlnPrice} PLN at {bitcoinPriceUpdatedEvent.Timestamp}"); var result = new BitcoinPriceInfo(bitcoinPriceUpdatedEvent.RateUsd, bitcoinPlnPrice, bitcoinPriceUpdatedEvent.Timestamp); return(result); }