use yahoo finance streaming api


In the past I used this ruby script to poll for the current stock data and put it into a database to create a little history.

Recently I saw a new feature on the yahoo finance homepage. Now it is possible to enable a streaming option and then you get a live update on certain values via AJAX. So I thought why not get this feature and let yahoo stream the content to the client instead of polling the server from time to time.

So I tried to capture the javascript request with wireshark, so that I could reproduce it. This is what it looks like:

GET /streamer/1.0?s=^GDAXI,USD=X&o=^N225,LHS.F,JI4.F,EEX.F,HEI.F,CBK.F,PRE.F,NDX1.F&k=c10,g00,h00,l10,p20,t10&j=c10,l10,p20,t10&r=0&marketid=us_market&callback=parent.yfs_u1f&mktmcb=parent.yfs_mktmcb&gencallback=parent.yfs_gencb HTTP/1.1
Host: streamerapi.finance.yahoo.com

Here is what I got on this request so far:

parameter ’s’ -> symbol on the main site (what you currently looking at)

parameter ‘o’ -> that is the ticker on the top

parameter ‘k’ and ‘j’ -> that are the values that are transfered

c10 -> unknown

g00 -> day low

h00 -> day high

l10 -> current price

p20 -> unknown

t10 -> timstamp

a00 -> ask

b00 -> bid

With that data you can build a Push-Client with your own custom data. Here is a sample Request for what I needed.

wget -Obla 'http://streamerapi.finance.yahoo.com/streamer/1.0?s=^GDAXI,USD=X&o=BEI.F,SIE.F,PRA.F&k=l10,a00,b00,g00,h00&j=l10,a00,b00,g00,h00&r=0&marketid=us_market&callback=parent.yfs_u1f&mktmcb=parent.yfs_mktmcb&gencallback=parent.yfs_gencb'

(Streaming the current ‘ask’, ‘bid’ and ‘price’ values for the stocks ‘BEI.F’,'SIE.F’ and ‘PRA.F’.)

The response for that looks like that:

<html>
<head>
<script type='text/javascript'> document.domain='finance.yahoo.com';</script>
</head>
<body></body>
<script>try{parent.yfs_mktmcb({"unixtime":1228213139,"open":1228228200,"close":1228251600});}catch(e){}</script>
<script>try{parent.yfs_u1f({"USD=X":{l10:"1.00",a00:"1.00",b00:"1.00",g00:"0.00",h00:"0.00"}});}catch(e){}</script>
<script>try{parent.yfs_u1f({"BEI.F":{l10:"42.31",a00:"41.70",b00:"41.53",g00:"42.31",h00:"43.95"}});}catch(e){}</script>
<script>try{parent.yfs_u1f({"SIE.F":{l10:"44.46",a00:"44.26",b00:"44.20",g00:"44.40",h00:"47.55"}});}catch(e){}</script>

No you can parse that document for the requested Data. But be carefull because the html structure is never closing (at least not as lang as the streaming goes on).

, , ,

  1. #1 by Mike on March 31st, 2009

    thanks for the info! below are my findings…
    -mike

    v00 – volume (accumulated since the start of the trading day)
    a50 – ask size
    b60 – bid size

    b20 -?
    b30 -?
    c10 – close price (??)
    c60 -?
    c63 -?
    c81 -?

  2. #2 by Nirav Patel on May 1st, 2009

    Hi,

    Your post seems quite impressive, I found that from Google while searching the same thing for .Net. Do you have any idea, how to implement such feature in .Net?

    Your help will be highly appreciated.

  3. #3 by jens on May 4th, 2009

    Hey,

    basically this shouldn’t be difficult to implement in .NET. First of all use the framework given http-client and use that as input stream. In this stream you need to replace the non-JSON content with white-spaces and maybe put quotes around the API symbols (at least the C parser I use requires it). After that you can use any JSON Parser and get ordinary .NET objects from the parser.
    That’s about it. If you combine these 3 steps you have your client.

  4. #4 by Qian on June 1st, 2009

    Hi,
    I am able to download the normal stock data. But I couldn’t able to download the FTSE data, I have been trying to solve this for age, couldn’t get it to work. I think the “^” symbol in front of FTSE mess things up. Have you got FTSE data to download? Do you have any ideas?

    Thanks very much.
    Qian

  5. #5 by jens on June 2nd, 2009

    I think downloading data for the FTSE shouldn’t be any different than the data in the sample (^GDAXI -> German Index). I tried the following in my command line and it worked right away:
    curl -s -o – -N ‘http://streamerapi.finance.yahoo.com/streamer/1.0?s=^FTSE&k=l10&callback=parent.yfs_u1f&mktmcb=parent.yfs_mktmcb&gencallback=parent.yfs_gencb’

    document.domain=’finance.yahoo.com’; try{parent.yfs_u1f({“^FTSE”:{l10:”4448.27″}});}catch(e){}try{parent.yfs_u1f({“^FTSE”:{l10:”4451.05″}});}catch(e){}

    I’m using curl for this, just because, it is simpler to handle. A sample for curl can be found here.

  6. #6 by xudong on June 19th, 2009

    how can i get the per transaction in the flash/yahoo finance flash picture? it seems available with the mouse movements. any clue?thanks

  7. #7 by Anonymous on June 26th, 2009

    available symbols do , or may include any of the following:
    a00,a50,b00,b20,b30,b60,c10,c60,c63,c64,c81,c82,c85,c86,g00,h00,l10,l84,l86,l90,l91,o40,o50,p20,p40,p41,p43,p44,t10,t50,t51,t53,t54,v00,z02,z08,z09

    I haven’t figured out all the numbers yet, but here are a few of the letters:
    a ask (a00)
    b bid (b00)
    c percent from previous day’s close
    l last trade (l10)
    t time of last trade (t10)
    v day’s volume (v00)

(will not be published)

  1. No trackbacks yet.