Get Stock Quotes From Command Line
When I conned my way into my first professional programming gig, I didn't really think much about money -- just that I was getting my foot in the door. But as my career has gone on, I've been more aware of money, investing, and retirement. I've recently regretfully gotten into stock trading -- you can imagine how many times a day I hit the ole F5 to see updated quotes, praying my investments push higher.
I also spend a large part of my day in iTerm, so switching back and forth between the browser and the terminal is time-consuming and annoying. I looked for a way to get stock quotes from the command line, and thanks to Yahoo, it's a simple process!
Get Current Price
Since cURL is amazing and easy to use, we'll roll with that:
#One stock curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1' #Multiple stocks, separated by comma curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl,meip&f=l1'
Yahoo! Finance's information, which is fairly "real time", provides quotes within the s
parameter and the f
parameter of l1
provides the formatted result.
Get Current Price with Change
If you'd like to know the amount changed on the day, tag c1
to the f
parameter:
curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1c1'
Not needing to jump over to the browser to get stock quotes has been nice...especially if the market is having a down day and you don't want to see a screen of red. Booooo.
Is there a way to get quotes of multiple stocks from the same command?
I’ve updated my first example to show how to get multiple stocks! (separate by comma)
On Windows you may need to replace the single quotes with double quotes.
I wrote you a simple shell script to use.
https://gist.github.com/chrisopedia/1e30869645aab537be12
Excellent, thank you!
Awesome share! Thank you.
Using MarketXLS works for me. Its great.
http://marketxls.com/stock-quotes-in-excel/
Any luck pulling an index?
Before May 2017, I used Yahoo Finance, and it was great, but at the moment Yahoo! closed free access and I switched to https://eodhistoricaldata.com, highly recommend them, you can easy get everything, they have examples for Excel, python, R and even Matlab. Creating console example is very easy:
Just whipped this up using marketwatch.com. ie, for AAPL:
If I use your command:
And nothing is return, am I missing something ?
I just want to put TESLA stock value within my ” conky config / to show that on my desktop