This commit is contained in:
hackerESQ
2024-08-24 22:19:40 -05:00
parent 5e89e66e7b
commit 54cf25aabc
13 changed files with 423 additions and 179 deletions
@@ -2,27 +2,28 @@
namespace App\Interfaces\MarketData;
use App\Models\Holding;
use Illuminate\Support\Collection;
use Scheb\YahooFinanceApi\ApiClientFactory;
class YahooMarketData implements MarketDataInterface
{
// api client
public $client;
public function __construct() {
// create yahoo finance client factory
$this->client = ApiClientFactory::createApiClient();
}
public function exists(String $symbol): Bool
{
return $this->quote($symbol)->isNotEmpty();
}
public function quote($symbol): Collection
{
$quote = $this->client->getQuote($symbol);
if (empty($quote)) return collect();
@@ -33,13 +34,18 @@ class YahooMarketData implements MarketDataInterface
'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()
]);
}
public function dividends($symbol, $startDate, $endDate): Collection
{
return collect($this->client->getHistoricalDividendData($symbol, $startDate, $endDate))
->map(function($dividend) use ($symbol) {
return [
'symbol' => $symbol,
'date' => $dividend->getDate()->format('Y-m-d H:i:s'),
@@ -50,6 +56,7 @@ class YahooMarketData implements MarketDataInterface
public function splits($symbol, $startDate, $endDate): Collection
{
return collect($this->client->getHistoricalSplitData($symbol, $startDate, $endDate))
->map(function($split) use ($symbol) {
$split_amount = explode(':', $split->getStockSplits());