Ejemplo n.º 1
0
        private PricePoints GetPricePoints(OrderBookDao.Entity orderBook)
        {
            if (pricePointsCache == null)
            {
                pricePointsCache = new Dictionary <string, Dictionary <OrderBookDao.Entity, PricePoints> >();
            }
            if (pricePointsCache.ContainsKey(selectedInstrument.Name) == false)
            {
                pricePointsCache.Add(selectedInstrument.Name, new Dictionary <OrderBookDao.Entity, PricePoints>());
            }
            var orderBookPricePoints = pricePointsCache[selectedInstrument.Name];

            if (orderBookPricePoints.ContainsKey(orderBook))
            {
                return(orderBookPricePoints[orderBook]);
            }

            PricePoints pricePoints = new PricePoints();

            pricePoints.rate         = orderBook.Rate;
            pricePoints.price_points = new Dictionary <float, PricePoint>();
            foreach (var pp in orderBook.GetPricePointsOrderByPrice())
            {
                pricePoints.price_points[pp.Price] = new PricePoint()
                {
                    os = pp.Os,
                    ol = pp.Ol,
                    ps = pp.Ps,
                    pl = pp.Pl
                };
            }
            orderBookPricePoints[orderBook] = pricePoints;
            return(pricePoints);
        }
Ejemplo n.º 2
0
        private static IEnumerable <OrderBookPricePointDao.Entity> GetRangePricePoint(OrderBookDao.Entity orderBook, float min, float max)
        {
            float start = GetRoundPrice(min);
            float end   = GetRoundPrice(max);

            foreach (var pricePoint in orderBook.GetPricePointsOrderByPrice())
            {
                if (start - 0.001f <= pricePoint.Price && pricePoint.Price <= end + 0.001f)
                {
                    yield return(pricePoint);
                }
            }
        }
Ejemplo n.º 3
0
        private static OrderBookPricePointDao.Entity GetRatePricePoint(OrderBookDao.Entity orderBook, float rate)
        {
            float min = float.MaxValue;

            OrderBookPricePointDao.Entity closedPricePoint = null;
            foreach (var pricePoint in orderBook.GetPricePointsOrderByPrice())
            {
                float d = Math.Abs(rate - pricePoint.Price);
                if (d < min)
                {
                    min = d;
                    closedPricePoint = pricePoint;
                }
            }
            return(closedPricePoint);
        }
Ejemplo n.º 4
0
        private void LoadChart(Chart chart, OrderBookDao.Entity orderBook)
        {
            PricePoints pricePoints = new PricePoints();

            pricePoints.rate         = orderBook.Rate;
            pricePoints.price_points = new Dictionary <float, PricePoint>();
            foreach (var pp in orderBook.GetPricePointsOrderByPrice())
            {
                pricePoints.price_points[pp.Price] = new PricePoint()
                {
                    os = pp.Os,
                    ol = pp.Ol,
                    ps = pp.Ps,
                    pl = pp.Pl
                };
            }
            LoadChart(chart, orderBook.DateTime, pricePoints);
        }