예제 #1
0
        private async Task HandleRiskManagerBlockTradingCommand(MatchingEngineRouteRisksCommand command)
        {
            switch (command.Action)
            {
            case RiskManagerAction.On:

                var routes = FindRejectRoutes(command);

                if (routes.Any())
                {
                    await _riskSystemCommandsLogRepository.AddErrorAsync(command.ActionType.ToString(),
                                                                         command.ToJson(),
                                                                         $"Route already exists: {routes.ToJson()}");

                    await _log.WriteWarningAsync(nameof(MatchingEngineRoutesManager),
                                                 nameof(HandleRiskManagerBlockTradingCommand), routes.ToJson(),
                                                 $"Route already exists. Command from risk system is not processed: {command.ToJson()} ");

                    return;
                }

                var newRoute = new MatchingEngineRoute
                {
                    Id                   = Guid.NewGuid().ToString().ToUpper(),
                    Rank                 = command.Rank,
                    Asset                = command.Asset,
                    ClientId             = command.ClientId,
                    Instrument           = command.Instrument,
                    TradingConditionId   = command.TradingConditionId,
                    Type                 = GetOrderDirection(command.Direction),
                    MatchingEngineId     = MatchingEngineConstants.Reject,
                    RiskSystemLimitType  = command.LimitType,
                    RiskSystemMetricType = command.Type
                };

                await AddOrReplaceRouteAsync(newRoute);

                break;

            case RiskManagerAction.Off:

                var existingRoutes = FindRejectRoutes(command);

                if (existingRoutes.Length != 1)
                {
                    throw new Exception(
                              $"Cannot disable BlockTradingForNewOrders route for command: {command.ToJson()}. Existing routes found for command: {existingRoutes.ToJson()}");
                }

                await DeleteRouteAsync(existingRoutes[0].Id);

                break;

            default:
                throw new NotSupportedException($"Action [{command.Action}] from risk managment system is not supported.");
            }
        }
예제 #2
0
        public async Task AddOrReplaceRouteAsync(IMatchingEngineRoute route)
        {
            // Create Editable Object
            var matchingEngineRoute = MatchingEngineRoute.Create(route);

            matchingEngineRoute.ClientId           = GetValueOrAnyIfValid(route.ClientId, ValidateClient);
            matchingEngineRoute.TradingConditionId = GetValueOrAnyIfValid(route.TradingConditionId, ValidateTradingCondition);
            matchingEngineRoute.Instrument         = GetValueOrAnyIfValid(route.Instrument, ValidateInstrument);
            matchingEngineRoute.Asset = GetValueOrAnyIfValid(route.Asset, null);

            await _repository.AddOrReplaceRouteAsync(matchingEngineRoute);

            _routesCacheService.SaveRoute(matchingEngineRoute);
        }
예제 #3
0
        //TODO: Risk manager related stuff may be removed one time..

        public Task AddOrReplaceRouteInCacheAsync(IMatchingEngineRoute route)
        {
            // Create Editable Object
            var matchingEngineRoute = MatchingEngineRoute.Create(route);

            matchingEngineRoute.ClientId           = GetValueOrAnyIfValid(route.ClientId, null);
            matchingEngineRoute.TradingConditionId = GetValueOrAnyIfValid(route.TradingConditionId, ValidateTradingCondition);
            matchingEngineRoute.Instrument         = GetValueOrAnyIfValid(route.Instrument, ValidateInstrument);
            matchingEngineRoute.Asset = GetValueOrAnyIfValid(route.Asset, null);

            _routesCacheService.SaveRoute(matchingEngineRoute);

            return(Task.CompletedTask);
        }