From 26185bbd3c1937da06f528b485e5897202f59760 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Sun, 1 Sep 2024 16:06:29 -0500 Subject: [PATCH] wip --- app/Interfaces/MarketData/YahooMarketData.php | 7 ++--- app/Models/MarketData.php | 12 +++++++++ app/Support/Spotlight.php | 18 ++++++++++--- lang/en.json | 3 +++ lang/es.json | 3 +++ resources/views/holding/show.blade.php | 20 +++++++++++--- routes/web.php | 27 ------------------- 7 files changed, 53 insertions(+), 37 deletions(-) diff --git a/app/Interfaces/MarketData/YahooMarketData.php b/app/Interfaces/MarketData/YahooMarketData.php index 8c5f9d1..0510523 100644 --- a/app/Interfaces/MarketData/YahooMarketData.php +++ b/app/Interfaces/MarketData/YahooMarketData.php @@ -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(); diff --git a/app/Models/MarketData.php b/app/Models/MarketData.php index a7ff06a..b614373 100644 --- a/app/Models/MarketData.php +++ b/app/Models/MarketData.php @@ -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'); diff --git a/app/Support/Spotlight.php b/app/Support/Spotlight.php index 3a300ee..e313865 100644 --- a/app/Support/Spotlight.php +++ b/app/Support/Spotlight.php @@ -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 ]); }); diff --git a/lang/en.json b/lang/en.json index 2ea0f49..f8eb69f 100644 --- a/lang/en.json +++ b/lang/en.json @@ -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", diff --git a/lang/es.json b/lang/es.json index a11c27d..18db073 100644 --- a/lang/es.json +++ b/lang/es.json @@ -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", diff --git a/resources/views/holding/show.blade.php b/resources/views/holding/show.blade.php index da5c2f6..cdb783a 100644 --- a/resources/views/holding/show.blade.php +++ b/resources/views/holding/show.blade.php @@ -45,6 +45,11 @@ +

+ {{ __('Market Cap') }}: + ${{ Number::forHumans($holding->market_data->market_cap ?? 0) }} +

+

{{ __('Forward PE') }}: {{ $holding->market_data->forward_pe }} @@ -56,8 +61,8 @@

- {{ __('Market Cap') }}: - ${{ Number::forHumans($holding->market_data->market_cap ?? 0) }} + {{ __('Book Value') }}: + {{ $holding->market_data->book_value }}

@@ -68,7 +73,16 @@ :high="$holding->market_data->fifty_two_week_high" :current="$holding->market_data->market_value" /> - +

+ +

+ {{ __('Dividend Yield') }}: + {{ $holding->market_data->dividend_yield }} +

+ +

+ {{ __('Last Dividend Date') }}: + {{ $holding->market_data?->last_dividend_date?->format('F d, Y') ?? 'Never' }}

diff --git a/routes/web.php b/routes/web.php index 974bef2..bd94463 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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 () {