예제 #1
0
        public ChartWindow(CandleSeries candleSeries, DateTime from, DateTime to)
        {
            InitializeComponent();

            if (candleSeries == null)
            {
                throw new ArgumentNullException("candleSeries");
            }

            _candleSeries = candleSeries;
            _trader       = MainWindow.Instance.Trader;

            Chart.ChartTheme = "ExpressionDark";

            var area = new ChartArea();

            Chart.Areas.Add(area);

            _candleElem = new ChartCandleElement
            {
                Antialiasing    = false,
                UpFillColor     = Colors.White,
                UpBorderColor   = Colors.Black,
                DownFillColor   = Colors.Black,
                DownBorderColor = Colors.Black,
            };

            area.Elements.Add(_candleElem);

            _trader.NewCandles += ProcessNewCandles;
            _trader.SubscribeCandles(_candleSeries, from, to);

            Title = candleSeries.ToString();
        }
예제 #2
0
        public ChartWindow(CandleSeries candleSeries, DateTimeOffset?from = null, DateTimeOffset?to = null)
        {
            InitializeComponent();

            _candleSeries = candleSeries ?? throw new ArgumentNullException(nameof(candleSeries));
            _trader       = MainWindow.Instance.Trader;

            Chart.ChartTheme = ChartThemes.ExpressionDark;

            var area = new ChartArea();

            Chart.Areas.Add(area);

            _candleElem = new ChartCandleElement
            {
                AntiAliasing    = false,
                UpFillColor     = Colors.White,
                UpBorderColor   = Colors.Black,
                DownFillColor   = Colors.Black,
                DownBorderColor = Colors.Black,
            };

            area.Elements.Add(_candleElem);

            _trader.CandleSeriesProcessing += ProcessNewCandle;
            _trader.SubscribeCandles(_candleSeries, from, to);

            Title = candleSeries.ToString();
        }
예제 #3
0
        private void ConnectClick(object sender, RoutedEventArgs e)
        {
            var pwd = PwdBox.Password;

            if (!IsConnected)
            {
                var settings = Properties.Settings.Default;

                if (settings.Username.IsEmpty())
                {
                    MessageBox.Show(this, LocalizedStrings.Str3751);
                    return;
                }

                if (pwd.IsEmpty())
                {
                    MessageBox.Show(this, LocalizedStrings.Str2975);
                    return;
                }

                if (Trader == null)
                {
                    // create connector
                    Trader = new RithmicTrader {
                        LogLevel = LogLevels.Debug
                    };

                    _logManager.Sources.Add(Trader);

                    // subscribe on connection successfully event
                    Trader.Connected += () =>
                    {
                        this.GuiAsync(() => OnConnectionChanged(true));
                    };

                    // subscribe on connection error event
                    Trader.ConnectionError += error => this.GuiAsync(() =>
                    {
                        OnConnectionChanged(Trader.ConnectionState == ConnectionStates.Connected);
                        MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959);
                    });

                    Trader.Disconnected += () => this.GuiAsync(() => OnConnectionChanged(false));

                    // subscribe on error event
                    //Trader.Error += error =>
                    //	this.GuiAsync(() => MessageBox.Show(this, error.ToString(), "Error"));

                    // 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.NewMyTrades   += trades => _myTradesWindow.TradeGrid.Trades.AddRange(trades);
                    Trader.NewOrders     += orders => _ordersWindow.OrderGrid.Orders.AddRange(orders);
                    Trader.NewStopOrders += orders => _stopOrdersWindow.OrderGrid.Orders.AddRange(orders);
                    Trader.NewPortfolios += portfolios =>
                    {
                        // subscribe on portfolio updates
                        portfolios.ForEach(Trader.RegisterPortfolio);

                        _portfoliosWindow.PortfolioGrid.Portfolios.AddRange(portfolios);
                    };
                    Trader.NewPositions += positions => _portfoliosWindow.PortfolioGrid.Positions.AddRange(positions);

                    // subscribe on error of order registration event
                    Trader.OrdersRegisterFailed += OrdersFailed;
                    // subscribe on error of order cancelling event
                    Trader.OrdersCancelFailed += OrdersFailed;

                    // subscribe on error of stop-order registration event
                    Trader.StopOrdersRegisterFailed += OrdersFailed;
                    // subscribe on error of stop-order cancelling event
                    Trader.StopOrdersCancelFailed += OrdersFailed;

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

                Trader.UserName = settings.Username;
                Trader.Server   = settings.Server;
                Trader.Password = pwd;
                Trader.CertFile = settings.CertFile;

                Trader.Connect();
            }
            else
            {
                Trader.Disconnect();
            }
        }
예제 #4
0
        private void ConnectClick(object sender, RoutedEventArgs e)
        {
            var pwd = PwdBox.Password;

            if (!IsConnected)
            {
                var settings = Properties.Settings.Default;

                if (settings.Username.IsEmpty())
                {
                    MessageBox.Show(this, LocalizedStrings.Str3751);
                    return;
                }

                if (pwd.IsEmpty())
                {
                    MessageBox.Show(this, LocalizedStrings.Str2975);
                    return;
                }

                if (Trader == null)
                {
                    // создаем подключение
                    Trader = new RithmicTrader {
                        LogLevel = LogLevels.Debug
                    };

                    _logManager.Sources.Add(Trader);

                    // подписываемся на событие успешного соединения
                    Trader.Connected += () =>
                    {
                        this.GuiAsync(() => OnConnectionChanged(true));

                        Trader.StartExport();
                    };

                    // подписываемся на событие разрыва соединения
                    Trader.ConnectionError += error => this.GuiAsync(() =>
                    {
                        OnConnectionChanged(Trader.ConnectionState == ConnectionStates.Connected);
                        MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959);
                    });

                    Trader.Disconnected += () => this.GuiAsync(() => OnConnectionChanged(false));

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

                    // подписываемся на ошибку подписки маркет-данных
                    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.NewMyTrades   += trades => _myTradesWindow.TradeGrid.Trades.AddRange(trades);
                    Trader.NewOrders     += orders => _ordersWindow.OrderGrid.Orders.AddRange(orders);
                    Trader.NewStopOrders += orders => _stopOrdersWindow.OrderGrid.Orders.AddRange(orders);
                    Trader.NewPortfolios += portfolios =>
                    {
                        // регистрирует портфели на обновление данных
                        portfolios.ForEach(Trader.RegisterPortfolio);

                        _portfoliosWindow.PortfolioGrid.Portfolios.AddRange(portfolios);
                    };
                    Trader.NewPositions += positions => _portfoliosWindow.PortfolioGrid.Positions.AddRange(positions);

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

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

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

                Trader.UserName = settings.Username;
                Trader.Server   = settings.Server;
                Trader.Password = pwd;
                Trader.CertFile = settings.CertFile;

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