I am writing an application that retreives stock information from a financial website. Presently I am using the WebClient method to retreive the HTML, and then I parse it using string functions. Then general structure of my code looks like this:
My code works fine, but is (I think) kind of slow. To download data for 500 stocks takes over ten minutes. I think my parsing code is quite efficient, so most of the time is taken up in getting the data from the website.
Is there a more efficient way to do this? Perhaps a faster method than the WebClient method? In particular, Im wondering if some advantage can be gained by the fact that all of the http requests are to the same website. The only thing that changes with each request is the search string on the end of the URL. In other words, once the connection to the server is established, perhaps you can recursively retreive information from the server without initiating a new request for each stock symbol?
Any suggestions or advice from you experts out there would be much appreciated! Thanks!
Code:
Public Function StockDownload()
Dim strStocks() = {array of stock symbols}
Dim intAllStocks = total number of stock symbols
Dim strData As String
Dim wc As New Net.WebClient()
Dim url As String
Main code
For i = 1 To intAllStocks
Get data from website
url = "web address" & "/q?s=" & strStocks(i - 1)
Dim b() As Byte = wc.DownloadData(url)
strData = System.Text.ASCIIEncoding.ASCII.GetString(b)
Parse Data
Here I have my code to parse the data
Next
My code works fine, but is (I think) kind of slow. To download data for 500 stocks takes over ten minutes. I think my parsing code is quite efficient, so most of the time is taken up in getting the data from the website.
Is there a more efficient way to do this? Perhaps a faster method than the WebClient method? In particular, Im wondering if some advantage can be gained by the fact that all of the http requests are to the same website. The only thing that changes with each request is the search string on the end of the URL. In other words, once the connection to the server is established, perhaps you can recursively retreive information from the server without initiating a new request for each stock symbol?
Any suggestions or advice from you experts out there would be much appreciated! Thanks!