public async Task <PositionsGroupCloseResponse> CloseGroupAsync([FromQuery] string assetPairId = null, [FromQuery] string accountId = null, [FromQuery] PositionDirectionContract?direction = null, [FromBody] PositionCloseRequest request = null) { var originator = GetOriginator(request?.Originator); var closeResult = await _tradingEngine.ClosePositionsGroupAsync(accountId, assetPairId, direction?.ToType <PositionDirection>(), originator, request?.AdditionalInfo); _operationsLogService.AddLog("Position liquidation started", string.Empty, $"instrument = [{assetPairId}], account = [{accountId}], direction = [{direction}], request = [{request.ToJson()}]", closeResult?.ToJson()); return(new PositionsGroupCloseResponse { Responses = closeResult.Select(r => new PositionCloseResponse { PositionId = r.Key, Result = r.Value.Item1.ToType <PositionCloseResultContract>(), OrderId = r.Value.Item2?.Id }).ToArray() }); }
private async Task Handle(ClosePositionsRegularFlowCommand command, IEventPublisher publisher) { var executionInfo = await _operationExecutionInfoRepository.GetAsync <SpecialLiquidationOperationData>( operationName : SpecialLiquidationSaga.OperationName, id : command.OperationId); if (executionInfo?.Data == null) { return; } var positions = _ordersCache.Positions .GetPositionsByAccountIds(executionInfo.Data.AccountId) .Where(p => executionInfo.Data.PositionIds.Contains(p.Id)) .ToList(); if (positions.Any()) { await _tradingEngine.ClosePositionsGroupAsync(positions, command.OperationId, OriginatorType.System); } }