Difference between revisions of "Online Quotes"

From GnuCash
Jump to: navigation, search
(Add more recent F::Q URLs)
(Updating enabled Quotes from outside GnuCash: grouping 'Warning About Open Files' and 'Cron and Non-X Usage'; use {{Version}}; syntaxhighlight)
Line 9: Line 9:
 
'''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.  
 
'''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.  
  
The GnuCash Help includes [http://www.gnucash.org/docs/v2.6/C/gnucash-help/acct-create.html#Online-price-setup instructions] on setting up online quotes.
+
The GnuCash Help includes [http://www.gnucash.org/docs/v{{Version}}/C/gnucash-help/acct-create.html#Online-price-setup instructions] on setting up online quotes.
  
 
==Requirements==
 
==Requirements==
Line 21: Line 21:
  
 
;Note: While [https://en.wikipedia.org/wiki/Unixoid unixoid] operating systems use a [https://en.wikipedia.org/wiki/Shebang_(Unix) shebang] <code>#!</code> to associate perl scripts with the perl interpreter, others might fail. So, if you get an error like
 
;Note: While [https://en.wikipedia.org/wiki/Unixoid unixoid] operating systems use a [https://en.wikipedia.org/wiki/Shebang_(Unix) shebang] <code>#!</code> to associate perl scripts with the perl interpreter, others might fail. So, if you get an error like
  gnc-fq-dump --help is not recognized as an internal or external command, operable program or batch file
+
  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 <tt>perl</tt>:
+
:you should repeat the command with a preceeding <tt>perl</tt>:
perl gnc-fq-dump --help
+
:<Syntaxhighlight lang="sh">
 +
perl gnc-fq-check
 +
</Syntaxhighlight>
  
 
===Finance::Quote===
 
===Finance::Quote===
Line 31: Line 33:
  
 
You can check the ''version'' and the list of ''available modules'' by running
 
You can check the ''version'' and the list of ''available modules'' by running
gnc-fq-check
+
<Syntaxhighlight lang="sh">
 +
gnc-fq-check
 +
</Syntaxhighlight>
 
from the command line.
 
from the command line.
  
 
If F::Q is missing, install it with
 
If F::Q is missing, install it with
perl -MCPAN -e shell
+
<Syntaxhighlight lang="sh">
 +
perl -MCPAN -e shell
 
   install Finance::Quote
 
   install Finance::Quote
 +
</Syntaxhighlight>
 
   
 
   
If F::Q is outdated, update it with
+
or, if F::Q is outdated, update it with
 +
<Syntaxhighlight lang="sh">
 
   upgrade Finance::Quote
 
   upgrade Finance::Quote
 +
</Syntaxhighlight>
  
 
You may also need  
 
You may also need  
  install Date::Manip
+
<Syntaxhighlight lang="sh">
 +
  install Date::Manip
 +
</Syntaxhighlight>
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Line 52: Line 62:
 
::If there is no recent perl-finance-quote offered by your ''package manager'' do the following:
 
::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  
 
::As root (su / sudo) run the GnuCash Finance Quote update script  
gnc-fq-update
+
::<Syntaxhighlight lang="sh">
 +
gnc-fq-update
 +
</Syntaxhighlight>
 
::It will install Finance::Quote and its dependencies.
 
::It will install Finance::Quote and its dependencies.
 
::* Some (Ubuntu based) distributions removed it from the package. In this case you can download it from [https://raw.github.com/Gnucash/gnucash/master/src/quotes/gnc-fq-update.in github].
 
::* Some (Ubuntu based) distributions removed it from the package. In this case you can download it from [https://raw.github.com/Gnucash/gnucash/master/src/quotes/gnc-fq-update.in github].
Line 64: Line 76:
 
:*'''MacOs:'''
 
:*'''MacOs:'''
 
::*from a Terminal prompt:
 
::*from a Terminal prompt:
/Applications/Gnucash.app/Contents/Resources/bin/gnc-fq-update
+
::<Syntaxhighlight lang="sh">
 +
/Applications/Gnucash.app/Contents/Resources/bin/gnc-fq-update
 +
</Syntaxhighlight>
 
::*Or use the applet that runs it from Finder in the dmg.
 
::*Or use the applet that runs it from Finder in the dmg.
  
 
Both the Microsoft Windows and MacOS X GnuCash packages include update tools for Finance::Quote. In Windows it's called "Install Online Banking" 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.
 
Both the Microsoft Windows and MacOS X GnuCash packages include update tools for Finance::Quote. In Windows it's called "Install Online Banking" 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.
  
==Warning About Open Files==
+
==Updating enabled Quotes from outside GnuCash==
 +
You can run
 +
:<Syntaxhighlight lang="sh">
 +
gnucash --add-price-quotes /path/to/file.gnucash
 +
</Syntaxhighlight>
 +
or on ''MacOSX'':
 +
:<Syntaxhighlight lang="sh">
 +
/Applications/Gnucash.app/Contents/MacOS/Gnucash --add-price-quotes /Users/<username>/Documents/test.gnucash
 +
</Syntaxhighlight>
 +
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.
 
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==
+
===Cron and Non-X Usage===
  
If you attempt to run
+
If you attempt to do that without [https://en.wikipedia.org/wiki/D-Bus dbus] running (for example, from a [https://en.wikipedia.org/wiki/Cron cron] job or [https://en.wikipedia.org/wiki/Secure_Shell ssh] without X forwarding), you may get errors such as
 
 
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
 
 
 
without [https://en.wikipedia.org/wiki/D-Bus 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.  
 
  GConf Error: Failed to contact configuration server; the most common cause is a missing or misconfigured D-Bus session bus daemon.  
Line 87: Line 105:
 
  (Details -  1: Not running within active session)
 
  (Details -  1: Not running within active session)
  
One resolution for this, courtesy of [http://www.estamos.de/blog/2009/05/08/running-syncevolution-as-cron-job/ SyncEvolution - The Missing Link], is to launch dbus for the duration of the quote retrieval with a cron command similar to
+
One resolution for this, courtesy of [http://www.estamos.de/blog/2009/05/08/running-syncevolution-as-cron-job/ SyncEvolution - The Missing Link], is to launch dbus for the duration of the quote retrieval with a cron command similar to:
 
+
<Syntaxhighlight lang="sh">
env `dbus-launch` sh -c 'trap "kill $DBUS_SESSION_BUS_PID" EXIT; gnucash --add-price-quotes /path/to/file.gnucash'
+
env `dbus-launch` sh -c 'trap "kill $DBUS_SESSION_BUS_PID" EXIT; gnucash --add-price-quotes /path/to/file.gnucash'
 +
</Syntaxhighlight>
  
''Note: This has been documented in [https://bugzilla.gnome.org/show_bug.cgi?id=639776 Bug #639776] ''
+
''Note: This has been documented in [https://bugzilla.gnome.org/show_bug.cgi?id=639776 Bug #639776].''
  
 
== Technical Details ==
 
== Technical Details ==
Line 103: Line 122:
  
 
You can get the path by running:
 
You can get the path by running:
perldoc -lm Finance::Quote
+
<Syntaxhighlight lang="sh">
 +
perldoc -lm Finance::Quote
 +
</Syntaxhighlight>
 
(Tested on Linux. Please update for: MacOS, Windows)
 
(Tested on Linux. Please update for: MacOS, Windows)
  
Line 109: Line 130:
  
 
* [https://code.gnucash.org/docs/C/gnucash-help/acct-create.html#Online-price-setup Development Snapshot]
 
* [https://code.gnucash.org/docs/C/gnucash-help/acct-create.html#Online-price-setup Development Snapshot]
* [http://www.gnucash.org/docs/v2.6/C/gnucash-help/acct-create.html#Online-price-setup 2.6 Help]
+
* [http://www.gnucash.org/docs/v{{Version}}/C/gnucash-help/acct-create.html#Online-price-setup {{Version}} Help]
* [http://www.gnucash.org/docs/v2.4/C/gnucash-help/acct-create.html#Online-price-setup 2.4 Help]
 
* [http://www.gnucash.org/docs/v2.2/C/gnucash-help/acct-create.html#Online-price-setup 2.2 Help]
 

Revision as of 05:22, 26 April 2018

Overview

GnuCash stores the share price of investments 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 at sourceforge, CPAN and GitHub (F::Q) to fetch these quotes online. Finance::Quote gathers its price data from websites 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.

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.

The GnuCash Help includes instructions on setting up online 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. Run perl -v on a command line to get the version number. If not, 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.

Note: You can re-run the Windows or OS X installation tools as often as you like or you can use CPAN as explained below.

You can check the version and the list of available modules by running

gnc-fq-check

from the command line.

If F::Q is missing, install it with

perl -MCPAN -e shell
  install Finance::Quote

or, if F::Q is outdated, update it with

  upgrade Finance::Quote

You may also need

  install Date::Manip

Troubleshooting

Depending on your operating system, there are other ways to install F::Q.

FAQ#Q: How do I install Finance::Quote on a Mac?
Windows#Finance::Quote
FAQ#Q: How do I fix a system error when getting stock quotes?
  • 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.
  • Some (Ubuntu based) distributions removed it from the package. In this case you can download it from github.
  • In the first line replace @-PERL-@ with the path to your perl executable, e.g., /usr/bin/perl 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
  • 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.

Both the Microsoft Windows and MacOS X GnuCash packages include update tools for Finance::Quote. In Windows it's called "Install Online Banking" 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.

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)

Documentation