PDA

View Full Version : RSS/XML: Source for DOW, NASDAQ, S&P?


mattboy_slim
06-12-2009, 02:10 PM
I've been looking for two days (no kidding) for a free RSS feed that simply has the DJIA, NASDAQ, and S&P (can be delayed quotes).

I see that Yahoo has a widget that you can put on your site, but I'm looking for something that I can just pull the variables from and insert into an existing design.

Maybe I'm just not searching with the proper terms perhaps?

Thanks in advance,
Matt

scrupul0us
06-12-2009, 09:32 PM
http://www.quoterss.com/

mattboy_slim
06-12-2009, 09:35 PM
I looked at that one this morning. I was initially excited, but unfortunately the option to choose your format doesn't work, and it only gives you the Full HTML every time.

mattboy_slim
06-12-2009, 09:37 PM
...unless someone knows how to pull the relevant information from the HTML:
http://www.quoterss.com/quote.php?symbol=^DJI&frmt=3&Freq=0

Old Pedant
06-12-2009, 10:12 PM
Man isn't that a bummer!

I even tried forcing format 5 (which is what the <select> *should* give for CSV format) and it didn't affect anything.

Did you notice that the NASDAQ feed is essentially identical??

Well, it wouldn't be too hard to "screen scrape" the data out of the HTML in there.

You could do it pretty easily using a few regular expressions.

But what about just using the Yahoo CSV feed??? It would actually be easier to use than RSS, even.

example:
http://download.finance.yahoo.com/d/quotes.csv?s=MSFT&S=IBM&f=sl1d1t1c1ohgv&e=.csv
http://download.finance.yahoo.com/d/quotes.csv?s=MSFT&S=IBM&f=sl1d1t1c1ohgv&e=.csv

Notice that you just put each symbol you want in there with "s=XXX". I dunno if there is a limit on the number of symbols

mattboy_slim
06-12-2009, 10:16 PM
Hmm, I've never attempted to get data out of a CSV file. I'm definitely not opposed to doing that at all. Do you have any examples that you could give on pulling data from a CSV file like that?

Thanks,
Matt

Old Pedant
06-12-2009, 10:28 PM
Dirt simple.

I assume you will use msxml2.ServerXMLHTTP??

So just something like this:

<table border=1 cellpadding=5>
<%
yahoo = "http://download.finance.yahoo.com/d/quotes.csv?$$$f=sl1d1t1c1ohgv&e=.csv"

stockArray = Array( "msft","hp","ibm" )
stocks = ""
For s = 0 To UBound(stockArray)
stocks = stocks & "s=" & stockArray(s) & "&"
Next

url = Replace( yahoo, "$$$", stocks )

Set xml = Server.CreateObject("msxml2.ServerXMLHTTP")
xml.open "GET", url, False

xml.send

lines = Split( xml.ResponseText, vbNewLine )
For i = 0 To UBound(lines)
Response.Write "<tr><td>" & Replace( lines(i), ",", "</td><td>" ) & "</td></tr>" & vbNewLine
Next
%>
</table>


I just tried it and it works like a charm.

Naturally, in real life you'd instead split each line into pieces on the commas and then parse the individual parts to something reasonable.

Hang on a sec...I'll do a quicky demo of that.

Old Pedant
06-12-2009, 10:43 PM
<html>
<head>
<style>
td { font-family: courier; text-align: right; }
</style>
</head>
<body>
<table border=1 cellpadding=5>
<tr>
<th>Symbol</th>
<th>Last<br/>Price</th>
<th>Last<br/>Date</th>
<th>Last<br/>Time</th>
<th>Change</th>
<th>NASDAQ<br/>Opening</th>
<th>Daily<br/>High</th>
<th>Daily<br/>Low</th>
<th>Daily<br/>Volume</th>
</tr>
<%
yahoo = "http://download.finance.yahoo.com/d/quotes.csv?$$$f=sl1d1t1c1ohgv&e=.csv"

stockArray = Array( "msft","hp","ibm" )
stocks = ""
For s = 0 To UBound(stockArray)
stocks = stocks & "s=" & stockArray(s) & "&"
Next

url = Replace( yahoo, "$$$", stocks )

Set xml = Server.CreateObject("msxml2.ServerXMLHTTP")
xml.open "GET", url, False

xml.send

lines = Split( xml.ResponseText, vbNewLine )
For i = 0 To UBound(lines)
line = Trim(lines(i))
If line="" Then Exit For

data = Split( line, "," )
symbol = Replace( data(0), """", "" )
closePrice = FormatCurrency( CDBL(data(1)) )
lastDate = CDate( Replace( data(2), """", "" ) )
lastTime = CDate( Replace( data(3), """", "" ) )
change = FormatCurrency( CDBL(data(4)) )
openPrice = FormatCurrency( CDBL(data(5)) )
highPrice = FormatCurrency( CDBL(data(6)) )
lowPrice = FormatCurrency( CDBL(data(7)) )
volume = CLNG( data(8) )
%>
<TR>
<TD><%=symbol%></td>
<td><%=closePrice%></td>
<td><%=lastDate%></td>
<td><%=lastTime%></td>
<td><%=change%></td>
<td><%=openPrice%></td>
<td><%=highPrice%></td>
<td><%=lowPrice%></td>
<td><%=FormatNumber(volume,0)%></td>
</tr>
<%
Next
%>
</table>
</body>
</html>

Old Pedant
06-12-2009, 10:43 PM
How's that??

See? Much simpler than using an RSS feed.

scrupul0us
06-13-2009, 01:24 AM
gotta love xml and dom... staples in any developers tool kit

Old Pedant
06-13-2009, 01:42 AM
Would love them if anybody produce a *REAL* XML RSS feed for stock quotes.

He's right: Do a search for them and you find all sorts of other people reporting that they don't exist. One enterprising soul created his own, probably by scraping either the Yahoo CSV feed or by "screen scraping" one of the others. But he only offers a limited number of stocks.

mattboy_slim
06-15-2009, 02:53 PM
Sorry for the delay, I haven't checked back in since late Friday. I'll give this a shot this morning and report back in just a little bit!

Thanks so much OP, this looks amazing!

mattboy_slim
06-15-2009, 05:08 PM
Well, that's pretty slick, I greatly appreciate it. The only real change I added was to get the "percentage" down or up, along with stripping out some of the data that I don't need. I'm sure I'll be able to clean up the "changepercent" formula to strip out the multiple data conversions of 'openPrice' once I can be sure I won't break anything. In the future, I'll make the exchanges/stocks configurable, but for the purposes of this discussion and project, they are static.

For reference I'm pulling the graphs from the Yahoo site also. I added a slideshow of the (3) graphs with the "invert" filter applied (may not work in all browsers) so that the image matched the black background.

Full Source: (content of 'js_slideshow.js' in attachment as .txt)

<html>
<body onLoad="SLIDES.play();" style="background-color:black;width:500px;">

<script type="text/javascript" src="../_js/js_slideshow.js"></script>
<script type="text/javascript">
SLIDES = new slideshow("SLIDES");
SLIDES.timeout=7000
SLIDES.add_slide(s = new slide('http://ichart.finance.yahoo.com/t?s=%5EDJI'));
s.filter = 'progid:DXImageTransform.Microsoft.Fade() invert';
SLIDES.add_slide(s = new slide('http://ichart.finance.yahoo.com/t?s=%5EIXIC'));
s.filter = 'progid:DXImageTransform.Microsoft.Fade() invert';
SLIDES.add_slide(s = new slide('http://ichart.finance.yahoo.com/t?s=%5EGSPC'));
s.filter = 'progid:DXImageTransform.Microsoft.Fade() invert';
</script>



<div style="float:left;"><IMG name="SLIDESIMG" src="http://ichart.finance.yahoo.com/t?s=%5EDJI" style="width:160px;filter: invert progid:DXImageTransform.Microsoft.Fade();margin-top:18px;margin-left:18px;"></div>


<script type="text/javascript">
<!--
if (document.images) {

SLIDES.image = document.images.SLIDESIMG;

// Create a function to ramp up the image opacity in Mozilla
var fadein_opacity = 0.04;
var fadein_img = SLIDES.image;
function fadein(opacity) {
if (typeof opacity != 'undefined') { fadein_opacity = opacity; }
if (fadein_opacity < 0.99 && fadein_img && fadein_img.style &&
typeof fadein_img.style.MozOpacity != 'undefined') {

fadein_opacity += .05;
fadein_img.style.MozOpacity = fadein_opacity;
setTimeout("fadein()", 150);
}
}

// Tell the slideshow to call our function whenever the slide is changed
SLIDES.post_update_hook = function() { fadein(0.04); }

}
//-->
</script>



<div style="font-size:12px;font-weight:bold;margin-left:10px;float:left;">
<table cellspacing="0" cellpadding="5" style="margin-top:12px;" >

<%
Set xml = Server.CreateObject("msxml2.ServerXMLHTTP")
xml.open "GET", "http://download.finance.yahoo.com/d/quotes.csv?s=^DJI,^IXIC,^GSPC&f=sl1d1t1c1ohgv&e=.csv", False
xml.send

lines = Split( xml.ResponseText, vbNewLine )
For i = 0 To UBound(lines)
line = Trim(lines(i))
If line="" Then Exit For

data = Split( line, "," )
symbol = Replace( data(0), """", "" )
if symbol = "^DJI" then
symbol = "DJIA"
elseif symbol = "^IXIC" then
symbol = "NASDAQ"
elseif symbol = "^GSPC" then
symbol = "S&amp;P"
else
symbol = "Error"
end if

closePrice = FormatCurrency( CDBL(data(1)) )
lastDate = CDate( Replace( data(2), """", "" ) )
lastTime = CDate( Replace( data(3), """", "" ) )
change = cdbl(data(4))
if change <= 0 then
changecolor = "#cb0000"
else
changecolor = "#35cb00"
end if

openPrice = FormatCurrency( CDBL(data(5)) )
changepercent = round((clng(change) / clng(openPrice) * 100),2)
%>
<tr><td style="color:white;"><%=symbol%></td><td style="color:white;"><%=closePrice%></td><td style="color:<%=changecolor%>;text-align:right;"><%=change%></td><td style="color:<%=changecolor%>;text-align:right;"><%=changepercent%>%</td></tr>

<% next %>
</table>
</div>
<br style="clear:both;">

<div style="width:500px;color:white;font-size:12px;text-align:center;margin-top:45px;">Provided by Yahoo! Finance</div>

</body>
</html>


Thanks again for the great suggestion and the associated help with it.

Matt