public static PriceByOrderSide GetTopPrices(
     IEnumerable <Order> myNotFinishedOrders,
     ILocalOrderBookSnapshot snapshot)
 {
     var(asks, bids) = FlattenSnapshot(snapshot);
     RemoveOrders(myNotFinishedOrders, asks, bids);
     return(FilterByPercentileTopPrices(asks, bids));
 }
        public static decimal?GetFilteredTopMidPrice(
            IEnumerable <Order> myNotFinishedOrders,
            ILocalOrderBookSnapshot snapshot)
        {
            var(asks, bids) = FlattenSnapshot(snapshot);
            RemoveOrders(myNotFinishedOrders, asks, bids);
            var prices = FilterByPercentileTopPrices(asks, bids);

            if (prices.TopAsk == null || prices.TopBid == null)
            {
                return(null);
            }

            return((prices.TopAsk.Value + prices.TopBid.Value) / 2);
        }
        private static (OrderBookSideFlat asks, OrderBookSideFlat bids) FlattenSnapshot(ILocalOrderBookSnapshot snapshot)
        {
            SortedDictionary <decimal, decimal> asks, bids;

            switch (snapshot)
            {
            case L1LocalOrderBookSnapshot l1:
                asks = l1.GetAsks();
                bids = l1.GetBids();
                break;

            case L2LocalOrderBookSnapshot l2:
                asks = l2.Asks;
                bids = l2.Bids;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(snapshot), snapshot, null);
            }

            return(new OrderBookSideFlat(asks), new OrderBookSideFlat(bids));
        }