예제 #1
0
        protected override void OnClosing(CancelEventArgs e)
        {
            _realConnector?.Dispose();
            _emuConnector?.Dispose();

            base.OnClosing(e);
        }
예제 #2
0
        protected override void OnClosing(CancelEventArgs e)
        {
            if (_connector != null)
            {
                _connector.Dispose();
            }

            base.OnClosing(e);
        }
예제 #3
0
        private void InitEmuConnector()
        {
            if (_emuConnector != null)
            {
                _emuConnector.Dispose();
                _logManager.Sources.Remove(_emuConnector);
            }

            _emuConnector = new RealTimeEmulationTrader <IMessageAdapter>(_realConnector.Adapter, _realConnector, _emuPf, false);
            _logManager.Sources.Add(_emuConnector);

            var settings = _emuConnector.EmulationAdapter.Emulator.Settings;

            settings.TimeZone    = TimeHelper.Est;
            settings.ConvertTime = true;

            SecurityPicker.MarketDataProvider = _emuConnector;

            // subscribe on connection successfully event
            _emuConnector.Connected += () =>
            {
                // update gui labels
                this.GuiAsync(() => { ChangeConnectStatus(true); });
            };

            // subscribe on disconnection event
            _emuConnector.Disconnected += () =>
            {
                // update gui labels
                this.GuiAsync(() => { ChangeConnectStatus(false); });
            };

            // subscribe on connection error event
            _emuConnector.ConnectionError += error => this.GuiAsync(() =>
            {
                // update gui labels
                ChangeConnectStatus(false);

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

            _emuConnector.NewMarketDepth     += OnDepth;
            _emuConnector.MarketDepthChanged += OnDepth;

            _emuConnector.NewPortfolio += PortfolioGrid.Positions.Add;
            _emuConnector.NewPosition  += PortfolioGrid.Positions.Add;

            _emuConnector.NewOrder   += OrderGrid.Orders.Add;
            _emuConnector.NewMyTrade += TradeGrid.Trades.Add;

            // subscribe on error of order registration event
            _emuConnector.OrderRegisterFailed += OrderGrid.AddRegistrationFail;

            _emuConnector.CandleSeriesProcessing += (s, candle) =>
            {
                //if (candle.State == CandleStates.Finished)
                _buffer.Add(candle);
            };

            _emuConnector.MassOrderCancelFailed += (transId, error) =>
                                                   this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str716));

            // subscribe on error event
            //_emuConnector.Error += error =>
            //	this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955));

            // subscribe on error of market data subscription event
            _emuConnector.MarketDataSubscriptionFailed += (security, msg, error) =>
            {
                if (error == null)
                {
                    return;
                }

                this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(msg.DataType, security)));
            };
        }
예제 #4
0
        private void InitConnector()
        {
            _emuConnector?.Dispose();

            try
            {
                if (File.Exists(_settingsFile))
                {
                    _realConnector.Load(new XmlSerializer <SettingsStorage>().Deserialize(_settingsFile));
                }
            }
            catch
            {
            }

            _emuConnector = new RealTimeEmulationTrader <IMessageAdapter>(_realConnector.MarketDataAdapter ?? new PassThroughMessageAdapter(new IncrementalIdGenerator()), _emuPf, false);
            _logManager.Sources.Add(_emuConnector);

            _emuConnector.EmulationAdapter.Emulator.Settings.TimeZone    = TimeHelper.Est;
            _emuConnector.EmulationAdapter.Emulator.Settings.ConvertTime = true;

            SecurityPicker.SecurityProvider   = new FilterableSecurityProvider(_emuConnector);
            SecurityPicker.MarketDataProvider = _emuConnector;

            _candleManager = new CandleManager(_emuConnector);

            // subscribe on connection successfully event
            _emuConnector.Connected += () =>
            {
                // update gui labels
                this.GuiAsync(() => { ChangeConnectStatus(true); });
            };

            // subscribe on disconnection event
            _emuConnector.Disconnected += () =>
            {
                // update gui labels
                this.GuiAsync(() => { ChangeConnectStatus(false); });
            };

            // subscribe on connection error event
            _emuConnector.ConnectionError += error => this.GuiAsync(() =>
            {
                // update gui labels
                ChangeConnectStatus(false);

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

            _emuConnector.NewMarketDepth     += OnDepth;
            _emuConnector.MarketDepthChanged += OnDepth;

            _emuConnector.NewPortfolio += PortfolioGrid.Portfolios.Add;
            _emuConnector.NewPosition  += PortfolioGrid.Positions.Add;

            _emuConnector.NewOrder   += OrderGrid.Orders.Add;
            _emuConnector.NewMyTrade += TradeGrid.Trades.Add;

            _realConnector.NewOrder   += OrderGrid.Orders.Add;
            _realConnector.NewMyTrade += TradeGrid.Trades.Add;

            // subscribe on error of order registration event
            _emuConnector.OrderRegisterFailed  += OrderGrid.AddRegistrationFail;
            _realConnector.OrderRegisterFailed += OrderGrid.AddRegistrationFail;

            _candleManager.Processing += (s, candle) =>
            {
                if (candle.State == CandleStates.Finished)
                {
                    _buffer.Add(candle);
                }
            };

            _emuConnector.MassOrderCancelFailed += (transId, error) =>
                                                   this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str716));
            _realConnector.MassOrderCancelFailed += (transId, error) =>
                                                    this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str716));

            // subscribe on error event
            _emuConnector.Error += error =>
                                   this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955));
            _realConnector.Error += error =>
                                    this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955));

            // subscribe on error of market data subscription event
            _emuConnector.MarketDataSubscriptionFailed += (security, msg, error) =>
            {
                if (error == null)
                {
                    return;
                }

                this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(msg.DataType, security)));
            };
        }