scheb/yahoo-finance-api

PHP library for accessing Yahoo Finance data

v2.1.0 2017-08-31 16:00 UTC

README

This is a PHP client for Yahoo Finance API.

It provides easy access to stock quotes via Yahoo's [YQL API] (http://developer.yahoo.com/yql/) and other non-official APIs.

WARNING: The non-official APIs (search, historical data) cannot be assumed stable and might break any time. So use them at your own risk.

Build Status PHP 7 ready Coverage Status Latest Stable Version License

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": "^2.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\ExchangeRate
$exchangeRate = $client->getExchangeRate("USD", "EUR");

// Returns an array of Scheb\YahooFinanceApi\Results\ExchangeRate
$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"]);