This commit is contained in:
hackerESQ
2024-09-01 16:06:29 -05:00
parent ce4a736101
commit 26185bbd3c
7 changed files with 53 additions and 37 deletions
@@ -3,13 +3,14 @@
namespace App\Interfaces\MarketData;
use Illuminate\Support\Collection;
use Scheb\YahooFinanceApi\ApiClient;
use Scheb\YahooFinanceApi\ApiClientFactory as YahooFinance;
class YahooMarketData implements MarketDataInterface
{
public function __construct(
public $client
) {
public ApiClient $client;
public function __construct() {
// create yahoo finance client factory
$this->client = YahooFinance::createApiClient();
+12
View File
@@ -28,6 +28,18 @@ class MarketData extends Model
'dividend_yield'
];
protected $casts = [
'last_dividend_date' => 'datetime',
'market_value' => 'float',
'fifty_two_week_high' => 'float',
'fifty_two_week_low' => 'float',
'forward_pe' => 'float',
'trailing_pe' => 'float',
'market_cap' => 'float',
'book_value' => 'float',
'dividend_yield' => 'float'
];
public function holdings()
{
return $this->hasMany(Holding::class, 'symbol', 'symbol');
+14 -4
View File
@@ -18,7 +18,10 @@ class Spotlight
return $results;
}
$portfolios = $request->user()->portfolios()->where('title', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
$portfolios = $request->user()->portfolios()
->where('title', 'LIKE', '%'.$request->input('search').'%')
->limit(5)
->get();
$portfolios->each(function($portfolio) use ($results) {
$results->push([
@@ -29,13 +32,20 @@ class Spotlight
]);
});
$holdings = $request->user()->holdings()->where('holdings.symbol', 'LIKE', '%'.$request->input('search').'%')->limit(5)->get();
$holdings = $request->user()->holdings()
->where('holdings.quantity', '>', 0)
->where(function ($query) use ($request) {
return $query->where('holdings.symbol', 'LIKE', '%'.$request->input('search').'%')
->orWhere('market_data.name', 'LIKE', '%'.$request->input('search').'%');
})
->limit(5)
->get();
$holdings->each(function($holding) use ($results) {
$results->push([
'name' => 'Holding: '. $holding->symbol,
'name' => 'Holding: '.$holding->market_data->name.' ('.$holding->symbol.')',
'description' => $holding->portfolio->title,
'link' => route('portfolio.show', ['portfolio' => $holding->portfolio->id]),
'link' => route('holding.show', ['portfolio' => $holding->portfolio->id, 'symbol' => $holding->symbol]),
'avatar' => null
]);
});
+3
View File
@@ -143,6 +143,9 @@
"Forward PE": "Forward PE",
"Trailing PE": "Trailing PE",
"Market Cap": "Market Cap",
"Book Value": "Book Value",
"Dividend Yield": "Dividend Yield",
"Last Dividend Date": "Last Dividend Date",
"Number of Transactions": "Number of Transactions",
"Market Data Age": "Market Data Age",
"Portfolio updated": "Portfolio updated",
+3
View File
@@ -143,6 +143,9 @@
"Forward PE": "PE a futuro",
"Trailing PE": "PE histórico",
"Market Cap": "Cap de mercado",
"Book Value": "Valor contable",
"Dividend Yield": "Rendimiento por dividendo",
"Last Dividend Date": "Fecha del último dividendo",
"Number of Transactions": "Número de Transacciones",
"Market Data Age": "Antigüedad de los Datos del Mercado",
"Portfolio updated": "Portafolio actualizado",
+16 -2
View File
@@ -45,6 +45,11 @@
<x-ib-card title="{{ __('Fundamentals') }}" class="md:col-span-4">
<p>
<span class="font-bold">{{ __('Market Cap') }}: </span>
${{ Number::forHumans($holding->market_data->market_cap ?? 0) }}
</p>
<p>
<span class="font-bold">{{ __('Forward PE') }}: </span>
{{ $holding->market_data->forward_pe }}
@@ -56,8 +61,8 @@
</p>
<p>
<span class="font-bold">{{ __('Market Cap') }}: </span>
${{ Number::forHumans($holding->market_data->market_cap ?? 0) }}
<span class="font-bold">{{ __('Book Value') }}: </span>
{{ $holding->market_data->book_value }}
</p>
<p>
@@ -68,7 +73,16 @@
:high="$holding->market_data->fifty_two_week_high"
:current="$holding->market_data->market_value"
/>
</p>
<p>
<span class="font-bold">{{ __('Dividend Yield') }}: </span>
{{ $holding->market_data->dividend_yield }}
</p>
<p>
<span class="font-bold">{{ __('Last Dividend Date') }}: </span>
{{ $holding->market_data?->last_dividend_date?->format('F d, Y') ?? 'Never' }}
</p>
</x-ib-card>
-27
View File
@@ -18,33 +18,6 @@ Route::get('/', function () {
Route::get('/test', function () {
//
return Alphavantage::fundamentals()->overview('TSLA');
$quote = Alphavantage::core()->quoteEndpoint('FFRHX');
$quote = Arr::get($quote, 'Global Quote', []);
return $quote;
$client = ApiClientFactory::createApiClient();
return $client->getQuote("IBM");
return $client->getHistoricalQuoteData(
"AAPL",
ApiClient::INTERVAL_1_DAY,
new \DateTime("-14 days"),
new \DateTime("today")
);
return $client->getHistoricalDividendData(
"AAPL",
new \DateTime("-5 years"),
new \DateTime("today")
);
});
Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified'])->group(function () {