using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Ecng.Common; using Ecng.Xaml; using StockSharp.Algo.Candles; using StockSharp.Quik; using StockSharp.TraderConnection; using StockSharp.Transaq; using StockSharp.Xaml.Charting; namespace CandlesChartProject { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { private CandleManager _candleManager; private CandleSeries _candleSeries; private ChartArea _chartArea; private ChartCandleElement _chartCandleElement; public MainWindow() { InitializeComponent(); interFace.SafeConnection = //new SafeConnection(new QuikTrader(QuikTerminal.GetDefaultPath())); new SafeConnection(new TransaqTrader { Login = "*********", Password = "********", Address = "213.247.141.133:3900".To(), }); } private void GetCandlesClick(object sender, RoutedEventArgs e) { RunProcessGetCandles(); } private void RunProcessGetCandles() { _candleManager = new CandleManager(interFace.SafeConnection.Trader); var security = interFace.SelectedSecurity; var timeFrame = TimeSpan.FromMinutes(5); _candleSeries = new CandleSeries(typeof (TimeFrameCandle), security, timeFrame); _candleSeries.ProcessCandle += Draw; _candleManager.Start(_candleSeries); } private void Draw(Candle candle) { var candleBounds = ((TimeSpan) candle.Arg).GetCandleBounds(_candleSeries.Security); if (candle.State == CandleStates.Finished || candle.OpenTime >= candleBounds.Min) { this.GuiAsync(() => Chart.ProcessCandle(_chartCandleElement, candle)); } } private void InitChart() { Chart.IsAutoScroll = true; _chartArea = new ChartArea(); Chart.Areas.Add(_chartArea); _chartCandleElement = new ChartCandleElement(); _chartArea.Elements.Add(_chartCandleElement); } private void WindowLoaded(object sender, RoutedEventArgs e) { InitChart(); } } }