Esempio n. 1
0
        private static MatchingEngineRouteContract TransformRoute(IMatchingEngineRoute route)
        {
            string GetEmptyIfAny(string value)
            {
                const string AnyValue = "*";

                return(value == AnyValue ? null : value);
            }

            OrderDirectionContract?GetDirection(OrderDirection?direction)
            {
                return(direction?.ToType <OrderDirectionContract>());
            }

            return(new MatchingEngineRouteContract
            {
                Id = route.Id,
                Rank = route.Rank,
                MatchingEngineId = route.MatchingEngineId,
                Asset = GetEmptyIfAny(route.Asset),
                ClientId = GetEmptyIfAny(route.ClientId),
                Instrument = GetEmptyIfAny(route.Instrument),
                TradingConditionId = GetEmptyIfAny(route.TradingConditionId),
                Type = GetDirection(route.Type)
            });
        }
Esempio n. 2
0
        public static int GetSpecificationLevel(IMatchingEngineRoute route)
        {
            var specLevel = 0;

            specLevel += IsAny(route.Instrument) ? 0 : 1;
            specLevel += !route.Type.HasValue ? 0 : 1;
            specLevel += IsAny(route.TradingConditionId) ? 0 : 1;
            specLevel += IsAny(route.ClientId) ? 0 : 1;
            specLevel += IsAny(route.Asset) ? 0 : 1;
            return(specLevel);
        }
Esempio n. 3
0
        public void SaveRoute(IMatchingEngineRoute route)
        {
            _lockSlim.EnterWriteLock();

            try
            {
                _routes[route.Id] = route;
            }
            finally
            {
                _lockSlim.ExitWriteLock();
            }
        }
Esempio n. 4
0
 private static IMatchingEngineRoute ToViewModel(IMatchingEngineRoute route)
 {
     return(new MatchingEngineRoute
     {
         Id = route.Id,
         Rank = route.Rank,
         MatchingEngineId = route.MatchingEngineId,
         Asset = GetEmptyIfAny(route.Asset),
         ClientId = GetEmptyIfAny(route.ClientId),
         Instrument = GetEmptyIfAny(route.Instrument),
         TradingConditionId = GetEmptyIfAny(route.TradingConditionId),
         Type = route.Type
     });
 }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public static int GetSpecificationPriority(IMatchingEngineRoute route)
        {
            //matching field or wildcard in such priority:
            //client, trading condition, type, instrument, asset type, asset.
            //Flag based 1+2+4+8+16+32 >> 1 with Client(32) is higher than 1 with TradingConditionId(16), Type(8), Instrument(4), Asset Type(2), Asset(1) = 31

            var priority = 0;

            priority += IsAny(route.Asset) ? 0 : 1;
            priority += IsAny(route.Instrument) ? 0 : 4;
            priority += route.Type == null ? 0 : 8;
            priority += IsAny(route.TradingConditionId) ? 0 : 16;
            priority += IsAny(route.ClientId) ? 0 : 32;
            return(priority);
        }
Esempio n. 8
0
 public static MatchingEngineRoute Create(IMatchingEngineRoute src)
 {
     return(new MatchingEngineRoute
     {
         Id = src.Id,
         Rank = src.Rank,
         TradingConditionId = src.TradingConditionId,
         ClientId = src.ClientId,
         Instrument = src.Instrument,
         Type = src.Type,
         MatchingEngineId = src.MatchingEngineId,
         Asset = src.Asset,
         RiskSystemLimitType = src.RiskSystemLimitType,
         RiskSystemMetricType = src.RiskSystemMetricType
     });
 }
Esempio n. 9
0
 public static MatchingEngineRouteEntity Create(IMatchingEngineRoute route)
 {
     return(new MatchingEngineRouteEntity
     {
         PartitionKey = GeneratePartitionKey(),
         RowKey = GenerateRowKey(route.Id),
         Id = route.Id,
         Rank = route.Rank,
         TradingConditionId = route.TradingConditionId,
         Instrument = route.Instrument,
         Type = route.Type?.ToString(),
         MatchingEngineId = route.MatchingEngineId,
         ClientId = route.ClientId,
         Asset = route.Asset,
         RiskSystemLimitType = route.RiskSystemLimitType,
         RiskSystemMetricType = route.RiskSystemMetricType
     });
 }
Esempio n. 10
0
        private static MatchingEngineRoute TransformRoute(IMatchingEngineRoute route)
        {
            string GetEmptyIfAny(string value)
            {
                const string AnyValue = "*";

                return(value == AnyValue ? null : value);
            }

            return(new MatchingEngineRoute
            {
                Id = route.Id,
                Rank = route.Rank,
                MatchingEngineId = route.MatchingEngineId,
                Asset = GetEmptyIfAny(route.Asset),
                ClientId = GetEmptyIfAny(route.ClientId),
                Instrument = GetEmptyIfAny(route.Instrument),
                TradingConditionId = GetEmptyIfAny(route.TradingConditionId),
                Type = route.Type
            });
        }
Esempio n. 11
0
 public async Task AddOrReplaceRouteAsync(IMatchingEngineRoute route)
 {
     await _tableStorage.InsertOrReplaceAsync(MatchingEngineRouteEntity.Create(route));
 }