Terminal stock price display with Go

Programming Snapshot – Terminal Stock Portfolio

© Lead Image © Jakub Krechowicz, 123RF.com

© Lead Image © Jakub Krechowicz, 123RF.com

Article from Issue 277/2023
Author(s):

Instead of pulling up a browser to check his investments, Mike Schilli tracks stock prices with the help of a Go program to display graphs in the terminal.

According to US Vice President Kamala Harris, most US citizens would run out of money if faced by only $400 of unexpected costs. Since hearing this, I have made it my job to check every day whether I still have sufficient financial reserves. This includes tracking the current share price performance of some well-known companies. While there are many apps with portfolio settings that monitor a number of selected shares, I prefer to use command-line tools written in Go that run in a terminal window.

Figure 1 shows the output of the Go Pofo program (Pofo stands for portfolio). The Pofo program's output displays in six tiles (three at the bottom and three at the top), with each tile containing a bar chart to illustrate the share price performance of Apple, Netflix, Meta, Amazon, Tesla, and Google over the past six weeks. The program grabs the current and historical share price data from the data dealer Twelve Data [1] in a fraction of a second shortly after launching. Twelve Data offers a free basic plan for hobbyists that allows up to eight requests per minute and up to 800 per day before a limit kicks in.

The program fetches the closing prices in US dollars of the six monitored shares on the New York Stock Exchange for the past 45 business days. It does so in one fell swoop with a single request to the server. Figure 2 shows the data for the hyper-nervous Netflix stock in the period between June 16 and July 31, 2023. In this time frame, the value of the share fluctuated wildly between $413.17 and $477.59. Alas, in a graph of absolute values, it is still more or less impossible to see any fluctuations, because, after all, the difference only accounts for around 15 percent of the total value.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Perl: Portfolio Watch

    We'll show you a Perl script that helps you draw area graphs to keep track of your portfolio's performance.

  • Perl: PerlPanel

    One panel has a neat collection of applets and another has spectacular looks – but a combination of the two is rare. Now help draws nigh for the desktop: PerlPanel is extensible with do-it-yourself widgets.

  • Determining assets across a shrinking number of financial APIs

    Financial wizard Mike Schilli is annoyed that some web services have discontinued serving up real-time stock market data. To keep an eye on his investment dollars, Mike taps into a little known interface for stock prices.

  • Perl: Cucumber

    The Cucumber test framework helps developers and product departments jointly formulate test cases, not as program code, but in plain English. The initially skeptical Perlmeister has acquired a taste for this.

  • Perl: Personal Finances

    A helpful Perl script gives you an immediate overview of your financial status, adding the balances of multiple accounts and share depots. It even allows users to add their own plugins.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News