<?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>Ray Acayan &#187; PHP</title>
	<atom:link href="http://www.RayAcayan.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.RayAcayan.com</link>
	<description>A Geek of All Trades</description>
	<lastBuildDate>Wed, 18 Aug 2010 19:40:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The Scrolling Stock Ticker Project</title>
		<link>http://www.RayAcayan.com/projects/the-scrolling-stock-ticker-project/</link>
		<comments>http://www.RayAcayan.com/projects/the-scrolling-stock-ticker-project/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 21:00:17 +0000</pubDate>
		<dc:creator>Ray Acayan</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Consulting]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Stocks]]></category>

		<guid isPermaLink="false">http://www.rayacayan.com/blog/?p=58</guid>
		<description><![CDATA[I. Overview The scrolling stock ticker above is a simple example of a lightweight component for retrieving real-time data and displaying it dynamically in a web browser. Many stock tickers today are based on heavy Java applets, which tend to slow down my computer considerably. Other tickers based on JavaScript and Ajax do not have [...]]]></description>
			<content:encoded><![CDATA[<p></br></p>
<h2 style="color:darkblue">I. Overview</h2>
<p>The scrolling stock ticker above is a simple example of a lightweight component for retrieving real-time data and displaying it dynamically in a web browser. Many stock tickers today are based on heavy Java applets, which tend to slow down my computer considerably. Other tickers based on JavaScript and Ajax do not have a scrolling feature. The basic marquee scrollers do not retrieve real-time data. So, I decided to develop my own simple scrolling stock ticker which combines all of these functions.<br />
<br /></br></p>
<h2 style="color:darkblue">II. Consulting</h2>
<p>I do my best to explain the concepts and techniques behind my projects.  If you like my work and can use my expertise in your projects, I am available for <span id="consulting_page" onmouseover="consulting_mouseOver()" onmousemove="consulting_mouseMove()" onmouseout="consulting_mouseOut()"><a href="http://www.rayacayan.com/blog/consulting/"><strong>consulting</strong></a></span> at a competitive rate.<br />
<br /></br></p>
<h2 style="color:darkblue">III. Components</h2>
<p><strong>1. Stock Data Retrieval Component</strong></p>
<p>This component is a group of PHP functions for querying a web data source, retrieving the resulting data, and storing the result in a DOM document object. These functions are located in a standalone PHP file.</p>
<p>First, the stock quotes are retrieved using the @fopen() file pointer to the following url:</p>
<div class="code">&#8220;http://finance.yahoo.com/d/quotes.csv?s=$stock&amp;f=sn1l1c1p2&amp;e=.csv&#8221;
</div>
<p>The Yahoo Finance site will return a comma-delimited CSV file based on the query parameters. More info on Yahoo&#8217;s data protocol can be found <a href="http://www.gummy-stuff.org/Yahoo-data.htm">here</a>. Other web services return data in RSS, JSON, or XML formats, which will require different query and parsing methods.</p>
<p>Next, the CSV-formatted results are parsed by the @fgetcsv() function, which stores the comma-delimited values into an array.  The array values are then placed into &lt;span&gt; elements and returned in the following format:</p>
<div class="code">&lt;span class=&#8221;stock_up&#8221;&gt;GOLD 5,000.00 +4,000.00, +400.0%&lt;/span&gt;</div>
<p><strong>2. CSS Display Component</strong></p>
<p>Not exactly a &#8220;component&#8221;, this is simply a CSS file which contains formatting for the &lt;span&gt; data above. For example:</p>
<div class="code">
.stock_up<br />
{<br />
&nbsp;&nbsp;  color: green;<br />
&nbsp;&nbsp;  cursor: hand;<br />
&nbsp;&nbsp;  cursor: pointer;<br />
&nbsp;&nbsp;  padding-bottom: 2px;<br />
&nbsp;&nbsp;  padding-left: 1em;<br />
&nbsp;&nbsp;  padding-right: 1em;<br />
&nbsp;&nbsp;  margin: 0px;<br />
}
</div>
<p><strong>3. Ajax Stock Update Component</strong></p>
<p>This component is a group of JavaScript functions for dynamically updating the stock quotes using Ajax.  Ajax is a group of web techniques for updating a web page without the user having to press the Refresh button.</p>
<p>The function uses the http_request.onreadystatechange property to call the Stock Data Retrieval Component (i.e. the standalone PHP file) to retrieve a new set of &lt;span&gt; elements containing the newly-updated stock quotes.  The document object is then updated dynamically by replacing the &lt;span&gt; contents of the &lt;div id=&#8221;RayStockTickerID&#8221;&gt; node as follows:</p>
<div class="code">document.getElementById(&#8216;RayStockTickerID&#8217;).innerHTML = http_request.responseText;</div>
<p><strong>4. Scrolling Marquee Component</strong></p>
<p>This component is a group of JavaScript functions which retrieve the stock quotes from the DOM document object, display the css-formatted stock quotes in a line of text, then scroll the text from right to left one pixel at a time with the setTimeout() function.</p>
<p>As each stock quote falls off the left of the screen, its &lt;span&gt; node is removed and appended to the end of the chain to create a continuous loop.  At the end of each loop, the stock quotes are updated dynamically by the Ajax Stock Update Component.</p>
<p><strong>5. Chart Display Component</strong></p>
<p>When you move the mouse to a particular stock in the ticker, this component will display an overlay of the corresponding daily stock chart.  This is accomplished using onmouseover() event handlers within each stock&#8217;s &lt;span&gt; tag.  The onmouseover() event calls a function which dynamically creates an &lt;img&gt; element and retrieves the chart from Yahoo Finance as follows:</p>
<div class="code">
  var imgbox=document.getElementById(&#8220;stockchart&#8221;);<br />
  imgbox.style.visibility=&#8217;visible&#8217;;<br />
  var img = document.createElement(&#8220;img&#8221;);<br />
  img.src=&#8217;http://ichart.finance.yahoo.com/t?s=&#8217; + stock;<br />
  imgbox.appendChild(img);
</div>
<p>The mousemove() function moves the chart based on the mouse cursor&#8217;s current position.  The onmouseout() function hides the chart by setting the imgbox visibility to &#8216;hidden&#8217;.</p>
<p><strong>6. Main Component</strong></p>
<p>The main component is a a section of PHP code in the main website which creates all the components above and initiates the program.<br />
<br /></br></p>
<h2 style="color:darkblue">IV. Future Enhancements</h2>
<p><strong>A. Different Input Formats</strong></p>
<p>As mentioned above, the input data streams may be formatted in RSS, JSON, XML, etc.  Functions can be developed for parsing and querying these other data protocols.</p>
<p><strong>B. Caching</strong></p>
<p>This simple project does not implement caching since it does not use previous stock data.  A cache can be developed to store data into an external database or text file before displaying it on the screen.</p>
<p><strong>C. Data Processing</strong></p>
<p>The incoming data can be processed and enriched before displaying to the web page.  For example, the stock ticker could display only those stocks which have crossed their 50-day moving average, or those that have exceeded their daily VaR limits within a portfolio.</p>
<p><strong>D. Different Output Formats</strong></p>
<p>Instead of a simple scrolling ticker display, this app can be modified to create an output data stream in other formats like RSS, JSON, XML, database, e-mail, etc, or other platforms such as Facebook, Twitter, and mobile devices.</p>
<p></br><br /></br></p>
]]></content:encoded>
			<wfw:commentRss>http://www.RayAcayan.com/projects/the-scrolling-stock-ticker-project/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

