Article Preview
Buy Now
COLUMN
From Scratch: Using StocksSocket in an Application
Issue: 2.3 (December/January 2003)
Author: William Leshner
Author Bio: William Leshner has been programming for twenty years and programming Macs for ten. He has spent a good deal of the last several years building REALbasic applications, including KidzMail, ResPloder, and several plugins and utilities.
Article Description: No description available.
Article Length (in bytes): 10,309
Starting Page Number: 40
Article Number: 2319
Resource File(s):
2319.zip Updated: 2013-03-11 19:07:57
Related Link(s): None
Excerpt of article text...
This is the third article in a series of three articles in which we are creating StocksSocket, a subclass of HTTPSocket that fetches stock information from a NASDAQ XML feed. In the first article we looked at how to subclass HTTPSocket to create StocksSocket and how to use StocksSocket to get stock information. In the second article we talked about how to parse the XML information we get back from the server. In this article we are going to see how to put StocksSocket to use in a simple application.
Stocks, The Project
"Stocks" is the name of the application that we will build on top of StocksSocket. Stocks is pretty simple; it consists of an EditField to enter comma-delimited stock symbols, a "Get" button to initiate a stock fetch, and a ListBox to display the results. We will only display the symbol, last price, and price change of each stock in the ListBox. We will add two simple enhancements to Stocks. The first enhancement is the ability to fetch stock information automatically every five minutes. The second enhancement is the ability to display each row in the ListBox in either red or green, depending on whether a stock is up or down.
We will begin Stocks with a blank REALbasic project. At the top of the blank window place an EditField, a PushButton, and a ChasingArrows control. Directly below those three controls place a ListBox. I like to name my controls as soon as possible so I don't forget and end up with a bunch of controls with similar names. I've named the main window "StocksWindow". I've named the EditField "QueryField", the PushButton "GetStocksButton", the ListBox "StocksListBox", and the ChasingArrows (yes, name that too) "ActivityIndicator".
The ListBox needs a bit of setup in the properties window. It will have three columns, so set its ColumnCount to 3. To set the column headings, enter "Symbol", "Last Price", and "Change" into the InitialValue property, each separated by a tab.
...End of Excerpt. Please purchase the magazine to read the full article.
Errata (2004-03-15)
Unfortunately, it appears that NASDAQ has shut down the stock feed that StocksSocket queries for stock information. I have yet to find a suitable replacement. The examples and code in these articles are still valuable, but they will no longer work to fetch stocks information. If I discover a replacement for the NASDAQ feed, I will update this page with the new information.