Yahoo shut down their stocks API a couple of years ago which of course made the posted script useless. I finally got
around to creating a replacement. After some searching I came across blog that provided a URL that will return
stock quotes. Links to the blog and github repo are provided in the attached script for those that are interested.
The data that is returned includes UTF-8 graphics characters which I strip out since aterm/xterm doesn't support them.
The data is also colorized. Since busybox less doesn't handle color, I strip those escape codes out as well.
If you have GNU less installed, you can enable color by setting the UseColor variable to 1.
The Stocks variable can be set to which stocks to display by default.
This is the help message:
tc@E310:~$ PriceQuote --help
Usage:
PriceQuote Get quotes for stocks listed in the Stocks variable.
Stocks=jpm,hd,aapl,axp,unh,gs
PriceQuote X,Y,Z Get quotes for X, Y, and Z instead of Stocks variable.
PriceQuote +X,Y,Z Get quotes for Stocks variable plus X, Y, and Z.
tc@E310:~$
When run, the script launches a new terminal and displays the results using less:
Stock Name Current Price Change % Change Day Range 52 Week Range
JPMorgan Chase & Co. 166.86 -0.75 -0.45 165.72 - 167.74 113.56 - 172.96
The Home Depot 372.63 5 1.36 366.70 - 373.50 246.59 - 375.15
Apple Inc. 149.99 2.12 1.43 147.48 - 150.40 112.59 - 157.26
American Express Company 181.89 0.59 0.33 179.65 - 182.38 111.90 - 189.03
UnitedHealth Group Incorporated 458.99 1.6 0.35 457.08 - 461.00 320.35 - 466.00
The Goldman Sachs Group 404.91 2.57 0.64 399.20 - 405.10 218.33 - 426.16
2021-11-12T21:00:02.000Z
The stocks listed here were used as examples only and chosen at random from the Dow 30. I own none of the stocks mentioned.
Of possible interest to anyone else who does any scripting:
I wrote a ToUpper function that allows you to pass a variable to it by reference instead of by value. In other words, you
pass the variable without the leading $ sign to the function:
ToUpper "VariableName"
The function then dereferences the variable to retrieve the string, converts it to uppercase, and places the result back
into the variable.
There is also a short section that calculates what size terminal is required to display the results.