// -------------------------- protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(Style.Colors.Background); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; float posY = 0; if (ClientManager.Training) { DrawNoData(g, "DISABLED"); DrawBorders(g); return; } try { lock (this) { if (priceData != null) { // Draw grid float rightDivider = Width - gridRightDivider; float gridCount = (int)((rightDivider - graphMarginX) / gridWidth); float gridSizeX = (rightDivider - graphMarginX) / gridCount; gridCount = (int)(Height / gridHeight); float gridSizeY = Height / gridCount; using (Pen pen = new Pen(Style.Colors.Primary.Dark2)) { for (float posX = graphMarginX; posX < rightDivider; posX += gridSizeX) { g.DrawLine(pen, (int)posX, gridOffset, (int)posX, Height); } for (posY = gridOffset; posY < Height; posY += gridSizeY) { g.DrawLine(pen, graphMarginX, (int)posY, rightDivider, (int)posY); } g.DrawLine(pen, rightDivider, gridOffset, rightDivider, Height); } Color pairNameColor; if (Blocked) { pairNameColor = Style.Colors.Secondary.Dark1; } else if (MarkedUser) { pairNameColor = Style.Colors.Terciary.Main; } else { pairNameColor = Style.Colors.Primary.Light1; } // ------------------ // Draw pair name using (Brush brush = new SolidBrush(pairNameColor)) { g.DrawString(pair.BaseCurrency + " / " + pair.QuoteCurrency, Style.Fonts.Medium, brush, new PointF(6, 7)); } posY = Style.Fonts.Medium.Height + 10; // Draw price float width = 0; string[] priceParts = Helper.SplitLeadingZeros(lastPrice.ToString("F8")); using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { width = g.MeasureString("Price: ", Style.Fonts.Tiny).Width; g.DrawString("Price: ", Style.Fonts.Tiny, brush, new PointF(7, posY)); } using (Brush brush = new SolidBrush(Style.Colors.Primary.Dark1)) { g.DrawString(priceParts[0], Style.Fonts.Tiny, brush, new PointF(7 + width, posY)); width += g.MeasureString(priceParts[0], Style.Fonts.Tiny).Width; } using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { g.DrawString(priceParts[1], Style.Fonts.Tiny, brush, new PointF(5 + width, posY)); } posY += Style.Fonts.Tiny.Height + 3; // Draw volume using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { width = g.MeasureString("Volume: ", Style.Fonts.Tiny).Width; g.DrawString("Volume: ", Style.Fonts.Tiny, brush, new PointF(7, posY)); } using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { g.DrawString(volume.ToString("F3"), Style.Fonts.Tiny, brush, new PointF(7 + width, posY)); } posY += Style.Fonts.Tiny.Height + 3; // Draw 24h change using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { width = g.MeasureString("Change: ", Style.Fonts.Tiny).Width; g.DrawString("Change: ", Style.Fonts.Tiny, brush, new PointF(7, posY)); } Color changeColor = Helper.LerpColor((float)change24, -30, 30, Style.Colors.Negative, Style.Colors.Positive); string changeString = ""; if (change24 > 0) { changeString += "+"; } changeString += change24.ToString("F2") + "%"; using (Brush brush = new SolidBrush(changeColor)) { g.DrawString(changeString, Style.Fonts.Tiny, brush, new PointF(5 + width, posY)); } // Draw min/max lines using (Pen pen = new Pen(Style.Colors.Secondary.Dark2, 3)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pen.DashPattern = new float[] { 2, 2 }; g.DrawLine(pen, graphMarginX + 5, 8, rightDivider - 5, 8); g.DrawLine(pen, graphMarginX + 5, Height - 8, rightDivider - 5, Height - 8); } double maxValue = 0; double minValue = double.MaxValue; // Find the minimum and maximum value for (int i = 0; i < priceData.Length; i++) { if (priceData[i].MarketData.PriceLast > maxValue) { maxValue = priceData[i].MarketData.PriceLast; } if (priceData[i].MarketData.PriceLast < minValue) { minValue = priceData[i].MarketData.PriceLast; } } maxValue *= 1.001; minValue *= 0.999; // Draw graph data Helper.DrawGraphLine(g, new RectangleF(graphMarginX, graphMarginY, rightDivider - graphMarginX, Height - (graphMarginY * 2)), priceData.ToArray(), maxValue, minValue, priceData.Last().Timestamp - (GraphTimeframe * 3600), 38, 1.5f); // Draw spread using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { PointF point = new PointF(graphMarginX + 4, Height - graphMarginY - 5 - Style.Fonts.Small.Height); float graphSpread = (float)((maxValue - minValue) / minValue) * 100; Helper.DrawTextShadow(g, "Spread: " + graphSpread.ToString("F4") + "%", point, Style.Fonts.Small, Color.Black); g.DrawString("Spread: " + graphSpread.ToString("F4") + "%", Style.Fonts.Small, brush, point); } // Draw legend using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { PointF point = new PointF(graphMarginX + 4, Height - graphMarginY - 10 - (Style.Fonts.Small.Height * 2)); string text = "Graph: " + GraphTimeframe + "h"; Helper.DrawTextShadow(g, text, point, Style.Fonts.Small, Color.Black); g.DrawString(text, Style.Fonts.Small, brush, point); } } else { DrawNoData(g); } } DrawBorders(g); } catch (Exception ex) { Console.WriteLine(ex.Message + " - " + ex.StackTrace); } }
private void DrawOpenPosition(Graphics g, TradeTracker.TradeData op, float posX, float posWidth) { string text = ""; float width = 0; float textPos = 0; string[] partsOpen = Helper.SplitLeadingZeros(op.buyPrice.ToString("F" + op.displayDigits)); string[] partsCurr = Helper.SplitLeadingZeros(op.openPrice.ToString("F" + op.displayDigits)); float posXOpen = 0; float posXClose = 0; using (Brush brush = new SolidBrush(Style.Colors.Primary.Dark2)) { // Draw open price (leading zeros) text = op.buyPrice.ToString("F" + op.displayDigits); width = g.MeasureString(text, Style.Fonts.Tiny).Width; textPos = (posWidth / 2) - (width / 2) + posX - 3; posXOpen = textPos; g.DrawString(partsOpen[0], Style.Fonts.Tiny, brush, new PointF(textPos, 10)); posXOpen += g.MeasureString(partsOpen[0], Style.Fonts.Tiny).Width; } using (Brush brush = new SolidBrush(Style.Colors.Terciary.Dark2)) { // Draw current price (leading zeros) text = op.openPrice.ToString("F" + op.displayDigits); width = g.MeasureString(text, Style.Fonts.Tiny).Width; textPos = (posWidth / 2) - (width / 2) + posX - 3; posXClose = textPos; g.DrawString(partsCurr[0], Style.Fonts.Tiny, brush, new PointF(textPos, 25)); posXClose += g.MeasureString(partsCurr[0], Style.Fonts.Tiny).Width; } using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { // Draw open price (remainder) g.DrawString(partsOpen[1], Style.Fonts.Tiny, brush, new PointF(posXOpen - 2, 10)); // Draw currency name text = op.pair.QuoteCurrency == "BTC" ? op.pair.BaseCurrency : op.pair.QuoteCurrency; width = g.MeasureString(text, Style.Fonts.Tiny).Width; textPos = (posWidth / 4) - (width / 2) - 4; g.DrawString(text, Style.Fonts.Tiny, brush, new PointF(posX + textPos, 40)); } using (Brush brush = new SolidBrush(Style.Colors.Terciary.Main)) { // Draw current price (remainder) g.DrawString(partsCurr[1], Style.Fonts.Tiny, brush, new PointF(posXClose - 2, 25)); } // Draw percent change Color percentColor = Helper.LerpColor((float)op.percentGain, -5f, 5, Style.Colors.Negative, Style.Colors.Positive); using (Brush brush = new SolidBrush(percentColor)) { text = (op.percentGain > 0 ? "+" : "") + op.percentGain.ToString("F3") + "%"; width = g.MeasureString(text, Style.Fonts.Tiny).Width; textPos = (posWidth * 0.67f) - (width / 2) - 3; g.DrawString(text, Style.Fonts.Tiny, brush, new PointF(posX + textPos, 40)); } using (Pen pen = new Pen(Style.Colors.Terciary.Dark2)) { g.DrawRectangle(pen, posX, positionBoxMargin, posWidth, topDivider - (2 * positionBoxMargin)); } DrawGraphPosition(g, op.buyTimestamp, posX + (posWidth / 2), Style.Colors.Terciary.Dark2, true); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(Style.Colors.Background); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; try { if (balances != null) { double btcValue = 0; for (int i = 0; i < balances.Length; i++) { if (balances[i].Key == "BTC") { btcValue += balances[i].Value.QuoteAvailable; } else { btcValue += balances[i].Value.BitcoinValue; } } // title + BTC value string text = "Wallet:" + btcValue.ToString("F8") + "BTC"; float width = g.MeasureString(text, Style.Fonts.Title).Width; float posX = (Width / 2) - ((width + 7) / 2); text = "Wallet:"; width = g.MeasureString(text, Style.Fonts.Title).Width; string[] btcValueSplit = Helper.SplitLeadingZeros(btcValue.ToString("F8")); float posY = 10; using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { g.DrawString(text, Style.Fonts.Title, brush, posX, posY); } using (Brush brushDark = new SolidBrush(Style.Colors.Terciary.Dark2)) { using (Brush brushNormal = new SolidBrush(Style.Colors.Terciary.Main)) { g.DrawString(btcValueSplit[0], Style.Fonts.Medium, brushDark, posX + width, posY); width += g.MeasureString(btcValueSplit[0], Style.Fonts.Medium).Width; g.DrawString(btcValueSplit[1], Style.Fonts.Medium, brushNormal, posX + width - 3, posY); } } width += g.MeasureString(btcValueSplit[1], Style.Fonts.Medium).Width; text = "BTC"; using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { g.DrawString(text, Style.Fonts.Title, brush, posX + width, posY); } posY = 35; // USD worth double usdWorth = btcValue * Trading.Strategies.BaseTrendMonitor.LastUSDTBTCPrice; string usdWorthText = usdWorth > 0 ? usdWorth.ToString("F2") : "???"; text = "$ " + usdWorthText; width = g.MeasureString(text, Style.Fonts.Title).Width; posX = (Width / 2) - ((width + 7) / 2); text = "$ "; width = g.MeasureString(text, Style.Fonts.Title).Width; using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { g.DrawString(text, Style.Fonts.Title, brush, posX, posY); } using (Brush brushDark = new SolidBrush(Style.Colors.Terciary.Dark2)) { g.DrawString(usdWorthText, Style.Fonts.Medium, brushDark, posX + width, posY); } posY = 70; // available funds text = "Available"; width = g.MeasureString(text, Style.Fonts.Small).Width; using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { g.DrawString(text, Style.Fonts.Small, brush, (Width / 2) - (width / 2), posY); } using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { using (Brush brushDark = new SolidBrush(Style.Colors.Primary.Dark2)) { using (Pen pen = new Pen(Style.Colors.Primary.Dark1)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; int cnt = 0; for (int i = 0; i < balances.Length; i++) { if (balances[i].Value.BitcoinValue < 0.00000001) { continue; } posY = 95 + (cnt * 25); cnt++; // quote name g.DrawString(balances[i].Key, Style.Fonts.Reduced, brush, 7, posY); // quote amount int digitCnt = GetDecimalCount((int)balances[i].Value.QuoteAvailable); string[] parts = Helper.SplitLeadingZeros(balances[i].Value.QuoteAvailable.ToString("F" + digitCnt)); width = g.MeasureString(parts[0], Style.Fonts.Reduced).Width; int partSpacing = parts[0] == "" ? 0 : -4; g.DrawString(parts[0], Style.Fonts.Reduced, brushDark, Width - 240, posY); g.DrawString(parts[1], Style.Fonts.Reduced, brush, Width - 240 + width + partSpacing, posY); // btc value btcValue = 0; if (balances[i].Key == "BTC") { btcValue = balances[i].Value.QuoteAvailable; } else { btcValue = balances[i].Value.BitcoinValue; } digitCnt = GetDecimalCount((int)btcValue); parts = Helper.SplitLeadingZeros(btcValue.ToString("F" + digitCnt)); width = g.MeasureString(parts[0], Style.Fonts.Reduced).Width; partSpacing = parts[0] == "" ? 0 : -4; g.DrawString(parts[0], Style.Fonts.Reduced, brushDark, Width - 125, posY); g.DrawString(parts[1], Style.Fonts.Reduced, brush, Width - 125 + width + partSpacing, posY); width += g.MeasureString(parts[1], Style.Fonts.Reduced).Width; g.DrawString("BTC", Style.Fonts.Reduced, brushDark, Width - 125 + width - 2, posY); if (i + 1 < balances.Length) { g.DrawLine(pen, 10, posY + 20, Width - 10, posY + 20); } } } } } } else { DrawNoData(g); } // Draw borders DrawBorders(g); } catch (Exception ex) { Console.WriteLine(ex.Message + " - " + ex.StackTrace); } }