2024-08-31 23:06:19 -05:00
|
|
|
<?php
|
|
|
|
|
|
2025-01-28 17:33:54 -06:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2024-08-31 23:06:19 -05:00
|
|
|
namespace App\Interfaces\MarketData;
|
|
|
|
|
|
2024-10-29 16:34:18 -05:00
|
|
|
use App\Interfaces\MarketData\Types\Dividend;
|
|
|
|
|
use App\Interfaces\MarketData\Types\Ohlc;
|
2025-01-28 17:14:49 -06:00
|
|
|
use App\Interfaces\MarketData\Types\Quote;
|
2024-10-29 16:34:18 -05:00
|
|
|
use App\Interfaces\MarketData\Types\Split;
|
2025-01-28 17:14:49 -06:00
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
use Illuminate\Support\Collection;
|
2024-08-31 23:06:19 -05:00
|
|
|
|
|
|
|
|
class FakeMarketData implements MarketDataInterface
|
|
|
|
|
{
|
2025-01-28 17:14:49 -06:00
|
|
|
public function exists(string $symbol): bool
|
2024-08-31 23:06:19 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 17:14:49 -06:00
|
|
|
public function quote(string $symbol): Quote
|
2024-08-31 23:06:19 -05:00
|
|
|
{
|
|
|
|
|
|
2024-10-29 16:34:18 -05:00
|
|
|
return new Quote([
|
2024-08-31 23:06:19 -05:00
|
|
|
'name' => 'ACME Company Ltd',
|
|
|
|
|
'symbol' => $symbol,
|
2024-10-29 16:34:18 -05:00
|
|
|
'market_value' => 230.19,
|
|
|
|
|
'fifty_two_week_high' => 512.90,
|
|
|
|
|
'fifty_two_week_low' => 341.20,
|
|
|
|
|
'forward_pe' => 20.1,
|
|
|
|
|
'trailing_pe' => 30.34,
|
|
|
|
|
'market_cap' => 9800700600,
|
|
|
|
|
'book_value' => 4.7,
|
2024-09-01 15:34:55 -05:00
|
|
|
'last_dividend_date' => now()->subDays(45),
|
2025-01-28 17:14:49 -06:00
|
|
|
'dividend_yield' => 0.033,
|
2024-08-31 23:06:19 -05:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 17:14:49 -06:00
|
|
|
public function dividends(string $symbol, $startDate, $endDate): Collection
|
2024-08-31 23:06:19 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return collect([
|
2024-10-29 16:34:18 -05:00
|
|
|
new Dividend([
|
2024-08-31 23:06:19 -05:00
|
|
|
'symbol' => $symbol,
|
2024-10-29 16:34:18 -05:00
|
|
|
'date' => now()->subMonths(3),
|
2024-08-31 23:06:19 -05:00
|
|
|
'dividend_amount' => 2.11,
|
2024-10-29 16:34:18 -05:00
|
|
|
]),
|
|
|
|
|
new Dividend([
|
2024-08-31 23:06:19 -05:00
|
|
|
'symbol' => $symbol,
|
2024-10-29 16:34:18 -05:00
|
|
|
'date' => now()->subMonths(6),
|
2024-08-31 23:06:19 -05:00
|
|
|
'dividend_amount' => 1.89,
|
2024-10-29 16:34:18 -05:00
|
|
|
]),
|
|
|
|
|
new Dividend([
|
2024-08-31 23:06:19 -05:00
|
|
|
'symbol' => $symbol,
|
2024-10-29 16:34:18 -05:00
|
|
|
'date' => now()->subMonths(9),
|
2024-08-31 23:06:19 -05:00
|
|
|
'dividend_amount' => 0.95,
|
2024-10-29 16:34:18 -05:00
|
|
|
]),
|
2024-08-31 23:06:19 -05:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 17:14:49 -06:00
|
|
|
public function splits(string $symbol, $startDate, $endDate): Collection
|
|
|
|
|
{
|
2024-08-31 23:06:19 -05:00
|
|
|
|
|
|
|
|
return collect([
|
2024-10-29 16:34:18 -05:00
|
|
|
new Split([
|
2024-08-31 23:06:19 -05:00
|
|
|
'symbol' => $symbol,
|
2024-10-29 16:34:18 -05:00
|
|
|
'date' => now()->subMonths(36),
|
2024-08-31 23:06:19 -05:00
|
|
|
'split_amount' => 10,
|
2025-01-28 17:14:49 -06:00
|
|
|
]),
|
2024-08-31 23:06:19 -05:00
|
|
|
]);
|
|
|
|
|
}
|
2024-09-09 20:50:18 -05:00
|
|
|
|
2025-01-28 17:14:49 -06:00
|
|
|
public function history(string $symbol, $startDate, $endDate): Collection
|
2024-09-09 20:50:18 -05:00
|
|
|
{
|
2024-09-11 21:58:34 -05:00
|
|
|
$numDays = Carbon::parse($startDate)->diffInDays($endDate, true);
|
2024-09-09 20:50:18 -05:00
|
|
|
|
2025-01-28 17:14:49 -06:00
|
|
|
for ($i = 0; $i < $numDays; $i++) {
|
2024-09-09 20:50:18 -05:00
|
|
|
|
2024-09-11 21:58:34 -05:00
|
|
|
$date = now()->subDays($i)->format('Y-m-d');
|
|
|
|
|
|
2024-10-29 16:34:18 -05:00
|
|
|
$series[$date] = new Ohlc([
|
2024-09-09 20:50:18 -05:00
|
|
|
'symbol' => $symbol,
|
2024-09-11 21:58:34 -05:00
|
|
|
'date' => $date,
|
2024-10-29 16:34:18 -05:00
|
|
|
'close' => rand(150, 400),
|
|
|
|
|
]);
|
2024-09-09 20:50:18 -05:00
|
|
|
}
|
2025-01-28 17:14:49 -06:00
|
|
|
|
2024-09-09 20:50:18 -05:00
|
|
|
return collect($series);
|
|
|
|
|
}
|
2025-01-28 17:14:49 -06:00
|
|
|
}
|