Fix: do not gracefully fail when symbol not found

This commit is contained in:
hackerESQ
2025-08-28 16:01:44 -05:00
parent 7d77b6fbc8
commit 19cac58692
3 changed files with 11 additions and 9 deletions
@@ -14,6 +14,7 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class AlpacaMarketData implements MarketDataInterface
{
@@ -51,9 +52,7 @@ class AlpacaMarketData implements MarketDataInterface
$quote = $response->json('trade');
if (is_null(Arr::get($quote, 'p'))) {
throw new \Exception('Could not find ticker on Alpaca');
}
throw_if(empty(Arr::get($quote, 'p')), NotFoundHttpException::class, "Symbol `{$symbol}` was not found");
$fundamental = cache()->remember(
'ap-symbol-'.$symbol,
@@ -159,6 +158,8 @@ class AlpacaMarketData implements MarketDataInterface
$history = $response->json('bars');
throw_if(empty($history), NotFoundHttpException::class, "Symbol `{$symbol}` was not found");
$chunkedHistory = collect($history)
->mapWithKeys(function ($history) use ($symbol) {