1#!/usr/bin/perl -w 2use strict; 3use Test::More; 4use Finance::Quote; 5 6if ( not $ENV{"ONLINE_TEST"} ) { 7 plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; 8} 9 10if ( not $ENV{"TEST_ALPHAVANTAGE_API_KEY"} ) { 11 plan skip_all => 12 'Set $ENV{TEST_ALPHAVANTAGE_API_KEY} to run this test; get one at https://www.alphavantage.co'; 13} 14 15my $q = Finance::Quote->new('AlphaVantage', 'alphavantage' => {'API_KEY' => $ENV{"TEST_ALPHAVANTAGE_API_KEY"}} ); 16my $year = ( localtime() )[5] + 1900; 17my $lastyear = $year - 1; 18 19my @symbols = qw/ 20 IBM 21 CSCO 22 SOLB.BR 23 SAP.DE 24 TD.TO 25 VFIAX 26 T 27 DIVO11.SA 28 TWTR 29 AAPL 30 ORCL 31 FB 32 CMCSA 33 INTC 34 NFLX 35 TSLA 36 NOK 37 BAC 38 GOOG 39 F 40 AXP 41 ERCB.DE 42 MRT-UN.TRT 43 BP.L 44/; 45 46plan tests => 1 + 11*(1+$#symbols) + 10; 47 48my %quotes = $q->alphavantage( @symbols, "BOGUS" ); 49ok(%quotes); 50 51foreach my $symbol (@symbols) { 52 ok( $quotes{ $symbol, "success" }, "$symbol success" ); 53 ok( $quotes{ $symbol, "symbol" } eq $symbol , "$symbol defined" ); 54 ok( $quotes{ $symbol, "open" } > 0, "$symbol returned open" ); 55 ok( $quotes{ $symbol, "close" } > 0, "$symbol returned close" ); 56 ok( $quotes{ $symbol, "last" } > 0, "$symbol returned last" ); 57 ok( $quotes{ $symbol, "high" } > 0, "$symbol returned high" ); 58 ok( $quotes{ $symbol, "low" } > 0, "$symbol returned low" ); 59 ok( $quotes{ $symbol, "volume" } >= 0, "$symbol returned volume" ); 60 ok( $quotes{ $symbol, "p_change" } =~ /^[\-\.\d]+$/, "$symbol returned p_change" ); 61 ok( substr( $quotes{ $symbol, "isodate" }, 0, 4 ) == $year 62 || substr( $quotes{ $symbol, "isodate" }, 0, 4 ) == $lastyear ); 63 ok( substr( $quotes{ $symbol, "date" }, 6, 4 ) == $year 64 || substr( $quotes{ $symbol, "date" }, 6, 4 ) == $lastyear ); 65} 66 67is( $quotes{ "IBM", "currency" }, 'USD' ); 68is( $quotes{ "CSCO", "currency" }, 'USD' ); 69is( $quotes{ "ERCB.DE", "currency" }, 'EUR' ); 70is( $quotes{ "SOLB.BR", "currency" }, 'EUR' ); 71is( $quotes{ "SAP.DE", "currency" }, 'EUR' ); 72is( $quotes{ "TD.TO", "currency" }, 'CAD' ); 73is( $quotes{ "MRT-UN.TRT", "currency" }, 'CAD' ); 74is( $quotes{ "BP.L", "currency" }, 'GBP' ); 75is( $quotes{ "DIVO11.SA", "currency" }, 'BRL' ); 76 77ok( !$quotes{ "BOGUS", "success" } ); 78