scheb / yahoo-finance-api
PHP library for accessing Yahoo Finance data
Installs: 127 071
Dependents: 7
Suggesters: 0
Security: 0
Stars: 278
Watchers: 31
Forks: 55
Open Issues: 2
Requires
- php: >=7.1.3
- ext-json: *
- guzzlehttp/guzzle: ^6.0|^7.0
Requires (Dev)
- escapestudios/symfony2-coding-standard: ^3.9
- phpunit/phpunit: ^7.5 || ^8 || ^9
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^3.11|^4.0
This package is auto-updated.
Last update: 2024-10-20 10:33:40 UTC
README
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.
⚠️ WARNING: These non-official APIs cannot be assumed stable and might break any time. Also, you might violate Yahoo's terms of service. So use them at your own risk.
Installation
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
Usage
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->getHistoricalQuoteData( "AAPL", ApiClient::INTERVAL_1_DAY, new \DateTime("-14 days"), new \DateTime("today") ); // Retrieve dividends history, returns an array of Scheb\YahooFinanceApi\Results\DividendData $dividendData = $client->getHistoricalDividendData( "AAPL", new \DateTime("-5 years"), new \DateTime("today") ); // Retrieve stock split history, returns an array of Scheb\YahooFinanceApi\Results\SplitData $splitData = $client->getHistoricalSplitData( "AAPL", new \DateTime("-5 years"), 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"]); // Returns an array of Scheb\YahooFinanceApi\Results\OptionChain $optionChain = $client->getOptionChain("AAPL"); $optionChain = $client->getOptionChain("AAPL", new \DateTime("2021-01-01"));
Version Guidance
License
This library is available under the MIT license.
Contributing
Want to contribute to this project? See CONTRIBUTING.md.
Support Me
I'm developing this library since 2014. I love to hear from people using it, giving me the motivation to keep working on my open source projects.
If you want to let me know you're finding it useful, please consider giving it a star ⭐ on GitHub.
If you love my work and want to say thank you, you can help me out for a beer 🍻️ via PayPal.