Skip to content

Commit

Permalink
Historical data no longer requires a crumb
Browse files Browse the repository at this point in the history
  • Loading branch information
scheb committed Dec 17, 2022
1 parent 1777728 commit 0b6e9db
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Scheb\YahooFinanceApi;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Cookie\CookieJar;
use Scheb\YahooFinanceApi\Exception\ApiException;
use Scheb\YahooFinanceApi\Results\DividendData;
use Scheb\YahooFinanceApi\Results\HistoricalData;
Expand Down Expand Up @@ -199,15 +198,9 @@ private function fetchQuotes(array $symbols): array

private function getHistoricalDataResponseBody(string $symbol, string $interval, \DateTimeInterface $startDate, \DateTimeInterface $endDate, string $filter): string
{
$cookieJar = new CookieJar();
$dataUrl = 'https://query1.finance.yahoo.com/v7/finance/download/'.urlencode($symbol).'?period1='.$startDate->getTimestamp().'&period2='.$endDate->getTimestamp().'&interval='.$interval.'&events='.$filter;

$initialUrl = 'https://finance.yahoo.com/quote/'.urlencode($symbol).'/history?p='.urlencode($symbol);
$responseBody = (string) $this->client->request('GET', $initialUrl, ['cookies' => $cookieJar])->getBody();
$crumb = $this->resultDecoder->extractCrumb($responseBody);

$dataUrl = 'https://query1.finance.yahoo.com/v7/finance/download/'.urlencode($symbol).'?period1='.$startDate->getTimestamp().'&period2='.$endDate->getTimestamp().'&interval='.$interval.'&events='.$filter.'&crumb='.urlencode($crumb);

return (string) $this->client->request('GET', $dataUrl, ['cookies' => $cookieJar])->getBody();
return (string) $this->client->request('GET', $dataUrl)->getBody();
}

private function validateIntervals(string $interval): void
Expand Down

0 comments on commit 0b6e9db

Please sign in to comment.