From 923b01e26952caf44f546b5c895dbb82d6ab9188 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 1 Sep 2015 14:47:40 -0700 Subject: [PATCH] Handle currencies with one-directional quotes and quotes < 1 in F::Q. Some currencies quotes are one-directional, so check both directions if necessary. Quotes with values < 1 often have too few significant digits, so in that case use the other direction if available. --- src/quotes/gnc-fq-dump | 9 +++++++++ src/quotes/gnc-fq-helper.in | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/quotes/gnc-fq-dump b/src/quotes/gnc-fq-dump index 2b1ab1e460..771e2ae201 100755 --- a/src/quotes/gnc-fq-dump +++ b/src/quotes/gnc-fq-dump @@ -166,6 +166,15 @@ if ($exchange eq "currency") { while ($#ARGV >= 0) { my $to = shift; my $result = $q->currency($from, $to); + unless (defined($result) && $result >= 1) { + my $inv_res = $q->currency($to, $from); + if (defined($inv_res)) { + my $tmp = $to; + $to = $from; + $from = $tmp; + $result = $inv_res; + } + } if (defined($result)) { printf "1 $from = $result $to\n"; } else { diff --git a/src/quotes/gnc-fq-helper.in b/src/quotes/gnc-fq-helper.in index edb6220c6c..6af1dee2e8 100755 --- a/src/quotes/gnc-fq-helper.in +++ b/src/quotes/gnc-fq-helper.in @@ -350,6 +350,19 @@ while(<>) { last unless $to_currency; my $price = $quoter->currency($from_currency, $to_currency); + my $inv_price = undef; + #Sometimes price quotes are available in only one direction, and if the + #direction we asked for results in a quote < 1 we want the other direction + #if it's available to get more significant digits. + unless (defined($price) && $price > 1) { + $inv_price = $quoter->currency($to_currency, $from_currency); + if (defined($inv_price)) { + my $tmp = $to_currency; + $to_currency = $from_currency; + $from_currency = $tmp; + $price = $inv_price; + } + } $quote_data{$from_currency, "success"} = defined($price); $quote_data{$from_currency, "symbol"} = $from_currency;