1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
--- orig/lib/Finance/Quote/Yahoo/Base.pm 2007-12-16 12:27:13.000000000 +0000
+++ lib/Finance/Quote/Yahoo/Base.pm 2008-03-08 16:02:04.000000000 +0000
@@ -56,7 +56,7 @@
# in the URL. These are recorded below, along with their corresponding
# field names.
-@FIELDS = qw/symbol name last date time net p_change volume bid ask
+@FIELDS = qw/symbol name last time date net p_change volume bid ask
close open day_range year_range eps pe div_date div div_yield
cap ex_div avg_vol currency/;
@@ -142,7 +142,7 @@
# yahoo_request (restricted function)
#
# This function expects a Finance::Quote object, a base URL to use,
-# a refernece to a list of symbols to lookup. If a fourth argument is
+# a reference to a list of symbols to lookup. If a fourth argument is
# used then it will act as a suffix that needs to be appended to the stocks
# in order to obtain the correct information. This function relies upon
# the fact that the various Yahoo's all work the same way.
@@ -189,12 +189,21 @@
@q = $quoter->parse_csv($_);
}
my $symbol = $q[0];
+ $symbol =~ s/GBP$/.L/;
my ($exchange) = $symbol =~ m/\.([A-Z]+)/;
# Strip out suffixes. Mmmm, functions as lvalues.
substr($symbol,-length($suffix),length($suffix)) = "";
- # If we weren't using a two dimesonal
+ # Some Yahoo Europe quotes have an N/A field before
+ # the date. Check for this and drop the N/A if it is
+ # there and the date is valid.
+
+ if($q[3] eq "N/A" && $q[4] =~ m/[0-9]+:[0-9]{2}[AP]M/) {
+ splice(@q,3,1);
+ }
+
+ # If we weren't using a two dimensional
# hash, we could do the following with
# a hash-slice. Alas, we can't. This just
# loads all the returned fields into our hash.
@@ -245,6 +254,8 @@
# backward compatability. Needed because Yahoo
# returns GBP as GBp. There may be others.
$info{$symbol,"currency"} =~ tr/a-z/A-Z/;
+ # Remove spaces from currency.
+ $info{$symbol,"currency"} =~ s/ //;
# printf "Currency %s specified by Yahoo\n", $info{$symbol,"currency"};
} else {
# Determine the currency from the exchange name.
@@ -265,7 +276,7 @@
# return in pence. We'd like them to return in pounds
# (divide by 100).
if (defined($exchange)) {
- if (($exchange eq "L" && $info{$symbol,"currency"} eq "GBP") ||
+ if ((($exchange eq "L" || $exchange eq "MF") && $info{$symbol,"currency"} eq "GBP") ||
($exchange eq "TA")) {
foreach my $field ($quoter->default_currency_fields) {
next unless ($info{$symbol,$field});
--- ../orig/libfinance-quote-perl-1.13/test/yahoo_europe.t 2007-01-01 07:23:58.000000000 +0100
+++ test/yahoo_europe.t 2008-06-29 18:30:06.000000000 +0200
@@ -12,23 +12,23 @@
my $year = (localtime())[5] + 1900;
my $lastyear = $year - 1;
-my %quotes = $q->yahoo_europe("12150.PA","BOGUS.L");
+my %quotes = $q->yahoo_europe("UG.PA","BOGUS.L");
ok(%quotes);
# Check the nav values are defined. These are the most
# used and most reliable indicators of success.
-ok($quotes{"12150.PA","last"} > 0);
-ok(length($quotes{"12150.PA","name"}) > 0);
-ok($quotes{"12150.PA","success"});
-ok($quotes{"12150.PA", "currency"} eq "EUR");
-ok(substr($quotes{"12150.PA","isodate"},0,4) == $year ||
- substr($quotes{"12150.PA","isodate"},0,4) == $lastyear);
-ok(substr($quotes{"12150.PA","date"},6,4) == $year ||
- substr($quotes{"12150.PA","date"},6,4) == $lastyear);
+ok($quotes{"UG.PA","last"} > 0);
+ok(length($quotes{"UG.PA","name"}) > 0);
+ok($quotes{"UG.PA","success"});
+ok($quotes{"UG.PA", "currency"} eq "EUR");
+ok(substr($quotes{"UG.PA","isodate"},0,4) == $year ||
+ substr($quotes{"UG.PA","isodate"},0,4) == $lastyear);
+ok(substr($quotes{"UG.PA","date"},6,4) == $year ||
+ substr($quotes{"UG.PA","date"},6,4) == $lastyear);
# Make sure we don't have spurious % signs.
-ok($quotes{"12150.PA","p_change"} !~ /%/);
+ok($quotes{"UG.PA","p_change"} !~ /%/);
# Check that a bogus stock returns no-success.
ok(! $quotes{"BOGUS","success"});
@@ -39,13 +39,13 @@
ok($londonquotes{"BAY.L","success"});
ok($londonquotes{"BAY.L","currency"} eq "GBP");
ok(($londonquotes{"BAY.L","currency"} eq "GBP") &&
- !defined($londonquotes{"BAY.L","currency_set_by_fq"}));
+ defined($londonquotes{"BAY.L","currency_set_by_fq"}));
%londonquotes = $q->fetch("yahoo_europe","CCR.L");
ok($londonquotes{"CCR.L","success"});
-ok($londonquotes{"CCR.L","currency"} eq "EUR");
-ok(($londonquotes{"CCR.L","currency"} eq "EUR") &&
- !defined($londonquotes{"CCR.L","currency_set_by_fq"}));
+ok($londonquotes{"CCR.L","currency"} eq "GBP");
+ok(($londonquotes{"CCR.L","currency"} eq "GBP") &&
+ defined($londonquotes{"CCR.L","currency_set_by_fq"}));
# Copenhangen stocks should be returned in Danisk Krone (DKK).
@@ -53,7 +53,7 @@
ok($copenhagenquotes{"TDC.CO","success"});
ok($copenhagenquotes{"TDC.CO","currency"} eq "DKK");
ok(($copenhagenquotes{"TDC.CO","currency"} eq "DKK") &&
- !defined($copenhagenquotes{"TDC.CO","currency_set_by_fq"}));
+ defined($copenhagenquotes{"TDC.CO","currency_set_by_fq"}));
# Two stocks from the German XETRA. One in EUR and one in USD.
@@ -61,6 +61,6 @@
ok($xetraquotes{"DBK.DE","success"});
ok($xetraquotes{"DBK.DE","currency"} eq "EUR");
ok(($xetraquotes{"DBK.DE","currency"} eq "EUR") &&
- !defined($xetraquotes{"DBK.DE","currency_set_by_fq"}));
+ defined($xetraquotes{"DBK.DE","currency_set_by_fq"}));
|