Example #1
0
        private bool CheckZeroQuote(ExternalOrderBook orderbook, bool isEodOrderbook)
        {
            // TODO: the code below supposes we have only one quote in orderbook
            var hasZeroVolume    = orderbook.Asks[0].Volume == 0 || orderbook.Bids[0].Volume == 0;
            var hasZeroPrice     = orderbook.Asks[0].Price == 0 || orderbook.Bids[0].Price == 0;
            var isOrderbookValid = !hasZeroVolume && !hasZeroPrice;

            var assetPair = _assetPairsCache.GetAssetPairByIdOrDefault(orderbook.AssetPairId);

            if (assetPair == null)
            {
                return(isOrderbookValid);
            }

            //EOD quotes should not change asset pair state
            if (isEodOrderbook)
            {
                return(isOrderbookValid);
            }

            if (!isOrderbookValid)
            {
                // suspend instrument in case of zero volumes only
                if (!assetPair.IsSuspended && hasZeroVolume)
                {
                    assetPair.IsSuspended = true;//todo apply changes to trading engine
                    _cqrsSender.SendCommandToSettingsService(new ChangeProductSuspendedStatusCommand()
                    {
                        ProductId   = assetPair.Id,
                        OperationId = _identityGenerator.GenerateGuid(),
                        Timestamp   = _dateService.Now(),
                        IsSuspended = true,
                    });

                    _log.Info($"Suspending instrument {assetPair.Id}", context: orderbook.ToContextData()?.ToJson());
                }
            }
            else
            {
                if (assetPair.IsSuspended)
                {
                    assetPair.IsSuspended = false;//todo apply changes to trading engine
                    _cqrsSender.SendCommandToSettingsService(new ChangeProductSuspendedStatusCommand
                    {
                        ProductId   = assetPair.Id,
                        OperationId = _identityGenerator.GenerateGuid(),
                        Timestamp   = _dateService.Now(),
                        IsSuspended = false,
                    });

                    _log.Info($"Un-suspending instrument {assetPair.Id}", context: orderbook.ToContextData()?.ToJson());
                }
            }

            return(isOrderbookValid);
        }
        private bool CheckZeroQuote(ExternalOrderBook orderbook)
        {
            var isOrderbookValid = orderbook.Asks[0].Volume != 0 && orderbook.Bids[0].Volume != 0;

            var assetPair = _assetPairsCache.GetAssetPairByIdOrDefault(orderbook.AssetPairId);

            if (assetPair == null)
            {
                return(isOrderbookValid);
            }

            if (!isOrderbookValid)
            {
                if (!assetPair.IsSuspended)
                {
                    assetPair.IsSuspended = true;//todo apply changes to trading engine
                    _cqrsSender.SendCommandToSettingsService(new SuspendAssetPairCommand
                    {
                        AssetPairId = assetPair.Id,
                        OperationId = _identityGenerator.GenerateGuid(),
                    });
                }
            }
            else
            {
                if (assetPair.IsSuspended)
                {
                    assetPair.IsSuspended = false;//todo apply changes to trading engine
                    _cqrsSender.SendCommandToSettingsService(new UnsuspendAssetPairCommand
                    {
                        AssetPairId = assetPair.Id,
                        OperationId = _identityGenerator.GenerateGuid(),
                    });
                }
            }

            return(isOrderbookValid);
        }