public async Task InsertOrReplaceAsync(QuoteThresholdSettings quoteThresholdSettings)
        {
            var entity = new QuoteThresholdSettingsEntity(GetPartitionKey(), GetRowKey());

            Mapper.Map(quoteThresholdSettings, entity);

            await _storage.InsertOrReplaceAsync(entity);
        }
        public void TestInitialize()
        {
            _quoteThresholdSettings = new QuoteThresholdSettings
            {
                Enabled = true,
                Value   = .2m
            };

            _quoteThresholdSettingsServiceMock.Setup(o => o.GetAsync())
            .Returns(() => Task.FromResult(_quoteThresholdSettings));

            _service = new QuoteService(
                _quoteThresholdSettingsServiceMock.Object,
                _quoteThresholdLogServiceMock.Object);
        }
示例#3
0
        public async Task UpdateAsync(Quote quote)
        {
            if (!await _instrumentService.IsAssetPairExistAsync(quote.AssetPairId))
            {
                return;
            }

            if (quote.Ask == 0 || quote.Bid == 0 || quote.Mid == 0)
            {
                _log.WarningWithDetails("Invalid quote received", quote);
                return;
            }

            Quote currentQuote = _cache.Get(GetKey(quote));

            if (currentQuote != null)
            {
                QuoteThresholdSettings quoteThresholdSettings = await _quoteThresholdSettingsService.GetAsync();

                if (quoteThresholdSettings.Enabled &&
                    Math.Abs(currentQuote.Mid - quote.Mid) / currentQuote.Mid > quoteThresholdSettings.Value)
                {
                    _log.WarningWithDetails("Invalid quote", new
                    {
                        Quote        = quote,
                        CurrentQuote = currentQuote,
                        Threshold    = quoteThresholdSettings.Value
                    });
                }
                else
                {
                    _exchanges.Add(quote.Source);
                    _cache.Set(quote);
                }
            }
            else
            {
                _exchanges.Add(quote.Source);
                _cache.Set(quote);
            }
        }
示例#4
0
        public async Task <QuoteThresholdSettings> GetAsync()
        {
            QuoteThresholdSettings quoteThresholdSettings = _cache.Get(CacheKey);

            if (quoteThresholdSettings == null)
            {
                quoteThresholdSettings = await _quoteThresholdSettingsRepository.GetAsync();

                if (quoteThresholdSettings == null)
                {
                    quoteThresholdSettings = new QuoteThresholdSettings
                    {
                        Enabled = true,
                        Value   = .2m
                    };
                }

                _cache.Initialize(new[] { quoteThresholdSettings });
            }

            return(quoteThresholdSettings);
        }
示例#5
0
        public async Task SetAsync(Quote quote)
        {
            Quote currentQuote = _cache.Get(GetKey(quote));

            if (currentQuote != null)
            {
                QuoteThresholdSettings quoteThresholdSettings = await _quoteThresholdSettingsService.GetAsync();

                if (quoteThresholdSettings.Enabled &&
                    Math.Abs(currentQuote.Mid - quote.Mid) / currentQuote.Mid > quoteThresholdSettings.Value)
                {
                    _quoteThresholdLogService.Error(currentQuote, quote, quoteThresholdSettings.Value);
                }
                else
                {
                    _cache.Set(quote);
                }
            }
            else
            {
                _cache.Set(quote);
            }
        }
示例#6
0
        public async Task <QuoteThresholdSettingsModel> GetQuoteThresholdSettingsAsync()
        {
            QuoteThresholdSettings quoteThresholdSettings = await _quoteThresholdSettingsService.GetAsync();

            return(Mapper.Map <QuoteThresholdSettingsModel>(quoteThresholdSettings));
        }
示例#7
0
        public async Task UpdateAsync(QuoteThresholdSettings quoteThresholdSettings)
        {
            await _quoteThresholdSettingsRepository.InsertOrReplaceAsync(quoteThresholdSettings);

            _cache.Set(quoteThresholdSettings);
        }