Пример #1
0
 public CryptoItemModel(CoinInfo info, CoinFullAggregatedData aggregatedData)
 {
     this.Info           = info;
     this.AggregatedData = aggregatedData;
 }
Пример #2
0
        /// <summary>
        /// Gets updates for a list of assets.
        /// Fires the OnSingleAssetUpdated event for each updated asset from the list.
        /// Fires the OnApiError event if something has gone wrong.
        /// </summary>
        /// <param name="assets">The assets<see cref="List{Asset}"/> to update.</param>
        protected override async Task GetAssetUpdatesAsync(List <Asset> assets)
        {
            if (assets.Count < 1)
            {
                return;
            }

            List <string> fromSymbols = new List <string>();

            assets.ForEach(ass => fromSymbols.Add(ass.Symbol));

            bool callFailed = false;
            int  timeout    = this.ApiData.UpdateInterval * 1000;

            do
            {
                callFailed = false;

                try
                {
                    PriceMultiFullResponse response = await this.client.Prices.MultipleSymbolFullDataAsync(fromSymbols, this.attachedConvertCurrencies);

                    this.ApiData.IncreaseCounter(1);
                    this.FireOnAppDataChanged();

                    var res = response.Raw;

                    if (res == null)
                    {
                        return;
                    }

                    assets.ForEach(ass =>
                    {
                        this.attachedConvertCurrencies.ForEach(con =>
                        {
                            try
                            {
                                CoinFullAggregatedData data = res[ass.Symbol][con];

                                if (ass.ConvertCurrency == con)
                                {
                                    ass.Price            = (double)data.Price;
                                    ass.LastUpdated      = DateTime.Now;
                                    ass.PercentChange24h = data.ChangePCT24Hour != null? (double)data.ChangePCT24Hour : -101;
                                    ass.PercentChange24h = -101;
                                    ass.PercentChange1h  = -101;
                                    ass.MarketCap        = data.MarketCap != null? (double)data.MarketCap : -1;
                                    ass.SupplyAvailable  = -1;
                                    ass.SupplyTotal      = -1;
                                    ass.Volume24hConvert = data.TotalVolume24HTo != null? data.TotalVolume24HTo.ToString() : "-";

                                    this.FireOnAssetUpdateReceived(ass);
                                }
                            }
                            catch (KeyNotFoundException)
                            {
                                // ignore
                            }
                        });
                    });
                }
                catch (HttpRequestException)
                {
                    // no internet connection?
                    callFailed = true;
                    Thread.Sleep(retryDelay);
                    timeout -= retryDelay;
                }
                catch (Exception e)
                {
                    OnApiErrorEventArgs args = new OnApiErrorEventArgs
                    {
                        ErrorType    = ErrorType.General,
                        ErrorMessage = e.Message
                    };

                    this.FireOnApiError(args);
                }
            }while (callFailed && timeout >= 0);
        }