Yahoo stock to RSS converter

NO LONGER RUNNING!

Update June 2010: I haven’t used this for a while and as you probably have noticed it’s no longer working. It did it’s thing, while there was not such service, but now at least Google financial provides some of the same services. Anyway, the source is still here, if you want to run it…

Inspired by Xanadb’ RSS Stock Ticker (which in turn was inspired by the now defunct Yahoo Finance RSS), I decided to try to make my own. I wanted to add a few things, mainly the ability to calculate loss/win for each stock and a total loss/win for all stocks.

The data for the feed is gotten from finance.yahoo.com

and you need the stock symbols that they use to build up a URL string that you can feed to your RSS program. But here’s an example:

http://tc.dk/stock.php?symbols=msft:100:20+csco:200:20.9

This will give you two rss items with the current stock price of Microsoft (msft) and Cisco (csco). The total value of a 100 Microsoft stocks is calculated and the win/loss if you paid 20us$ for them is calculated. The same is done for 200 Cisco stocks brought at 20.90us$.
Here’s an example of how Thunderbird will show the data:
stock rss view

The parameters:

  • The symbols parameter is for listing.. stock symbols, separated by + signs. The stock count and acquisition price is optional (but you can’t add the acquisition price with out the count, as it’s the order that decided what’s what). Tips: If your stock isn’t on an american stock excange, post fix it with the city of the exhange you want to use. Copenhagen is co. So, my Danske Bank stocks are danske.co. Search on Yahoo to find the correct ending.
  • The total=[yes|no] parameter means that a total item will be added, showing total loss/win for all the stocks. Default is no.
  • The title=[text] parameter will be added to the rss feed title. Use this for portfolio names. Change spaces to %20.
  • The timedif=[integer number] is used to correct the trading time (6 is Central European Time). Default is 0 (zero), and the base whatever yahoo decided (I think it’s US eastern time).
  • The link=[yes|no]
    can be used to remove the link from each item. Mostly used to work
    around an error, where the rss reader ignores GUID data, when there’s a
    link (thunderbird 1.0 does this). Default is yes
  • The randomlink=[yes|no]
    is used to add a randompart to the link in each item, thrus fooling rss
    readers to think it’s a new story each time. Default is no. (added in 0.0.3)
  • The totalonly=[yes|no] parameter is used if you only want one item returned with all the totals. Default is no. (added in 0.0.3)
  • The graph=[yes,1ds,1d,5d,3m,6m,1y,2y,5y,my|no] adds one or more image links to graphs displaying [1 day small, 1 day, 5 days, 3 months, 6 months, 1 year, 2 years, 5 years or max years]. It’s possible to specify more that one graph by seperating them with comma or +: graph=1d+1y for the 1 day and 1 year graphs. The old option “yes” will display the 1ds (1 Day Small) graph. Please note that your RSS viewer need to be online to see these image (added in 0.0.4, big/multi-graph added in 0.0.8)
  • The fulltitle=[yes|no]
    parameter is used if you want the full title of the symbol displayed in the title of each item (e.i. “Microsoft” for msft). (added in 0.0.4)
  • The titlenoshort=[yes|no]
    forces fulltitle=yes and only uses the fulltitle on the headlines (makes them a bit shorter) (added in 0.0.7)
  • The titlenochange=[yes|no]
    removed the day change value from the title (makes them a bit shorter) (added in 0.0.7)

An example of usage:

http://tc.dk/stock.php?symbols=msft:100:20&
title=My%20Stocks&totalonly=yes

(should be on one line, with no spaces)

Will display only a total item, with Microsoft information. The title of the RSS feed will be “My Stock”.

Another example showing a current day grap and a 3 month graph for Cisco and Microsoft:

http://tc.dk/stock.php?symbols=msft+csco&total=yes&
title=My%20Stock&graph=1ds,3m

(should be on one line, with no spaces)

For more information, take a look at the comment in the source code zip (which is released under a Creative Commons License).
But really you don’t have to…
Feel free to run the code from your own server – in fact, please do so, instead of using my server. Please add a comment and link to your server. If you make any changes to the code, please let me know and I’ll add the changes to the script here. Look in the code for known problems and a to-do list.
There’s a lot of different RSS readers out there…

People hosting this script:

People who’ve helped to make it better:

  • ttys0: Suggested the multi/big graph functionality and supplied the needed urls.

50 thoughts on “Yahoo stock to RSS converter

  1. TC Post author

    I’ve had to add a leach blocker that makes sure that nobody gets an answer more than once every 20 minuts. I know that this makes it hard to debugging a request string when you are making it the first time, but I’ll see if I can’t find some way around that.

    Score one for the selfcenterede idiots that can’t see a good thing without abusing it.

    Reply
  2. Hillary

    tc: I have installed tickershock on our mac (which has Tiger) and have added the stocks I want to watch (all 30 of the Dow stocks), but price alone is not enough information. I need to add volume to the feed. Do you have a url that’s an RSS feed that can display Price and Volume too? thanks in advance, Hillary

    Reply
  3. TC Post author

    Hillary, sorry, but there isn’t any volume information in the Yahoo data I’m using for this, so no… sorry.

    Reply
  4. Chris Wine

    I am looking to get the souce, but your link seems broken. Could you point me somewhere to download script?

    Thanks,
    CW

    Reply
  5. TC Post author

    Hi, Chris

    I fixed the link – I had given the file the extension .text instead of .txt…

    Reply
  6. Judy Dee

    This is great and i have been using it to track some stocks. However, I was wondering if the % change figure is correct – this is given as the % of the final price, whereas, i would expect to see it expressed as % of the original purchase price.
    If you agree with the logic, can this be fixed?

    Reply
  7. Nando

    TC:
    are you aware if yahoo places some sort of restriction on accessing their feed?

    would they, for instance be a bit annoyed if I slurped up that data for use on our intranet homepage?

    Reply
  8. TC Post author

    Judy: You are correct, I’ll fix it really soon now…

    Nando: No, I’m not aware of any restrictions. I’m kind if thinging that if nobody abuses it, it will probably keep running. But if you want to experiment, use an external ip for stress testing and tell me the result 😉

    Reply
  9. TC Post author

    Judy: I fix the procentage calculation and added a few more options for version 0.0.7. Thanks for the input.

    Reply
  10. ttys0

    Hello,

    I have added the following parameters to display the graphs available from yahoo finance.

    graph1d : 1 day
    graph5d : 5 days
    graph3m : 3 months
    graph6m : 6 months
    graph1y : 1 year
    graph2y : 2 years
    graph5y : 5 years
    graphmy : Maximum

    Just add the following to the source.

    if ((isset($_GET[‘graph1d’])) and ($_GET[‘graph1d’]==’yes’))
    $desc .= ‘<br /><img src="http://ichart.finance.yahoo…‘.$symbol.’" alt="[Chart]" border="0" />’;

    if ((isset($_GET[‘graph5d’])) and ($_GET[‘graph5d’]==’yes’))
    $desc .= ‘<br /><img src="http://ichart.finance.yahoo…‘.$symbol.’" alt="[Chart]" border="0" />’;

    if ((isset($_GET[‘graph3m’])) and ($_GET[‘graph3m’]==’yes’))
    $desc .= ‘<br /><img src="http://chart.finance.yahoo….‘.$symbol.’" alt="[Chart]" border="0" />’;

    if ((isset($_GET[‘graph6m’])) and ($_GET[‘graph6m’]==’yes’))
    $desc .= ‘<br /><img src="http://chart.finance.yahoo….‘.$symbol.’" alt="[Chart]" border="0" />’;

    if ((isset($_GET[‘graph1y’])) and ($_GET[‘graph1y’]==’yes’))
    $desc .= ‘<br /><img src="http://chart.finance.yahoo….‘.$symbol.’" alt="[Chart]" border="0" />’;

    if ((isset($_GET[‘graph2y’])) and ($_GET[‘graph2y’]==’yes’))
    $desc .= ‘<br /><img src="http://chart.finance.yahoo….‘.$symbol.’" alt="[Chart]" border="0" />’;

    if ((isset($_GET[‘graph5y’])) and ($_GET[‘graph5y’]==’yes’))
    $desc .= ‘<br /><img src="http://chart.finance.yahoo….‘.$symbol.’" alt="[Chart]" border="0" />’;

    if ((isset($_GET[‘graphmy’])) and ($_GET[‘graphmy’]==’yes’))
    $desc .= ‘<br /><img src="http://chart.finance.yahoo….‘.$symbol.’" alt="[Chart]" border="0" />’;

    I have tested with 0005.HK, it works, hope it helps. :)

    Reply
  11. TC Post author

    Version 0.0.8 of the code with the graph suggestions by ttys0 incorporated is out. I did it a bit differently then ttys0 suggested, to keep the number of parameters down, but the effect is the same.

    an example graph=1ds,3m,1y for three graphs, with 1 day, 3 months and 1 year.

    Once again, thanks to ttys0 for the suggestion

    Reply
  12. JCH

    Is is possible to suppress the following info from the feed? Thanks

    "More Graph options
    It’ now possible to specify that you want more graphs graph=1d,5d,5y will give you one 1 day, 5 day and 5 year graphs. See the site for more info http://blog.tc.dk/item/8 "

    Reply
  13. enea gjoka

    I was wondering if i could somehow use this php code in my website i’m trying feedforall right now to convert rss to html but for come reason it will only accept an xml file and not http://tc.dk/stock.php?symb
    is there any otehr way i could use the information that is provided by the link i just typed on my website.

    Reply
  14. TC Post author

    Enea: I’m not sure I understand your problem. The feed returned by the link, is xml and is even set as that in the http header (text/xml)…

    Reply
  15. enea gjoka

    i’m trying to make my school project dynamic so that peopel can see the constant and uptoday prices of the stocks that our class has invested in now how would i do that, i only want to use parts of the information that is given by stock.php and i want that information to be everchanging on my website. just like yahoo has stock prices apper ont eh left with updated infor every second.

    Reply
  16. TC Post author

    Hi Enea,
    (please email me if you want more help on this tc@tc.dk).
    I’m guessing you are trying to use the feedforall rss2html.php script? I just tried it and it works fine for me. You did insert the url in line 153 in rss2html.pas?
    TC

    Reply
  17. Matt

    This looks like a fantastic script. Having a problem right now. I installed the PHP script on my site, and when I reference it using the example syntax for msft and csco:

    http://mysite.com/stock.php

    I am receiving the message:

    More Graph options
    mfts is unknown!
    csco is unknown!
    Total (0-0=0)

    Any idea why this is happeneing?

    Reply
  18. TC Post author

    Matt:

    The graph comment: That’s an administrator message, set around line 104 and 105 in the script (the two $note variables). Just comment them out to get rid of the message (add "//" infront of them).
    Well, mfts, is easy, because it should be msft 😉

    But csco should work!

    Could you try of a url like this:
    http://finance.yahoo.com/d/

    And see what you get back from yahoo? You may be blocked or someting.

    Reply
  19. TC Post author

    Zloy: I don’t know. What kind of image are you expecting and where? What are you doing that isn’t working for you?

    Reply
  20. Brie

    Thanks for putting this together. I’m glad i’m not the only one trying to get something like this for their site. I’m a little lost on where to start. I downloaded your source code for the stock.php. Could you provide some further steps for me?

    Reply
  21. TC Post author

    Brie: You need an web server with php working. Upload the script somewhere on your server and run it. If your server is brie-corp.com and you place the script in the root of that, brie-corp.com/stock.php?symbols=msft should give you a rss xml file with information on microsoft. The file can be read by a RSS reader (as mentioned above) or by a RSS module on your site (lots of http://www.opensourcecms.com CMS systems has RSS modules)

    Hope that helps

    Reply
  22. erik

    I’m missing a way to view the stock price in procentage. I would like to have a headline like this: stockname stockprice (change / change in %)

    ex. fakestock 22.40 (-0.40 / 1.75%)
    btw. nice job with the rss

    Reply
  23. Carol

    My stock used to give me the stock price each day for four stocks. It no longer works. What can I do?

    Reply
  24. TC Post author

    It’s working again.

    I thought that there was a problem with Yahoo rejecting my requests, but that was only a local problem on my desktop (and not related to yahoo).

    What was really wrong was that something bad had crawled into stock.dat.php – deleting it solved the problem!

    Sorry, it took so long.

    Reply
  25. TC Post author

    Changed the leach checker so that it’s on a ip+symbol set, so that you can have more than one request, if it’s for different symbols, with in the 20 minutes

    Up version number to 0.0.9

    Reply
  26. cb

    Glad the feed is back up. Great work!

    However, I get an invalid feed error with this stock quote setup:
    http://tc.dk/stock.php?symb…^ftse&total=no&fulltitle=yes&graph=1d

    It is because of the caret symbol in front of the ftse quote. This is the symbol used by Yahoo.

    You can check the validation at the W3C website (http://validator.w3.org/feed/).

    Is there a way around this error?

    Reply
  27. TC Post author

    Hi, cb.

    Replace the "^" with a character encoding "%5E" – so that it looks like this:

    htxtp://tc.dk/stock.php?symbols=%5Eftse&total=no&fulltitle=yes&graph=1d
    (I’ve added an x to the http part to stop nucleus from translating the url)

    Hope it help!

    Reply
  28. Flip

    damn, does’nt work for me.
    after clicking on one of the links, everything appears quite fine.
    But after adding the page as a dynamic bookmark in Firefox, only the header "My Stocks" appears.
    The whole stock infos are missing

    Reply
  29. Dan

    Hey man, thx for sharing the source for this… I found you from google, just downloaded the source and put it on my own server for my own rss portal feed…great stuff!

    Reply
  30. Wesley Griffiths

    Very nice! I think RSS is a really powerful tool especially for stocks.

    This reminds me of:
    http://www.stock-spy.com
    But instead of being an RSS ticker like this tool it actually creates a chart of the news with the stock prices. I think you can learn a lot about what kind of news makes the stock price move by looking at those charts.

    Reply
  31. mmjaeger

    really nice script – thank you for making it open source.
    I was running it with e.g. about ten indices and it appeared to be quite slow – I was wondering how I could cache the results by running a cron-job e.g. every 20 minutes and read the data then from the local server. I hope somebody can help.

    thank you in advance for your input

    Reply
  32. TC Post author

    Hi mmjaeger.

    The problem with caching is that you make the data a bit older each time. I didn’t really make it as something you would run every minute.

    But if I should add a cache to this, I would probably demand database support in some way, and add a small database cache right, at the top of the getyahoostockprice function.

    Reply
  33. PeteH

    This is extremely well done. Nearly exactly what I was looking for. I was hoping for two improvements: (1) Percentage change (in addition to absolute price change); and (2) sorting the symbols in alphabetical order. That would be nirvana!
    Thanks

    Reply
  34. StockRSS

    Is this script now "defunct" as well? Is there anything else available out there to replace this?

    Reply
  35. Cheree Croswell

    Hi there could I reference some of the information from this post if I reference you with a link back to your site?

    Reply
  36. TC Post author

    Len, it doesn’t do anything any more. It’s not longer running. Use google finance..

    Reply

Leave a Reply