示例#1
0
        protected async Task FetchValueInfo()
        {
            if (DateTime.Compare(LastFetchTime, DateTime.Now.AddSeconds(-9.0d)) < 0)
            {
                await LogHandlerService.LogAsync("Fetching DigitalPrice Exchange Info.");

                var client           = new WebClient();
                var DigitalPriceJSON = await client.DownloadStringTaskAsync("https://digitalprice.io/markets/get-currency-summary?currency=BALANCE_COIN_BITCOIN");

                var btcPrice = await client.DownloadStringTaskAsync("https://blockchain.info/tobtc?currency=USD&value=1");

                DigitalPriceCurrencyInfo[] DigitalPriceInfo = null;

                try
                {
                    DigitalPriceInfo = JsonConvert.DeserializeObject <DigitalPriceCurrencyInfo[]>(DigitalPriceJSON);

                    for (int i = 0; i < DigitalPriceInfo.Length; i++)
                    {
                        if (DigitalPriceInfo[i].MiniCurrency == "dal-btc")
                        {
                            DallarInfo          = DigitalPriceInfo[i];
                            DallarInfo.USDValue = decimal.Round(DallarInfo.Price / Convert.ToDecimal(btcPrice), 8, MidpointRounding.AwayFromZero);
                            LastFetchTime       = DateTime.Now;
                            return;
                        }
                    }
                }
                catch (Exception e)
                {
                    await LogHandlerService.LogAsync($"Failed to get DigitalPrice Exchange Info: {e.ToString()}");
                }
            }
        }
示例#2
0
        public bool GetPriceInfo(out DigitalPriceCurrencyInfo PriceInfo, out bool bStale)
        {
            if (DallarInfo != null)
            {
                bStale = false;

                PriceInfo = DallarInfo.Clone();
                if (DateTime.Compare(LastFetchTime, DateTime.Now.AddSeconds(-12.0d)) < 0)
                {
                    bStale = true;
                }
                return(true);
            }

            bStale    = true;
            PriceInfo = null;
            return(false);
        }