Files
investbrain/app/Console/Commands/RefreshDividendData.php
T

61 lines
1.3 KiB
PHP
Raw Normal View History

2024-08-29 23:36:44 -05:00
<?php
namespace App\Console\Commands;
2024-08-30 20:22:28 -05:00
use App\Models\Dividend;
2025-01-28 17:14:49 -06:00
use App\Models\Holding;
2024-08-29 23:36:44 -05:00
use Illuminate\Console\Command;
2024-08-30 21:58:38 -05:00
class RefreshDividendData extends Command
2024-08-29 23:36:44 -05:00
{
/**
* The name and signature of the console command.
*
* @var string
*/
2024-09-19 21:25:56 -05:00
protected $signature = 'refresh:dividend-data
{--force : Refresh all holdings}
{--user= : Limit refresh to user\'s holdings}';
2024-08-29 23:36:44 -05:00
/**
* The console command description.
*
* @var string
*/
2024-08-30 21:58:38 -05:00
protected $description = 'Refresh dividend data from data provider';
2024-08-29 23:36:44 -05:00
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
2024-09-19 21:25:56 -05:00
$holdings = Holding::distinct();
2024-08-29 23:36:44 -05:00
2025-01-28 17:14:49 -06:00
if (! ($this->option('force') ?? false)) {
2024-09-19 21:25:56 -05:00
$holdings->where('quantity', '>', 0);
2025-01-28 17:14:49 -06:00
}
2024-09-19 21:25:56 -05:00
if ($this->option('user')) {
$holdings->myHoldings($this->option('user'));
}
2024-09-19 21:25:56 -05:00
foreach ($holdings->get(['symbol']) as $holding) {
2025-01-28 17:14:49 -06:00
$this->line('Refreshing '.$holding->symbol);
2024-08-30 21:58:38 -05:00
Dividend::refreshDividendData($holding->symbol);
2024-08-29 23:36:44 -05:00
}
}
}