This section of the documentation explains how to manage orders in a .NET application using the StockSharp trading framework. The code facilitates operations like buying and selling securities by interacting with the trading service.
- Order Handling: Submitting buy and sell orders.
- UI Components:
SecurityEditorandPortfolioEditorfor selecting securities and portfolios. - Order Feedback: Handling responses for new orders and failed orders.
- Clone the repository.
- Open the solution in Visual Studio.
- Find and add required connector via NuGet package
- Build and run the application.
The constructor initializes the application and loads existing settings. The Connect_Click method sets up necessary bindings and event handlers for order operations:
public MainWindow()
{
InitializeComponent();
if (File.Exists(_connectorFile))
{
_connector.Load(_connectorFile.Deserialize<SettingsStorage>());
}
}
private void Connect_Click(object sender, RoutedEventArgs e)
{
SecurityEditor.SecurityProvider = _connector;
PortfolioEditor.Portfolios = new PortfolioDataSource(_connector);
_connector.NewOrder += OrderGrid.Orders.Add;
_connector.OrderRegisterFailed += OrderGrid.AddRegistrationFail;
_connector.NewMyTrade += MyTradeGrid.Trades.Add;
_connector.Connect();
}The application provides methods to submit buy and sell orders. These methods are triggered by UI events (e.g., button clicks) and use the selected security and portfolio details to create and register orders with the trading service:
private void Buy_Click(object sender, RoutedEventArgs e)
{
var order = new Order
{
Security = SecurityEditor.SelectedSecurity,
Portfolio = PortfolioEditor.SelectedPortfolio,
Price = decimal.Parse(TextBoxPrice.Text),
Volume = 1, // Example volume
Side = Sides.Buy,
};
_connector.RegisterOrder(order);
}
private void Sell_Click(object sender, RoutedEventArgs e)
{
var order = new Order
{
Security = SecurityEditor.SelectedSecurity,
Portfolio = PortfolioEditor.SelectedPortfolio,
Price = decimal.Parse(TextBoxPrice.Text),
Volume = 1, // Example volume
Side = Sides.Sell,
};
_connector.RegisterOrder(order);
}The application listens for new orders and failed order registration events to update the UI appropriately:
_connector.NewOrder += OrderGrid.Orders.Add;
_connector.OrderRegisterFailed += OrderGrid.AddRegistrationFail;This setup allows users to interactively manage trading orders through a UI, offering capabilities to buy and sell securities using configured trading services. This guide should help users understand the order handling process within the application and provide clear instructions on how to extend or modify this functionality.
Feel free to adjust the snippets and explanations to better fit the actual implementation details or specific configurations in your project.