This commit is contained in:
hackerESQ
2024-09-01 15:34:55 -05:00
parent d68fc89f75
commit ce4a736101
11 changed files with 117 additions and 62 deletions
@@ -17,26 +17,40 @@ class AlphaVantageMarketData implements MarketDataInterface
public function quote($symbol): Collection
{
$fundamental = Alphavantage::fundamentals()->overview($symbol);
$quote = Alphavantage::core()->quoteEndpoint($symbol);
$quote = Arr::get($quote, 'Global Quote', []);
$fundamental = cache()->tags(['quote', 'alpha-vantage', $symbol])->remember(
'symbol-'.$symbol,
1440,
function () use ($symbol) {
return Alphavantage::fundamentals()->overview($symbol);
}
);
if (empty($fundamental)) return collect();
return collect([
'name' => Arr::get($fundamental, 'Name'),
'symbol' => Arr::get($fundamental, 'Symbol'),
'market_value' => Arr::get($quote, 'Global Quote')['05. price'],
'market_value' => Arr::get($quote, '05. price'),
'fifty_two_week_high' => Arr::get($fundamental, '52WeekHigh'),
'fifty_two_week_low' => Arr::get($fundamental, '52WeekLow'),
'forward_pe' => Arr::get($fundamental, 'ForwardPE'),
'trailing_pe' => Arr::get($fundamental, 'TrailingPE'),
'market_cap' => Arr::get($fundamental, 'MarketCapitalization')
'market_cap' => Arr::get($fundamental, 'MarketCapitalization'),
'book_value' => Arr::get($fundamental, 'BookValue'),
'last_dividend_date' => Arr::get($fundamental, 'DividendDate') != 'None'
? Arr::get($fundamental, 'DividendDate')
: null,
'dividend_yield' => Arr::get($fundamental, 'DividendYield') != 'None'
? Arr::get($fundamental, 'DividendYield')
: null
]);
}
public function dividends($symbol, $startDate, $endDate): Collection
{
$dividends = Alphavantage::fundamentals()->dividends($symbol);
return collect($dividends)
+4 -1
View File
@@ -23,7 +23,10 @@ class FakeMarketData implements MarketDataInterface
'fifty_two_week_low' => 341.20,
'forward_pe' => 20.1,
'trailing_pe' => 30.34,
'market_cap' => 9800700600
'market_cap' => 9800700600,
'book_value' => 4.7,
'last_dividend_date' => now()->subDays(45),
'dividend_yield' => .033
]);
}
@@ -36,7 +36,10 @@ class YahooMarketData implements MarketDataInterface
'fifty_two_week_low' => $quote->getFiftyTwoWeekLow(),
'forward_pe' => $quote->getForwardPE(),
'trailing_pe' => $quote->getTrailingPE(),
'market_cap' => $quote->getMarketCap()
'market_cap' => $quote->getMarketCap(),
'book_value' => $quote->getBookValue(),
'last_dividend_date' => $quote->getDividendDate(),
'dividend_yield' => $quote->getTrailingAnnualDividendYield()
]);
}