| Online Stock Streaming using ASP.Net |
|
|
|
| Written by Shabdar | ||||||||
| Monday, 24 November 2008 11:51 | ||||||||
|
IntroductionIt always made me wonder how sites like http://finance.yahoo.com and http://finance.google.com display stock quotes online so quickly and without refreshing entire page. So I decided to implement something similar. It looks very difficult to implement these kind of streaming, but ASP.Net and it's feature rich AJAX controls makes it really simple to implement this. This is my first attempt to build similar streaming web page. This sample may sound fairly easy to you and some of you might think that everyone knows this. But it might provide a good base for those who wants to build similar web sites and still have no idea where to start. Using CodeSample code provided in this article includes a web page Default.aspx and Default.aspx.cs code behind. Default.aspx (UI) UI code is fairly simple. First component is Script Manager. This component is necessary for AJAX functionality. After Script Manager, next component is UpdatePanel. This ajax control stops ASP.Net page from posting back. Instead of posting back page, it sends control inputs to server using client side javascripts. When it receives response from server, it refreshes content inside it on client side. Next control is an AJAX timer control. It rebinds grid with new quotes every 2 seconds. Default.aspx.cs (Code Behind) GetGridData() function simulates quotes for different stock symbols. Instead of simulated data you can replace this function to fetch real time quotes from other sources. This function builds a data table using random quotes and returns it. Timer1_Tick() function is a timer function which executes every 2 seconds. It rebinds grid with simulated stock data. Points of InterestAs you can see here, I am using a simulation for stock quotes. It would be interesting to know how can we fetch real time quotes from Yahoo/Google or any other source.
These are few links I have found which discusses this,
Comments/Questions
Add New Comment/Question
|
||||||||
| Last Updated on Wednesday, 24 March 2010 09:32 | ||||||||