From 5fa3d6a83c93c1f7eaa7b114f44da9af59c7deca Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Wed, 18 Sep 2024 21:15:52 -0500 Subject: [PATCH] enable force option for refresh market data --- app/Console/Commands/RefreshMarketData.php | 6 ++++-- app/Models/MarketData.php | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/RefreshMarketData.php b/app/Console/Commands/RefreshMarketData.php index 16310f9..8816b78 100644 --- a/app/Console/Commands/RefreshMarketData.php +++ b/app/Console/Commands/RefreshMarketData.php @@ -14,7 +14,7 @@ class RefreshMarketData extends Command * @var string */ protected $signature = 'refresh:market-data - {--force= : Ignore refresh delay}'; + {--force : Ignore refresh delay}'; /** * The console command description. @@ -40,6 +40,8 @@ class RefreshMarketData extends Command */ public function handle() { + $force = $this->option('force') ?? false; + // get all symbols from market data $holdings = Holding::where('quantity', '>', 0) ->select(['symbol']) @@ -49,7 +51,7 @@ class RefreshMarketData extends Command foreach ($holdings as $holding) { $this->line('Refreshing ' . $holding->symbol); - MarketData::getMarketData($holding->symbol); + MarketData::getMarketData($holding->symbol, $force); } } } diff --git a/app/Models/MarketData.php b/app/Models/MarketData.php index 4359364..d7ce420 100644 --- a/app/Models/MarketData.php +++ b/app/Models/MarketData.php @@ -50,7 +50,7 @@ class MarketData extends Model return $query->where('symbol', $symbol); } - public static function getMarketData($symbol) + public static function getMarketData($symbol, $force = false) { $market_data = self::firstOrNew([ 'symbol' => $symbol @@ -58,7 +58,8 @@ class MarketData extends Model // check if new or stale if ( - !$market_data->exists + $force + || !$market_data->exists || is_null($market_data->updated_at) || $market_data->updated_at->diffInMinutes(now()) >= config('investbrain.refresh') ) {