This is a PHP client for Yahoo Finance API.
Since YQL APIs have been discontinued in November 2017, this client is using non-official API endpoints for quotes, search and historical data.
Download via Composer:
composer require scheb/yahoo-finance-api
Alternatively you can also add the package directly to composer.json:
{
"require": {
"scheb/yahoo-finance-api": "^4.0"
}
}
and then tell Composer to install the package:
composer update scheb/yahoo-finance-api
use Scheb\YahooFinanceApi\ApiClient;
use Scheb\YahooFinanceApi\ApiClientFactory;
use GuzzleHttp\Client;
// Create a new client from the factory
$client = ApiClientFactory::createApiClient();
// Or use your own Guzzle client and pass it in
$options = [/*...*/];
$guzzleClient = new Client($options);
$client = ApiClientFactory::createApiClient($guzzleClient);
// Returns an array of Scheb\YahooFinanceApi\Results\SearchResult
$searchResult = $client->search("Apple");
// Returns an array of Scheb\YahooFinanceApi\Results\HistoricalData
$historicalData = $client->getHistoricalData("AAPL", ApiClient::INTERVAL_1_DAY, new \DateTime("-14 days"), new \DateTime("today"));
// Returns Scheb\YahooFinanceApi\Results\Quote
$exchangeRate = $client->getExchangeRate("USD", "EUR");
// Returns an array of Scheb\YahooFinanceApi\Results\Quote
$exchangeRates = $client->getExchangeRates([
["USD", "EUR"],
["EUR", "USD"],
]);
// Returns Scheb\YahooFinanceApi\Results\Quote
$quote = $client->getQuote("AAPL");
// Returns an array of Scheb\YahooFinanceApi\Results\Quote
$quotes = $client->getQuotes(["AAPL", "GOOG"]);
Version | Status | PHP Version |
---|---|---|
1.x | EOL | >= 5.3.0 |
2.x | EOL | >= 5.6.0 |
3.x | EOL | >= 5.6.0 |
4.x | Maintained | >= 7.1.3 |
Want to contribute to this project? See CONTRIBUTING.md.
This bundle is available under the MIT license.