Exemplo n.º 1
0
 public static Currency Get(CurrencyCodes currencyCode)
 {
     if (CurrencyDictionary.ContainsKey(currencyCode))
     {
         return(CurrencyDictionary[currencyCode]);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
 public static bool Exists(CurrencyCodes currencyCode)
 {
     return(CurrencyDictionary.ContainsKey(currencyCode));
 }
Exemplo n.º 3
0
        private async Task GetAllSymbols()
        {
            using (var client = new BinanceClient())
            {
                var result = await client.GetAllPricesAsync();

                if (result.Success)
                {
                    AllPrices = new ObservableCollection <BinanceSymbolViewModel>(result.Data.Select(r => new BinanceSymbolViewModel(r.Symbol, r.Price)).OrderBy(s => s.SymbolCurrency).ThenBy(s => s.SymbolAsset).ToList());

                    foreach (var price in AllPrices)
                    {
                        if (CurrencyDictionary.ContainsKey(price.SymbolCurrency))
                        {
                            if (!CurrencyDictionary[price.SymbolCurrency].Contains(price.SymbolAsset))
                            {
                                CurrencyDictionary[price.SymbolCurrency].Add(price.SymbolAsset);
                            }
                        }
                        else
                        {
                            CurrencyDictionary.Add(price.SymbolCurrency, new ObservableCollection <string> {
                                price.SymbolAsset
                            });
                        }

                        if (AssetDictionary.ContainsKey(price.SymbolAsset))
                        {
                            if (!AssetDictionary[price.SymbolAsset].Contains(price.SymbolCurrency))
                            {
                                AssetDictionary[price.SymbolAsset].Add(price.SymbolCurrency);
                            }
                        }
                        else
                        {
                            AssetDictionary.Add(price.SymbolAsset, new ObservableCollection <string> {
                                price.SymbolCurrency
                            });
                        }
                    }

                    var cdKeys = CurrencyDictionary.Keys.ToList();
                    var adKeys = AssetDictionary.Keys.ToList();
                    for (int k = 0; k < cdKeys.Count; k++)
                    {
                        CurrencyDictionary[cdKeys[k]] = new ObservableCollection <string>(CurrencyDictionary[cdKeys[k]].OrderBy(v => v));
                    }
                    for (int k = 0; k < adKeys.Count; k++)
                    {
                        AssetDictionary[adKeys[k]] = new ObservableCollection <string>(AssetDictionary[adKeys[k]].OrderBy(v => v));
                    }
                }
                else
                {
                    messageBoxService.ShowMessage($"Error getting all symbols data.\n{result.Error.Message}", $"Error Code: {result.Error.Code}", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            List <Task> tasks = new List <Task>();

            foreach (var symbol in AllPrices)
            {
                var task = new Task(() => binanceSocketClient.SubscribeToKlineStream(symbol.Symbol.ToLower(), KlineInterval.OneMinute, (data) =>
                {
                    symbol.Price = data.Data.Close;
                }));
                tasks.Add(task);
                task.Start();
            }
            Task.WaitAll(tasks.ToArray());
        }