public async Task InsertOrReplaceAsync(QuoteTimeoutSettings quoteTimeoutSettings)
        {
            var entity = new QuoteTimeoutSettingsEntity(GetPartitionKey(), GetRowKey());

            Mapper.Map(quoteTimeoutSettings, entity);

            await _storage.InsertOrReplaceAsync(entity);
        }
Ejemplo n.º 2
0
        private async Task ValidateQuoteAsync(IReadOnlyCollection <LimitOrder> limitOrders, Quote quote)
        {
            QuoteTimeoutSettings quoteTimeoutSettings = await _quoteTimeoutSettingsService.GetAsync();

            if (quoteTimeoutSettings.Enabled && DateTime.UtcNow - quote.Time > quoteTimeoutSettings.Value)
            {
                _log.WarningWithDetails("Quote timeout is expired", new
                {
                    quote,
                    Timeout = quoteTimeoutSettings.Value
                });

                SetError(limitOrders, LimitOrderError.InvalidQuote);
            }
        }
        public async Task <QuoteTimeoutSettings> GetAsync()
        {
            QuoteTimeoutSettings quoteTimeoutSettings = _cache.Get(CacheKey);

            if (quoteTimeoutSettings == null)
            {
                quoteTimeoutSettings = await _quoteTimeoutSettingsRepository.GetAsync();

                if (quoteTimeoutSettings == null)
                {
                    quoteTimeoutSettings = new QuoteTimeoutSettings
                    {
                        Enabled = true,
                        Value   = TimeSpan.FromSeconds(5)
                    };
                }

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

            return(quoteTimeoutSettings);
        }
Ejemplo n.º 4
0
        public async Task <QuoteTimeoutSettingsModel> GetQuoteTimeoutSettingsAsync()
        {
            QuoteTimeoutSettings quoteTimeoutSettings = await _quoteTimeoutSettingsService.GetAsync();

            return(Mapper.Map <QuoteTimeoutSettingsModel>(quoteTimeoutSettings));
        }
Ejemplo n.º 5
0
        public void TestInitialize()
        {
            _assets.AddRange(new[]
            {
                new Asset
                {
                    Id       = "USD",
                    Accuracy = 2
                },
                new Asset
                {
                    Id       = "BTC",
                    Accuracy = 8
                }
            });

            _assetPairs.Add(new AssetPair
            {
                Id                = "BTCUSD",
                BaseAssetId       = "BTC",
                QuotingAssetId    = "USD",
                Accuracy          = 3,
                InvertedAccuracy  = 8,
                MinVolume         = 0.0001,
                MinInvertedVolume = 1
            });

            _balances.AddRange(new[]
            {
                new Balance(ExchangeNames.Lykke, "BTC", 1000000),
                new Balance(ExchangeNames.Lykke, "USD", 1000000)
            });

            _quoteTimeoutSettings = new QuoteTimeoutSettings
            {
                Enabled = true,
                Error   = TimeSpan.FromSeconds(1)
            };

            _balanceServiceMock.Setup(o => o.GetByAssetIdAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns((string exchange, string assetId) =>
            {
                return(Task.FromResult(_balances.Single(o => o.Exchange == exchange && o.AssetId == assetId)));
            });

            _assetsServiceWithCacheMock
            .Setup(o => o.TryGetAssetAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns((string assetId, CancellationToken token) =>
            {
                return(Task.FromResult(_assets.Single(o => o.Id == assetId)));
            });

            _assetsServiceWithCacheMock
            .Setup(o => o.TryGetAssetPairAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns((string assetPairId, CancellationToken token) =>
            {
                return(Task.FromResult(_assetPairs.Single(o => o.Id == assetPairId)));
            });

            _instrumentServiceMock.Setup(o => o.GetAllAsync())
            .Returns(() => Task.FromResult <IReadOnlyCollection <Instrument> >(_instruments));

            _quoteTimeoutSettingsServiceMock.Setup(o => o.GetAsync())
            .Returns(() => Task.FromResult(_quoteTimeoutSettings));

            _pnLStopLossEngineService.Setup(o => o.GetTotalMarkupByAssetPairIdAsync(It.IsAny <string>()))
            .Returns(() => Task.FromResult(0m));

            _orderBooksUpdatesReportPublisher.Setup(o => o.PublishAsync(It.IsAny <OrderBookUpdateReport>()))
            .Returns(() => Task.FromResult(0m));

            _service = new MarketMakerService(
                _instrumentServiceMock.Object,
                _lykkeExchangeServiceMock.Object,
                _orderBookServiceMock.Object,
                _balanceServiceMock.Object,
                _marketMakerStateServiceMock.Object,
                _quoteServiceMock.Object,
                _b2C2OrderBookServiceMock.Object,
                _quoteTimeoutSettingsServiceMock.Object,
                _summaryReportServiceMock.Object,
                _positionServiceMock.Object,
                _assetsServiceWithCacheMock.Object,
                _marketMakerSettingsServiceMock.Object,
                _tradeServiceMock.Object,
                _assetPairLinkServiceMock.Object,
                _pnLStopLossEngineService.Object,
                _fiatEquityStopLossService.Object,
                _noFreshQuotesStopLossService.Object,
                _orderBooksUpdatesReportPublisher.Object,
                false,
                EmptyLogFactory.Instance);
        }
        public async Task UpdateAsync(QuoteTimeoutSettings quoteTimeoutSettings, string userId)
        {
            await _quoteTimeoutSettingsRepository.InsertOrReplaceAsync(quoteTimeoutSettings);

            _cache.Set(quoteTimeoutSettings);
        }
        public async Task SaveAsync(QuoteTimeoutSettings quoteTimeoutSettings)
        {
            await _quoteTimeoutSettingsRepository.InsertOrReplaceAsync(quoteTimeoutSettings);

            _cache.Set(quoteTimeoutSettings);
        }