Sooty Solutions - Burnaby BC Consulting Company - Advising Business Managers on Security, Information Technology, Business Process Performance, & Best Practices
Sooty HomeContractors are BetterThe Sooty ApproachLong Range PlanningThe Sooty PartnersContact Us

MarketWired RSS Feed Notifier in Java

This is beginners java programming project. You should have written your own programs using the internet (i.e. Google) as a crutch and be able to integrate 'found code scraps' into a working programs without asking for help. You should have installed the Java JDK on your computer. You don't need an IDE ... any editor (notepad) can be used for support (get Textpad if you can). The program probably works on Linux but this has not been tested.

The project is currently in "alpha" with debuging dumps into log files to help track down problems. It is a single 200 line program and only needs a text file to hold your portfolio of stocks. I run it from the Windows 10 task scheduler and test it with very simple CMD batch command files. The code is as-is with no copyright and no support. I hacked it together in half a day (and looks it) but it is my "production version" and it runs automatically every day before the markets open and just after they close.

Yahoo Finance Sucks but It's Better than Any Other Free Service

Sooty is a dividend investor and the Yahoo Finance "portfolio feature" used to be a great place to track investments. Over the last few years Yahoo has changed the layout and content so it is more difficult for a serious investor to find the information they need. I love my broker for its "banking" functions but it does not do "news". I've tried some of the free portfolio trackers (Google, TMX, Morningstar) but the current Yahoo layout is still maginally better. To really see how they compare you need to create an account and set up your portfolio in the (non-trivial) tools they provide.

The Yahoo portfolio news (below your stocks table) has become so cluttered it is difficult to use. It's not just the paid ads but the news feed is full of links to "analysis" companies offering free advice or "for fee" reports keyed to the stocks in the Yahoo portfolio. You now have to scan through many pages of junk links to find dividend notices and company alerts.

I'll continue to use Yahoo to track my daily stock prices but I now use my Java RSS scanner for dividend notices.

MarketWired (NASDAQ) Investor News RSS

MarketWired is part of NASDAQ and provides just news items for US and Canadian exchanges (not just NASDAQ stocks as far as I can tell). No ads, no free advice, no for fee reports, just news for from the investor media services of publically traded companies. The problem is they report on all companies not just the ones in my portfolio.

The RSS feed retains News Releases for only 24 hours (if it is 6:00 PM now then any news from 5:00 PM yesterday is gone) so you must check at least once every day. I check just before the markets open and just after they close. A news item registered into their system in the middle of the day will alert twice...better twice than not at all.

XML Parsing

The format of the MarketWired RSS page is very simple XML so you don't need an XML parser to decode it. Standard Java text tools are enough to extract the data. In fact most RSS services use this very simple format (although some nest titles within titles) and the RSS code example should work with most sites.

You can see the RSS webpage at: ( Most browsers allow you to see the webpage source. In Firefox use: Tools -> Web Developer -> Page Source to save the raw XML.
An "interesting" news item (like a dividend report) in the XML looks like:

   <title>Teekay Corporation Declares Dividend</title>
	&lt;div class="mw_release"&gt;
	&lt;p&gt;&lt;strong&gt;HAMILTON, BERMUDA--(Marketwired - July 7, 2017) -&lt;/strong&gt;
	Teekay Corporation (&lt;em&gt;Teekay&lt;/em&gt; or &lt;em&gt;the Company&lt;/em&gt;) (NYSE:TK)
	announced that its Board of Directors has declared a cash dividend on its common stock of $0.055
	per share for the quarter ended June 30, 2017. The cash dividend is payable on August 16, 2017 to
	all shareholders of record as at August 4, 2017.
   <category domain="">NYSE:TK</category>
   <pubDate>Fri, 07 Jul 2017 06:59:00 EDT</pubDate>
What we want from this XML fragment is data between <title> and </title> and associated link for the full news report between the <link> and </link> tags. All we need to do is read a line from the XML and line.indexOf("<title>"); to find positions of the tags then extract the data. We can ignore the rest.

Once we have a "title" we can check it against our portfolio. I have about 25 stocks so I load an array from a text file when the program starts. The "title" is extracted it is checked against each stock. The program keeps the hits and ignores the rest. If one of the lines in my portfolio file was "Teekay Corporation" then the title and link would be flagged and generate an alert.

The MarketWired RSS offers about 4000 "titles" in a month and most dividend paying stocks report in the last half of the month so most days generate no alerts. In my case the first business day after the 15th of the month will generate over a dozen alerts during the afternoon run and a duplicate set on next morning's run.

The MarketWired feed misses a few Canadian stocks that I own (like Dream Global) so I cloned the to pull GlobeNewswire (much longer XML link address):

You may want to add other RSS feeds for specific exchanges (like Europe) or specific investment types (like ETFs) and have a batch stream that runs several of these clones in separate job steps. Wikipedia has a list of Press Release Agencies but not all have XML feeds. Some like CNW Group have news I want but no XML feed so I've had to create a specific parser (not posted on for their news page.

The link for MarketWired feed is short and probably stable. The GlobeNewswire link is very long and I suspect quiet fragile. Some developer at GlobeNewswire will decide that the link needs fixing and break my I would recommend you write a separate clone for each RSS feed. Because each clone is 99% the same code you may be tempted to put all your RSS feeds in a single program. However fragile links and quirks in parsing the feeds will mean a collection of tailored clones will be easier to debug and maintain (the old "modular" versus "integrated" tradeoff).

Javax Swing Alert and Java AWT Display

Finally the program checks the selected title to see if it contains the word "dividend" or "distribution". Stocks news items passing this last filter then generates a Javax Swing alert. Clicking the "Details" button on the alert passes the link to my default browser and brings up the details page. (In my production version I added a "Skip" button so I don't browse to every altered link)

The Javax Swing alert:

...and "Details" using Java AWT (Abstract Window Toolkit):

The program. The portfolio.txt list of stocks. The ReadRSS.cmd Window batch (build) file.