Пример #1
0
		private void ConnectClick(object sender, RoutedEventArgs e)
		{
			if (!_isConnected)
			{
				if (Connector == null)
				{
					var isDde = IsDde.IsChecked == true;

					if (SmartLogin.Text.IsEmpty())
					{
						MessageBox.Show(this, LocalizedStrings.Str2965);
						return;
					}
					if (SmartPassword.Password.IsEmpty())
					{
						MessageBox.Show(this, LocalizedStrings.Str2966);
						return;
					}
					if (isDde && QuikPath.Text.IsEmpty())
					{
						MessageBox.Show(this, LocalizedStrings.Str2967);
						return;
					}

					// создаем агрегирующее подключение (+ сразу инициализируем настройки переподключения)
					Connector = InitReconnectionSettings(new Connector());

					// добавляем подключения к SmartCOM и Quik
					var quikTs = new LuaFixTransactionMessageAdapter(Connector.TransactionIdGenerator)
					{
						Login = "******",
						Password = "******".To<SecureString>(),
						Address = QuikTrader.DefaultLuaAddress,
						TargetCompId = "StockSharpTS",
						SenderCompId = "quik",
						ExchangeBoard = ExchangeBoard.Forts,
						Version = FixVersions.Fix44_Lua,
						RequestAllPortfolios = true,
						MarketData = FixMarketData.None,
						TimeZone = TimeHelper.Moscow
					};
					var quikMd = new FixMessageAdapter(Connector.TransactionIdGenerator)
					{
						Login = "******",
						Password = "******".To<SecureString>(),
						Address = QuikTrader.DefaultLuaAddress,
						TargetCompId = "StockSharpMD",
						SenderCompId = "quik",
						ExchangeBoard = ExchangeBoard.Forts,
						Version = FixVersions.Fix44_Lua,
						RequestAllSecurities = true,
						MarketData = FixMarketData.MarketData,
						TimeZone = TimeHelper.Moscow
					};
					quikMd.RemoveTransactionalSupport();

					Connector.Adapter.InnerAdapters[quikMd] = 1;
					Connector.Adapter.InnerAdapters[quikTs] = 1;

					var smartCom = new SmartComMessageAdapter(Connector.TransactionIdGenerator)
					{
						Login = SmartLogin.Text,
						Password = SmartPassword.Password.To<SecureString>(),
						Address = SmartAddress.SelectedAddress,
					};
					Connector.Adapter.InnerAdapters[smartCom] = 0;

					// очищаем из текстового поля в целях безопасности
					//SmartPassword.Clear();

					var logManager = new LogManager();
					logManager.Listeners.Add(new FileLogListener("sample.log"));
					logManager.Sources.Add(Connector);

					// подписываемся на событие успешного соединения
					Connector.Connected += () =>
					{
						// возводим флаг, что соединение установлено
						_isConnected = true;

						// разблокируем кнопку Экспорт
						this.GuiAsync(() => ChangeConnectStatus(true));
					};

					// подписываемся на событие разрыва соединения
					Connector.ConnectionError += error => this.GuiAsync(() =>
					{
						// заблокируем кнопку Экспорт (так как соединение было потеряно)
						ChangeConnectStatus(false);

						MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959);	
					});

					// подписываемся на ошибку обработки данных (транзакций и маркет)
					Connector.Error += error =>
						this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955));

					// подписываемся на ошибку подписки маркет-данных
					Connector.MarketDataSubscriptionFailed += (security, type, error) =>
						this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(type, security)));

					Connector.NewSecurities += securities => _securitiesWindow.SecurityPicker.Securities.AddRange(securities);
					Connector.NewOrders += orders => _ordersWindow.OrderGrid.Orders.AddRange(orders);

					// подписываемся на событие о неудачной регистрации заявок
					Connector.OrdersRegisterFailed += OrdersFailed;
					// подписываемся на событие о неудачном снятии заявок
					Connector.OrdersCancelFailed += OrdersFailed;

					// подписываемся на событие о неудачной регистрации стоп-заявок
					Connector.StopOrdersRegisterFailed += OrdersFailed;
					// подписываемся на событие о неудачном снятии стоп-заявок
					Connector.StopOrdersCancelFailed += OrdersFailed;

					// устанавливаем поставщик маркет-данных
					_securitiesWindow.SecurityPicker.MarketDataProvider = Connector;

					ShowSecurities.IsEnabled = ShowOrders.IsEnabled = true;
				}

				Connector.Connect();
			}
			else
			{
				Connector.Disconnect();
			}
		}
Пример #2
0
        /// <summary>
        /// Создать <see cref="SmartTrader"/>.
        /// </summary>
        public SmartTrader()
        {
            _adapter = new SmartComMessageAdapter(TransactionIdGenerator);

            Adapter.InnerAdapters.Add(_adapter.ToChannel(this));
        }
Пример #3
0
		/// <summary>
		/// Создать <see cref="SmartTrader"/>.
		/// </summary>
		public SmartTrader()
		{
			_adapter = new SmartComMessageAdapter(TransactionIdGenerator);

			Adapter.InnerAdapters.Add(_adapter.ToChannel(this));
		}
Пример #4
0
		private void QuikConnectionMouseDoubleClick(object sender, RoutedEventArgs e)
		{
			if (_connector == null)
			{
				_connector = new Connector();

				if (QuikCheckBox.IsChecked == true)
				{
					var quikTs = new LuaFixTransactionMessageAdapter(_connector.TransactionIdGenerator)
					{
						Login = "******",
						Password = "******".To<SecureString>(),
						Address = QuikTrader.DefaultLuaAddress,
						TargetCompId = "StockSharpTS",
						SenderCompId = "quik",
						ExchangeBoard = ExchangeBoard.Forts,
						Version = FixVersions.Fix44_Lua,
						RequestAllPortfolios = true,
						MarketData = FixMarketData.None,
						TimeZone = TimeHelper.Moscow
					};
					var quikMd = new FixMessageAdapter(_connector.TransactionIdGenerator)
					{
						Login = "******",
						Password = "******".To<SecureString>(),
						Address = QuikTrader.DefaultLuaAddress,
						TargetCompId = "StockSharpMD",
						SenderCompId = "quik",
						ExchangeBoard = ExchangeBoard.Forts,
						Version = FixVersions.Fix44_Lua,
						RequestAllSecurities = true,
						MarketData = FixMarketData.MarketData,
						TimeZone = TimeHelper.Moscow
					};
					quikMd.RemoveTransactionalSupport();

					_connector.Adapter.InnerAdapters[quikMd.ToChannel(_connector, "Quik MD")] = 1;
					_connector.Adapter.InnerAdapters[quikTs.ToChannel(_connector, "Quik TS")] = 1;
				}

				if (SmartComCheckBox.IsChecked == true)
				{
					var smartCom = new SmartComMessageAdapter(_connector.TransactionIdGenerator)
					{
						Login = Login.Text,
						Password = Password.Password.To<SecureString>(),
						Address = Address.SelectedAddress,
					};
					_connector.Adapter.InnerAdapters[smartCom.ToChannel(_connector, "SmartCOM")] = 0;
				}

				if (PlazaCheckBox.IsChecked == true)
				{
					var pool = new PlazaConnectionPool();

					_connector.Adapter.InnerAdapters[new PlazaTransactionMessageAdapter(_connector.TransactionIdGenerator, pool)
					{
						ConnectionPoolSettings =
						{
							IsCGate = true,
						}
					}.ToChannel(_connector, "Plaza TS")] = 0;
					_connector.Adapter.InnerAdapters[new PlazaStreamMessageAdapter(_connector.TransactionIdGenerator, pool)
					{
						ConnectionPoolSettings =
						{
							IsCGate = true,
						}
					}.ToChannel(_connector, "Plaza MD")] = 0;
				}

				if (_connector.Adapter.InnerAdapters.Count == 0)
				{
					MessageBox.Show(this, LocalizedStrings.Str2971);
					return;
				}

				_securityProvider = new FilterableSecurityProvider(_connector);

				_connector.ConnectionError += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959));
				_connector.Connect();
			}
			else
			{
				Disconnect();
			}
		}