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-04-09 19:25:15 -05:00
|
|
|
use Carbon\CarbonPeriod;
|
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,
|
2025-04-09 19:25:15 -05:00
|
|
|
'currency' => 'USD',
|
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,
|
2025-04-09 19:25:15 -05:00
|
|
|
'meta_data' => [],
|
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,
|
2025-04-09 19:25:15 -05:00
|
|
|
'date' => now()->subMonths(12),
|
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
|
|
|
{
|
2025-04-09 19:25:15 -05:00
|
|
|
$endDate = now()->isBefore(Carbon::parse(config('investbrain.daily_change_time_of_day')))
|
|
|
|
|
? now()->subDay()
|
|
|
|
|
: now();
|
2024-09-09 20:50:18 -05:00
|
|
|
|
2025-04-09 19:25:15 -05:00
|
|
|
$days = CarbonPeriod::create($startDate, $endDate)->filter('isWeekday');
|
2024-09-09 20:50:18 -05:00
|
|
|
|
2025-04-09 19:25:15 -05:00
|
|
|
$countOfDays = $days->count();
|
|
|
|
|
|
|
|
|
|
foreach ($days as $index => $date) {
|
|
|
|
|
|
|
|
|
|
$date = $date->toDateString();
|
2024-09-11 21:58:34 -05:00
|
|
|
|
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,
|
2025-04-09 19:25:15 -05:00
|
|
|
'open' => rand(150, 400),
|
|
|
|
|
'high' => rand(150, 400),
|
|
|
|
|
'low' => rand(150, 400),
|
|
|
|
|
'close' => $index == $countOfDays - 1
|
|
|
|
|
? 230.19 // most recent close should match current market value
|
|
|
|
|
: rand(150, 400),
|
2024-10-29 16:34:18 -05:00
|
|
|
]);
|
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
|
|
|
}
|