ExecutionUpdate

View as Markdown

Definition

ExecutionUpdate is used for subscribing to execution update events.

Remember to unsubscribe if you are no longer using the subscription.

Syntax

ExecutionUpdate

Examples

1/* Example of subscribing/unsubscribing to execution update events from an Add On. The concept can be carried over
2to any NinjaScript object you may be working on. */
3public class MyAddOnTab : NTTabPage
4{
5 private Account account;
6 public MyAddOnTab()
7 {
8 // Find our Sim101 account
9 lock (Account.All)
10 account = Account.All.FirstOrDefault(a => a.Name == "Sim101");
11
12 // Subscribe to execution updates
13 if (account != null)
14 account.ExecutionUpdate += OnExecutionUpdate;
15 }
16
17 /* This method is fired as new executions come in, an existing execution is amended
18 (e.g. by the broker's back office), or an execution is removed (e.g. by the broker's back office) */
19 private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
20 {
21 // Output the execution
22 NinjaTrader.Code.Output.Process(string.Format("Instrument: {0} Quantity: {1} Price: {2}",
23 e.Execution.Instrument.FullName, e.Quantity, e.Price), PrintTo.OutputTab1);
24 }
25
26 // Called by TabControl when tab is being removed or window is closed
27 public override void Cleanup()
28 {
29 // Make sure to unsubscribe to the execution subscription
30 if (account != null)
31 account.ExecutionUpdate -= OnExecutionUpdate;
32 }
33
34 // Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code.
35}