Example Code

Checking Stock Prices With DataSocket in LabVIEW

Code and Documents

Attachment

Introduction

LabVIEW is not a traditional tool for financial management, but that doesn't mean you can't use it to check on your investments. This VI demonstrates how to use Yahoo.com's stock checker in an automated loop to keep track of your stock prices. It can be extrapolated to other instances where reading html source is necessary in LabVIEW.

Steps to Complete

Download Stock Checker.vi.

Run VI, after entering tickers in the left hand control.

Every three seconds, the prices update.

Stock Checker.png

Additional Notes

Yahoo updates slower than every three seconds, so you may want to turn down the update rate for processor considerations.

Example is written in LabVIEW 2009. If Yahoo's formatting changes, this may not work down the road.

Verne D. // Software R&D // National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Vignesh_Ramji
Member
Member
on

Hi Verne_D

Great share. I need to ask you as to why the field returns other text as opposed to the price for a given ticker ?

2018-08-30_13h46_13.png

GybrushThreepwood
Member
Member
on

Probably they changed the html string... so you'll need to correct the string search!

 

The best way to find out the strings you should search for is using a browser. Do the yahoo querry there. e.g.:

"http://finance.yahoo.com/q?s=BTC-USD"

then view the HTML of the page and search the Value you want. Then you can search the surrounding strings in labview.:

 

e.g.: in Firefox you see the line which belongs to the value

GybrushThreepwood_0-1583823951677.png

then you can adjust your string search to search the strings surrounding your wanted value:

 

GybrushThreepwood_1-1583824013405.png

and then you get the  values:

GybrushThreepwood_3-1583824273375.png

If they change their page constantly this might not be a good way to get the values cause you need to change your string search accordingly.

 

Anyway, I'll give it a try now and run it for some time 🙂

 

Thanks Verne_D for the basic vi and idea!! 🙂

Contributors