private async Task <ImmutableDictionary <string, decimal> > InitializeSymbolPrices() { try { var symbolPrices = await _binanceApi.GetPricesAsync(); var immutableSymbolPrices = symbolPrices.ToImmutableList(); var immutablePrices = symbolPrices.ToImmutableDictionary(s => s.Symbol, s => s.Value); _cache.SetSymbolPrices(immutablePrices); foreach (var symbolPrice in immutableSymbolPrices) { _cache.SetSymbolPrice(symbolPrice.Symbol, symbolPrice.Value); } return(immutablePrices); } catch (Exception ex) { _cache.ClearSymbolPrices(); _log.LogError($"Symbol Prices initialization error {ex.Message}"); return(new Dictionary <string, decimal>().ToImmutableDictionary()); } }
private void OnStatisticError() { if (_cache.GetSymbolPrices() != null) { _cache.ClearSymbolPrices(); } if (_cache.GetSymbolStatistics() != null) { _cache.ClearSymbolStatistics(); } }