chore: code style

This commit is contained in:
hackerESQ
2025-01-28 17:14:49 -06:00
parent c4736fae70
commit e8ef0921ad
123 changed files with 1051 additions and 1197 deletions
+38 -35
View File
@@ -2,36 +2,39 @@
namespace App\Interfaces\MarketData;
use Illuminate\Support\Collection;
use Scheb\YahooFinanceApi\ApiClient;
use App\Interfaces\MarketData\Types\Dividend;
use App\Interfaces\MarketData\Types\Ohlc;
use App\Interfaces\MarketData\Types\Quote;
use App\Interfaces\MarketData\Types\Split;
use App\Interfaces\MarketData\Types\Dividend;
use Illuminate\Support\Collection;
use Scheb\YahooFinanceApi\ApiClient;
use Scheb\YahooFinanceApi\ApiClientFactory as YahooFinance;
class YahooMarketData implements MarketDataInterface
{
public ApiClient $client;
public function __construct() {
public function __construct()
{
// create yahoo finance client factory
$this->client = YahooFinance::createApiClient();
}
public function exists(String $symbol): Bool
public function exists(string $symbol): bool
{
return $this->quote($symbol)->isNotEmpty();
}
public function quote(String $symbol): Quote
public function quote(string $symbol): Quote
{
$quote = $this->client->getQuote($symbol);
if (empty($quote)) return collect();
if (empty($quote)) {
return collect();
}
return new Quote([
'name' => $quote->getLongName() ?? $quote->getShortName(),
@@ -44,52 +47,52 @@ class YahooMarketData implements MarketDataInterface
'market_cap' => $quote->getMarketCap(),
'book_value' => $quote->getBookValue(),
'last_dividend_date' => $quote->getDividendDate(),
'dividend_yield' => $quote->getTrailingAnnualDividendYield() * 100
'dividend_yield' => $quote->getTrailingAnnualDividendYield() * 100,
]);
}
public function dividends(String $symbol, $startDate, $endDate): Collection
public function dividends(string $symbol, $startDate, $endDate): Collection
{
return collect($this->client->getHistoricalDividendData($symbol, $startDate, $endDate))
->map(function($dividend) use ($symbol) {
return new Dividend([
'symbol' => $symbol,
'date' => $dividend->getDate(),
'dividend_amount' => $dividend->getDividends(),
]);
});
->map(function ($dividend) use ($symbol) {
return new Dividend([
'symbol' => $symbol,
'date' => $dividend->getDate(),
'dividend_amount' => $dividend->getDividends(),
]);
});
}
public function splits(String $symbol, $startDate, $endDate): Collection
{
public function splits(string $symbol, $startDate, $endDate): Collection
{
return collect($this->client->getHistoricalSplitData($symbol, $startDate, $endDate))
->map(function($split) use ($symbol) {
$split_amount = explode(':', $split->getStockSplits());
->map(function ($split) use ($symbol) {
$split_amount = explode(':', $split->getStockSplits());
return new Split([
'symbol' => $symbol,
'date' => $split->getDate(),
'split_amount' => $split_amount[0] / $split_amount[1],
]);
});
return new Split([
'symbol' => $symbol,
'date' => $split->getDate(),
'split_amount' => $split_amount[0] / $split_amount[1],
]);
});
}
public function history(String $symbol, $startDate, $endDate): Collection
public function history(string $symbol, $startDate, $endDate): Collection
{
return collect($this->client->getHistoricalQuoteData($symbol, ApiClient::INTERVAL_1_DAY, $startDate, $endDate))
->mapWithKeys(function($history) use ($symbol) {
->mapWithKeys(function ($history) use ($symbol) {
$date = $history->getDate()->format('Y-m-d');
return [ $date => new Ohlc([
'symbol' => $symbol,
'date' => $date,
'close' => $history->getClose(),
]) ];
return [$date => new Ohlc([
'symbol' => $symbol,
'date' => $date,
'close' => $history->getClose(),
])];
});
}
}
}