예제 #1
0
        public StrategyConnector()
        {
            EntityFactory = _entityFactory = new StrategyEntityFactory();

            SessionHolder = BasketSessionHolder = new BasketSessionHolder(TransactionIdGenerator);

            TransactionAdapter = new BasketMessageAdapter(MessageAdapterTypes.Transaction, BasketSessionHolder);
            MarketDataAdapter  = new BasketMessageAdapter(MessageAdapterTypes.MarketData, BasketSessionHolder);

            ApplyMessageProcessor(MessageDirections.In, true, true);
            ApplyMessageProcessor(MessageDirections.Out, true, true);
        }
예제 #2
0
        public StudioConnector()
        {
            EntityFactory = new StudioEntityFactory(this);

            SessionHolder = _sessionHolder = new BasketSessionHolder(TransactionIdGenerator);

            MarketDataAdapter  = _marketDataAdapter = new StudioMarketDataAdapter(_sessionHolder);
            TransactionAdapter = _transactionAdapter = new BasketMessageAdapter(MessageAdapterTypes.Transaction, _sessionHolder);

            ApplyMessageProcessor(MessageDirections.In, true, false);
            ApplyMessageProcessor(MessageDirections.In, false, true);
            ApplyMessageProcessor(MessageDirections.Out, true, true);

            _transactionAdapter.NewOutMessage += TransactionAdapterNewOutMessage;

            CreateEmulationSessionHolder();

            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            cmdSvc.Register <LookupSecuritiesCommand>(this, false, cmd => LookupSecurities(cmd.Criteria));
            cmdSvc.Register <RequestTradesCommand>(this, false, cmd => new NewTradesCommand(Trades).Process(this));
            //cmdSvc.Register<RequestPortfoliosCommand>(this, cmd => Portfolios.ForEach(pf => new PortfolioCommand(pf, true).Process(this)));
            cmdSvc.Register <RequestPositionsCommand>(this, false, cmd => Positions.ForEach(pos => new PositionCommand(CurrentTime, pos, true).Process(this)));
            cmdSvc.Register <RequestMarketDataCommand>(this, false, cmd => AddExport(cmd.Security, cmd.Type));
            cmdSvc.Register <RefuseMarketDataCommand>(this, false, cmd => RemoveExport(cmd.Security, cmd.Type));

            //NewPortfolios += portfolios => portfolios.ForEach(pf => new PortfolioCommand(pf, true).Process(this));
            PortfoliosChanged      += portfolios => portfolios.ForEach(pf => new PortfolioCommand(pf, false).Process(this));
            NewPositions           += positions => positions.ForEach(pos => new PositionCommand(CurrentTime, pos, true).Process(this));
            PositionsChanged       += positions => positions.ForEach(pos => new PositionCommand(CurrentTime, pos, false).Process(this));
            NewTrades              += trades => new NewTradesCommand(trades).Process(this);
            NewNews                += news => new NewNewsCommand(news).Process(this);
            LookupSecuritiesResult += securities => new LookupSecuritiesResultCommand(securities).Process(this);
            //LookupPortfoliosResult += portfolios => new LookupPortfoliosResultCommand(portfolios).Process(this);

            UpdateSecurityLastQuotes = false;
            UpdateSecurityByLevel1   = false;
        }
예제 #3
0
        private void QuikConnectionMouseDoubleClick(object sender, RoutedEventArgs e)
        {
            if (_connector == null)
            {
                _connector            = new Connector();
                _connector.Connected += _connector.StartExport;

                var session = new BasketSessionHolder(_connector.TransactionIdGenerator);

                _connector.MarketDataAdapter  = new BasketMessageAdapter(MessageAdapterTypes.MarketData, session);
                _connector.TransactionAdapter = new BasketMessageAdapter(MessageAdapterTypes.Transaction, session);

                _connector.ApplyMessageProcessor(MessageDirections.In, true, false);
                _connector.ApplyMessageProcessor(MessageDirections.In, false, true);
                _connector.ApplyMessageProcessor(MessageDirections.Out, true, true);

                if (QuikCheckBox.IsChecked == true)
                {
                    session.InnerSessions.Add(new QuikSessionHolder(_connector.TransactionIdGenerator)
                    {
                        IsTransactionEnabled = true,
                        IsMarketDataEnabled  = true,
                    }, 1);
                }

                if (SmartComCheckBox.IsChecked == true)
                {
                    session.InnerSessions.Add(new SmartComSessionHolder(_connector.TransactionIdGenerator)
                    {
                        Login                = Login.Text,
                        Password             = Password.Password.To <SecureString>(),
                        Address              = Address.SelectedAddress,
                        IsTransactionEnabled = true,
                        IsMarketDataEnabled  = true,
                    }, 0);
                }

                if (PlazaCheckBox.IsChecked == true)
                {
                    session.InnerSessions.Add(new PlazaSessionHolder(_connector.TransactionIdGenerator)
                    {
                        IsCGate = true,
                        IsTransactionEnabled = true,
                        IsMarketDataEnabled  = true,
                    }, 0);
                }

                if (session.InnerSessions.Count == 0)
                {
                    MessageBox.Show(LocalizedStrings.Str2971);
                    return;
                }

                _securityProvider = new FilterableSecurityProvider(_connector);

                _connector.ConnectionError += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959));
                _connector.Connect();
            }
            else
            {
                Disconnect();
            }
        }
예제 #4
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());

                    var session = new BasketSessionHolder(Connector.TransactionIdGenerator);

                    Connector.MarketDataAdapter  = new BasketMessageAdapter(MessageAdapterTypes.MarketData, session);
                    Connector.TransactionAdapter = new BasketMessageAdapter(MessageAdapterTypes.Transaction, session);

                    Connector.ApplyMessageProcessor(MessageDirections.In, true, false);
                    Connector.ApplyMessageProcessor(MessageDirections.In, false, true);
                    Connector.ApplyMessageProcessor(MessageDirections.Out, true, true);

                    // добавляем подключения к SmartCOM и Quik
                    session.InnerSessions.Add(new QuikSessionHolder(Connector.TransactionIdGenerator)
                    {
                        IsDde = isDde,
                        Path  = QuikPath.Text,
                        IsTransactionEnabled = true,
                        IsMarketDataEnabled  = true,
                    }, 1);
                    //session.InnerSessions.Add(new PlazaSessionHolder(Connector.TransactionIdGenerator)
                    //{
                    //	IsCGate = true,
                    //	IsTransactionEnabled = true,
                    //	IsMarketDataEnabled = true,
                    //}, 0);
                    session.InnerSessions.Add(new SmartComSessionHolder(Connector.TransactionIdGenerator)
                    {
                        Login                = SmartLogin.Text,
                        Password             = SmartPassword.Password.To <SecureString>(),
                        Address              = SmartAddress.SelectedAddress,
                        IsTransactionEnabled = true,
                        IsMarketDataEnabled  = true,
                    }, 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.ProcessDataError += 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();
            }
        }
예제 #5
0
 public BasketEmulationAdapter(BasketSessionHolder sessionHolder, EmulationSettings settings)
     : base(MessageAdapterTypes.Transaction, sessionHolder)
 {
     _settings = settings;
 }
예제 #6
0
 public StudioMarketDataAdapter(BasketSessionHolder sessionHolder)
     : base(MessageAdapterTypes.MarketData, sessionHolder)
 {
 }