Esempio n. 1
0
        private void UpdateChartPoints(OrderBookDataSet dataSet)
        {
            var fontHeight = (int)Font.GetHeight();

            if (_askChartPoints.Count >= _pointsGraphCount)
            {
                _askChartPoints.RemoveAt(0); // Remove the first element from ask array
                _bidChartPoints.RemoveAt(0); // From bid
            }

            if (dataSet != null)
            {
                _askChartPoints.Add(new Point(_chartWidth, GetY(dataSet.Ask[0].Price, fontHeight)));
                _bidChartPoints.Add(new Point(_chartWidth, GetY(dataSet.Bid[0].Price, fontHeight)));
            }

            // Shit both arrays (bid, ask), make a visual move. Run throughout the array (all points) starting from the 1st and decrease X coordinate with the step
            for (int i = 0; i < _askChartPoints.Count - 1; i++)
            {
                _askChartPoints[i] = new Point(_askChartPoints[i].X - _pointsGraphStep, _askChartPoints[i].Y); // ask. Shift a horisontal coordinate of the whole array with a step. This makes a move. Bigger step - faster move
                _bidChartPoints[i] = new Point(_bidChartPoints[i].X - _pointsGraphStep, _bidChartPoints[i].Y); // bid
            }

            Invalidate();
        }
Esempio n. 2
0
        // Draw a vertical stack of the prices
        private void DrawPriceBar(Graphics g, OrderBookDataSet dataSet)
        {
            if (dataSet == null)
            {
                return;
            }

            var fontHeight = (int)Font.GetHeight();

            for (var p = _priceStart; p < _priceEnd; p += _priceStep)
            {
                g.DrawString(p.ToString(CultureInfo.CurrentCulture), Font, Brushes.LightGray, _chartWidth, GetY(p, fontHeight) - fontHeight / 2);
            }

            var maxVolume = Math.Max(dataSet.Ask.Max(d => d.Volume), dataSet.Bid.Max(d => d.Volume));

            // Price bar background width calculation
            var priceBarBackGroundWidth = _orderBackgroundWidth + (int)g.MeasureString(maxVolume.ToString(), Font).Width;

            // Render ask (uppder) part of the DOM
            foreach (var record in dataSet.Ask)
            {
                DrawPriceBarRow(g, record, priceBarBackGroundWidth, fontHeight, Brushes.LightPink, maxVolume);
            }

            // Draw bid (lower) part of the DOM
            foreach (var record in dataSet.Bid)
            {
                DrawPriceBarRow(g, record, priceBarBackGroundWidth, fontHeight, Brushes.LimeGreen, maxVolume);
            }

            if (ActiveOrders != null)
            {
                foreach (var activeOrder in ActiveOrders)
                {
                    g.DrawRectangle(Pens.Black, _chartWidth - 2, GetY(activeOrder.Price, fontHeight) - fontHeight / 2, priceBarBackGroundWidth + 4, fontHeight - _backGroundReduction);
                }
            }
        }
Esempio n. 3
0
 public void RaiseOrderBookReceived(OrderBookDataSet data) => OnOrderBookReceived(new EventArgs <OrderBookDataSet>(data));