Consolidate all knowledge about Finance::Quote sources into one

place. Rename functions.  Determine if F::Q is installed properly, and
if so, what quote sources are installed.  Clean up actual calls to
F::Q.  If F::Q isn't available, dim the entire quotes frame in the
Edit Account dialog, and add a warning message about F::Q.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7650 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2002-12-08 00:21:25 +00:00
parent cd1b6b6b37
commit eb868d71d5
13 changed files with 444 additions and 170 deletions

View File

@ -1,3 +1,37 @@
2002-12-07 David Hampton <hampton@employees.org>
* src/app-utils/gnc-ui-util.c: Consolidate all knowledge about
Finance::Quote sources into one place. New and renamed functions
for mapping back and forth from Finance::Quote name to internal
name to user visible name. Functions to record whether or not F::Q
is installed properly, and if so, whether a particular source is
available.
* src/app-utils/gw-app-utils-spec.scm:
* src/gnome-utils/dialog-utils.c:
* src/scm/price-quotes.scm:
Removed all knowledge about Finance::Quote sources and now use the
common database.
* src/quotes/finance-quote-helper.in: Collapse all stock price
retrieval into a single call using the F::Q->fetch method instead
of individual per-source calls.
* src/quotes/finance-quote-check.in: New helper program to read
and return a list of all available F::Q methods.
* src/scm/price-quotes.scm: Code to call new finance-quote-check
program.
* src/scm/main.scm: Check for available F::Q methods when starting
up.
* src/gnome/glade/account.glade:
* src/gnome-utils/dialog-account.c:
* src/gnome-utils/dialog-utils.c:
When not retrieving stock quotes for an account, dim the price
source labels as well as the option menus.
2002-12-07 Derek Atkins <derek@ihtfp.com>
* src/register/ledger-core/split-register-control.c:
@ -25,7 +59,7 @@
gnc_commodity_equal(), because the average user doesn't need
to know why commodities are not equal.
2002-12-7 Benoit Grégoire <bock@step.polymtl.ca>
2002-12-07 Benoit Grégoire <bock@step.polymtl.ca>
More Doxygenification. Created an Engine module, and a
Deprecated list. Unfortunately, unless we turn on EXTRACT_ALL
(not very practical currently) not all functions will appear
@ -60,7 +94,7 @@
* po/nl.po: Fix use of msgid_plural by adding the appropriate
header entry.
2002-12-6 Benoit Grégoire <bock@step.polymtl.ca>
2002-12-06 Benoit Grégoire <bock@step.polymtl.ca>
* src/import-export/ofx/gnc-ofx-import.c: Do the "right"
thing for setting split amount and value.
@ -76,7 +110,7 @@
* po/nl.po -- don't use msgid_plural -- it fails to work.
2002-12-6 Benoit Grégoire <bock@step.polymtl.ca>
2002-12-06 Benoit Grégoire <bock@step.polymtl.ca>
* src/import-export/import-backend.c: Fix for gcc2

View File

@ -57,7 +57,49 @@ static int auto_decimal_places = 2; /* default, can be changed */
static gboolean reverse_balance_inited = FALSE;
static SCM reverse_balance_callback_id = SCM_UNDEFINED;
static gboolean reverse_type[NUM_ACCOUNT_TYPES];
static gboolean fq_is_installed = FALSE;
typedef struct quote_source_t {
gboolean supported;
gboolean translate;
char *user_name; /* User friendly name */
char *internal_name; /* Name used internally. */
char *fq_name; /* Name used by finance::quote. */
} quote_source;
static quote_source quote_sources[NUM_SOURCES] = {
{ TRUE, TRUE, N_("(none)"), NULL, NULL },
{ FALSE, TRUE, N_("-- Single Sources --"), NULL, NULL },
{ FALSE, FALSE, "AEX", "AEX", "aex" },
{ FALSE, FALSE, "ASX", "ASX", "asx" },
{ FALSE, FALSE, "DWS", "DWS", "dwsfunds" },
{ FALSE, FALSE, "Fidelity Direct", "FIDELITY_DIRECT", "fidelity_direct" },
{ FALSE, FALSE, "Motley Fool", "FOOL", "fool" },
{ FALSE, FALSE, "Fund Library", "FUNDLIBRARY", "fundlibrary" },
{ FALSE, FALSE, "TD Waterhouse Canada", "TDWATERHOUSE", "tdwaterhouse" },
{ FALSE, FALSE, "TIAA-CREF", "TIAACREF", "tiaacref" },
{ FALSE, FALSE, "T. Rowe Price", "TRPRICE_DIRECT", "troweprice_direct" }, /* Not Implemented */
{ FALSE, FALSE, "Trustnet", "TRUSTNET", "trustnet" },
{ FALSE, FALSE, "Union Investments", "UNIONFUNDS", "unionfunds" },
{ FALSE, FALSE, "Vanguard", "VANGUARD", "vanguard" },
{ FALSE, FALSE, "VWD", "VWD", "vwd" },
{ FALSE, FALSE, "Yahoo", "YAHOO", "yahoo" },
{ FALSE, FALSE, "Yahoo Asia", "YAHOO_ASIA", "yahoo_asia" },
{ FALSE, FALSE, "Yahoo Australia", "YAHOO_AUSTRALIA", "yahoo_australia" },
{ FALSE, FALSE, "Yahoo Europe", "YAHOO_EUROPE", "yahoo_europe" },
{ FALSE, FALSE, "Zuerich Investments", "ZIFUNDS", "zifunds" },
{ FALSE, TRUE, N_("-- Multiple Sources --"), NULL, NULL },
{ FALSE, FALSE, "Asia (Yahoo, ...)", "ASIA", "asia" },
{ FALSE, FALSE, "Australia (ASX, Yahoo, ...)", "AUSTRALIA", "australia" },
{ FALSE, FALSE, "Canada (Yahoo, ...)", "CANADA", "canada" },
{ FALSE, FALSE, "Canada Mutual (Fund Library, ...)", "CANADAMUTUAL", "canadamutual" },
{ FALSE, FALSE, "Dutch (AEX, ...)", "DUTCH", "dutch" },
{ FALSE, FALSE, "Europe (Yahoo, ...)", "EUROPE", "europe" },
{ FALSE, FALSE, "Fidelity (Fidelity, ...)", "FIDELITY", "fidelity" },
{ FALSE, FALSE, "T. Rowe Price", "TRPRICE", "troweprice" },
{ FALSE, FALSE, "U.K. Unit Trusts", "UKUNITTRUSTS", "uk_unit_trusts" },
{ FALSE, FALSE, "USA (Yahoo, Fool ...)", "USA", "usa" },
};
/********************************************************************\
* gnc_color_deficits *
@ -721,90 +763,127 @@ gnc_get_reconcile_flag_order (void)
/* Get the full name of a quote source */
const char *
gnc_get_source_name (PriceSourceCode source)
gnc_price_source_enum2name (PriceSourceCode source)
{
switch (source)
{
case SOURCE_NONE :
return _("(none)");
case SOURCE_YAHOO :
return "Yahoo";
case SOURCE_YAHOO_EUROPE :
return "Yahoo Europe";
case SOURCE_FIDELITY :
return "Fidelity";
case SOURCE_TROWEPRICE :
return "T. Rowe Price";
case SOURCE_VANGUARD :
return "Vanguard";
case SOURCE_ASX :
return "ASX";
case SOURCE_TIAA_CREF :
return "TIAA-CREF";
case SOURCE_TRUSTNET :
return "Trustnet";
case SOURCE_VWD :
return "VWD";
default:
break;
if (source >= NUM_SOURCES) {
PWARN("Unknown source %d", source);
return NULL;
}
PWARN("Unknown source");
return NULL;
return quote_sources[source].user_name;
}
/* Get the codename string of a quote source */
const char *
gnc_get_source_code_name (PriceSourceCode source)
gnc_price_source_enum2internal (PriceSourceCode source)
{
switch (source)
{
case SOURCE_NONE :
return NULL;
case SOURCE_YAHOO :
return "YAHOO";
case SOURCE_YAHOO_EUROPE :
return "YAHOO_EUROPE";
case SOURCE_FIDELITY :
return "FIDELITY";
case SOURCE_TROWEPRICE :
return "TRPRICE";
case SOURCE_VANGUARD :
return "VANGUARD";
case SOURCE_ASX :
return "ASX";
case SOURCE_TIAA_CREF :
return "TIAACREF";
case SOURCE_TRUSTNET :
return "TRUSTNET";
case SOURCE_VWD :
return "VWD";
default:
break;
if (source >= NUM_SOURCES) {
PWARN("Unknown source %d", source);
return NULL;
}
PWARN("Unknown source");
return NULL;
return quote_sources[source].internal_name;
}
/* Get the codename string of a source */
PriceSourceCode
gnc_get_source_code (const char * codename)
gnc_price_source_internal2enum (const char * internal_name)
{
gint i;
if (internal_name == NULL)
return SOURCE_NONE;
if (safe_strcmp(internal_name, "") == 0)
return SOURCE_NONE;
for (i = 1; i < NUM_SOURCES; i++)
if (safe_strcmp(internal_name, quote_sources[i].internal_name) == 0)
return i;
PWARN("Unknown source %s", internal_name);
return SOURCE_NONE;
}
/* Get the codename string of a source */
PriceSourceCode
gnc_price_source_fq2enum (const char * fq_name)
{
gint i;
if (fq_name == NULL)
return SOURCE_NONE;
if (safe_strcmp(fq_name, "") == 0)
return SOURCE_NONE;
for (i = 1; i < NUM_SOURCES; i++)
if (safe_strcmp(fq_name, quote_sources[i].fq_name) == 0)
return i;
// NYSE and Nasdaq have deliberately been left out. Don't always print them.
// PWARN("Unknown source %s", fq_name);
return SOURCE_NONE;
}
/* Get the codename string of a source */
const char *
gnc_price_source_internal2fq (const char * codename)
{
gint i;
if (codename == NULL)
return SOURCE_NONE;
return NULL;
if (safe_strcmp(codename, "") == 0)
return SOURCE_NONE;
return NULL;
if (safe_strcmp(codename, "CURRENCY") == 0)
return "currency";
for (i = 1; i < NUM_SOURCES; i++)
if (safe_strcmp(codename, gnc_get_source_code_name(i)) == 0)
return i;
if (safe_strcmp(codename, quote_sources[i].internal_name) == 0)
return quote_sources[i].fq_name;
PWARN("Unknown source");
return SOURCE_NONE;
PWARN("Unknown source %s", codename);
return NULL;
}
/* Get whether or not a quote source should be sensitive in the menu */
void
gnc_price_source_set_fq_installed (GList *sources_list)
{
GList *node;
PriceSourceCode code;
char *source;
if (!sources_list)
return;
fq_is_installed = TRUE;
for (node = sources_list; node; node = node->next) {
source = node->data;
code = gnc_price_source_fq2enum (source);
if ((code != SOURCE_NONE) && (code < NUM_SOURCES)) {
quote_sources[code].supported = TRUE;
}
}
}
gboolean
gnc_price_source_have_fq (void)
{
return fq_is_installed;
}
/* Get whether or not a quote source should be sensitive in the menu */
gboolean
gnc_price_source_sensitive (PriceSourceCode source)
{
if (source >= NUM_SOURCES) {
PWARN("Unknown source");
return FALSE;
}
return quote_sources[source].supported;
}
static const char *

View File

@ -116,23 +116,49 @@ char * gnc_account_get_full_name (Account *account);
typedef enum
{
SOURCE_NONE = 0,
SPECIFIC_SOURCES,
SOURCE_AEX,
SOURCE_ASX,
SOURCE_DWS,
SOURCE_FIDELITY_DIRECT,
SOURCE_FOOL,
SOURCE_FUNDLIBRARY,
SOURCE_TDWATERHOUSE,
SOURCE_TIAA_CREF,
SOURCE_TROWEPRICE_DIRECT,
SOURCE_TRUSTNET,
SOURCE_UNION,
SOURCE_VANGUARD,
SOURCE_VWD,
SOURCE_YAHOO,
SOURCE_YAHOO_ASIA,
SOURCE_YAHOO_AUSTRALIA,
SOURCE_YAHOO_EUROPE,
SOURCE_ZUERICH,
GENERAL_SOURCES,
SOURCE_ASIA,
SOURCE_AUSTRALIA,
SOURCE_CANADA,
SOURCE_CANADAMUTUAL,
SOURCE_DUTCH,
SOURCE_EUROPE,
SOURCE_FIDELITY,
SOURCE_TROWEPRICE,
SOURCE_VANGUARD,
SOURCE_ASX,
SOURCE_TIAA_CREF,
SOURCE_TRUSTNET,
SOURCE_VWD,
SOURCE_UKUNITTRUSTS,
SOURCE_USA,
NUM_SOURCES
} PriceSourceCode;
/* NOTE: If you modify PriceSourceCode, please update price-quotes.scm
as well. */
const char * gnc_get_source_name (PriceSourceCode source);
const char * gnc_get_source_code_name (PriceSourceCode source);
PriceSourceCode gnc_get_source_code (const char * codename);
const char * gnc_price_source_enum2name (PriceSourceCode source);
const char * gnc_price_source_enum2internal (PriceSourceCode source);
const char * gnc_price_source_internal2fq (const char * codename);
PriceSourceCode gnc_price_source_internal2enum (const char * internal_name);
PriceSourceCode gnc_price_source_fq2enum (const char * fq_name);
gboolean gnc_price_source_sensitive (PriceSourceCode source);
void gnc_price_source_set_fq_installed (GList *sources_list);
gboolean gnc_price_source_have_fq (void);
/* Locale functions *************************************************/

View File

@ -8,6 +8,7 @@
(use-modules (g-wrap gw-standard-spec))
(use-modules (g-wrap gw-wct-spec))
(use-modules (g-wrap gw-glib-spec))
(use-modules (g-wrapped gw-engine-spec))
@ -15,6 +16,7 @@
(gw:wrapset-depends-on ws "gw-standard")
(gw:wrapset-depends-on ws "gw-wct")
(gw:wrapset-depends-on ws "gw-glib")
(gw:wrapset-depends-on ws "gw-engine")
@ -428,6 +430,22 @@ determines formatting details.")
'()
"Returns the commodity EURO")
(gw:wrap-function
ws
'gnc:price-source-internal2fq
'(<gw:mchars> callee-owned const)
"gnc_price_source_internal2fq"
'(((<gw:mchars> caller-owned const) str))
"Returns a string with the Finace::Quote identifier correspopnding to the internal name.")
(gw:wrap-function
ws
'gnc:price-source-set-fq-installed
'<gw:void>
"gnc_price_source_set_fq_installed"
'(((gw:glist-of (<gw:mchars> callee-owned) callee-owned) choices))
"Takes a list of installed Finance::Quote souces and records it internally.")
(gw:wrap-function
ws
'gnc:account-separator-char

View File

@ -94,8 +94,11 @@ struct _AccountWindow
/* These probably don't belong here anymore, but until we figure out
what we want, we'll leave them alone. */
GtkWidget * price_quote_frame;
GtkWidget * get_quote_check;
GtkWidget * source_label;
GtkWidget * source_menu;
GtkWidget * quote_tz_label;
GtkWidget * quote_tz_menu;
GtkWidget * tax_related_button;
@ -205,7 +208,7 @@ gnc_account_to_ui(AccountWindow *aw)
if (price_src && aw->type != CURRENCY)
gtk_option_menu_set_history (GTK_OPTION_MENU (aw->source_menu),
gnc_get_source_code (price_src));
gnc_price_source_internal2enum (price_src));
}
{
@ -353,7 +356,7 @@ gnc_ui_to_account(AccountWindow *aw)
gint code;
code = gnc_option_menu_get_active (aw->source_menu);
string = gnc_get_source_code_name (code);
string = gnc_price_source_enum2internal (code);
old_string = xaccAccountGetPriceSrc (account);
if (safe_strcmp (string, old_string) != 0)
xaccAccountSetPriceSrc (account, string);
@ -1153,11 +1156,13 @@ gnc_type_list_select_cb(GtkCList * type_list, gint row, gint column,
gtk_widget_set_sensitive(aw->get_quote_check, sensitive);
gtk_widget_set_sensitive(aw->quote_tz_menu, sensitive && get_quote);
gtk_widget_set_sensitive(aw->quote_tz_label, sensitive && get_quote);
sensitive = (aw->type == STOCK ||
aw->type == MUTUAL);
gtk_widget_set_sensitive(aw->source_menu, sensitive && get_quote);
gtk_widget_set_sensitive(aw->source_label, sensitive && get_quote);
sensitive = (aw->type != EQUITY &&
aw->type != CURRENCY &&
@ -1183,7 +1188,9 @@ gnc_type_list_unselect_cb(GtkCList * type_list, gint row, gint column,
aw->type = BAD_TYPE;
gtk_widget_set_sensitive(aw->get_quote_check, FALSE);
gtk_widget_set_sensitive(aw->source_label, FALSE);
gtk_widget_set_sensitive(aw->source_menu, FALSE);
gtk_widget_set_sensitive(aw->quote_tz_label, FALSE);
gtk_widget_set_sensitive(aw->quote_tz_menu, FALSE);
}
@ -1423,11 +1430,13 @@ get_quote_check_cb (GtkWidget *w, gpointer data)
aw->type == MUTUAL ||
aw->type == CURRENCY);
gtk_widget_set_sensitive(aw->quote_tz_label, sensitive && get_quote);
gtk_widget_set_sensitive(aw->quote_tz_menu, sensitive && get_quote);
sensitive = (aw->type == STOCK ||
aw->type == MUTUAL);
gtk_widget_set_sensitive(aw->source_label, sensitive && get_quote);
gtk_widget_set_sensitive(aw->source_menu, sensitive && get_quote);
}
@ -1493,14 +1502,23 @@ gnc_account_window_create(AccountWindow *aw)
gtk_signal_connect (GTK_OBJECT (aw->commodity_edit), "changed",
GTK_SIGNAL_FUNC (commodity_changed_cb), aw);
if (gnc_price_source_have_fq()) {
gtk_widget_destroy(glade_xml_get_widget (xml, "finance_quote_warning"));
} else {
gtk_widget_set_sensitive(glade_xml_get_widget (xml, "price_quote_frame"),
FALSE);
}
aw->get_quote_check = glade_xml_get_widget (xml, "get_quote_check");
gtk_signal_connect (GTK_OBJECT (aw->get_quote_check), "toggled",
GTK_SIGNAL_FUNC (get_quote_check_cb), aw);
aw->source_label = glade_xml_get_widget (xml, "source_label");
box = glade_xml_get_widget (xml, "source_box");
aw->source_menu = gnc_ui_source_menu_create(aw_get_account (aw));
gtk_box_pack_start(GTK_BOX(box), aw->source_menu, TRUE, TRUE, 0);
aw->quote_tz_label = glade_xml_get_widget (xml, "quote_tz_label");
box = glade_xml_get_widget (xml, "quote_tz_box");
aw->quote_tz_menu = gnc_ui_quote_tz_menu_create(aw_get_account (aw));
gtk_box_pack_start(GTK_BOX(box), aw->quote_tz_menu, TRUE, TRUE, 0);

View File

@ -63,7 +63,8 @@ gnc_ui_source_menu_create(Account *account)
for (i = 0; i < NUM_SOURCES; i++)
{
item = gtk_menu_item_new_with_label(gnc_get_source_name(i));
item = gtk_menu_item_new_with_label(gnc_price_source_enum2name(i));
gtk_widget_set_sensitive(item, gnc_price_source_sensitive(i));
gtk_widget_show(item);
gtk_menu_append(menu, item);
}

View File

@ -427,7 +427,7 @@
<widget>
<class>GtkLabel</class>
<name>label813</name>
<name>source_label</name>
<label>The source for price quotes:</label>
<justify>GTK_JUSTIFY_RIGHT</justify>
<wrap>False</wrap>
@ -444,7 +444,7 @@
<widget>
<class>GtkLabel</class>
<name>label847713</name>
<name>quote_tz_label</name>
<label>Timezone for these quotes:</label>
<justify>GTK_JUSTIFY_RIGHT</justify>
<wrap>False</wrap>
@ -504,6 +504,24 @@
</widget>
</widget>
</widget>
<widget>
<class>GtkLabel</class>
<name>finance_quote_warning</name>
<sensitive>False</sensitive>
<label>Warning: Finance::Quote not installed properly.</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
</widget>

View File

@ -1,5 +1,6 @@
Makefile
Makefile.in
finance-quote-check
finance-quote-helper
update-finance-quote
histprices

View File

@ -2,7 +2,7 @@
gncsharedir = ${GNC_SHAREDIR}
bin_SCRIPTS = gnc-prices update-finance-quote
gncshare_SCRIPTS = finance-quote-helper
gncshare_SCRIPTS = finance-quote-helper finance-quote-check
EXTRA_DIST = \
.cvsignore \
@ -23,7 +23,14 @@ finance-quote-helper: finance-quote-helper.in
-e 's:@-PERLINCL-@:${PERLINCL}:g'
chmod +x $@.tmp
mv $@.tmp $@
CLEANFILES = finance-quote-helper
finance-quote-check: finance-quote-check.in
rm -f $@.tmp
sed < $< > $@.tmp \
-e 's:@-PERL-@:${PERL}:g' \
-e 's:@-PERLINCL-@:${PERLINCL}:g'
chmod +x $@.tmp
mv $@.tmp $@
update-finance-quote: update-finance-quote.in
rm -f $@.tmp
@ -32,4 +39,5 @@ update-finance-quote: update-finance-quote.in
-e 's:@-PERLINCL-@:${PERLINCL}:g'
chmod +x $@.tmp
mv $@.tmp $@
CLEANFILES += update-finance-quote
CLEANFILES = finance-quote-helper finance-quote-check update-finance-quote

View File

@ -0,0 +1,91 @@
#!@-PERL-@ -w
######################################################################
### finance-quote-check - check for the presence of Finance::Quote
### From finance-quote-helper.
### Copyright 2001 Rob Browning <rlb@cs.utexas.edu>
###
### This program is free software; you can redistribute it and/or
### modify it under the terms of the GNU General Public License as
### published by the Free Software Foundation; either version 2 of
### the License, or (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program# if not, contact:
###
### Free Software Foundation Voice: +1-617-542-5942
### 59 Temple Place - Suite 330 Fax: +1-617-542-2652
### Boston, MA 02111-1307, USA gnu@gnu.org
######################################################################
use lib '@-PERLINCL-@';
use strict;
use English;
use FileHandle;
# Input: <none>
#
# Output (on standard output, one output form per input line):
#
# A list of quote sources supported by Finance::Quote, or the single
# term missing-lib if finance quote could not be executed.
#
# Exit status
#
# 0 - success
# non-zero - failure
sub check_modules {
my @modules = qw(Date::Manip Finance::Quote LWP);
my @missing;
foreach my $mod (@modules) {
if (eval "require $mod") {
$mod->import();
}
else {
push (@missing, $mod);
}
}
return unless @missing;
print STDERR "\n";
print STDERR "You need to install the following Perl modules:\n";
foreach my $mod (@missing) {
print STDERR " ".$mod."\n";
}
print STDERR "\n";
print STDERR "Run 'update-finance-quote' as root to install them.\n";
print "missing-lib\n";
exit 1;
}
#---------------------------------------------------------------------------
# Runtime.
# Check for and load non-standard modules
check_modules ();
# Create a stockquote object.
my $quoter = Finance::Quote->new();
my $prgnam = "scmio-finance-quote";
my @qsources;
my @sources = $quoter->sources();
foreach my $source (@sources) {
push(@qsources, "\"$source\"");
}
printf "(%s)\n", join(" ", qq/@qsources/);
## Local Variables:
## mode: perl
## End:

View File

@ -334,63 +334,24 @@ while(<>) {
my($quote_method_name, $symbols) = @$result;
my %quote_data;
SWITCH:
{
if($quote_method_name =~ m/^yahoo$/) {
%quote_data = $quoter->yahoo(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^yahoo_europe$/) {
%quote_data = $quoter->yahoo_europe(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^fidelity_direct$/) {
%quote_data = $quoter->fidelity_direct(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^troweprice_direct$/) {
%quote_data = $quoter->troweprice_direct(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^vanguard$/) {
%quote_data = $quoter->vanguard(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^asx$/) {
%quote_data = $quoter->asx(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^tiaacref$/) {
%quote_data = $quoter->tiaacref(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^trustnet$/) {
%quote_data = $quoter->trustnet(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^vwd/) {
%quote_data = $quoter->vwd(@$symbols);
last SWITCH;
}
if($quote_method_name =~ m/^currency$/) {
my ($from_currency, $to_currency) = @$symbols;
if($quote_method_name =~ m/^currency$/) {
my ($from_currency, $to_currency) = @$symbols;
last SWITCH unless $from_currency;
last SWITCH unless $to_currency;
last SWITCH unless $from_currency;
last SWITCH unless $to_currency;
my $price = $quoter->currency($from_currency, $to_currency);
last SWITCH unless $price;
my $price = $quoter->currency($from_currency, $to_currency);
last SWITCH unless $price;
$quote_data{$from_currency, "success"} = 1;
$quote_data{$from_currency, "symbol"} = $from_currency;
$quote_data{$from_currency, "currency"} = $to_currency;
$quote_data{$from_currency, "last"} = $price;
$quote_data{$from_currency, "success"} = 1;
$quote_data{$from_currency, "symbol"} = $from_currency;
$quote_data{$from_currency, "currency"} = $to_currency;
$quote_data{$from_currency, "last"} = $price;
my @new_symbols = ($from_currency);
$symbols = \@new_symbols;
last SWITCH;
}
my @new_symbols = ($from_currency);
$symbols = \@new_symbols;
} else {
%quote_data = $quoter->fetch($quote_method_name, @$symbols);
}
if(!%quote_data) {

View File

@ -433,10 +433,16 @@ string and 'directories' must be a list of strings."
;; +jsled - 2002.07.08
(load-from-path "fin.scm")
(gnc:update-splash-screen (_ "Checking Finance::Quote..."))
(gnc:use-guile-module-here! '(gnucash price-quotes))
; (gnc:price-source-set-fq-installed (gnc:fq-check-sources))
(let ((sources (gnc:fq-check-sources)))
(if (list? sources)
(gnc:price-source-set-fq-installed sources)))
(gnc:update-splash-screen (_ "Loading tip-of-the-day..."))
(gnc:initialize-tip-of-the-day)
(gnc:use-guile-module-here! '(gnucash price-quotes))
(set-current-module original-module))
(gnc:hook-add-dangler gnc:*book-opened-hook*

View File

@ -23,6 +23,7 @@
(define-module (gnucash price-quotes))
(export yahoo-get-historical-quotes)
(export gnc:fq-check-sources)
(export gnc:book-add-quotes)
(export gnc:add-quotes-to-book-at-url)
@ -210,6 +211,47 @@
result)
#f))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define gnc:*finance-quote-check*
(gnc:find-file "finance-quote-check"
(gnc:config-var-value-get gnc:*share-path*)))
(define (gnc:fq-check-sources)
(let ((program #f))
(define (start-program)
(set! program (gnc:run-sub-process #f
gnc:*finance-quote-check*
gnc:*finance-quote-check*)))
(define (get-sources)
(and program
(let ((from-child (cadr program))
(results #f))
(catch
#t
(lambda ()
(write (list 'checking-sources))
(newline)
(set! results (read from-child))
;; (write (list 'results results)) (newline)
results)
(lambda (key . args)
key)))))
(define (kill-program)
(and program
(let ((pid (car program)))
(close-input-port (cadr program))
(close-output-port (caddr program))
(gnc:cleanup-sub-process (car program) 1))))
(dynamic-wind
start-program
get-sources
kill-program)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Finance::Quote based instantaneous quotes -- used by the
@ -356,35 +398,6 @@
;; (commodity-4 currency-4 tz-4) ...)
;; ...)
(define (src->fq-method-sym src)
(cond
((string=? "YAHOO" src) 'yahoo)
((string=? "YAHOO_EUROPE" src) 'yahoo-europe)
((string=? "FIDELITY" src) 'fidelity)
((string=? "TRPRICE" src) 'troweprice)
((string=? "VANGUARD" src) 'vanguard)
((string=? "ASX" src) 'asx)
((string=? "TIAACREF" src) 'tiaacref)
((string=? "TRUSTNET" src) 'trustnet)
((string=? "VWD" src) 'vwd)
((string=? "CURRENCY" src) 'currency)
(else #f)))
;; NOTE: If you modify this, please update finance-quote-helper.in as well.
(define (fq-method-sym->str src-sym)
(case src-sym
((yahoo) "yahoo")
((yahoo-europe) "yahoo_europe")
((fidelity) "fidelity_direct")
((troweprice) "troweprice_direct")
((vanguard) "vanguard")
((asx) "asx")
((tiaacref) "tiaacref")
((trustnet) "trustnet")
((vwd) "vwd")
((currency) "currency")
(else #f)))
(define (account->fq-cmd account)
;; Returns (cons fq-method-sym
;; (list commodity currency assumed-timezone-str))
@ -392,7 +405,7 @@
(currency (gnc:default-currency))
(src (and account (gnc:account-get-price-src account)))
(tz (gnc:account-get-quote-tz account))
(fq-method-sym (and src (src->fq-method-sym src)))
(fq-method-sym (and src (gnc:price-source-internal2fq src)))
(mnemonic (and commodity (gnc:commodity-get-mnemonic commodity))))
(and
commodity
@ -406,23 +419,23 @@
(currency-cmd-list (call-with-values
(lambda () (partition!
(lambda (cmd)
(not (eq? (car cmd) 'currency)))
(not (equal? (car cmd) "currency")))
big-list))
(lambda (a b) (set! cmd-list a) b)))
(cmd-hash (make-hash-table 31)))
;; Now collect symbols going to the same backend.
(item-list->hash! cmd-list cmd-hash car cdr hashq-ref hashq-set! #t)
(item-list->hash! cmd-list cmd-hash car cdr hash-ref hash-set! #t)
;; Now translate to just what finance-quote-helper expects.
(append
(hash-fold
(lambda (key value prior-result)
(cons (cons (fq-method-sym->str key) value)
(cons (cons key value)
prior-result))
'()
cmd-hash)
(map (lambda (cmd) (cons (fq-method-sym->str (car cmd)) (list (cdr cmd))))
(map (lambda (cmd) (cons (car cmd) (list (cdr cmd))))
currency-cmd-list))))
(define (fq-call-data->fq-calls fq-call-data)