| 1 | /* Example of subscribing/unsubscribing to market data from an Add On. The concept can be carried over |
| 2 | to any NinjaScript object you may be working on. */ |
| 3 | public class MyAddOnTab : NTTabPage |
| 4 | { |
| 5 | private AccountSelector accountSelector |
| 6 | |
| 7 | public MyAddOnTab() |
| 8 | { |
| 9 | // Note: pageContent (not demonstrated in this example) is the page content of the XAML |
| 10 | // Find account selector |
| 11 | accountSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "accountSelector") as AccountSelector; |
| 12 | |
| 13 | // When the account selector's selection changes, unsubscribe and resubscribe |
| 14 | accountSelector.SelectionChanged += (o, args) => |
| 15 | { |
| 16 | if (accountSelector.SelectedAccount != null) |
| 17 | { |
| 18 | // Unsubscribe to any prior account subscriptions |
| 19 | accountSelector.SelectedAccount.AccountItemUpdate -= OnAccountItemUpdate; |
| 20 | accountSelector.SelectedAccount.ExecutionUpdate -= OnExecutionUpdate; |
| 21 | accountSelector.SelectedAccount.OrderUpdate -= OnOrderUpdate; |
| 22 | accountSelector.SelectedAccount.PositionUpdate -= OnPositionUpdate; |
| 23 | |
| 24 | // Subscribe to new account subscriptions |
| 25 | accountSelector.SelectedAccount.AccountItemUpdate += OnAccountItemUpdate; |
| 26 | accountSelector.SelectedAccount.ExecutionUpdate += OnExecutionUpdate; |
| 27 | accountSelector.SelectedAccount.OrderUpdate += OnOrderUpdate; |
| 28 | accountSelector.SelectedAccount.PositionUpdate += OnPositionUpdate; |
| 29 | } |
| 30 | }; |
| 31 | } |
| 32 | |
| 33 | // Called by TabControl when tab is being removed or window is closed |
| 34 | public override void Cleanup() |
| 35 | { |
| 36 | // Clean up our resources |
| 37 | base.Cleanup(); |
| 38 | } |
| 39 | |
| 40 | // Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code. |
| 41 | } |