public ChartWindow(CandleSeries candleSeries, DateTimeOffset?from = null, DateTimeOffset?to = null) { InitializeComponent(); _candleSeries = candleSeries ?? throw new ArgumentNullException(nameof(candleSeries)); _trader = MainWindow.Instance.Trader; Chart.ChartTheme = ChartThemes.ExpressionDark; var area = new ChartArea(); Chart.Areas.Add(area); _candleElem = new ChartCandleElement { AntiAliasing = false, UpFillColor = Colors.White, UpBorderColor = Colors.Black, DownFillColor = Colors.Black, DownBorderColor = Colors.Black, }; area.Elements.Add(_candleElem); _trader.CandleSeriesProcessing += ProcessNewCandle; _trader.SubscribeCandles(_candleSeries, from, to); Title = candleSeries.ToString(); }
private void ConnectClick(object sender, RoutedEventArgs e) { if (!_isConnected) { if (Trader == null) { // create connector Trader = new CoinCapTrader(); // { LogLevel = LogLevels.Debug }; _logManager.Sources.Add(Trader); Trader.Restored += () => this.GuiAsync(() => { // update gui labels ChangeConnectStatus(true); MessageBox.Show(this, LocalizedStrings.Str2958); }); // subscribe on connection successfully event Trader.Connected += () => { // set flag (connection is established) _isConnected = true; // update gui labels this.GuiAsync(() => ChangeConnectStatus(true)); }; Trader.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false)); // subscribe on connection error event Trader.ConnectionError += error => this.GuiAsync(() => { // update gui labels ChangeConnectStatus(false); MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959); }); // subscribe on error event Trader.Error += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955)); // subscribe on error of market data subscription event Trader.MarketDataSubscriptionFailed += (security, msg, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(msg.DataType, security))); Trader.NewSecurity += _securitiesWindow.SecurityPicker.Securities.Add; Trader.NewTrade += _tradesWindow.TradeGrid.Trades.Add; // set market data provider _securitiesWindow.SecurityPicker.MarketDataProvider = Trader; ShowSecurities.IsEnabled = ShowTrades.IsEnabled = true; } Trader.Connect(); } else { Trader.Disconnect(); } }