/// <summary> Добавляем цену и объем в коллекцию </summary> /// <param name="price"></param> /// <param name="volume"></param> public void Add(decimal price, long volume, bool isBuy) { lock (syncLock) { var elem = Collection.FirstOrDefault(e => e.Price == price); if (elem.IsNull()) { elem = new ChartFull() { Price = price, VolBuy = 0, VolSell = 0 }; Collection.Add(elem); } initMinMax(elem); if (elem.NotIsNull()) { if (isBuy) { elem.VolBuy += volume; elem.CountSell++; if (Max.Buy.Volume < elem.VolBuy) { Max.Buy.Price = elem.Price; Max.Buy.Volume = elem.VolBuy; } } else { elem.VolSell += volume; elem.CountSell++; if (Max.Sell.Volume < elem.VolSell) { Max.Sell.Price = elem.Price; Max.Sell.Volume = elem.VolSell; } } if (Max.Volume.Volume < elem.VolBuy + elem.VolSell) { Max.Volume.Price = elem.Price; Max.Volume.Volume = elem.VolBuy + elem.VolSell; } if (Min.Volume.Volume > elem.VolBuy + elem.VolSell) { Min.Volume.Price = elem.Price; Min.Volume.Volume = elem.VolBuy + elem.VolSell; } if (Max.DVolume.Volume < elem.VolBuy - elem.VolSell) { Max.DVolume.Price = elem.Price; Max.DVolume.Volume = elem.VolBuy - elem.VolSell; } if (Min.DVolume.Volume > elem.VolBuy - elem.VolSell) { Min.DVolume.Price = elem.Price; Min.DVolume.Volume = elem.VolBuy - elem.VolSell; } } } }
private void initMinMax(ChartFull elem) { if (Min.IsNull()) { Min = new Attr(); } if (Max.IsNull()) { Max = new Attr(); } if (Max.Buy.IsNull()) { Max.Buy = new Chart() { Price = elem.Price, Volume = elem.VolBuy }; } if (Max.Sell.IsNull()) { Max.Sell = new Chart() { Price = elem.Price, Volume = elem.VolSell }; } if (Max.Volume.IsNull()) { Max.Volume = new Chart() { Price = elem.Price, Volume = MIN }; } if (Min.Volume.IsNull()) { Min.Volume = new Chart() { Price = elem.Price, Volume = MAX }; } if (Max.DVolume.IsNull()) { Max.DVolume = new Chart() { Price = elem.Price, Volume = MIN }; } if (Min.DVolume.IsNull()) { Min.DVolume = new Chart() { Price = elem.Price, Volume = MAX }; } }
/// <summary> /// Рисует линию горизонтального объема /// </summary> private int PaintLineHVol(Graphics canvas, RectangleF rect, Chart maxElem, Chart minElem, ChartFull hv, Color?colorVol = null, bool isDelta = false) { var widthLayoutVolume = rect.Width; var value = hv.VolBuy + hv.VolSell; if (isDelta) { value = hv.VolBuy - hv.VolSell; } float y = GMath.GetCoordinate(Panel.Rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, hv.Price); var height = GMath.GetCoordinate(Panel.Rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, hv.Price - Panel.Params.MinStepPrice) - y; if (y == 0 || y == Panel.Rect.Height) { return(-1); } int x1 = 0, x2 = 0; if (value < 0) { x1 = GMath.GetCoordinate(widthLayoutVolume, maxElem.Volume, minElem.Volume, value); x2 = GMath.GetCoordinate(widthLayoutVolume, maxElem.Volume, minElem.Volume, 0); } else { x1 = GMath.GetCoordinate(widthLayoutVolume, maxElem.Volume, minElem.Volume, 0); x2 = GMath.GetCoordinate(widthLayoutVolume, maxElem.Volume, minElem.Volume, value); } var p1 = new PointF(rect.X + widthLayoutVolume - x1, y); var p2 = new PointF(rect.X + widthLayoutVolume - x2, y); RectDraw rectVol = new RectDraw(); var color = ColorVol; if (isDelta) { if (value < 0) { color = this.ColorDeltaNegative; } else { color = this.ColorDeltaPositive; } } if (maxElem.Price == hv.Price) { color = ColorMaxVol; } if (minElem.Price == hv.Price) { color = ColorMaxVol; } if (colorVol.NotIsNull()) { color = (Color)colorVol; } rectVol.ColorBorder = color; rectVol.ColorFill = color; rectVol.Paint(canvas, p1.X, y - height / 2, p2.X - p1.X, height - 1 <= 0 ? 1 : height - 1); return(0); }