<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>underdog-blog &#187; streaming api</title>
	<atom:link href="http://blog.underdog-projects.net/tag/streaming-api/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.underdog-projects.net</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 23 Oct 2010 18:43:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>what&#8217;s the sitch</title>
		<link>http://blog.underdog-projects.net/2009/04/whats-the-sitch/</link>
		<comments>http://blog.underdog-projects.net/2009/04/whats-the-sitch/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 22:26:32 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[yahoo finance]]></category>
		<category><![CDATA[streaming api]]></category>

		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=196</guid>
		<description><![CDATA[As I have a lot to do right am not really coming closer to my goal to write a general purpose app which can pull data from the yahoo streaming server. So I decided to post a few facts about the yahoo api. I hope this helps someone developing his app. So lets see what [...]]]></description>
			<content:encoded><![CDATA[<p>As I have a lot to do right am not really coming closer to my goal to write a general purpose app which can pull data from the yahoo streaming server. So I decided to post a few facts about the yahoo api. I hope this helps someone developing his app. So lets see what we have. First an explanation of these cryptic symbols:</p>
<blockquote><p>a00: ask price<br />
b00: bid price<br />
g00: day&#8217;s range low<br />
h00: day&#8217;s range high<br />
j10: market cap<br />
v00: volume<br />
a50: ask size<br />
b60: bid size<br />
b30: ecn bid<br />
o50: ecn bid size<br />
z03: ecn ext hr bid<br />
z04: ecn ext hr bid size<br />
b20: ecn ask<br />
o40: ecn ask size<br />
z05: ecn ext hr ask<br />
z07: ecn ext hr ask size<br />
h01: ecn day&#8217;s high<br />
g01: ecn day&#8217;s low<br />
h02: ecn ext hr day&#8217;s high<br />
g11: ecn ext hr day&#8217;s low<br />
t10: last trade time, will be in unix epoch format<br />
t50: ecnQuote/last/time<br />
t51: ecn ext hour time<br />
t53: RTQuote/last/time<br />
t54: RTExthourQuote/last/time<br />
l10: last trade<br />
l90: ecnQuote/last/value<br />
l91: ecn ext hour price<br />
l84: RTQuote/last/value<br />
l86: RTExthourQuote/last/value<br />
c10: quote/change/absolute<br />
c81: ecnQuote/afterHourChange/absolute<br />
c60: ecnQuote/change/absolute<br />
z02: ecn ext hour change<br />
z08: ecn ext hour change<br />
c63: RTQuote/change/absolute<br />
c85: RTExthourQuote/afterHourChange/absolute<br />
c64: RTExthourQuote/change/absolute<br />
p20: quote/change/percent<br />
c82: ecnQuote/afterHourChange/percent<br />
p40: ecnQuote/change/percent<br />
p41: ecn ext hour percent change<br />
z09: ecn ext hour percent change<br />
p43: RTQuote/change/percent<br />
c86: RTExtHourQuote/afterHourChange/percent<br />
p44: RTExtHourQuote/change/percent</p></blockquote>
<p>These are the ones I found in the javascript sources. For most of it I don&#8217;t have a clue what it is for so don&#8217;t ask me what it means.</p>
<p>Next thing I want to mention is the result. A general approach would be to request your data and then run it through a proper JSON parser so you can work with the data as an object. Luckily this doesn&#8217;t work. The JSON returned is not 100 percent compliant with the JSON definition. Yahoo packs these symbols (seen above) not into quotes, so the parser denies to read it. A simple way around it is to string replace all possible symbols with quotes.</p>
<p>That&#8217;s it so far. I will post more if I have new information to share.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.underdog-projects.net/2009/04/whats-the-sitch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>bringing the yahoo finance stream to the shell</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/</link>
		<comments>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 14:17:06 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[yahoo finance]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[streaming api]]></category>

		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97</guid>
		<description><![CDATA[A little while ago a posted a primitive way to get to yahoo finance streaming data. As you can guess this was just the beginning. To raise the bar I tried to parse the received data and bring it to the shell. To get this done I needed several tools. curl &#8211; to send and [...]]]></description>
			<content:encoded><![CDATA[<p>A little while ago a posted a primitive way to get to yahoo finance streaming data. As you can guess this was just the beginning. To raise the bar I tried to parse the received data and bring it to the shell. To get this done I needed several tools.</p>
<ul>
<li>curl &#8211; to send and receive the http request</li>
</ul>
<ul>
<li><a href="http://blog.underdog-projects.net/2009/01/streaming-editor-improved/">transform</a> &#8211; a primitive tool to do streaming operations within one line</li>
</ul>
<ul>
<li>spidermonkey shell (a javascript shell which can parse and reformat the data)</li>
</ul>
<p>The complete logic will be done in the javascript. So lets start with the curl command line:</p>
<pre class="prettyprint lang-sh">curl -s -o - -N 'http://streamerapi.finance.yahoo.com/streamer/1.0?s=JAVA,MSFT&amp;k=l10&amp;callback=parent.yfs_u1f&amp;mktmcb=parent.yfs_mktmcb&amp;gencallback=parent.yfs_gencb'</pre>
<p>Let&#8217;s see what we have here. First we call the yahoo streaming api and want the current price (l10) for the stocks of Sun ans Microsoft. The callback part cannot be changed. If you change this part the whole request will not succeed. Also important is to get the output to STDOUT so that we can pipe the output to the next application.</p>
<p>Second part of the work is just to call the transform application (<a href="http://blog.underdog-projects.net/2009/01/streaming-editor-improved/">further explanation here</a>).</p>
<p>The third part is to pipe the output of the transform process into the javascript shell. I started the shell with the following command:</p>
<pre class="prettyprint lang-sh">js -f script.js</pre>
<p>The script script.js look like this:</p>
<pre class="prettyprint lang-js">yfs_u1f = function(tmp) {
try{
print("msft: "+tmp.MSFT.l10);
}catch(ex){}
try{
print("java: "+tmp.JAVA.l10);
}catch(ex){}
};

yfs_mktmcb = function(tmp) {
/*ignore timestamp */

};
var parent=this;
parent.yfs_u1f = yfs_u1f;
parent.yfs_mktmcb = yfs_mktmcb;

while(1==1){
var t = readline();
if(t.substr(0,3) == "try"){
eval(t);
}
}</pre>
<p>First we have to implement the callback functions which will be called from the http response. Then we construct an object called parent where we map these functions into. Now we have a working construct to receive the data and are able to work with it in our shell. What we need now is a little while loop to continuously read from STDIN and wait for new data. By the way accessing the tmp variable in the callback function seems somewhat complicated to me. I&#8217;m sure there is an easier way to access it but I have no clue how. If you have an idea how to do it better please post it to the comments.</p>
<p>The complete bash statement would look like this:</p>
<pre class="prettyprint lang-sh">curl -s -o - -N 'http://streamerapi.finance.yahoo.com/streamer/1.0?s=JAVA,MSFT&amp;k=l10&amp;callback=parent.yfs_u1f&amp;mktmcb=parent.yfs_mktmcb&amp;gencallback=parent.yfs_gencb' | /tmp/transform | js -f script.js</pre>
<p>If you run this you should get this output:</p>
<blockquote><p>msft: 17.83<br />
java: 4.47<br />
msft: 17.84<br />
msft: 17.86<br />
msft: 17.81<br />
java: 4.46</p></blockquote>
<p>Now you can use whatever tools you want to work with that data. For me this will be piped directly into my postgres db for further processing.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>use yahoo finance streaming api</title>
		<link>http://blog.underdog-projects.net/2008/12/use-yahoo-finance-streaming-api/</link>
		<comments>http://blog.underdog-projects.net/2008/12/use-yahoo-finance-streaming-api/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 10:23:33 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[yahoo finance]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[streaming api]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=36</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>In the past I used <a href="http://rubyforge.org/projects/yahoofinance/">this ruby script</a> to poll for the current stock data and put it into a database to create a little history.</p>
<p>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.</p>
<p>So I tried to capture the javascript request with wireshark, so that I could reproduce it. This is what it looks like:</p>
<blockquote><p>GET /streamer/1.0?s=^GDAXI,USD=X&amp;o=^N225,LHS.F,JI4.F,EEX.F,HEI.F,CBK.F,PRE.F,NDX1.F&amp;k=c10,g00,h00,l10,p20,t10&amp;j=c10,l10,p20,t10&amp;r=0&amp;marketid=us_market&amp;callback=parent.yfs_u1f&amp;mktmcb=parent.yfs_mktmcb&amp;gencallback=parent.yfs_gencb HTTP/1.1<br />
Host: streamerapi.finance.yahoo.com</p></blockquote>
<p>Here is what I got on this request so far:</p>
<p>parameter &#8216;s&#8217; -&gt; symbol on the main site (what you currently looking at)</p>
<p>parameter &#8216;o&#8217; -&gt; that is the ticker on the top</p>
<p>parameter &#8216;k&#8217; and &#8216;j&#8217; -&gt; that are the values that are transfered</p>
<p>c10 -&gt; unknown</p>
<p>g00 -&gt; day low</p>
<p>h00 -&gt; day high</p>
<p>l10 -&gt; current price</p>
<p>p20 -&gt; unknown</p>
<p>t10 -&gt; timstamp</p>
<p>a00 -&gt; ask</p>
<p>b00 -&gt; bid</p>
<p>With that data you can build a Push-Client with your own custom data. Here is a sample Request for what I needed.</p>
<pre class="prettyprint lang-sh">wget -Obla 'http://streamerapi.finance.yahoo.com/streamer/1.0?s=^GDAXI,USD=X&amp;o=BEI.F,SIE.F,PRA.F&amp;k=l10,a00,b00,g00,h00&amp;j=l10,a00,b00,g00,h00&amp;r=0&amp;marketid=us_market&amp;callback=parent.yfs_u1f&amp;mktmcb=parent.yfs_mktmcb&amp;gencallback=parent.yfs_gencb'</pre>
<p>(Streaming the current &#8216;ask&#8217;, &#8216;bid&#8217; and &#8216;price&#8217; values for the stocks &#8216;BEI.F&#8217;,'SIE.F&#8217; and &#8216;PRA.F&#8217;.)</p>
<p>The response for that looks like that:</p>
<pre class="prettyprint lang-html">&lt;html&gt;
&lt;head&gt;
&lt;script type='text/javascript'&gt; document.domain='finance.yahoo.com';&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;&lt;/body&gt;
&lt;script&gt;try{parent.yfs_mktmcb({"unixtime":1228213139,"open":1228228200,"close":1228251600});}catch(e){}&lt;/script&gt;
&lt;script&gt;try{parent.yfs_u1f({"USD=X":{l10:"1.00",a00:"1.00",b00:"1.00",g00:"0.00",h00:"0.00"}});}catch(e){}&lt;/script&gt;
&lt;script&gt;try{parent.yfs_u1f({"BEI.F":{l10:"42.31",a00:"41.70",b00:"41.53",g00:"42.31",h00:"43.95"}});}catch(e){}&lt;/script&gt;
&lt;script&gt;try{parent.yfs_u1f({"SIE.F":{l10:"44.46",a00:"44.26",b00:"44.20",g00:"44.40",h00:"47.55"}});}catch(e){}&lt;/script&gt;</pre>
<p>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).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.underdog-projects.net/2008/12/use-yahoo-finance-streaming-api/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

