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 (Key.Text.IsEmpty()) { MessageBox.Show(this, LocalizedStrings.Str3689); return; } else if (Secret.Password.IsEmpty()) { MessageBox.Show(this, LocalizedStrings.Str3690); return; } if (Trader == null) { // create connector Trader = new BiboxTrader(); // { 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.NewMyTrade += _myTradesWindow.TradeGrid.Trades.Add; Trader.NewTrade += _tradesWindow.TradeGrid.Trades.Add; Trader.NewOrder += _ordersWindow.OrderGrid.Orders.Add; Trader.NewPortfolio += _portfoliosWindow.PortfolioGrid.Portfolios.Add; Trader.NewPosition += _portfoliosWindow.PortfolioGrid.Positions.Add; // subscribe on error of order registration event Trader.OrderRegisterFailed += _ordersWindow.OrderGrid.AddRegistrationFail; // subscribe on error of order cancelling event Trader.OrderCancelFailed += OrderFailed; Trader.MassOrderCancelFailed += (transId, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str716)); // set market data provider _securitiesWindow.SecurityPicker.MarketDataProvider = Trader; ShowSecurities.IsEnabled = ShowTrades.IsEnabled = ShowMyTrades.IsEnabled = ShowOrders.IsEnabled = ShowPortfolios.IsEnabled = true; } Trader.Key = Key.Text; Trader.Secret = Secret.Password; // clear password box for security reason //Secret.Clear(); Trader.Connect(); } else { Trader.Disconnect(); } }