Skip to content

Commit

Permalink
Merge pull request #31 from investbrainapp/dev
Browse files Browse the repository at this point in the history
Uses last dividend created date as start date instead of last dividend date
  • Loading branch information
hackerESQ authored Nov 14, 2024
2 parents 1a124a2 + 1c63e2b commit 8d4e004
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 74 deletions.
14 changes: 7 additions & 7 deletions app/Models/Dividend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Dividend extends Model

protected $casts = [
'date' => 'datetime',
'last_date' => 'datetime',
'last_dividend_update' => 'datetime',
];

public function marketData() {
Expand Down Expand Up @@ -55,22 +55,22 @@ public static function refreshDividendData(string $symbol): void
{
$dividends_meta = self::where(['symbol' => $symbol])
->selectRaw('COUNT(symbol) as total_dividends')
->selectRaw('MAX(date) as last_date')
->selectRaw('MAX(created_at) as last_dividend_update')
->get()
->first();

// assume we need to populate ALL dividend data
$start_date = new \DateTime('@0');
$start_date = new Carbon('@0');
$end_date = now();

// nope, refresh forward looking only
if ( $dividends_meta->total_dividends ) {

$start_date = $dividends_meta->last_date->addHours(24);
$start_date = $dividends_meta->last_dividend_update->addHours(24);
}

// skip refresh if there's already recent data
if ($start_date >= $end_date) {
if ($start_date->greaterThan($end_date)) {

return;
}
Expand Down
Loading

0 comments on commit 8d4e004

Please sign in to comment.