NewsSubscription
Definition
NewsSubscription can be used for subscribing to News events.
Remember to unsubscribe if you are no longer using the subscription.
Properties
| Property | Description |
|---|---|
| Update | Event handler for subscribing/unsubscribing to market depth events |
Syntax
NewsSubscription
Examples
/* Example of subscribing/unsubscribing to news from an Add On. The concept can be carried overto any NinjaScript object you may be working on. */public class MyAddOnTab : NTTabPage{private NewsSubscription newsSubscription;private NewsItems newsItems;public MyAddOnTab(){// Subscribe to newsnewsSubscription = new NewsSubscription();newsSubscription.Update += OnNews;newsItems = new NewsItems(10);}// This method is fired as new News events come in. Old News events are not provided when you subscribe.private void OnNews(object sender, NewsEventArgs e){// Print the headline of the newsNinjaTrader.Code.Output.Process(string.Format("ID: {0} News Provider: {1} Headline: {2}",e.Id,e.NewsProvider,e.Headline), PrintTo.OutputTab1);// Maintain the news itemsnewsItems.Update(e);}// Called by TabControl when tab is being removed or window is closedpublic override void Cleanup(){// Make sure to unsubscribe to the News subscriptionif (newsSubscription != null)newsSubscription.Update -= OnNews;}// Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code.}