June 21, 2008

ASP Stock Ticker

Another little ASP script that I had to whip up was a stock ticker. I had searched around for a free javascript version, however they where either way to complicated and ad ridden to use, or they just did not work. So like most situation call for I just gave up on that idea and whipped up my own version.

It is very simple, it just pulls the CVS data on the stock from yahoo finance and prints out a table row, that way I can use single calls in a table row, and just make a new row and call for each different stock. Also I have an up and down arrow image, but you can make your own. This should be a good starter for people looking for a simple stock ticker. I am using an asp include to call the whole page for code simplification, but you can just drop the code in a page and it will work.


<%
function getQuote(name,location)
strURL = location
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "GET",strUrl, false
objXMLHTTP.send
ProcessUrl = objXMLHTTP.ResponseText
Set objXMLHTTP = Nothing
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

dim quote
quote = Array()

' Split the string at the comma characters and add each field to a ListBox
quote = Split(ProcessUrl, ",")

if quote(4) >= 0 then
Response.Write "<td>" & name & "</td><td><img src='images/up.gif'></td><td><font color='green'>" & quote(1) & "</font></td><td><font color='green'>" & quote(4) & "</font></td>"
else
Response.Write "<td>" & name & "</td><td><img src='images/down.gif'></td><td><font color='red'>" & quote(1) & "</font></td><td><font color='red'>" & quote(4) & "</font></td>"
end if
end function
%>

<center>
<h3>Stock Ticker</h3>
<table width="190" border="0" cellspacing="1" cellpadding="1">
<tr>
<% getQuote "Dow", "http://download.finance.yahoo.com/d/quotes.csv?s=%5EDJI&f=sl1d1t1c1ohgv&e=.csv" %>
</tr>
<tr>
<% getQuote "Nasdaq", "http://download.finance.yahoo.com/d/quotes.csv?s=%5EIXIC&f=sl1d1t1c1ohgv&e=.csv" %>
</tr>
<tr>
<% getQuote "S&P 500", "http://download.finance.yahoo.com/d/quotes.csv?s=%5EGSPC&f=sl1d1t1c1ohgv&e=.csv" %>
</tr>
<tr>
<% getQuote "10Yr Bond(%)", "http://download.finance.yahoo.com/d/quotes.csv?s=%5ETNX&f=sl1d1t1c1ohgv&e=.csv" %>
</tr>
</table>
</center>

No comments: