Esempio n. 1
0
        /// <summary>
        /// Checks levels' identifier and fills them if they are empty.
        /// </summary>
        /// <returns></returns>
        private async Task MigrateLevels()
        {
            IReadOnlyCollection <Instrument> instruments = await _instrumentRepository.GetAllAsync();

            foreach (Instrument instrument in instruments)
            {
                if (instrument.Levels.Any(o => string.IsNullOrEmpty(o.Id)))
                {
                    _log.InfoWithDetails("Migrating instrument levels.", instrument);

                    IReadOnlyCollection <InstrumentLevel> levels = instrument.Levels
                                                                   .Select(o => new InstrumentLevel
                    {
                        Id     = !string.IsNullOrEmpty(o.Id) ? o.Id : Guid.NewGuid().ToString(),
                        Number = o.Number,
                        Markup = o.Markup,
                        Volume = o.Volume
                    })
                                                                   .ToArray();

                    instrument.UpdateLevels(levels);

                    await _instrumentRepository.UpdateAsync(instrument);

                    _log.InfoWithDetails("Instrument updated.", instrument);
                }
            }
        }
        public async Task <IReadOnlyCollection <Instrument> > GetAllAsync()
        {
            IReadOnlyCollection <Instrument> instruments = _cache.GetAll();

            if (instruments == null)
            {
                instruments = await _instrumentRepository.GetAllAsync();

                _cache.Initialize(instruments);
            }

            return(instruments);
        }
Esempio n. 3
0
        public async Task <IReadOnlyCollection <Instrument> > GetAllAsync()
        {
            IReadOnlyCollection <Instrument> instruments = _cache.GetAll();

            if (instruments == null)
            {
                instruments = await _instrumentRepository.GetAllAsync();

                foreach (Instrument instrument in instruments)
                {
                    instrument.CrossInstruments = await _crossInstrumentRepository.GetAsync(instrument.AssetPairId);
                }

                _cache.Initialize(instruments);
            }

            return(instruments);
        }