fix: upgrade the exists() market data provider method

This commit is contained in:
hackerESQ
2025-01-28 20:32:43 -06:00
parent 0f135f4024
commit 4ece09368e
7 changed files with 49 additions and 42 deletions
+11 -23
View File
@@ -26,15 +26,7 @@ class YahooMarketData implements MarketDataInterface
public function exists(string $symbol): bool
{
try {
$this->quote($symbol);
return true;
} catch (\Throwable $e) {
return false;
}
return (bool) $this->quote($symbol);
}
public function quote(string $symbol): Quote
@@ -42,22 +34,18 @@ class YahooMarketData implements MarketDataInterface
$quote = $this->client->getQuote($symbol);
if (is_null($quote)) {
throw new \Exception('Symbol ('.$symbol.') does not exist');
}
return new Quote([
'name' => $quote->getLongName() ?? $quote->getShortName(),
'name' => $quote?->getLongName() ?? $quote?->getShortName(),
'symbol' => $symbol,
'market_value' => $quote->getRegularMarketPrice(),
'fifty_two_week_high' => $quote->getFiftyTwoWeekHigh(),
'fifty_two_week_low' => $quote->getFiftyTwoWeekLow(),
'forward_pe' => $quote->getForwardPE(),
'trailing_pe' => $quote->getTrailingPE(),
'market_cap' => $quote->getMarketCap(),
'book_value' => $quote->getBookValue(),
'last_dividend_date' => $quote->getDividendDate(),
'dividend_yield' => $quote->getTrailingAnnualDividendYield() * 100,
'market_value' => $quote?->getRegularMarketPrice(),
'fifty_two_week_high' => $quote?->getFiftyTwoWeekHigh(),
'fifty_two_week_low' => $quote?->getFiftyTwoWeekLow(),
'forward_pe' => $quote?->getForwardPE(),
'trailing_pe' => $quote?->getTrailingPE(),
'market_cap' => $quote?->getMarketCap(),
'book_value' => $quote?->getBookValue(),
'last_dividend_date' => $quote?->getDividendDate(),
'dividend_yield' => $quote?->getTrailingAnnualDividendYield() * 100,
]);
}