Example #1
0
        /// <summary>
        /// Update the symbol cache and asset cache.
        /// </summary>
        /// <param name="api"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task UpdateCacheAsync(IBinanceApi api, CancellationToken token = default)
        {
            var symbols = await api.GetSymbolsAsync(token)
                          .ConfigureAwait(false);

            UpdateCache(symbols);
        }
Example #2
0
        /// <summary>
        /// Update the symbol cache and asset cache.
        /// </summary>
        /// <param name="api"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task UpdateCacheAsync(IBinanceApi api, CancellationToken token = default)
        {
            var symbols = await api.GetSymbolsAsync(token)
                          .ConfigureAwait(false);

            Cache.Clear();
            Cache.Set(symbols);
            AddCacheRedirections();

            var assets = new List <Asset>();

            foreach (var symbol in symbols)
            {
                if (!assets.Contains(symbol.BaseAsset))
                {
                    assets.Add(symbol.BaseAsset);
                }

                if (!assets.Contains(symbol.QuoteAsset))
                {
                    assets.Add(symbol.QuoteAsset);
                }
            }

            Asset.Cache.Clear();
            Asset.Cache.Set(assets);
            Asset.AddCacheRedirections();
        }
Example #3
0
        public async Task <IEnumerable <Interface.Model.Symbol> > GetSymbolsAsync(CancellationToken cancellationToken)
        {
            var result = await binanceApi.GetSymbolsAsync(cancellationToken).ConfigureAwait(false);

            var symbols = result.Select(s => new Interface.Model.Symbol
            {
                NotionalMinimumValue = s.NotionalMinimumValue,
                BaseAsset            = new Interface.Model.Asset {
                    Symbol = s.BaseAsset.Symbol, Precision = s.BaseAsset.Precision
                },
                Price = new Interface.Model.InclusiveRange {
                    Increment = s.Price.Increment                                          /*, Minimum = s.Price.Minimum, Maximum = s.Price.Maximum*/
                },                                                                         // HACK : remove Price Min and Max because it realtime calcs hits performance.
                Quantity = new Interface.Model.InclusiveRange {
                    Increment = s.Quantity.Increment, Minimum = s.Quantity.Minimum, Maximum = s.Quantity.Maximum
                },
                QuoteAsset = new Interface.Model.Asset {
                    Symbol = s.QuoteAsset.Symbol, Precision = s.QuoteAsset.Precision
                },
                Status           = (Interface.Model.SymbolStatus)s.Status,
                IsIcebergAllowed = s.IsIcebergAllowed,
                OrderTypes       = (IEnumerable <Interface.Model.OrderType>)s.OrderTypes
            }).ToList();

            return(symbols);
        }
Example #4
0
        private async Task <List <Symbol> > InitializeSymbols()
        {
            var symbols = await _binanceApi.GetSymbolsAsync();

            _cache.SetSymbols(symbols.ToList());

            return(symbols.ToList());
        }
        public async Task <IEnumerable <ExchangeStartInfo> > InitializeSymbols()
        {
            var symbols = await _api.GetSymbolsAsync();

            var loggedExchangeStartInfo = _candlestickRepository.GetStartDates();
            var exchangeStartInfo       = new List <ExchangeStartInfo>();
            var count                    = 1;
            var latestStartDate          = default(DateTime?);
            var hasStartSymbolConfigured = !string.IsNullOrEmpty(_startSymbol);
            var startSymbolTriggered     = !hasStartSymbolConfigured;

            foreach (var symbol in symbols)
            {
                if (hasStartSymbolConfigured && symbol == _startSymbol)
                {
                    startSymbolTriggered = true;
                }

                if (!startSymbolTriggered)
                {
                    continue;
                }

                if ((_onlySymbols.Any() && !_onlySymbols.Contains(symbol)) || _excludeSymbols.Any(s => s == symbol))
                {
                    continue;
                }
                var info = loggedExchangeStartInfo.FirstOrDefault(i => i.SymbolLabel == symbol);
                if (info != null)
                {
                    info.Symbol = symbol;
                    Log.Logger.ForContext("Action", "InitializeSymbols")
                    .Debug("Already logged start date for symbol {Symbol}", symbol);
                    count++;
                    exchangeStartInfo.Add(info);
                    latestStartDate = info.StartDate;
                    continue;
                }
                var startDate = await GetStartDate(symbol, null);

                if (startDate.HasValue)
                {
                    Log.Logger.ForContext("Action", "InitializeSymbols")
                    .Information($"Found start date {{StartDate}} for symbol {{Symbol}}. {count++} of {symbols.Count()}", startDate, symbol);
                    _candlestickRepository.LogStartDate(startDate.Value, symbol);
                    exchangeStartInfo.Add(new ExchangeStartInfo {
                        Symbol = symbol, StartDate = startDate.Value
                    });
                }
                else
                {
                    Log.Logger.ForContext("Action", "InitializeSymbols")
                    .Error($"Failed to find start date for symbol {symbol}. {count++} of {symbols.Count()}");
                }
            }

            return(exchangeStartInfo);
        }
        private async Task <List <Symbol> > InitializeSymbols()
        {
            try
            {
                var symbols = await _binanceApi.GetSymbolsAsync();

                _cache.SetSymbols(symbols.ToList());

                return(symbols.ToList());
            }
            catch (Exception ex)
            {
                _cache.ClearSymbols();

                _log.LogError($"Symbols initialization error {ex.Message}");

                return(new List <Symbol>());
            }
        }