Results 1 to 6 of 6

Thread: Newbie needs guidance on the next step past GUI--Importing Stock Data into App

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    6

    Newbie needs guidance on the next step past GUI--Importing Stock Data into App

    I'm taking a VB class for financial analysts, and we're tasked with constructing a progrm we can use on the job. What I'm trying to do is build a VB program that will take Stock and Company information from certain sites on the Internet and extracting that information into the program to do some research on a company before investing. I have some grand plans, but based upon what I have read/heard on this forum I'm taking stock information from two websites (Yahoo Finance and Reuters) and populate several different tabs in this program I'm making (exporting to an Access database and Excel are also in the works, but I think I can figure that out).

    I built the GUI with 4 different tabs that will house Earnings data, Trading Information, Company News, and Insider information that can be pulled from these two sites. I've attached the GUI to help give the flavor for what I'm trying to do. Here's an example of the sites I'm looking to grab data from (using COH as an example):

    http://finance.yahoo.com/q?s=COH
    http://finance.yahoo.com/q/ks?s=COH
    http://finance.yahoo.com/q/it?s=COH
    http://stocks.us.reuters.com/stocks/...utionalHolders
    http://stocks.us.reuters.com/stocks/...-15-Highlights

    I found a nifty little app that converts websites to DHTML and saves it on your PC in txt format, so I have decoded at least to that point.

    So here's my question. I know the basics of looping, arrays, procedures and functions, but I don't know where to begin on how to import web data into my little text boxes. It would seem like there's lots of different ways to do it, but I'm just looking for a gentle nudge in the right direction on the process by which I would go about doing this. Could somebody outline this for me? I'd really appreciate any guidance that could be provided.

    Thanks in advance for any help y'all can give.
    Attached Files Attached Files

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    6

    Re: Newbie needs guidance on the next step past GUI--Importing Stock Data into App

    BTW, I'm using Visual Studio 2005...

  3. #3
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: Newbie needs guidance on the next step past GUI--Importing Stock Data into App

    I am now developing a project in which I have to retrieve the EUR-USD ratio from the internet. I download the file from internet and then read it to update the EURUSD. I think you'll find the idea quite useful for your project:

    VB Code:
    1. 'Lee el cambio euro-dolar desde internet - Gets EURUSD from Internet
    2.         If My.Computer.Network.IsAvailable Then
    3.             Try
    4.                 ' Descarga fichero de internet - Downloads the file
    5.                 My.Computer.Network.DownloadFile(My.Settings.EURUSDurl, My.Settings.EURUSDfic, _
    6.                 String.Empty, String.Empty, False, My.Settings.TimeOutConexion, True)
    7.                 ' Establece nuevo cambio Euro-Dólar - Establish new EURUSD
    8.                 Dim cadena As String = File.ReadAllText(My.Settings.EURUSDfic).Trim
    9.                 Dim PosicionSeparador As Integer = cadena.IndexOf(",")
    10.                 cadena = Strings.Right(cadena, cadena.Length - PosicionSeparador - 1)
    11.                 txtEuroDolar.Text = cadena.Replace(".", CaracterDecimal)
    12.             Catch ex As Exception
    13.                 ' Superado el tiempo de conexión - Timeout
    14.                 lblConexion.Text = "TIMEOUT"
    15.             End Try
    16.         Else
    17.             lblConexion.Text = "SIN ACCESO" ' No access to network
    18.         End If

    The settings I am using are:
    EURUSDurl = http://finance.yahoo.com/d/quotes.cs...=X&f=sl1&e=txt

    TimeOutConexion = 10000

    EURUSDfic=EURUSD.txt

    P.D.: You can play with finance.yahoo.com url to find other economic values.

  4. #4
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: Newbie needs guidance on the next step past GUI--Importing Stock Data into App

    If you are wondering what caracterdecimal is...
    I live in Spain and our character for decimal is ',' instead of '.'
    I am just replacing decimal signs

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    6

    Re: Newbie needs guidance on the next step past GUI--Importing Stock Data into App

    Thanks, Shardox, this is definitely a good place to start for me...

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    6

    Re: Newbie needs guidance on the next step past GUI--Importing Stock Data into App

    Making progress here with Yahoo taking a different path, but uncertain how to code this next part. I have the first part of the app working now, it's actually pulling data from Yahoo Finance! Pretty cool stuff...makes me think this project is actually doable! But here's where I need help...


    My GetHTML function is declared like this:


    VB Code:
    1. Public Function GetPageHTML(ByVal URL As String) As String
    2.          ' Retrieves the HTML from the specified URL
    3.         Dim objWC As New System.Net.WebClient()
    4.         Return New System.Text.UTF8Encoding().GetString(objWC.DownloadData(URL))
    5.     End Function

    Then I go to the website and download the information from Yahoo Finance like this:


    VB Code:
    1. Private Sub btnRefresh1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh1.Click
    2.         'Goes to Yahoo Finance and grabs the data
    3.         Dim strHTML As String
    4.         strHTML = GetPageHTML("http://quote.yahoo.com/d/quotes.csv?s=COH&f=nl1va2c1")
    5.         'MsgBox(strHTML)
    6.         Dim separator As Char() = {","}
    7.         Dim returnValue As String()
    8.  
    9.         returnValue = strHTML.Split(separator)
    10.         'MsgBox(returnValue(0))
    11.         'MsgBox(returnValue(1))
    12.         txtCo1.Text = returnValue(0)
    13.         txtPrice1.Text = returnValue(1)
    14.         txtVol1.Text = returnValue(2)
    15.         txtAvgVol1.Text = returnValue(3)
    16.         txtChgVol1.Text = (returnValue(2) / returnValue(3)) - 1
    17.         txtPriceChg1.Text = returnValue(4)
    18.  
    19.         txtPrice1.Text = FormatCurrency(txtPrice1.Text, 2, TriState.UseDefault, TriState.True)
    20.         txtVol1.Text = FormatNumber(txtVol1.Text, 0, TriState.UseDefault, TriState.True)
    21.         txtAvgVol1.Text = FormatNumber(txtAvgVol1.Text, 0, TriState.UseDefault, TriState.True)
    22.         txtChgVol1.Text = FormatPercent(txtChgVol1.Text, 2, TriState.UseDefault, TriState.True)
    23.  
    24.     End Sub

    The above example has the stock symbol hard-wire into it (in this case "COH"). I'd like for it to take the symbol out of a box I have labeled "txtSymbol.text" and put it in where COH is currently located at. I'd also like to change the parameters at the end (in the above example this would be "nl1va2c1"). The parameters reference particular fields on the Yahoo pages that would correspond to things like price, volume, etc. The whole list can be found here

    So I would have basically a function to call upon with the standard "http://quote.yahoo.com/d/quotes.csv?s=" Then have the txtSymbol.text stock symbol inserted (which will change with each stock I analyze, grabbed from the text box), and then another function to call the parameters at the end (in this case nl1va2c1). Maybe some sort of concatenate function? How would I go about coding this correctly?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width