Ejemplo n.º 1
0
        private async Task HandleTradingDisabled(ProductContract product, string username)
        {
            if (product.IsTradingDisabled)
            {
                _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled),
                               $"Trading disabled for product {product.ProductId}");
                var allRfq = await RetrieveAllRfq(product.ProductId, canBePaused : true);

                _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled),
                               $"Found rfqs to pause: {allRfq.Select(x => x.Id).ToJson()}");

                foreach (var rfq in allRfq)
                {
                    _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled),
                                   $"Trying to pause rfq: {rfq.Id}");
                    await _rfqPauseService.AddAsync(rfq.Id,
                                                    PauseSource.TradingDisabled,
                                                    username);
                }
            }
            else
            {
                _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled),
                               $"Trading enabled for product {product.ProductId}");
                var allRfq = await RetrieveAllRfq(product.ProductId, canBeResumed : true, canBeStopped : true);

                _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled),
                               $"Found rfqs to resume or stop: {allRfq.Select(x => x.Id).ToJson()}");

                foreach (var rfq in allRfq)
                {
                    if (rfq.PauseSummary?.CanBeResumed ?? false)
                    {
                        _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled),
                                       $"Trying to resume rfq: {rfq.Id}");
                        await _rfqPauseService.ResumeAsync(rfq.Id,
                                                           PauseCancellationSource.TradingEnabled,
                                                           username);
                    }
                    else if (rfq.PauseSummary?.CanBeStopped ?? false)
                    {
                        _log.WriteInfo(nameof(ProductChangedProjection), nameof(HandleTradingDisabled),
                                       $"Trying to stop pending pause for rfq: {rfq.Id}");
                        await _rfqPauseService.StopPendingAsync(rfq.Id,
                                                                PauseCancellationSource.TradingEnabled,
                                                                username);
                    }
                    else
                    {
                        _log.WriteWarning(nameof(ProductChangedProjection), nameof(HandleTradingDisabled),
                                          $"Unexpected state for rfq: {rfq.Id}, {rfq.ToJson()}");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <RfqResumeErrorCode> ResumeAsync(string id, [FromBody] RfqResumeRequest request)
        {
            var errorCode = await _rfqPauseService.ResumeAsync(id, PauseCancellationSource.Manual, request.Initiator);

            return(errorCode);
        }