# Setting Up the Quote Retrieval

If you have more than a couple of commodities, you will tire of having to update their quotes constantly. &app; has the ability to automatically download the most recent quote for your commodities using the Internet. This is accomplished through the &app-perl; module &app-fq;, which must be installed in order to activate this feature.

## Prerequisites for an Online Quote update with &app-fq; are

- the &app-perl; language interpreter and

- the &app-perl;-module &app-fq; with any dependencies.

If you get stuck while performing the steps described here, you can reach many helpful users on the channels mentioned under .

You can also leave out this step and manually update your stock quotes.

## Installing &app-perl;

The installation of &app-perl; is essentially dependent on the operating system used. The effort for installation is low and is described in this section.

To check if &app-perl; is already installed on your system, call the command `perl -v` in the terminal.

    $ perl -v
    This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux-gnu-thread-multi

If you are shown the version number of the &app-perl; interpreter, skip the next details and continue instead with .

### On &lin;

1. On most systems &app-perl; is probably already installed. If with the previous command does not show a version, then the easiest way is to use your system’s package manager for installation.

2. When using the &app; &flatpak; package, &app-perl; and &app-fq; are already functionally installed.

### On &mac;

1. &app-perl; is normally already set up under &mac;.

### On &win;

1. Under &win; run the program &mc.winOS.inst-fq; to run. This will install Strawberry Perl. &app; Version 2.2.6 and before require ActivePerl. in version 5.8.

   &app; Version 2.4 and before require ActivePerl Version 5.16.3 and later.

2. For execution you need Administrator privilegies, which are requested in the dialog. The installation can take more then 15 minutes.

3. If during the installation the error message `No such file or directory` or `permission denied` are displayed, then it may help to disable the antivirus software temporarily.

Afterwards it’s a good idea to include the folder where &app; is installed, under &win; e.g. `C:\Program Files (x86)\gnucash\bin`, to your `PATH` environment variable. This way it’s easier for you to use some when needed. Please refer to the documentation for your operating system for more information.

## Installing &app-fq;

To determine if the &app-perl; module &app-fq; is already installed on your system, type `perldoc Finance::Quote` in a terminal window and check to see if there is any documentation

    $ perldoc Finance::Quote
    NAME
        Finance::Quote - Get stock and mutual fund quotes from various exchanges

    SYNOPSIS
           [...]

available. If you are now shown documentation, then &app-fq; is already installed and you can configure periodical quotes update as described in . If no documentation is displayed, you will have to continue with this chapter.

The process of installing &app-fq; depends on the system. For the different supported systems, you can follow the instructions below:

### On &lin;

1. Close &app;.

2. Run the `gnc-fq-check` command to verify that the program is already in a directory that is entered in the `PATH` environment variable. If you’ve installed &app; packages provided by your distribution, `gnc-fq-check` must be on your `PATH`. The currentness of your distribution can be checked under &app-fq;- versions.

3. Next, update with `sudo gnc-fq-update` or `su -c gnc-fq-update` with root privileges &app-fq;. It depends on your distribution. For more information, see the next chapter at .

4. Run `gnc-fq-dump` to check &app-fq; works properly. This program returns the version number of &app-fq; module currently installed as well as a list of sources available via the &app-fq; module. It will also inform you if there is a problem with your installation or if it is missing, and may suggest a fix.

### On &mac;

1. Close &app;.

2. Install &app-xcode; You can install &app-xcode; from the App Store or install the much smaller Xcode command line tools by running `sudo xcode-select --install` from a Terminal.app prompt. if it is not installed. It contains devel tools, which are required by CPAN to build and test the needed &app-fq; modules.

3. Run the Update Finance Quote app in the &app; dmg.

   You can run it from the dmg or copy it to the same folder to which you copied &app;. It will open a Terminal window and run a script for you which will ask lots of questions. Accept the default for each unless you know what you’re doing.

### On &win;

1. Close &app;.

2. Run &mc.winOS.inst-fq;. This is a small utility that installs &app-fq; for you.

## Helper Scripts for Update and Diagnostics

&app; provides several utilities that will help you select the correct symbols and verification for the desired online quote source. Another script performs the first-time installation or keeps &app-fq; up to date. And finally, tools for error analysis are also available.

### Running &app-perl; Scripts Under &win;

1. Open a CMD or Powershell window: Click Start and type either `cmd` or `powershell` then select the resulting menu item. You don't need to run as administrator.

2. Since, as previously recommended, the &app; directory was entered in the `PATH` envinronment variable, prefix any gnc-fq-xxx &app-perl; script command with Perl and a space, e.g. `perl gnc-fq-check`. Otherwise you have to execute the command e.g. `C:\strawberry-perl\bin\perl.exe C:\Program Files (x86)\gnucash\bin\ gnc-fq-check`.

### gnc-fq-check

This program returns the version number of &app-fq; module currently installed as well as a list of sources available via &app-fq;. It will also inform you if there is a problem with your installation and may suggest a fix.

    $ gnc-fq-check
    Can't locate Mozilla/CA.pm in @INC (you may need to install the Mozilla::CA module)
    (@INC contains: /usr/lib/perl5/site_perl/5.30.1/x86_64-linux-thread-multi /usr/
    lib/perl5/site_perl/5.30.1 /usr/lib/perl5/vendor_perl/5.30.1/x86_64-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.30.1 /usr/lib/perl5/5.30.1/x86_64-linux-thread-multi
    /usr/lib/perl5/5.30.1 /usr/lib/perl5/site_perl)
    at /usr/lib/perl5/vendor_perl/5.30.1/Finance/Quote/Tiaacref.pm line 33.
    Compilation failed in require at (eval 303) line 1.
    BEGIN failed--compilation aborted at (eval 303) line 1.
     at /usr/local/bin/gnc-fq-check line 91.
    ("1.47" "adig" "aex" "aiahk" "alphavantage" "amfiindia" "asegr" "asia" "asx"
    "australia" "bamosz" "bet" "bmonesbittburns" "bourso" "brasil" "bse" "bsero" "canada"
    "canadamutual" "citywire" "cominvest" "cse" "deka" "dutch" "dwsfunds" "europe"
    "fetch_live_currencies" "fidelity" "fidelity_direct" "fidelityfixed" "financecanada"
    "finanzpartner" "finland" "fool" "france" "ftfunds" "ftportfolios" "ftportfolios_direct"
    "fundlibrary" "goldmoney" "greece" "hex" "hu" "hufund" "hungary" "hustock" "indiamutual"
    "known_currencies" "lerevenu" "maninv" "morningstar" "morningstarjp" "mstaruk" "nasdaq"
    "nyse" "nz" "nzx" "platinum" "romania" "seb_funds" "sixfunds" "sixshares"
    "stockhousecanada_fund" "tdefunds" "tdwaterhouse" "tiaacref" "tnetuk" "troweprice"
    "troweprice_direct" "trustnet" "tsp" "tsx" "uk_unit_trusts" "ukfunds" "unionfunds"
    "usa" "usfedbonds" "vanguard" "vwd" "yahoo" "yahoo_asia" "yahoo_australia"
    "yahoo_brasil" "yahoo_europe" "yahoo_json" "yahoo_nz" "yahoo_yql" "za" "za_unittrusts")

The first part is the error message about a missing &app-perl;-modul Mozilla/CA.pm. At the end in parentheses is the normal output of the currently installed &app-fq; version The most recent &app-fq; version is &app-fq-vers;. and a list of available sources.

If an error is displayed, see the next section . Otherwise, continue with .

### gnc-fq-update

This program installs or updates the &app-fq; software module along with its dependencies.

Windows users are generally better off using the update-tool &mc.winOS.inst-fq;.

This program needs superuser or administrative privileges to succeed in &lin; or &mac; but not in &win;.

`gnc-fq-update` will launch a &app-perl; CPAN See CPAN Frequently Asked Questions for details. module internally. When you launch the CPAN module for the first time, you must setup and configure it. However, on the most systems if you accept the default settings or answer the first question `Are you ready for manual configuration? [yes]` with `no`, you will be able to install &app-fq; successfully.

### gnc-fq-dump

This program returns quote data for a source and a list of symbols in a format which is easy to read for humans. It is useful for checking that a given online quote source is up and functional.

You can use this command to verify that the symbol , which you want to use for your security for online quote retrieval, works for the desired qoute source. .

With `gnc-fq-dump` you can check symbols faster than from &app; if an error occurs during the retrieval with &app;. This might save you from running &app; with debug logging enabled while checking a nonworking symbol.

- To get verbose information about a security, run a command from the command line of the form:

                    gnc-fq-dump
                    -v
                    Source
                    Symbol

  e.g. `gnc-fq-dump -v yahoo_json IBM`.

- To retrieve currency exchange rate run the following command: `gnc-fq-dump -v currency USD EUR` Since &app-fq; 1.41 the default source for currencies is hardcoded to be Alpha Vantage. Also read the notes on . The old yahoo currencies are still available as `gnc-fq-dump yahoo_json USDEUR=X`.

To test that &app-fq; is working for currencies within &app;,

1. find a transaction between the desired commodity and the book currency and

2. right-click on it, then

3. select &gmi.ac.ed-ex; in the context menu.

The will appear. Click the Fetch Rate button and if everything is behaving itself the current rate will fill in the exchange rate box.

### gnc-fq-helper

This is a script that &app; uses to retrieve quotes and not usually useful for the user to run. Should the retrieval of a symbol in &app; result in failures, this script can be used to perform diagnostics and help developers decide if the error is in &app; or &app-fq;.

## Configuring for Getting Quotes Periodically

The command `gnucash-cli --quotes get &user-datafile;` The Online Quotes Retrieval command has been changed from &app; 4.0. The old command `gnucash --add-price-quotes &user-datafile;` is still available, but it is deprecated and will be removed in the future release. If you've upgraded from &app; 3.11 or previous version, it is recommended to use the new command `gnucash-cli`. can be used to fetch the current quotes of your stocks and write them directly into your &app;-data file without starting the GUI. Thus an automatic, regular updating of the price database is possible.

The command will fail if it cannot get a lock on the data file, for example if the data file is open in another &app; instance or if the last session for the file crashed.

The file specified &user-datafile; will depend on the name and location of your data file. This can be determined by the name displayed in the top frame of the &app; window, before the -.

The file name can also be found under File in the recently opened file list. If you place the mouse over the menu item with the number 1 in the list of recently opened files, the complete file name is displayed in the status bar.

You have to register the `gnucash-cli` with a scheduler in order to get Online Quotes automatically and periodically. The method depends on your OS.

### Automated quote retrieval every Friday at 4:00 p.m.

### On &lin; and &mac;

Register `gnucash-cli` with cron.

1. Run `crontab -e`.

2. Add the following line to your crontab:

       0 16 * * 5 gnucash-cli --quotes get &user-datafile; > /dev/null 2>&1

   If there is no graphic session that has already started the dbus, running on your computer at the time of the quote request, you must do the entry as follows instead:

       0 16 * * 5 env `dbus-launch` sh -c 'trap "kill $DBUS_SESSION_BUS_PID" EXIT;
       gnucash-cli --quotes get &user-datafile; > /dev/null 2>&1

   (Do not copy the line breaks into the crontab, they were inserted here only for the purpose of readability).

### On &win;

Register `gnucash-cli` with Task Scheduler.

1. Select Start Windows Administrative Tools Task Scheduler .

2. Select Create Task.

3. Enter the appropirate items on Create Task Window.

Adjust the time to the close of the stock exchange and consider fund quotes, that the net asset value (NAV) is determined well after the markets closed. The types have their description in .

Some users have made additions to the wiki and shared their experiences on the Online Quotes Page on GnuCash Wiki.