Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stock Quotes
Yahoo has a great service whereby is you sent it a list of stock symbols in a http request, it returns the quotes in a comma delimited string.
For example this line will give you a Microsoft quote:
More is documented here:

Anyway, I am attempting to use this to send stock quotes to my LED sign during the day. With HomeSeer I wrote a script to gather this data and it was pretty simple.

So, how should I do this in CQC? Do you think its possible to do it without a driver? If I can get the result in a variable, its pretty easy to split apart, but that is the trick.

Or another idea is use the RSS reader. I just need to find a service that processes quotes and returns the results as an RSS feed.
You would use the HTTPClient CML class to do the GET operation, then use the StringTokenizer to pull the values out. You'd have to have though some way of letting the user indicate what stocks he wants to watch, and therefore what fields are available, and deal with converting the names to valid field names, though if they use the standard ticker symbols I assume that would already be the case.
Dean Roddey
Explorans limites defectum
I 'cheated' and did this by creating an aspx file that gets the quotes from Yahoo's web service for specific symbols that it pulls from a config file. I set the WebBrowser to refresh every 5 minutes.

I started with the source located here
Care to share your work?
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
That sounds like a good idea, but I need the actual numbers to display on my LED sign. A web browser won't work in my situation. Thanks though.
It should be really easy to do a CML driver for a comma delimited list of stock symbols and quotes.

What I would do is create a configuration file which you would enter all your symbols into. Then in your CML driver you simply read that file line by line using a loop and then create your fields.

Then as Dean said you use the "HTTPClient CML class to do the GET operation" which should return the entire csv file. Then you just get the CVS file line by line in a loop and split out each line using the comma as the delimiter and store it in an array.

You can set it up to only poll when the market is open. The numbers probably only update every X mintues so you could limit the polling to say every 10 minutes between 9:30am and 4:00pm Monday through Friday. This would reduce the amount of network traffic for both you and yahoo.

You could get advanced and have CQC notify you when the price hits a certain level by using CQCs event system.

My personal opinion is that it's best to do this as a driver so that it can be distributed to others and also so that it integrates well with all the other feature of CQC.
Z-Wave World Magazine|Baltimore Hackerspace
"Why think outside the box when you could let the box think for you." - My take on Home Automation
Squintz has the right idea. The stock quotes will update about every minute, but they are delayed so you aren't getting real-time quotes. You will run into a problem with this feed though. Using Smart-Sniff you get what is shown below in the http stream, but the SendGET throws an exception with the error being "The connection was reset". You can try and ignore it and just xcode out x characters out of the buffer, but that doesn't always work.

Google has real time quotes that update once per second on a webpage, but no type of api or anything...yet. Hopefully that will happen eventually

Quote:GET /d/quotes.csv?s=msft+BA+ADBE&f=snl1d1t1ohgdr HTTP/1.0
User-Agent: Mozilla/4.0
Accept: */*

HTTP/1.1 200 OK
Date: Thu, 08 Jan 2009 15:59:14 GMT
Set-Cookie: B=7qh94gl4mc8mi&b=3&s=uj; expires=Tue, 02-Jun-2037 20:00:00 GMT; path=/;
Cache-Control: private
Connection: close
Content-Type: application/octet-stream

"MSFT","Microsoft Corpora",19.95,"1/8/2009","10:44am",19.68,19.97,19.55,0.46,10.31
"BA","BOEING CO",44.44,"1/8/2009","10:44am",44.50,44.6946,44.04,1.60,8.75
"ADBE","Adobe Systems Inc",24.09,"1/8/2009","10:44am",24.01,24.12,23.63,0.00,15.25

Edit: Here is a macro you can try out. You feed it the URL for the stock quote and the number of spaces you want between entries and it will return the parsed file as a string. If it looks like you aren't getting back all the information go into the macro and increase the size of ContLen on line 136. If you get a return back of "GetWebPage: The source data was
badly formed for this encoding" try reducing that number. To return the above quotes with 5 spaces between each entry you would use

Quote: 5 LVar:Quotes

Attached Files
.cqcmacropack   YahooStockQuotes.CQCMacroPack (Size: 1.85 KB / Downloads: 3)
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
sic0048 Wrote:Care to share your work?

I just noticed the version on my web server is not the one loading from a config file. I may have lost that in my latest main machine upgrade. Anyways, attached in the version I do have on my web server. You just update the list of symbols in quickquotes.aspx.

Attached Files
.zip (Size: 6.96 KB / Downloads: 15)

Possibly Related Threads…
Thread Author Replies Views Last Post
  CML Macros - Replacing Quotes gReatAutomation 2 264 02-13-2021, 11:59 AM
Last Post: Dean Roddey
  Fun with single and double quotes within strings jrlewis 10 3,144 09-08-2008, 12:46 PM
Last Post: Dean Roddey
  CML-Embedded Quotes in a String Mikla 2 960 12-17-2006, 07:56 AM
Last Post: Mikla

Forum Jump:

Users browsing this thread: 1 Guest(s)