NewsSubscription

View as Markdown

Definition

NewsSubscription can be used for subscribing to News events.

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

Properties

PropertyDescription
UpdateEvent handler for subscribing/unsubscribing to market depth events

Syntax

NewsSubscription

Examples

1/* Example of subscribing/unsubscribing to news 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 NewsSubscription newsSubscription;
6 private NewsItems newsItems;
7
8 public MyAddOnTab()
9 {
10 // Subscribe to news
11 newsSubscription = new NewsSubscription();
12 newsSubscription.Update += OnNews;
13 newsItems = new NewsItems(10);
14 }
15
16 // This method is fired as new News events come in. Old News events are not provided when you subscribe.
17 private void OnNews(object sender, NewsEventArgs e)
18 {
19 // Print the headline of the news
20 NinjaTrader.Code.Output.Process(string.Format("ID: {0} News Provider: {1} Headline: {2}",
21 e.Id,
22 e.NewsProvider,
23 e.Headline), PrintTo.OutputTab1);
24
25 // Maintain the news items
26 newsItems.Update(e);
27 }
28
29 // Called by TabControl when tab is being removed or window is closed
30 public override void Cleanup()
31 {
32 // Make sure to unsubscribe to the News subscription
33 if (newsSubscription != null)
34 newsSubscription.Update -= OnNews;
35 }
36
37 // Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code.
38}