krivov / yahoo-finance-api
PHP library for accessing Yahoo Finance data
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 62
pkg:composer/krivov/yahoo-finance-api
Requires
- php: >=8.3.3
- ext-json: *
- guzzlehttp/guzzle: ^6.0|^7.0
Requires (Dev)
- escapestudios/symfony2-coding-standard: ^3.9
- friendsofphp/php-cs-fixer: ^3.59
- phpunit/phpunit: ^7.5 || ^8 || ^9
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^3.11|^4.0
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:
php composer.phar require scheb/yahoo-finance-api
Alternatively you can also add the bundle directly to composer.json:
{
"require": {
"scheb/yahoo-finance-api": "^3.0"
}
}
and then tell Composer to install the bundle:
php composer.phar 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->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"]);
Contribute
You're welcome to contribute to this library by creating a pull requests or feature request in the issues section. For pull requests, please follow these guidelines:
- Symfony code style
- Please add/update test cases
- Test methods should be named
[method]_[scenario]_[expected result]
To run the test suite install the dependencies with composer install and then execute bin/phpunit.
License
This bundle is available under the MIT license.