dev-perl/Finance-Quote: Add v1.520 with AlphaVantage patch.
Package-Manager: Portage-3.0.30, Repoman-3.0.3
This commit is contained in:
		
							parent
							
								
									3593307469
								
							
						
					
					
						commit
						71b5f3492f
					
				
					 5 changed files with 207 additions and 0 deletions
				
			
		
							
								
								
									
										41
									
								
								dev-perl/Finance-Quote/files/alphavantage-currency.patch
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								dev-perl/Finance-Quote/files/alphavantage-currency.patch
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| diff --git a/lib/Finance/Quote/CurrencyRates/AlphaVantage.pm b/lib/Finance/Quote/CurrencyRates/AlphaVantage.pm
 | ||||
| index b6c4d7f..47b9393 100644
 | ||||
| --- a/lib/Finance/Quote/CurrencyRates/AlphaVantage.pm
 | ||||
| +++ b/lib/Finance/Quote/CurrencyRates/AlphaVantage.pm
 | ||||
| @@ -53,14 +53,15 @@ sub multipliers
 | ||||
|  { | ||||
|    my ($this, $ua, $from, $to) = @_; | ||||
|   | ||||
| -  my $url = 'https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE';
 | ||||
| +  my $url = 'https://www.alphavantage.co/query?function=FX_DAILY';
 | ||||
|    my $try_cnt = 0; | ||||
|    my $json_data; | ||||
| +  my $rate;
 | ||||
|    do { | ||||
|      $try_cnt += 1; | ||||
|      my $reply = $ua->get($url | ||||
| -        . '&from_currency=' . ${from}
 | ||||
| -        . '&to_currency=' . ${to}
 | ||||
| +        . '&from_symbol=' . ${from}
 | ||||
| +        . '&to_symbol=' . ${to}
 | ||||
|          . '&apikey=' . $this->{API_KEY}); | ||||
|   | ||||
|      return unless ($reply->code == 200); | ||||
| @@ -77,7 +78,16 @@ sub multipliers
 | ||||
|      sleep (20) if (($try_cnt < 5) && ($json_data->{'Note'})); | ||||
|    } while (($try_cnt < 5) && ($json_data->{'Note'})); | ||||
|   | ||||
| -  my $rate = $json_data->{'Realtime Currency Exchange Rate'}->{'5. Exchange Rate'};
 | ||||
| +  if( !$json_data->{'Time Series FX (Daily)'} ) {
 | ||||
| +    ### No data in JSON
 | ||||
| +    $rate = 0.0;
 | ||||
| +  } else {
 | ||||
| +    my $target = substr($json_data->{'Meta Data'}->{'5. Last Refreshed'}, 0, 10);
 | ||||
| +    $rate =
 | ||||
| +      $json_data->{'Time Series FX (Daily)'}->{target}->{'4. close'};
 | ||||
| +  }
 | ||||
| +
 | ||||
| +  ### Rate from JSON: $rate
 | ||||
|   | ||||
|    return unless $rate + 0; | ||||
|   | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue