<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: bringing the yahoo finance stream to the shell</title>
	<atom:link href="http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 02 Jan 2012 22:31:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Ulf</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-410</link>
		<dc:creator>Ulf</dc:creator>
		<pubDate>Wed, 21 Apr 2010 12:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-410</guid>
		<description>Hello Jens,

thank you for your hint using streamerapi.


i am not whether it helps. i found some c code for buffering with libcurl. here we go:

//Declaration bla bla
#include 
#include &quot;/usr/include/curl/curl.h&quot;
#include &quot;/usr/include/curl/easy.h&quot;
using namespace std;

//Hello I am a function pointer!
int writer(char *data, size_t size, size_t nmemb, string *buffer){
	/* See: http://curl.haxx.se/libcurl/c/getinmemory.html */
	int result = 0;
	if(buffer != NULL) {
		buffer -&gt; append(data, size * nmemb);
		result = size * nmemb;
	}
	return result;
} 


//writer is used here
string download_data_to_buffer(string strUrl){
	/* (A) Variable Declaration */
	CURL *curl;			/* That is the connection, see: curl_easy_init */
	string buffer;		/* See: CURLOPT_WRITEDATA */	
	curl = curl_easy_init();	/* (B) Initilise web query */
	/* (C) Set Options of the web query 
	 * See also:  http://curl.haxx.se/libcurl/c/curl_easy_setopt.html  */
	if (curl){		
		curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str() );
		curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);	/* Function Pointer &quot;writer&quot; manages the required buffer size */
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;buffer );	/* Data Pointer &amp;buffer stores downloaded web content */	
	}	
    curl_easy_perform(curl);	/* (D) Fetch the data */
	curl_easy_cleanup(curl);	/* (E) Close the connection */
	return buffer;
}


compile with

g++ -c  -I/usr/include/curl piipapo.c
g++ -o testtest piipapo.o -L/usr/lib/libcurl -lcurl


I am not sure if it helps you.</description>
		<content:encoded><![CDATA[<p>Hello Jens,</p>
<p>thank you for your hint using streamerapi.</p>
<p>i am not whether it helps. i found some c code for buffering with libcurl. here we go:</p>
<p>//Declaration bla bla<br />
#include<br />
#include &#8220;/usr/include/curl/curl.h&#8221;<br />
#include &#8220;/usr/include/curl/easy.h&#8221;<br />
using namespace std;</p>
<p>//Hello I am a function pointer!<br />
int writer(char *data, size_t size, size_t nmemb, string *buffer){<br />
	/* See: <a href="http://curl.haxx.se/libcurl/c/getinmemory.html" rel="nofollow">http://curl.haxx.se/libcurl/c/getinmemory.html</a> */<br />
	int result = 0;<br />
	if(buffer != NULL) {<br />
		buffer -&gt; append(data, size * nmemb);<br />
		result = size * nmemb;<br />
	}<br />
	return result;<br />
} </p>
<p>//writer is used here<br />
string download_data_to_buffer(string strUrl){<br />
	/* (A) Variable Declaration */<br />
	CURL *curl;			/* That is the connection, see: curl_easy_init */<br />
	string buffer;		/* See: CURLOPT_WRITEDATA */<br />
	curl = curl_easy_init();	/* (B) Initilise web query */<br />
	/* (C) Set Options of the web query<br />
	 * See also:  <a href="http://curl.haxx.se/libcurl/c/curl_easy_setopt.html" rel="nofollow">http://curl.haxx.se/libcurl/c/curl_easy_setopt.html</a>  */<br />
	if (curl){<br />
		curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str() );<br />
		curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);<br />
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);	/* Function Pointer &#8220;writer&#8221; manages the required buffer size */<br />
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;buffer );	/* Data Pointer &amp;buffer stores downloaded web content */<br />
	}<br />
    curl_easy_perform(curl);	/* (D) Fetch the data */<br />
	curl_easy_cleanup(curl);	/* (E) Close the connection */<br />
	return buffer;<br />
}</p>
<p>compile with</p>
<p>g++ -c  -I/usr/include/curl piipapo.c<br />
g++ -o testtest piipapo.o -L/usr/lib/libcurl -lcurl</p>
<p>I am not sure if it helps you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-363</link>
		<dc:creator>Bryan</dc:creator>
		<pubDate>Fri, 05 Feb 2010 23:15:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-363</guid>
		<description>Would it be possible to access the stock info for a specified time of the day? Yahoo uses streamerapi for their Historical charts (which includes the current price for every minute of the day).

http://finance.yahoo.com/charts?s=IBM#chart1:symbol=ibm;range=1d;charttype=line;crosshair=on;ohlcvalues=0;logscale=on;source=undefined

I&#039;m not able to get anything returned from trying the URIs you mentioned, so I can&#039;t explore my idea, but do you think it might work if {&quot;open&quot; : &quot;1265380231&quot;, &quot;close&quot; : &quot;1265403631&quot;} (In the URI of course) were the same timestamp?

So theoretically I should be able to access the Bid price from 9:43 am for IBM from the historical data.</description>
		<content:encoded><![CDATA[<p>Would it be possible to access the stock info for a specified time of the day? Yahoo uses streamerapi for their Historical charts (which includes the current price for every minute of the day).</p>
<p><a href="http://finance.yahoo.com/charts?s=IBM#chart1:symbol=ibm;range=1d;charttype=line;crosshair=on;ohlcvalues=0;logscale=on;source=undefined" rel="nofollow">http://finance.yahoo.com/charts?s=IBM#chart1:symbol=ibm;range=1d;charttype=line;crosshair=on;ohlcvalues=0;logscale=on;source=undefined</a></p>
<p>I&#8217;m not able to get anything returned from trying the URIs you mentioned, so I can&#8217;t explore my idea, but do you think it might work if {&#8220;open&#8221; : &#8220;1265380231&#8243;, &#8220;close&#8221; : &#8220;1265403631&#8243;} (In the URI of course) were the same timestamp?</p>
<p>So theoretically I should be able to access the Bid price from 9:43 am for IBM from the historical data.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jens</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-224</link>
		<dc:creator>jens</dc:creator>
		<pubDate>Mon, 20 Jul 2009 14:38:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-224</guid>
		<description>Hi,

in general this looks perfectly fine to me. But there were a few things which troubled me with my implementation (mainly buffering). In short you have 3 buffers to look at. 
First one is easy - curl: Curl provides a parameter which disables the buffering (--no-buffer).
Second buffer is the pipe: On that end I can only speak for the linux implementation of pipes. You can&#039;t control pipe buffering. All pipes are controlled by the kernel and there is no way to influence that behavior.
Third buffer is the stdin buffer for your streamreader. In C you can influence that buffer size, so I think this should also be possible in C++ too.

For me solving the problems with the first and third buffer solved the problem. The kernel never did anything unexpected which prevents this from functioning (again - linux kernel).

Finally, the reason why google.com always works is easy. The site google.com has a relatively fixed size and after downloading this the stream will be closed. After the close all buffers will be flushed and you see all the data in you application. On the other hand, if this stream is not closed, the flush can take some time. Without explicit flushing (as explained above) the stream flushed very irregularly (several minutes) on my machine. So as you can see, without minimizing buffers it can take quite a while.

I hope this helps (If not just post again, maybe I can get a simple c++ application running on a Windows machine just to get more insight)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>in general this looks perfectly fine to me. But there were a few things which troubled me with my implementation (mainly buffering). In short you have 3 buffers to look at.<br />
First one is easy &#8211; curl: Curl provides a parameter which disables the buffering (&#8211;no-buffer).<br />
Second buffer is the pipe: On that end I can only speak for the linux implementation of pipes. You can&#8217;t control pipe buffering. All pipes are controlled by the kernel and there is no way to influence that behavior.<br />
Third buffer is the stdin buffer for your streamreader. In C you can influence that buffer size, so I think this should also be possible in C++ too.</p>
<p>For me solving the problems with the first and third buffer solved the problem. The kernel never did anything unexpected which prevents this from functioning (again &#8211; linux kernel).</p>
<p>Finally, the reason why google.com always works is easy. The site google.com has a relatively fixed size and after downloading this the stream will be closed. After the close all buffers will be flushed and you see all the data in you application. On the other hand, if this stream is not closed, the flush can take some time. Without explicit flushing (as explained above) the stream flushed very irregularly (several minutes) on my machine. So as you can see, without minimizing buffers it can take quite a while.</p>
<p>I hope this helps (If not just post again, maybe I can get a simple c++ application running on a Windows machine just to get more insight)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steve</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-223</link>
		<dc:creator>steve</dc:creator>
		<pubDate>Sat, 18 Jul 2009 16:20:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-223</guid>
		<description>Regarding my previous post its the other way round....
it works for normal response like
www.google.com
but does not work for
url “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”&#124;test.exe

Sorry about that, a bit tired...</description>
		<content:encoded><![CDATA[<p>Regarding my previous post its the other way round&#8230;.<br />
it works for normal response like<br />
<a href="http://www.google.com" rel="nofollow">http://www.google.com</a><br />
but does not work for<br />
url “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”|test.exe</p>
<p>Sorry about that, a bit tired&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steve</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-222</link>
		<dc:creator>steve</dc:creator>
		<pubDate>Sat, 18 Jul 2009 16:01:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-222</guid>
		<description>Hi,

I am on windows 2000, doing something like 
curl URL&#124;test.exe

Apparently, I am not getting anything from curl because the stream is continuous. However, I can get some thing if I do
curl &quot;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&quot;&#124;test.exe

Any help will be great.


#include &quot;stdafx.h&quot;
#include 
#include 
#include 
#include 
#include 

using namespace std;



int main(int argc, char* argv[])
{
	ofstream myfile;
	
	string s;
	string buf;
	do {
	myfile.open (&quot;example.txt&quot;);
	cin &gt;&gt; buf;
	s.append(buf);
	myfile &lt;&lt; buf;
	myfile.close();
	} while (!cin.eof());
	
	
	return 0;
}</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I am on windows 2000, doing something like<br />
curl URL|test.exe</p>
<p>Apparently, I am not getting anything from curl because the stream is continuous. However, I can get some thing if I do<br />
curl &#8220;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&#8221;|test.exe</p>
<p>Any help will be great.</p>
<p>#include &#8220;stdafx.h&#8221;<br />
#include<br />
#include<br />
#include<br />
#include<br />
#include </p>
<p>using namespace std;</p>
<p>int main(int argc, char* argv[])<br />
{<br />
	ofstream myfile;</p>
<p>	string s;<br />
	string buf;<br />
	do {<br />
	myfile.open (&#8220;example.txt&#8221;);<br />
	cin &gt;&gt; buf;<br />
	s.append(buf);<br />
	myfile &lt;&lt; buf;<br />
	myfile.close();<br />
	} while (!cin.eof());</p>
<p>	return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steve</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-220</link>
		<dc:creator>steve</dc:creator>
		<pubDate>Sun, 12 Jul 2009 21:34:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-220</guid>
		<description>I solved it using &quot; for the URL, my bad.</description>
		<content:encoded><![CDATA[<p>I solved it using &#8221; for the URL, my bad.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steve</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-219</link>
		<dc:creator>steve</dc:creator>
		<pubDate>Sun, 12 Jul 2009 15:14:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-219</guid>
		<description>One question guys, does this script work on Sundays?

Here is the error message when I tried on Sunday

D:\curl&gt;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
&#039;k&#039; is not recognized as an internal or external command,
operable program or batch file.
&#039;callback&#039; is not recognized as an internal or external command,
operable program or batch file.
&#039;mktmcb&#039; is not recognized as an internal or external command,
operable program or batch file.
&#039;gencallback&#039; is not recognized as an internal or external command,
operable program or batch file.</description>
		<content:encoded><![CDATA[<p>One question guys, does this script work on Sundays?</p>
<p>Here is the error message when I tried on Sunday</p>
<p>D:\curl&gt;curl -s -o &#8211; -N <a href="http://streamerapi.finance.yahoo.com/streamer/1.0?s=JAVA" rel="nofollow">http://streamerapi.finance.yahoo.com/streamer/1.0?s=JAVA</a><br />
,MSFT&amp;k=l10&amp;callback=parent.yfs_u1f&amp;mktmcb=parent.yfs_mktmcb&amp;gencallback=parent.<br />
yfs_gencb<br />
&#8216;k&#8217; is not recognized as an internal or external command,<br />
operable program or batch file.<br />
&#8216;callback&#8217; is not recognized as an internal or external command,<br />
operable program or batch file.<br />
&#8216;mktmcb&#8217; is not recognized as an internal or external command,<br />
operable program or batch file.<br />
&#8216;gencallback&#8217; is not recognized as an internal or external command,<br />
operable program or batch file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-169</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Thu, 18 Jun 2009 18:37:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-169</guid>
		<description>Hi, I tried to run the command shown but I get this error:

js: uncaught JavaScript runtime exception: ReferenceError: &quot;readline&quot; is not defined.

I&#039;m not familiar with java so I was wondering if there is another function I can use instead of readline.

BTW: I&#039;m running Mac OSX

Thanks</description>
		<content:encoded><![CDATA[<p>Hi, I tried to run the command shown but I get this error:</p>
<p>js: uncaught JavaScript runtime exception: ReferenceError: &#8220;readline&#8221; is not defined.</p>
<p>I&#8217;m not familiar with java so I was wondering if there is another function I can use instead of readline.</p>
<p>BTW: I&#8217;m running Mac OSX</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KrisBelucci</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-83</link>
		<dc:creator>KrisBelucci</dc:creator>
		<pubDate>Tue, 02 Jun 2009 08:18:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-83</guid>
		<description>Hi, good post. I have been wondering about this issue,so thanks for posting.</description>
		<content:encoded><![CDATA[<p>Hi, good post. I have been wondering about this issue,so thanks for posting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jens</title>
		<link>http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/comment-page-1/#comment-48</link>
		<dc:creator>jens</dc:creator>
		<pubDate>Mon, 11 May 2009 12:53:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=97#comment-48</guid>
		<description>&lt;a href=&quot;#comment-46&quot; rel=&quot;nofollow&quot;&gt;@ Prosenjit Kundu&lt;/a&gt; 
hey,

I tried it with ^DJI and the url works fine - here what I entered:
curl -s -o - -N &#039;http://streamerapi.finance.yahoo.com/streamer/1.0?s=^DJI&amp;k=l10&amp;callback=parent.yfs_u1f&amp;mktmcb=parent.yfs_mktmcb&amp;gencallback=parent.yfs_gencb&#039;

But there is a catch here. The javascript used to extract the information has the symbol hardcoded, so this needs to be refit.

For me I have an improved script, which does this a more generic way:
yfs_u1f = function(tmp) {
try{
  var source = tmp.toSource();
  var name = source.slice(source.indexOf(&quot;&#039;&quot;)+1,source.lastIndexOf(&quot;&#039;&quot;));
  var price = ((new Number(tmp[name].a00) + new Number(tmp[name].b00))/2);
  if(! isNaN(price) )
  {
  print(&quot;insert into realtime(symbol,date,price) values(&#039;&quot;+name+&quot;&#039;,current_timestamp,&quot;+price+&quot;);&quot;);
  }
}catch(ex){}
};

-&gt; But even in this version, the values requested, are hardcoded (in my version ask and bid). My tryouts to bring this into one generic c application failed so far, because the yahoo JSON code isn&#039;t a hundret percent compatible with the JSON standard.</description>
		<content:encoded><![CDATA[<p><a href="#comment-46" rel="nofollow">@ Prosenjit Kundu</a><br />
hey,</p>
<p>I tried it with ^DJI and the url works fine &#8211; here what I entered:<br />
curl -s -o &#8211; -N &#8216;<a href="http://streamerapi.finance.yahoo.com/streamer/1.0?s=" rel="nofollow">http://streamerapi.finance.yahoo.com/streamer/1.0?s=</a>^DJI&#038;k=l10&#038;callback=parent.yfs_u1f&#038;mktmcb=parent.yfs_mktmcb&#038;gencallback=parent.yfs_gencb&#8217;</p>
<p>But there is a catch here. The javascript used to extract the information has the symbol hardcoded, so this needs to be refit.</p>
<p>For me I have an improved script, which does this a more generic way:<br />
yfs_u1f = function(tmp) {<br />
try{<br />
  var source = tmp.toSource();<br />
  var name = source.slice(source.indexOf(&#8220;&#8216;&#8221;)+1,source.lastIndexOf(&#8220;&#8216;&#8221;));<br />
  var price = ((new Number(tmp[name].a00) + new Number(tmp[name].b00))/2);<br />
  if(! isNaN(price) )<br />
  {<br />
  print(&#8220;insert into realtime(symbol,date,price) values(&#8216;&#8221;+name+&#8221;&#8216;,current_timestamp,&#8221;+price+&#8221;);&#8221;);<br />
  }<br />
}catch(ex){}<br />
};</p>
<p>-> But even in this version, the values requested, are hardcoded (in my version ask and bid). My tryouts to bring this into one generic c application failed so far, because the yahoo JSON code isn&#8217;t a hundret percent compatible with the JSON standard.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

