Esempio n. 1
0
        public IMatchingEngineRoute FindRoute(string clientId, string tradingConditionId, string instrumentId, OrderDirection orderType)
        {
            var routes     = _routesCacheService.GetRoutes();
            var instrument = string.IsNullOrEmpty(instrumentId)
                ? null
                : _assetPairsCache.GetAssetPairById(instrumentId);

            var topRankRoutes = routes
                                .Where(r => EqualsOrAny(r.ClientId, clientId) &&
                                       EqualsOrAny(r.TradingConditionId, tradingConditionId) &&
                                       EqualsOrAny(r.Instrument, instrumentId) &&
                                       (!r.Type.HasValue || IsAny(r.Instrument) || r.Type.Value == orderType) &&
                                       IsAssetMatches(r.Asset, r.Type, instrument, orderType))
                                .GroupBy(r => r.Rank)
                                .OrderBy(gr => gr.Key)
                                .FirstOrDefault()?
                                .Select(gr => gr)
                                .ToArray();

            if (topRankRoutes == null)
            {
                return(null);
            }

            if (topRankRoutes.Length == 1)
            {
                return(topRankRoutes[0]);
            }

            var mostSpecificRoutes = topRankRoutes
                                     .GroupBy(GetSpecificationLevel)
                                     .OrderByDescending(gr => gr.Key)
                                     .First()
                                     .Select(gr => gr)
                                     .ToArray();

            if (mostSpecificRoutes.Length == 1)
            {
                return(mostSpecificRoutes[0]);
            }

            var highestPriorityRoutes = mostSpecificRoutes
                                        .GroupBy(GetSpecificationPriority)
                                        .OrderByDescending(gr => gr.Key)
                                        .First()
                                        .Select(gr => gr)
                                        .ToArray();

            if (highestPriorityRoutes.Length >= 1 &&
                highestPriorityRoutes.Select(r => r.MatchingEngineId).Distinct().Count() == 1)
            {
                return(highestPriorityRoutes[0]);
            }

            return(null);
        }
Esempio n. 2
0
 public IEnumerable <IMatchingEngineRoute> GetRoutes()
 {
     return(_routesCacheService.GetRoutes().Select(ToViewModel));
 }