Click or drag to resize

Own trades

MyTradeGrid - a table to display own trades.

Main members

Below is the appearance of the component, as well as code snippets with its use. The code example is taken from Samples/OpenECry/SampleOEC.

GUI Mytrade Grid
XAML
<Window x:Class="SampleOEC.MyTradesWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:StockSharp.Localization;assembly=StockSharp.Localization"
    xmlns:xaml="http://schemas.stocksharp.com/xaml"
    Title="{x:Static loc:LocalizedStrings.MyTrades}" Height="284" Width="644">
  <xaml:MyTradeGrid x:Name="TradeGrid" x:FieldModifier="public" />
</Window>
C#
private void ConnectClick(object sender, RoutedEventArgs e)
{
    if (!_isConnected)
    {

        .......................................


            // subscribe on connection successfully event
            Trader.Connected += () =>
            {
                // set flag (connection is established)
                _isConnected = true;

                // update gui labes
                this.GuiAsync(() => ChangeConnectStatus(true));

                // subscribe on news
                Trader.RegisterNews();
            };

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

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

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

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

            Trader.NewSecurity += security => _securitiesWindow.SecurityPicker.Securities.Add(security);
            Trader.NewMyTrade += trade => _myTradesWindow.TradeGrid.Trades.Add(trade);
            Trader.NewTrade += trade => _tradesWindow.TradeGrid.Trades.Add(trade);
            Trader.NewOrder += order => _ordersWindow.OrderGrid.Orders.Add(order);
            Trader.NewStopOrder += order => _stopOrdersWindow.OrderGrid.Orders.Add(order);
            Trader.NewPortfolio += portfolio =>
            {
                _portfoliosWindow.PortfolioGrid.Portfolios.Add(portfolio);

                // subscribe on portfolio updates
                Trader.RegisterPortfolio(portfolio);
            };
            Trader.NewPosition += position => _portfoliosWindow.PortfolioGrid.Positions.Add(position);

            // subscribe on error of order registration event
            Trader.OrderRegisterFailed += _ordersWindow.OrderGrid.AddRegistrationFail;
            // subscribe on error of order cancelling event
            Trader.OrderCancelFailed += OrderFailed;

            // subscribe on error of stop-order registration event
            Trader.StopOrderRegisterFailed += _stopOrdersWindow.OrderGrid.AddRegistrationFail;
            // subscribe on error of stop-order cancelling event
            Trader.StopOrderCancelFailed += OrderFailed;

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

            Trader.NewNews += news => _newsWindow.NewsPanel.NewsGrid.News.Add(news);

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

            // set news provider
            _newsWindow.NewsPanel.NewsProvider = Trader;

            ShowSecurities.IsEnabled = ShowTrades.IsEnabled =
            ShowMyTrades.IsEnabled = ShowOrders.IsEnabled = 
            ShowPortfolios.IsEnabled = ShowStopOrders.IsEnabled = true;
        }


        Trader.Login = Login.Text;
        Trader.Password = Password.Password;
        Trader.Address = Address.SelectedAddress;

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

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

        Trader.Disconnect();
    }
}