wip sync daily holdings
This commit is contained in:
@@ -2,17 +2,21 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Portfolio;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Interfaces\MarketData\MarketDataInterface;
|
||||
use Illuminate\Contracts\Console\PromptsForMissingInput;
|
||||
use function Laravel\Prompts\search;
|
||||
|
||||
class SyncDailyChange extends Command
|
||||
class SyncDailyChange extends Command implements PromptsForMissingInput
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'sync:daily-change';
|
||||
protected $signature = 'sync:daily-change
|
||||
{portfolio_id : The ID of the portfolio to re-calculate.}
|
||||
{--force : Don\'t ask to confirm.}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -21,6 +25,24 @@ class SyncDailyChange extends Command
|
||||
*/
|
||||
protected $description = 'Re-calculates daily snapshots of your portfolio\'s daily performance. Use discretion as this is a resource intensive command.';
|
||||
|
||||
/**
|
||||
* Prompt for missing input arguments using the returned questions.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function promptForMissingArgumentsUsing(): array
|
||||
{
|
||||
return [
|
||||
'portfolio_id' => fn () => search(
|
||||
label: 'Choose the portfolio you wish to re-calculate:',
|
||||
placeholder: 'E.g. My favorite stocks',
|
||||
options: fn ($value) => strlen($value) > 0
|
||||
? Portfolio::where('title', 'like', "%{$value}%")->pluck('title', 'id')->all()
|
||||
: []
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
@@ -38,7 +60,17 @@ class SyncDailyChange extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// get history
|
||||
// $history = app(MarketDataInterface::class)->history($symbol);
|
||||
try {
|
||||
|
||||
$portfolio = Portfolio::findOrFail($this->argument('portfolio_id'));
|
||||
|
||||
$portfolio->syncDailyChanges();
|
||||
|
||||
$this->line('Awesome! Daily change history for '. $portfolio->title .' has been completed.');
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user