Building a Yahoo stock quote ticker
page 6 of 7
by Jason Perry
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 52472/ 60

Auto-Updating the Flash Ticker

We could stop here, but why not make our ticker auto update? We know that the Yahoo stock data is updated every 20 minutes so let's make our stock ticker check how long its been running and update itself using that interval.

Luckily, Flash has included the getTimer() method, which allows us to get the time in milliseconds our application has been running. With this we can set the current time on the timer and set an interval equal to 20 minutes or (20 * 60000). Now using the ClipEvent( enterFrame ) call back function we can determine if the ticker has been running for 20 minutes and, if so, update the stocks. For those who don't know, the ClipEvent( enterFrame ) is constantly called during the life time of an Flash Application, making it a good place for constant data checks.

To implement the timer, make the following code changes to the stockTicker movie clip.


	//sets interval for timer
onClipEvent( load )
{
	var current = getTimer();
	var interval = (20 * 60000);  //every 10 minutes syncs stock data
	
		//sets first set of stocks
	this.removeAll();
	_root.quoteArray.sort();
	for( quotes in _root.quoteArray )
	{
		_root.GetQuote( _root.quoteArray[quotes] );
	}
	
	this.setDataAllWidth( 0 );
	this.sortItemsBy( "text", "ASC" );
}

	//checks to see if timer has elapsed
onClipEvent( enterFrame )
{
			//time has elapsed
	if( (current + interval) <= getTimer() )
	{
		current = getTimer();

			//gets new data fro stocks
		this.removeAll();
		_root.quoteArray.sort();		
		for( quotes in _root.quoteArray )
		{
			_root.GetQuote( _root.quoteArray[quotes] );
		}

		this.setDataAllWidth( 0 );
		this.sortItemsBy( "text", "ASC" );
	}
}

View Entire Article

User Comments

Title: Nasdaq, S&P500 fix   
Name: John Dalnes
Date: 2009-07-15 1:11:34 PM
Comment:
I found this works for Nasdaq and other indexes
if (symbol.IndexOf("^") == 0)
{
url = "http://finance.yahoo.com/d/q?s=" + symbol + "&d=t&f=sl1d1t1c1ohgvj1pp2wern";

}
else
{

url = "http://quote.yahoo.com/d/quotes.csv?s=" + symbol + "&d=t&f=sl1d1t1c1ohgvj1pp2wern";
}
Title: index quotes   
Name: tilistor
Date: 2009-03-23 11:21:46 AM
Comment:
Dude try like this from your code:

http://download.finance.yahoo.com/d/quotes.csv?s=%5EDJI&f=sl1d1t1c1ohgv&e=.csv

Replace ^ with %5E

Cheers,
Title: webservice   
Name: stock market
Date: 2009-01-27 7:30:08 AM
Comment:
pls give the code how to access webservice in the aspx page in asp.net?
Title: Index quotes   
Name: Steve
Date: 2009-01-08 9:41:40 AM
Comment:
Did anyone solve this problem of the ^ being translated to the hex code "%5E"? If you enter the ^ mmaulaly in the browser within a URL it works fine. It doesn't work from within the my VB code webclient.
Title: index quotes again   
Name: kdasgupta
Date: 2008-12-06 6:13:17 PM
Comment:
Looks like Yahoo Quote stopped handling URL decoding of special characters. So, when I enter ^DJI for DOW, it is encoded as "%5EDJI". At Yahoo end, the special characters are not decoded to its corresponding character value, hence Yahoo quote service does not find any price data for the encoded symbol. "INDU" in place of ^DJI works fine.
Can anybode suggest fix for this problem? Thanks.
Title: index quotes again   
Name: Li
Date: 2008-10-30 7:52:35 PM
Comment:
I have the same problem getting S&P and Nasdaq. When I put in ^GSPC and ^IXIC, they are not working. But, if I put in "INDU", it works for Dow. Can anybody help?

thanks!
Title: Index quotes   
Name: Greg K.
Date: 2008-10-13 9:17:20 AM
Comment:
To get an index quote, use ^ instead of $.

Dow - ^DJI
S&P - ^GSPC
ND - ^IXIC

full list on finance.yahoo.com.

Good luck!
Title: WSDL file for web service   
Name: Edi Hansen
Date: 2008-07-21 12:45:11 PM
Comment:
Hi,
Is there a WSDL file for this web service? I'm trying to query web service via SSIS web services task..
thanks!
Title: Index values : $SPX, $COMPQ   
Name: Liya Tansky
Date: 2008-07-09 8:33:13 PM
Comment:
Hi, I'm trying to get values of indexes like $SPX and $COMPQ,
Your example works great for stocks, but returns empty data for $SPX. What should I change in the url in order to get to its values?

Thanks in advance
Title: Web service   
Name: Ces M
Date: 2008-06-26 9:59:57 AM
Comment:
The web service seems to work fine. It pulls data from Yahoo. My question is do I still need a flash remote package which is almost $1000? Or can we just use simple actionscript to get xml file from the web service?
Title: No longer works   
Name: Ben Poole
Date: 2008-05-22 10:59:23 AM
Comment:
it appears that Yahoo! has moved this web service, or changed the link. The pages I have used this code on are now broken, and I can't browse directly to the web service anymore.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 12:12:19 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search