Online Stock Quotes
December 8, 2003 9:18 PM   Subscribe

Stock quotes. No, not like "We don't need no steenkin' badges," the current price of a given stock. I need to put a little box on a page that will update (when refreshed) with current quotes for, say, five different specific stocks. This has got to be easy. Anybody got a free javascript lying around to do this? And if that's ridiculously simple, what about plotting the five specific stocks against each other over time?
posted by soyjoy to Computers & Internet (6 answers total)
As for JavaScript, I'd have no idea -- the very idea gives me the heebie jeebies. But the whole thing is probably 20 lines of Perl if you configure your web server to do SSI exec: scrape the data points, format, and emit them.

As far as plotting history, you'll need some kind of persistence for the data, which puts JavaScript right out unless you do something ridiculously and torturously clever. It's probably another 20ish lines of Perl or PHP to do if you can keep a database table up to date.
posted by majick at 9:32 PM on December 8, 2003

Thanks, majick. I could get someone to help with the Perl, I guess - I thought there would be a simpler way.

I didn't think JavaScript could handle the charting, of course. But when you say "keep a database table up to date" do you mean I would have to manually update the values or have some additional script that could handle that?
posted by soyjoy at 6:59 AM on December 9, 2003

Or if it's for personal use, you could just use an inline image and snag the images straight from Yahoo - Like this one:
posted by kokogiak at 9:59 AM on December 9, 2003

Presumably some other script would have to run -- as a cron job or with some other scheduling system -- to put the latest data points into database storage for you. While its there, you might as well have it generate the chart itself and plop the graphic somewhere you can serve it, since its only going to be updated as often as the script runs.

The quick and easy way to do all this -- if you were to ask me -- is with two scripts:

Script 1 runs every so often, scrapes the datapoints off your stock quote source, and shoves them in the database. While its at it, it generates a nice fresh chart and plops the file somewhere in your /images directory. The chart will lag a little behind the latest data points, but it'll be faster for your viewers.

Script 2 runs with every page load and scrapes the latest up-to-the-second values from your data source, then spits them out on the page. That's slow(ish; I have an few pages that do this kind of thing for personal use -- what movies are playing at my favorite theaters and the like -- which are quite fast enough, but they would quickly be crushed under the weight of the public gaze), but your specification above calls for "current quotes." If you can live with data as old as the most recent Script 1 run, you can just spit out the most recent values from your database.

That's about the simplest way that comes to mind. It's possible there's some quote service out there which provides a "plop this javascript on your site" snippet, but I wouldn't count on it.
posted by majick at 10:00 AM on December 9, 2003

We had the MSN/MoneyCentral ticker running on our intranet for a while. The guy that maintained it is long gone, and the code has been dismantled, but give this link a shot. It worked fine, allowed custom stock picks, and had news as well. Install the CNBC Ticker on Your Web site
posted by theora55 at 12:08 PM on December 9, 2003

Thanks, majick and all. This gives me a few options for how to handle this. I appreciate it.
posted by soyjoy at 1:20 PM on December 9, 2003

« Older Is it possible to direct certain groups of sounds...   |   Projection TVs Newer »
This thread is closed to new comments.