private async Task Handle(SpecialLiquidationStartedInternalEvent e, ICommandSender sender) { var executionInfo = await _operationExecutionInfoRepository.GetAsync <SpecialLiquidationOperationData>( operationName : OperationName, id : e.OperationId); if (executionInfo?.Data == null) { return; } if (executionInfo.Data.SwitchState(SpecialLiquidationOperationState.Started, SpecialLiquidationOperationState.PriceRequested)) { var positionsVolume = GetNetPositionCloseVolume(executionInfo.Data.PositionIds, executionInfo.Data.AccountId); executionInfo.Data.Instrument = e.Instrument; executionInfo.Data.Volume = positionsVolume; executionInfo.Data.RequestNumber = 1; RequestPrice(sender, executionInfo); _chaosKitty.Meow(e.OperationId); await _operationExecutionInfoRepository.Save(executionInfo); } }
private async Task Handle(SpecialLiquidationStartedInternalEvent e, ICommandSender sender) { var executionInfo = await _operationExecutionInfoRepository.GetAsync <SpecialLiquidationOperationData>( operationName : OperationName, id : e.OperationId); if (executionInfo?.Data == null) { return; } if (executionInfo.Data.SwitchState(SpecialLiquidationOperationState.Started, SpecialLiquidationOperationState.PriceRequested)) { var positionsVolume = GetNetPositionCloseVolume(executionInfo.Data.PositionIds, executionInfo.Data.AccountId); //special command is sent instantly for timeout control.. it is retried until timeout occurs sender.SendCommand(new GetPriceForSpecialLiquidationTimeoutInternalCommand { OperationId = e.OperationId, CreationTime = _dateService.Now(), TimeoutSeconds = _marginTradingSettings.SpecialLiquidation.PriceRequestTimeoutSec, }, _cqrsContextNamesSettings.TradingEngine); executionInfo.Data.Instrument = e.Instrument; executionInfo.Data.Volume = positionsVolume; if (_marginTradingSettings.ExchangeConnector == ExchangeConnectorType.RealExchangeConnector) { //send it to the Gavel sender.SendCommand(new GetPriceForSpecialLiquidationCommand { OperationId = e.OperationId, CreationTime = _dateService.Now(), Instrument = e.Instrument, Volume = positionsVolume != 0 ? positionsVolume : 1,//hack, requested by the bank RequestNumber = 1, }, _cqrsContextNamesSettings.Gavel); } else { _specialLiquidationService.FakeGetPriceForSpecialLiquidation(e.OperationId, e.Instrument, positionsVolume); } _chaosKitty.Meow(e.OperationId); await _operationExecutionInfoRepository.Save(executionInfo); } }