public IQuote GetBestQuoteWithAvailableVolume(string symbol) { IList <T> quotes = null; _lockManager.EnterRead(symbol); try { quotes = StorageService.GetQuotesByPrice(symbol); } finally { _lockManager.ExitRead(symbol); } if (quotes == null || quotes.Count == 0) { return(null); } foreach (var quote in quotes) { // Candidate quote, is it better than the existing one (if there is an existing one) if (!_quoteValidationPredicates.All(p => p(quote))) { _observer.OnCandidateQuoteMiss(quote); continue; } // Quotes are already sorted from storage...first valid one we get is it // Technically still a race condition here in that this quote might at this point be invalid/missing/changed...but I'm taking that as an ok for the implementation // as the actual trade execution still ensures proper availability on a trade attempt, and the locking/checking/looping here is likely not worth it, since // as soon as anything is returned to a consumer, it's out of date anyhow.... return(quote); } return(null); }