private void btnGetInfo_Click(object sender, RoutedEventArgs e) { Info.CryptoCompare.Api api = new Info.CryptoCompare.Api(); api.Refresh(); int count = api.CoinList.Count(); Info.CryptoCompare.CoinFullInfoData dat = api.GetFullInfo(1182); int i = 0; }
private void GetData(Info.CryptoCompare.HistoType type) { string exchange = "Cryptopia"; canvas.Children.Clear(); MarketPair mp = GetMarketPair(); List <Info.CryptoCompare.HistoMinuteData> dat; string histoLimit = txtlimit.Text; string cacheKey = exchange + "-" + type.ToString() + "-" + histoLimit + ":" + mp.MarketCurrency + "-" + mp.BaseCurrency; if (cache.ContainsKey(cacheKey)) { dat = cache[cacheKey]; } else { Info.CryptoCompare.Api api = new Info.CryptoCompare.Api(); dat = api.GetHistoData(mp.MarketCurrency, mp.BaseCurrency, exchange, type, histoLimit); cache.Add(cacheKey, dat); } List <OhlcvData> data = new List <OhlcvData>(); double s = 100000000; foreach (Info.CryptoCompare.HistoMinuteData d in dat) { DateTime time = Info.CryptoCompare.Dates.FromUnixTime(d.Time); data.Add(new OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time)); } Rectangle rect = new Rectangle(); rect.Stroke = new SolidColorBrush(Colors.Gray); rect.StrokeThickness = 2; rect.Fill = new SolidColorBrush(Colors.Black); rect.Width = canvas.Width; rect.Height = canvas.Height; Canvas.SetLeft(rect, 0); Canvas.SetTop(rect, 0); canvas.Children.Add(rect); Bounds bounds = GetBounds(data); int height = Convert.ToInt32(Math.Ceiling(RoundUp(bounds.High) - RoundDown(bounds.Low))); if (height == 0) { height = 1; } double scale = canvas.Height / height; double linespace = Math.Floor((double)height / 10); if (linespace == 0) { linespace = 1; } for (double i = bounds.High; i >= bounds.Low; i -= linespace) { double top = (bounds.High - i) / height * canvas.Height; Rectangle l = new Rectangle(); l.Stroke = new SolidColorBrush(Colors.Gray); l.StrokeThickness = 1; l.Fill = new SolidColorBrush(Colors.Gray); l.Width = canvas.Width; l.Height = 1; Canvas.SetLeft(l, 0); Canvas.SetTop(l, top); canvas.Children.Add(l); Label label = new Label(); label.Content = (i / s).ToString("F8"); label.Foreground = new SolidColorBrush(Colors.Gray); Canvas.SetLeft(label, canvas.Width - 75); Canvas.SetTop(label, (bounds.High - i - linespace) / height * canvas.Height); canvas.Children.Add(label); } int left = 0; int space = 5; int candlewidth = 5; int wickwidth = 1; foreach (OhlcvData d in data) { left = left + space + candlewidth; Rectangle r = new Rectangle(); Rectangle wick = new Rectangle(); r.StrokeThickness = 1; wick.StrokeThickness = 1; double top; if (d.Close != d.Open) { if (d.Close > d.Open) { r.Stroke = new SolidColorBrush(Colors.Green); r.Fill = new SolidColorBrush(Colors.Green); wick.Stroke = new SolidColorBrush(Colors.Green); wick.Fill = new SolidColorBrush(Colors.Green); top = top = (bounds.High - d.Close) / height * canvas.Height; Canvas.SetTop(r, top); } else { r.Stroke = new SolidColorBrush(Colors.Red); r.Fill = new SolidColorBrush(Colors.Red); wick.Stroke = new SolidColorBrush(Colors.Red); wick.Fill = new SolidColorBrush(Colors.Red); top = (bounds.High - d.Open) / height * canvas.Height; Canvas.SetTop(r, top); } r.Width = candlewidth; r.Height = scale * Math.Abs(d.Open - d.Close); } else { r.Stroke = new SolidColorBrush(Colors.CornflowerBlue); r.Fill = new SolidColorBrush(Colors.CornflowerBlue); wick.Stroke = new SolidColorBrush(Colors.CornflowerBlue); wick.Fill = new SolidColorBrush(Colors.CornflowerBlue); if (height != 0 && bounds.High - d.Close != 0) { top = (bounds.High - d.Close) / height * canvas.Height; } else { top = canvas.Height / 2; } Canvas.SetTop(r, top); if (height != 0 && bounds.High - d.High != 0) { top = (bounds.High - d.High) / height * canvas.Height; } else { top = canvas.Height / 2; } Canvas.SetTop(wick, top); r.Width = candlewidth; r.Height = 1; } wick.Width = wickwidth; if (d.High != d.Low) { wick.Height = scale * Math.Abs(d.High - d.Low); } else { wick.Height = 1; } if (height != 0) { top = (bounds.High - d.High) / height * canvas.Height; } else { top = canvas.Height / 2; } Canvas.SetTop(wick, top); Canvas.SetLeft(r, left); Canvas.SetLeft(wick, left + 2); canvas.Children.Add(r); canvas.Children.Add(wick); } }
private void GetData(Info.CryptoCompare.HistoType type) { string exchange = txtExchange.Text; candlechart.Children.Clear(); MarketPair mp = GetMarketPair(); List <Info.CryptoCompare.HistoMinuteData> dat; string histoLimit = txtlimit.Text; int period = Convert.ToInt32(txtPeriod.Text); string cacheKey = exchange + "-" + type.ToString() + "-" + histoLimit + ":" + mp.MarketCurrency + "-" + mp.BaseCurrency; if (cache.ContainsKey(cacheKey)) { dat = cache[cacheKey]; } else { Info.CryptoCompare.Api api = new Info.CryptoCompare.Api(); dat = api.GetHistoData(mp.MarketCurrency, mp.BaseCurrency, exchange, type, histoLimit); cache.Add(cacheKey, dat); } int periodCounter = 0; double s = 100000000; ObservableCollection <CandleChart.OhlcvData> data = new ObservableCollection <CandleChart.OhlcvData>(); CandleChart.OhlcvData tempOhlcv = new CandleChart.OhlcvData(); foreach (Info.CryptoCompare.HistoMinuteData d in dat) { DateTime time = Info.CryptoCompare.Dates.FromUnixTime(d.Time); if (period == 1) { data.Add(new CandleChart.OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time)); } else { if (periodCounter == 0) { tempOhlcv = new CandleChart.OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time); periodCounter++; } else { if (periodCounter == period - 1) { CandleChart.OhlcvData dd = new CandleChart.OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time); if (tempOhlcv.High < dd.High) { tempOhlcv.High = dd.High; } if (tempOhlcv.Low > dd.Low) { tempOhlcv.Low = dd.Low; } tempOhlcv.Close = dd.Close; tempOhlcv.VolumeTo = dd.VolumeTo; tempOhlcv.VolumeFrom = dd.VolumeFrom; data.Add(tempOhlcv); periodCounter = 0; } else { periodCounter++; } } } } candlechart.Items = data; }
private void GetData2(Info.CryptoCompare.HistoType type) { string exchange = "Cryptopia"; canvas.Children.Clear(); MarketPair mp = GetMarketPair(); List <Info.CryptoCompare.HistoMinuteData> dat; string histoLimit = txtlimit.Text; int period = Convert.ToInt32(txtPeriod.Text); string cacheKey = exchange + "-" + type.ToString() + "-" + histoLimit + ":" + mp.MarketCurrency + "-" + mp.BaseCurrency; if (cache.ContainsKey(cacheKey)) { dat = cache[cacheKey]; } else { Info.CryptoCompare.Api api = new Info.CryptoCompare.Api(); dat = api.GetHistoData(mp.MarketCurrency, mp.BaseCurrency, exchange, type, histoLimit); cache.Add(cacheKey, dat); } List <OhlcvData> data = new List <OhlcvData>(); OhlcvData tempOhlcv = new OhlcvData(); int periodCounter = 0; double s = 100000000; foreach (Info.CryptoCompare.HistoMinuteData d in dat) { DateTime time = Info.CryptoCompare.Dates.FromUnixTime(d.Time); if (period == 1) { data.Add(new OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time)); } else { if (periodCounter == 0) { tempOhlcv = new OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time); periodCounter++; } else { if (periodCounter == period - 1) { OhlcvData dd = new OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time); if (tempOhlcv.High < dd.High) { tempOhlcv.High = dd.High; } if (tempOhlcv.Low > dd.Low) { tempOhlcv.Low = dd.Low; } tempOhlcv.Close = dd.Close; tempOhlcv.VolumeTo = dd.VolumeTo; tempOhlcv.VolumeFrom = dd.VolumeFrom; data.Add(tempOhlcv); periodCounter = 0; } else { periodCounter++; } } } } Rectangle rect = new Rectangle(); rect.Stroke = new SolidColorBrush(Colors.Gray); rect.StrokeThickness = 2; rect.Fill = new SolidColorBrush(Colors.GhostWhite); rect.Width = canvas.Width; rect.Height = canvas.Height; Canvas.SetLeft(rect, 0); Canvas.SetTop(rect, 0); canvas.Children.Add(rect); Bounds bounds = GetBounds(data); int height = Convert.ToInt32(Math.Ceiling(RoundUp(bounds.High) - RoundDown(bounds.Low))); int volheight = Convert.ToInt32(Math.Ceiling(RoundUp(bounds.VolHigh) - RoundDown(bounds.VolLow))); if (volheight == 0) { volheight = 1; } if (volheight > 10) { volheight = (volheight % 10) * 1000; } if (volheight == 0) { volheight = 1000; } if (volheight == 10) { volheight = 10; } if (height == 0) { height = 1; } double horizontalMargin = 30; double scale = (canvas.Height - horizontalMargin) / height; double volscale = (canvas.Height - horizontalMargin) / volheight; double linespace = Math.Floor((double)height / 10); if (linespace == 0) { linespace = 1; } double left = 0; int space = 5; double candlewidth = Math.Floor(canvas.Width / data.Count) - 5; int wickwidth = 1; List <Label> labels = new List <Label>(); double chartHeight = canvas.Height - horizontalMargin; for (double i = bounds.High; i >= bounds.Low; i -= linespace) { double top = (bounds.High - i) / height * chartHeight; top += horizontalMargin; Rectangle l = new Rectangle(); l.Stroke = new SolidColorBrush(Color.FromArgb(200, 128, 128, 128)); l.StrokeThickness = 1; l.Fill = new SolidColorBrush(Color.FromArgb(200, 128, 128, 128)); l.Width = canvas.Width; l.Height = 1; Canvas.SetLeft(l, 0); Canvas.SetTop(l, top); canvas.Children.Add(l); Label label = new Label(); label.Content = (i / s).ToString("F8"); label.Foreground = new SolidColorBrush(Colors.Gray); Canvas.SetLeft(label, canvas.Width - 75); Canvas.SetTop(label, top - 10 - 10); //Canvas.SetTop(label, (bounds.High - i + horizontalMargin - linespace + (linespace * 0.3)) / height * chartHeight); labels.Add(label); } foreach (OhlcvData d in data) { left = left + space + candlewidth; Rectangle r = new Rectangle(); Rectangle wick = new Rectangle(); r.StrokeThickness = 1; wick.StrokeThickness = 1; double top; //volume stuff... Rectangle vol = new Rectangle(); vol.StrokeThickness = 1; vol.Stroke = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128)); vol.Fill = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128)); vol.Width = candlewidth; double scaledVolume = GetScaledVolume(d.VolumeTo); vol.Height = volscale * scaledVolume; Canvas.SetLeft(vol, left); Canvas.SetTop(vol, canvas.Height - (volscale * scaledVolume)); canvas.Children.Add(vol); //candles and wicks if (d.Close != d.Open) { if (d.Close > d.Open) { r.Stroke = new SolidColorBrush(Colors.Green); r.Fill = new SolidColorBrush(Colors.Green); wick.Stroke = new SolidColorBrush(Colors.Green); wick.Fill = new SolidColorBrush(Colors.Green); top = (bounds.High - d.Close) / height * chartHeight; top += horizontalMargin; Canvas.SetTop(r, top); } else { r.Stroke = new SolidColorBrush(Colors.Red); r.Fill = new SolidColorBrush(Colors.Red); wick.Stroke = new SolidColorBrush(Colors.Red); wick.Fill = new SolidColorBrush(Colors.Red); top = (bounds.High - d.Open) / height * chartHeight; top += horizontalMargin; Canvas.SetTop(r, top); } r.Width = candlewidth; r.Height = scale * Math.Abs(d.Open - d.Close); } else { r.Stroke = new SolidColorBrush(Colors.CornflowerBlue); r.Fill = new SolidColorBrush(Colors.CornflowerBlue); wick.Stroke = new SolidColorBrush(Colors.CornflowerBlue); wick.Fill = new SolidColorBrush(Colors.CornflowerBlue); if (height != 0 && bounds.High - d.Close != 0) { top = (bounds.High - d.Close) / height * chartHeight; top += horizontalMargin; } else { top = canvas.Height / 2; } Canvas.SetTop(r, top); if (height != 0 && bounds.High - d.High != 0) { top = (bounds.High - d.High) / height * chartHeight; top += horizontalMargin; } else { top = canvas.Height / 2; } Canvas.SetTop(wick, top); r.Width = candlewidth; r.Height = 1; } wick.Width = wickwidth; if (d.High != d.Low) { wick.Height = scale * Math.Abs(d.High - d.Low); } else { wick.Height = 1; } if (height != 0) { top = (bounds.High - d.High) / height * chartHeight; top += horizontalMargin; } else { top = canvas.Height / 2; } Canvas.SetTop(wick, top); Canvas.SetLeft(r, left); Canvas.SetLeft(wick, left + (candlewidth / 2)); canvas.Children.Add(r); canvas.Children.Add(wick); } foreach (Label l in labels) { canvas.Children.Add(l); } }