0

TLDR: I am unable to get online stock quotes from within GnuCash and KMyMoney. It seems that something is wrong with the perl Finance::Quote module. What is the easiest way to fix this?

Background

Many free applications like KMyMoney and GnuCash use the perl library Finance::Quote to get stock, bond, and currency quotes from various websites. However, those websites often change their public-facing URLs, breaking this functionality for those applications. I am using a long-term support Linux distribution (Ubuntu LTS) because I like the stability, but there are no updates for this library in backports, so my software is now broken.

This recently happened with Ubuntu 22.04 LTS. KMyMoney installed with version 1.51 of Finance::Quote (libfinance-quote-perl, released in 2021), but a this is now failing due to recent changes on Yahoo. This is how I verified the installed version of this library:

perl -MFinance::Quote -e 'print "$Finance::Quote::VERSION\n"'

GnuCash has another utility that you can use to verify that this is the problem (replace yahoo_json with your data provider if different):

gnc-fq-dump -v yahoo_json AAPL

The error output looks something like the following:

Finance::Quote fields Gnucash uses:
    symbol: AAPL                 <=== required
      date: ** missing **        <=== recommended
  currency: ** missing **        <=== required
      last: **missing**          <=\
       nav: **missing**          <=== one of these
     price: **missing**          <=/
  timezone:                      <=== optional

** This stock quote cannot be used by GnuCash!

All fields returned by Finance::Quote for stock AAPL

stock field value


AAPL errormsg: Error retrieving quote for AAPL. Attempt to fetch the URL https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL resulted in HTTP response 401 (Unauthorized) AAPL last: missing AAPL nav: missing AAPL price: missing AAPL success: 0 AAPL symbol: AAPL

We can tell it is a server problem because it is returning HTTP code 401.

What is the best way to get online quotes working again that does not involve upgrading the entire operating system?

DavidPostill
  • 162,382

1 Answers1

1

There may be a number of ways to get an updated version of this library, including downloading the newer package from the next version of your distro and forcing it to install, or adding the next distro to your apt.sources.list and pinning the versions so that only this package updates, building a custom backport by adding the deb-src header for the next distro and running apt source -b, or some other things that I didn't consider (add your solutions below!)

Given that there should be a new 24.04 LTS release in the next few weeks, here is how I updated the library using CPAN:

  1. As the root user, run perl -MCPAN -e shell
  2. Answer any questions with the defaults. Install Term::Readline and CPAN::DistnameInfo if prompted and desired.
  3. Enter: upgrade Finance::Quote

This will install a new systemwide version of the library, including updating all the dependencies which may take a while. If you do not have a C compiler installed. you may need to sudo apt install build-essential to get started.

Once the upgrade is complete the same command can be used to do upgrades in the future. While this will "pollute" your installed packages, the nice thing is that the application dependencies don't break. The downside is that installing distro packages that were installed for the first time this way may get downgraded when other packages are installed.

Finally, running this command again shows success and the GUI applications now work:

gnc-fq-dump -v yahoo_json AAPL
The output now looks something like the following:
Finance::Quote fields Gnucash uses:
symbol: AAPL                 &lt;=== required
  date: 04/17/2024           &lt;=== recommended

currency: USD <=== required last: 168 <=
nav: <=== one of these price: <=/ timezone: <=== optional

All fields returned by Finance::Quote for stock AAPL

stock field value


AAPL close: 169.38 AAPL currency: USD AAPL date: 04/17/2024 AAPL div_yield: 0.56086904 [...] AAPL success: 1 AAPL symbol: AAPL AAPL type: EQUITY AAPL volume: 50205853 AAPL year_range: 162.8 - 199.62