clean up scheduled tasks
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Portfolio;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -38,37 +39,27 @@ class CaptureDailyChange extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
User::all()->each(function($user){
|
||||
Portfolio::with('holdings.market_data')->get()->each(function($portfolio){
|
||||
|
||||
$this->line('Capturing daily change for ' . $user->name);
|
||||
$this->line('Capturing daily change for ' . $portfolio->title);
|
||||
|
||||
$portfolios = $user->portfolios()->withoutWishlists()->with(['holdings.market_data'])->get();
|
||||
$total_cost_basis = $portfolio->holdings->sum('total_cost_basis');
|
||||
|
||||
$total_cost_basis = $portfolios->reduce(function ($carry, $portfolio) {
|
||||
return $carry + $portfolio->holdings->sum('total_cost_basis');
|
||||
$total_dividends = $portfolio->holdings->sum('dividends_earned');
|
||||
|
||||
$realized_gains = $portfolio->holdings->sum('realized_gain_dollars');
|
||||
|
||||
$total_market_value = $portfolio->holdings->sum(function($holding) {
|
||||
return $holding->market_data->market_value * $holding->quantity;
|
||||
});
|
||||
|
||||
$total_dividends = $portfolios->reduce(function ($carry, $portfolio) {
|
||||
return $carry + $portfolio->holdings->sum('dividends_earned');
|
||||
});
|
||||
|
||||
$realized_gains = $portfolios->reduce(function ($carry, $portfolio) {
|
||||
return $carry + $portfolio->holdings->sum('realized_gain_loss_dollars');
|
||||
});
|
||||
|
||||
$total_market_value = $portfolios->reduce(function ($carry, $portfolio) {
|
||||
return $carry + $portfolio->holdings->sum(function($holding) {
|
||||
return $holding->market_data->market_value * $holding->quantity;
|
||||
}) ;
|
||||
});
|
||||
|
||||
$user->daily_changes()->create([
|
||||
$portfolio->daily_changes()->create([
|
||||
'date' => now(),
|
||||
'total_cost_basis' => $total_cost_basis,
|
||||
'total_market_value' => $total_market_value,
|
||||
'total_dividends' => $total_dividends,
|
||||
'realized_gains' => $realized_gains,
|
||||
'total_gain_loss' => $total_market_value - $total_cost_basis
|
||||
'total_cost_basis' => $total_cost_basis,
|
||||
'total_gain' => $total_market_value - $total_cost_basis,
|
||||
'total_dividends_earned' => $total_dividends,
|
||||
'realized_gains' => $realized_gains
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ class RefreshDividendData extends Command
|
||||
|
||||
foreach ($holdings as $holding) {
|
||||
$this->line('Refreshing ' . $holding->symbol);
|
||||
|
||||
Dividend::refreshDividendData($holding->symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Holding;
|
||||
use App\Models\MarketData;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -40,11 +41,16 @@ class RefreshMarketData extends Command
|
||||
public function handle()
|
||||
{
|
||||
// get all symbols from market data
|
||||
$symbols = MarketData::get(['symbol']);
|
||||
$symbols = Holding::where('quantity', '>', 0)
|
||||
->select(['symbol'])
|
||||
->distinct()
|
||||
->get()
|
||||
->pluck('symbol');
|
||||
|
||||
foreach ($symbols as $symbol) {
|
||||
$this->line('Refreshing ' . $symbol->symbol);
|
||||
$symbol->refreshMarketData();
|
||||
$this->line('Refreshing ' . $symbol);
|
||||
|
||||
MarketData::getMarketData($symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ class RefreshSplitData extends Command
|
||||
|
||||
foreach ($holdings as $holding) {
|
||||
$this->line('Refreshing ' . $holding->symbol);
|
||||
|
||||
Split::refreshSplitData($holding->symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,11 +50,6 @@ class MarketData extends Model
|
||||
return $query->where('symbol', $symbol);
|
||||
}
|
||||
|
||||
public function refreshMarketData()
|
||||
{
|
||||
return static::getMarketData($this->attributes['symbol']);
|
||||
}
|
||||
|
||||
public static function getMarketData($symbol)
|
||||
{
|
||||
$market_data = self::firstOrNew([
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user