Exemplo n.º 1
0
        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)
                {
                    // create connector
                    Trader = new ITCHTrader();

                    ConfigManager.RegisterService(new FilterableSecurityProvider(Trader));

                    // update gui labes
                    Trader.ReConnectionSettings.WorkingTime = ExchangeBoard.Forts.WorkingTime;
                    Trader.Restored += () => this.GuiAsync(() =>
                    {
                        // разблокируем кнопку Экспорт (соединение было восстановлено)
                        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.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.NewTrades        += trades => _tradesWindow.TradeGrid.Trades.AddRange(trades);
                    Trader.NewOrderLogItems += items => _orderLogWindow.OrderLogGrid.LogItems.AddRange(items);

                    // set market data provider
                    _securitiesWindow.SecurityPicker.MarketDataProvider = Trader;

                    ShowSecurities.IsEnabled = ShowTrades.IsEnabled = ShowOrdersLog.IsEnabled = true;
                }

                Trader.Login            = Login.Text;
                Trader.Password         = Password.Password;
                Trader.PrimaryAddress   = Primary.EndPoint;
                Trader.DuplicateAddress = Duplicate.EndPoint;
                Trader.RecoveryAddress  = Recovery.EndPoint;

                // clear password box for security reason
                //Password.Clear();

                Trader.Connect();
            }
            else
            {
                Trader.Disconnect();
            }
        }
Exemplo n.º 2
0
		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)
				{
					// create connector
					Trader = new ITCHTrader();

					ConfigManager.RegisterService(new FilterableSecurityProvider(Trader));

					// update gui labes
					Trader.ReConnectionSettings.WorkingTime = ExchangeBoard.Forts.WorkingTime;
					Trader.Restored += () => this.GuiAsync(() =>
					{
						// разблокируем кнопку Экспорт (соединение было восстановлено)
						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.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.NewTrades += trades => _tradesWindow.TradeGrid.Trades.AddRange(trades);
					Trader.NewOrderLogItems += items => _orderLogWindow.OrderLogGrid.LogItems.AddRange(items);

					// set market data provider
					_securitiesWindow.SecurityPicker.MarketDataProvider = Trader;

					ShowSecurities.IsEnabled = ShowTrades.IsEnabled = ShowOrdersLog.IsEnabled = true;
				}

				Trader.Login = Login.Text;
				Trader.Password = Password.Password;
				Trader.PrimaryAddress = Primary.EndPoint;
				Trader.DuplicateAddress = Duplicate.EndPoint;
				Trader.RecoveryAddress = Recovery.EndPoint;

				// clear password box for security reason
				//Password.Clear();

				Trader.Connect();
			}
			else
			{
				Trader.Disconnect();
			}
		}