示例#1
0
        private void ConnectClick(object sender, RoutedEventArgs e)
        {
            if (!_isConnected)
            {
                if (Trader.Login.IsEmpty())
                {
                    MessageBox.Show(this, LocalizedStrings.Str2974);
                    return;
                }
                else if (Trader.Password.IsEmpty())
                {
                    MessageBox.Show(this, LocalizedStrings.Str2975);
                    return;
                }

                if (!_initialized)
                {
                    _initialized = true;

                    // 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, msg, error) =>
                                                           this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(msg.DataType, security)));

                    Trader.NewSecurity     += _securitiesWindow.SecurityPicker.Securities.Add;
                    Trader.NewTrade        += _tradesWindow.TradeGrid.Trades.Add;
                    Trader.NewOrderLogItem += _orderLogWindow.OrderLogGrid.LogItems.Add;

                    var subscribed = false;
                    //if (AllDepths.IsChecked == true)
                    {
                        Trader.LookupSecuritiesResult += (error, securities) =>
                        {
                            if (subscribed)
                            {
                                return;
                            }

                            subscribed = true;

                            Trader.SendInMessage(new MarketDataMessage
                            {
                                IsSubscribe   = true,
                                DataType      = MarketDataTypes.OrderLog,
                                TransactionId = Trader.TransactionIdGenerator.GetNextId(),
                            });
                        };
                    }

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

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

                Trader.Connect();
            }
            else
            {
                Trader.Disconnect();
            }
        }
示例#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
                    {
                        //LogLevel = LogLevels.Debug,
                        CreateDepthFromOrdersLog = true
                    };

                    _logManager.Sources.Add(Trader);

                    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)));

                    var isAllDepths = AllDepths.IsChecked == true;

                    Trader.NewSecurities += securities =>
                    {
                        foreach (var security in securities)
                        {
                            _securitiesWindow.SecurityPicker.Securities.Add(security);

                            if (isAllDepths && _requestedBoards.Add(security.Board.Code))
                            {
                                Trader.SendInMessage(new MarketDataMessage
                                {
                                    SecurityId = new SecurityId
                                    {
                                        BoardCode = security.Board.Code,
                                    },
                                    IsSubscribe   = true,
                                    DataType      = MarketDataTypes.OrderLog,
                                    TransactionId = Trader.TransactionIdGenerator.GetNextId(),
                                });
                            }
                        }
                    };
                    Trader.NewTrades        += _tradesWindow.TradeGrid.Trades.AddRange;
                    Trader.NewOrderLogItems += _orderLogWindow.OrderLogGrid.LogItems.AddRange;

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

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

                Trader.Login            = Login.Text;
                Trader.Password         = Password.Password;
                Trader.PrimaryMulticast = new MulticastSourceAddress
                {
                    GroupAddress  = GroupAddr.Address,
                    SourceAddress = SourceAddr.Address,
                    Port          = Port.Value ?? 0
                };
                Trader.RecoveryAddress = Recovery.EndPoint;
                Trader.ReplayAddress   = Replay.EndPoint;
                Trader.SecurityCsvFile = SecuritiesCsv.Text;

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

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