Difference between revisions of "Online Quotes"
m (Updated link to https://bugs.gnucash.org/show_bug.cgi?id=639776) |
(→Cron and Non-X Usage: Use {{BugURL}} to avoid future changes) |
||
Line 159: | Line 159: | ||
</Syntaxhighlight> | </Syntaxhighlight> | ||
− | ''Note: This has been documented in [ | + | ''Note: This has been documented in [{{BugURL}}/show_bug.cgi?id=639776 Bug #639776].'' |
== Technical Details == | == Technical Details == |
Revision as of 20:10, 3 October 2018
Back to: Using GnuCash | german version |
Contents
Overview
GnuCash stores the share prices of investments in the respective buy/sell/split transactions and additional quotes in an internal price database. Although it is possible to enter prices manually into the price database, it is more convenient to update them from online sources. GnuCash uses an external Perl module called Finance::Quote (F::Q) to fetch these quotes online.
Finance::Quote is managed at
- GitHub,
- CPAN (both recent), and
- SourceForge,
- SourceForge (hopeless outdated, last news: 2015-Aug-22 Release 1.38).
There are bugtrackers at
- http://rt.cpan.org/Public/Dist/Display.html?Status=Active&Name=Finance-Quote and
- https://github.com/finance-quote/finance-quote/issues.
Finance::Quote gathers its price data from several websites around the world that provide this information in different ways. Some offer
- an API like JSON or YQL,
- downloads, usually as CSV file, and finally
- quite literally by extracting information from the web page itself.
Because websites change frequently we advise you to keep Finance::Quote up-to-date.
The GnuCash Help includes instructions on setting up online quotes.
Finance::Quote is external to GnuCash. Thus, for it to work, you need Perl installed (see below), and occasionally you will need to update it separately from GnuCash.
Helper Scripts
For your convenience, we ship a bunch of gnc-fq-* programs, which again are Perl scripts:
- gnc-fq-check
- returns the version number and the list of available F::Q modules,
- gnc-fq-update
- installs or updates F::Q and its dependencies, if Perl is already installed;
- gnc-fq-dump
- returns data for a source and a list of symbols,
- gnc-fq-helper
- a filter, which does the same, but in- and output are Scheme expressions.
You might use them for troubleshooting, if Gnucash fails to update quotes.
Requirements
Perl
F::Q relies on Perl, which must be installed. Perl is handled differently on the different operating systems.
- Unix (Linux, AIX, *BSD, HPUX, Solaris,...): Perl is probably already installed or gets installed as dependency, if you install Finance::Quote by your systems package manager. Run
perl -v
on a command line to get the version number. If that fails, use your package manager to install it. - Mac OS X: Perl is already installed. Open a Terminal application (in the Utilities folder of your Applications folder) and run
perl -v
to see the version number. - Windows: <to be moved from Windows#Finance::Quote etc.>
Source: [1]
- Note
- While unixoid operating systems use a shebang
#!
to associate perl scripts with the perl interpreter, others might fail. So, if you get an error like
gnc-fq-check is not recognized as an internal or external command, operable program or batch file
- you should repeat the command with a preceeding perl:
perl gnc-fq-check
Finance::Quote
As mentioned previously, Finance::Quote is a Perl module that must be installed to enable online quote fetching. Finance::Quote, in turn, depends on a number of other Perl modules.
You can check the version and the list of available modules by running
gnc-fq-check
from the command line.
Installing or Updating
Both the Microsoft Windows and MacOS X GnuCash packages include update tools for Finance::Quote. In Windows it's called Install Online Price Retrieval
and it's located in the GnuCash group in the Start Menu. In OS X it's Update Finance::Quote
and it's in the dmg along with GnuCash. On Linux search in your distributions package manager for finance-quote. They may prefix it with perl, lib or both.
Note: You can re-run the Windows or MacOS installation tools as often as you like or you can use CPAN as explained below.
Depending on your operating system, there are other advanced ways to install F::Q.
- Linux:
- If there is no recent perl-finance-quote offered by your package manager do the following:
- As root (su / sudo) run the GnuCash Finance Quote update script
gnc-fq-update
- It will install Finance::Quote and its dependencies.
- Note for (Ubuntu based) distributions
- Some of them removed it from the package. In this case you can
- download it from github e.g. into your personal ~/bin directory,
- In the first line replace @-PERL-@ with the path to your perl executable, e.g., /usr/bin/perl, remove the trailing .in from its name and mark the file as executable.
- A discussion of how to fix it in Ubuntu can be found at [2].
- That script, as of 2.6.12, uses CPAN to install:
- Date::Manip
- Finance::Quote
- and their dependencies
- That script, as of 2.6.12, uses CPAN to install:
- MacOs:
- from a Terminal prompt:
/Applications/Gnucash.app/Contents/Resources/bin/gnc-fq-update
- Or use the applet that runs it from Finder in the dmg.
Using CPAN:
perl -MCPAN -e shell
# Either, if F::Q is missing, install it with
install Finance::Quote
# or, if F::Q is outdated, update it with
upgrade Finance::Quote
# finally check for Date::Manip
install Date::Manip
# and exit:
q
- Note
- On the first run of
cpan
it needs some configuration:
CPAN.pm requires configuration, but most of it can be done automatically. If you answer 'no' below, you will enter an interactive dialog for each configuration option instead. Would you like to configure as much as possible automatically? [yes]
- It is usually save to accept the defaults.
- Sources
- FAQ#Q: How do I install Finance::Quote on a Mac?
- Windows#Finance::Quote
- FAQ#Q: How do I fix a "system error" or "unknown error" when getting stock quotes?
Finding the right Source and Symbol
Because not all sources offer all commodities and different sources use different symbols, it is the high art to find the right combination. Common symbols are:
- Ticker symbols: 1-4 character abbreviation of company names, often used for US shares;
- National Security Identification Numbers: like CUSIP, often used by national fund companies;
- ISIN: International Security Identification Numbers, at least in the EU they are more and more replacing the different NSINs;
- sometimes completed by an appendix indicating the market place.
gnc-fq-dump -v <Source> <Symbol>
If your commodity is a mutual fund and F::Q offers its fund company as source (deka, dws, ...) look on their website, which symbols they use and you are done.
Is there a source for its registered exchange (AEX, ASX, ...) do the same.
In other cases google the ISIN to get a list of possible sources.
Global players: Alphavantage and Yahoo* are stronger in shares and Morningstar* in funds.
Updating enabled Quotes from outside GnuCash
You can run
gnucash --add-price-quotes /path/to/file.gnucash
or on MacOSX:
/Applications/Gnucash.app/Contents/MacOS/Gnucash --add-price-quotes /Users/<username>/Documents/test.gnucash
to update all enabled quotes.
Warning About Open Files
Updating quotes will modify the GNUCash file/database. As multi-user access is not supported, the file/database should be closed prior to updating quotes.
Cron and Non-X Usage
If you attempt to do that without dbus running (for example, from a cron job or ssh without X forwarding), you may get errors such as
GConf Error: Failed to contact configuration server; the most common cause is a missing or misconfigured D-Bus session bus daemon. See http://projects.gnome.org/gconf/ for information. (Details - 1: Not running within active session)
One resolution for this, courtesy of SyncEvolution - The Missing Link, is to launch dbus for the duration of the quote retrieval with a cron command similar to:
env `dbus-launch` sh -c 'trap "kill $DBUS_SESSION_BUS_PID" EXIT; gnucash --add-price-quotes /path/to/file.gnucash'
Note: This has been documented in Bug #639776.
Technical Details
Where the F::Q files are stored depends on your OS/Distro:
- Linux depends on the way it was installed:
- by package manager: /usr/share/perl5/[vendor/]Finance/Quote
- by CPAN or gnc-fq-update: /usr/share/perl5/site/Finance/Quote
- self compiled: /usr/local/share/perl/5.xx.x/Finance/Quote
- Windows: C:\Perl\site\lib\Finance\Quote
You can get the path by running:
perldoc -lm Finance::Quote
(Tested on Linux. Please update for: MacOS, Windows)