enable force option for refresh market data

This commit is contained in:
hackerESQ
2024-09-18 21:15:52 -05:00
parent 17e9bce1ae
commit 5fa3d6a83c
2 changed files with 7 additions and 4 deletions
+4 -2
View File
@@ -14,7 +14,7 @@ class RefreshMarketData extends Command
* @var string * @var string
*/ */
protected $signature = 'refresh:market-data protected $signature = 'refresh:market-data
{--force= : Ignore refresh delay}'; {--force : Ignore refresh delay}';
/** /**
* The console command description. * The console command description.
@@ -40,6 +40,8 @@ class RefreshMarketData extends Command
*/ */
public function handle() public function handle()
{ {
$force = $this->option('force') ?? false;
// get all symbols from market data // get all symbols from market data
$holdings = Holding::where('quantity', '>', 0) $holdings = Holding::where('quantity', '>', 0)
->select(['symbol']) ->select(['symbol'])
@@ -49,7 +51,7 @@ class RefreshMarketData extends Command
foreach ($holdings as $holding) { foreach ($holdings as $holding) {
$this->line('Refreshing ' . $holding->symbol); $this->line('Refreshing ' . $holding->symbol);
MarketData::getMarketData($holding->symbol); MarketData::getMarketData($holding->symbol, $force);
} }
} }
} }
+3 -2
View File
@@ -50,7 +50,7 @@ class MarketData extends Model
return $query->where('symbol', $symbol); return $query->where('symbol', $symbol);
} }
public static function getMarketData($symbol) public static function getMarketData($symbol, $force = false)
{ {
$market_data = self::firstOrNew([ $market_data = self::firstOrNew([
'symbol' => $symbol 'symbol' => $symbol
@@ -58,7 +58,8 @@ class MarketData extends Model
// check if new or stale // check if new or stale
if ( if (
!$market_data->exists $force
|| !$market_data->exists
|| is_null($market_data->updated_at) || is_null($market_data->updated_at)
|| $market_data->updated_at->diffInMinutes(now()) >= config('investbrain.refresh') || $market_data->updated_at->diffInMinutes(now()) >= config('investbrain.refresh')
) { ) {