Get Stock Quotes From Command Line

By  on  

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.

Recent Features

  • By
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

  • By
    CSS vs. JS Animation: Which is Faster?

    How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps? This article serves as a point-by-point...

Incredible Demos

  • By
    Telephone Link Protocol

    We've always been able to create links with protocols other than the usual HTTP, like mailto, skype, irc ,and more;  they're an excellent convenience to visitors.  With mobile phone browsers having become infinitely more usable, we can now extend that convenience to phone numbers: The tel...

  • By
    CSS Rounded Corners

    The ability to create rounded corners with CSS opens the possibility of subtle design improvements without the need to include images.  CSS rounded corners thus save us time in creating images and requests to the server.  Today, rounded corners with CSS are supported by all of...

Discussion

  1. Suraj

    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)

  2. Alper

    On Windows you may need to replace the single quotes with double quotes.

  3. I wrote you a simple shell script to use.

    https://gist.github.com/chrisopedia/1e30869645aab537be12

  4. Awesome share! Thank you.

  5. Harrison Delfino

    Using MarketXLS works for me. Its great.
    http://marketxls.com/stock-quotes-in-excel/

  6. Mike

    Any luck pulling an index?

  7. 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:

    curl -s "https://eodhistoricaldata.com/api/eod/AAPL.US?from=2017-01-05&to=2017-02-10&api_token=OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX&period=d"
    
  8. Joseph Spenner

    Just whipped this up using marketwatch.com. ie, for AAPL:

     curl -s https://www.marketwatch.com/investing/stock/aapl |grep '<meta name="price" content="' |cut -d'"' -f4
    
  9. JF

    If I use your command:

    curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=tsla&f=l1'
    

    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

  10. while 1 ; do clear ; for STONK in AMC AQB GME TSLA ; do echo -e -n "\e[1;36m${STONK}\t\e[1;33m" ; curl -s https://www.marketwatch.com/investing/stock/${STONK} |grep '<meta name="price" content="' |cut -d'"' -f4 ; echo -e -n "\e[0m" ; done ; sleep 60 ; done

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!