private void ConnectClick(object sender, RoutedEventArgs e) { if (!_isConnected) { if (Login.Text.IsEmpty()) { MessageBox.Show(this, LocalizedStrings.Str2974); return; } else if (Password.Password.IsEmpty()) { MessageBox.Show(this, LocalizedStrings.Str2975); return; } if (Trader == null) { if (Trader != null) { Trader.Dispose(); } // создаем подключение Trader = new BlackwoodTrader { //LogLevel = LogLevels.Debug, }; _logManager.Sources.Add(Trader); Trader.ReConnectionSettings.ConnectionSettings.Restored += () => this.GuiAsync(() => { // разблокируем кнопку Экспорт (соединение было восстановлено) ChangeConnectStatus(true); MessageBox.Show(this, LocalizedStrings.Str2958); }); // подписываемся на событие успешного соединения Trader.Connected += () => { // возводим флаг, что соединение установлено _isConnected = true; Trader.StartExport(); // разблокируем кнопку Экспорт this.GuiAsync(() => ChangeConnectStatus(true)); }; // подписываемся на событие запуска экспорта Trader.ExportStarted += () => { // запускаем подписку на новости Trader.RegisterNews(); Trader.SubscribeHighLow(true); Trader.SubscribeImbalance(); Trader.SubscribeCrossLock(); Trader.RequestPreMarketIndications(); }; // подписываемся на событие успешного отключения Trader.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false)); // подписываемся на событие разрыва соединения Trader.ConnectionError += error => this.GuiAsync(() => { // заблокируем кнопку Экспорт (так как соединение было потеряно) ChangeConnectStatus(false); MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959); }); // подписываемся на ошибку обработки данных (транзакций и маркет) Trader.ProcessDataError += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955)); // подписываемся на ошибку подписки маркет-данных Trader.MarketDataSubscriptionFailed += (security, type, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(type, security))); Trader.NewSecurities += securities => _securitiesWindow.SecurityPicker.Securities.AddRange(securities); Trader.NewMyTrades += trades => _myTradesWindow.TradeGrid.Trades.AddRange(trades); Trader.NewTrades += trades => _tradesWindow.TradeGrid.Trades.AddRange(trades); Trader.NewOrders += orders => _ordersWindow.OrderGrid.Orders.AddRange(orders); Trader.NewStopOrders += orders => _stopOrdersWindow.OrderGrid.Orders.AddRange(orders); Trader.NewPortfolios += portfolios => { // регистрирует портфели на обновление данных portfolios.ForEach(Trader.RegisterPortfolio); _portfoliosWindow.PortfolioGrid.Portfolios.AddRange(portfolios); }; Trader.NewPositions += positions => _portfoliosWindow.PortfolioGrid.Positions.AddRange(positions); // подписываемся на событие о неудачной регистрации заявок Trader.OrdersRegisterFailed += OrdersFailed; // подписываемся на событие о неудачном снятии заявок Trader.OrdersCancelFailed += OrdersFailed; // подписываемся на событие о неудачной регистрации стоп-заявок Trader.StopOrdersRegisterFailed += OrdersFailed; // подписываемся на событие о неудачном снятии стоп-заявок Trader.StopOrdersCancelFailed += OrdersFailed; Trader.NewNews += news => _newsWindow.NewsPanel.NewsGrid.News.Add(news); // устанавливаем поставщик маркет-данных _securitiesWindow.SecurityPicker.MarketDataProvider = Trader; ShowSecurities.IsEnabled = ShowTrades.IsEnabled = ShowNews.IsEnabled = ShowMyTrades.IsEnabled = ShowOrders.IsEnabled = ShowPortfolios.IsEnabled = ShowStopOrders.IsEnabled = true; } var address = Address.Text.To <IPAddress>(); Trader.Login = Login.Text; Trader.Password = Password.Password; Trader.ExecutionAddress = new IPEndPoint(address, BlackwoodAddresses.ExecutionPort); Trader.MarketDataAddress = new IPEndPoint(address, BlackwoodAddresses.MarketDataPort); Trader.HistoricalDataAddress = new IPEndPoint(address, BlackwoodAddresses.HistoricalDataPort); // очищаем из текстового поля в целях безопасности //Password.Clear(); Trader.Connect(); } else { Trader.SubscribeHighLow(false); Trader.UnRegisterNews(); Trader.StopExport(); Trader.Disconnect(); } }
private void ConnectClick(object sender, RoutedEventArgs e) { if (!_isConnected) { if (Login.Text.IsEmpty()) { MessageBox.Show(this, LocalizedStrings.Str2974); return; } else if (Password.Password.IsEmpty()) { MessageBox.Show(this, LocalizedStrings.Str2975); return; } if (Trader == null) { if (Trader != null) { Trader.Dispose(); } // create connector Trader = new BlackwoodTrader { //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.RegisterNews(); Trader.SubscribeHighLow(true); Trader.SubscribeImbalance(); Trader.SubscribeCrossLock(); Trader.RequestPreMarketIndications(); }; 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.NewStopOrder += _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; // subscribe on error of stop-order registration event Trader.StopOrderRegisterFailed += _ordersWindow.OrderGrid.AddRegistrationFail; // subscribe on error of stop-order cancelling event Trader.StopOrderCancelFailed += OrderFailed; Trader.MassOrderCancelFailed += (transId, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str716)); Trader.NewNews += news => _newsWindow.NewsPanel.NewsGrid.News.Add(news); // set market data provider _securitiesWindow.SecurityPicker.MarketDataProvider = Trader; // set news provider _newsWindow.NewsPanel.NewsProvider = Trader; ShowSecurities.IsEnabled = ShowTrades.IsEnabled = ShowNews.IsEnabled = ShowMyTrades.IsEnabled = ShowOrders.IsEnabled = ShowPortfolios.IsEnabled = true; } var address = Address.Text.To <IPAddress>(); Trader.Login = Login.Text; Trader.Password = Password.Password; Trader.ExecutionAddress = new IPEndPoint(address, BlackwoodAddresses.ExecutionPort); Trader.MarketDataAddress = new IPEndPoint(address, BlackwoodAddresses.MarketDataPort); Trader.HistoricalDataAddress = new IPEndPoint(address, BlackwoodAddresses.HistoricalDataPort); // clear password box for security reason //Password.Clear(); Trader.Connect(); } else { Trader.SubscribeHighLow(false); Trader.UnRegisterNews(); Trader.Disconnect(); } }
private void ConnectClick(object sender, RoutedEventArgs e) { if (!_isConnected) { if (Login.Text.IsEmpty()) { MessageBox.Show(this, LocalizedStrings.Str2974); return; } else if (Password.Password.IsEmpty()) { MessageBox.Show(this, LocalizedStrings.Str2975); return; } if (Trader == null) { if (Trader != null) Trader.Dispose(); // create connector Trader = new BlackwoodTrader { //LogLevel = LogLevels.Debug, }; _logManager.Sources.Add(Trader); Trader.Restored += () => this.GuiAsync(() => { // update gui labes ChangeConnectStatus(true); MessageBox.Show(this, LocalizedStrings.Str2958); }); // subscribe on connection successfully event Trader.Connected += () => { // set flag (connection is established) _isConnected = true; // update gui labes this.GuiAsync(() => ChangeConnectStatus(true)); // запускаем подписку на новости Trader.RegisterNews(); Trader.SubscribeHighLow(true); Trader.SubscribeImbalance(); Trader.SubscribeCrossLock(); Trader.RequestPreMarketIndications(); }; Trader.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false)); // subscribe on connection error event Trader.ConnectionError += error => this.GuiAsync(() => { // update gui labes 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, type, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(type, security))); Trader.NewSecurities += securities => _securitiesWindow.SecurityPicker.Securities.AddRange(securities); Trader.NewMyTrades += trades => _myTradesWindow.TradeGrid.Trades.AddRange(trades); Trader.NewTrades += trades => _tradesWindow.TradeGrid.Trades.AddRange(trades); Trader.NewOrders += orders => _ordersWindow.OrderGrid.Orders.AddRange(orders); Trader.NewStopOrders += orders => _stopOrdersWindow.OrderGrid.Orders.AddRange(orders); Trader.NewPortfolios += portfolios => { // subscribe on portfolio updates portfolios.ForEach(Trader.RegisterPortfolio); _portfoliosWindow.PortfolioGrid.Portfolios.AddRange(portfolios); }; Trader.NewPositions += positions => _portfoliosWindow.PortfolioGrid.Positions.AddRange(positions); // subscribe on error of order registration event Trader.OrdersRegisterFailed += OrdersFailed; // subscribe on error of order cancelling event Trader.OrdersCancelFailed += OrdersFailed; // subscribe on error of stop-order registration event Trader.StopOrdersRegisterFailed += OrdersFailed; // subscribe on error of stop-order cancelling event Trader.StopOrdersCancelFailed += OrdersFailed; Trader.NewNews += news => _newsWindow.NewsPanel.NewsGrid.News.Add(news); // set market data provider _securitiesWindow.SecurityPicker.MarketDataProvider = Trader; // set news provider _newsWindow.NewsPanel.NewsProvider = Trader; ShowSecurities.IsEnabled = ShowTrades.IsEnabled = ShowNews.IsEnabled = ShowMyTrades.IsEnabled = ShowOrders.IsEnabled = ShowPortfolios.IsEnabled = ShowStopOrders.IsEnabled = true; } var address = Address.Text.To<IPAddress>(); Trader.Login = Login.Text; Trader.Password = Password.Password; Trader.ExecutionAddress = new IPEndPoint(address, BlackwoodAddresses.ExecutionPort); Trader.MarketDataAddress = new IPEndPoint(address, BlackwoodAddresses.MarketDataPort); Trader.HistoricalDataAddress = new IPEndPoint(address, BlackwoodAddresses.HistoricalDataPort); // clear password box for security reason //Password.Clear(); Trader.Connect(); } else { Trader.SubscribeHighLow(false); Trader.UnRegisterNews(); Trader.Disconnect(); } }