PHPackages                             scheb/yahoo-finance-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. scheb/yahoo-finance-api

ActiveLibrary[API Development](/categories/api)

scheb/yahoo-finance-api
=======================

PHP library for accessing Yahoo Finance data

v5.1.0(7mo ago)318204.8k↑12.1%635MITPHPPHP &gt;=8.1CI passing

Since Jan 18Pushed 2mo ago29 watchersCompare

[ Source](https://github.com/scheb/yahoo-finance-api)[ Packagist](https://packagist.org/packages/scheb/yahoo-finance-api)[ Docs](https://github.com/scheb/yahoo-finance-api)[ RSS](/packages/scheb-yahoo-finance-api/feed)WikiDiscussions 5.x Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (36)Used By (5)

scheb/yahoo-finance-api
=======================

[](#schebyahoo-finance-api)

**This is a PHP client for Yahoo Finance API.**

[![Build Status](https://github.com/scheb/yahoo-finance-api/actions/workflows/ci.yaml/badge.svg?branch=5.x)](https://github.com/scheb/yahoo-finance-api/actions?query=workflow%3ACI+branch%3A5.x)[![Code Coverage](https://camo.githubusercontent.com/430454e79f2e53eed23815a1d0c6110b04b9aee9277d079b001d40e8de432bdb/68747470733a2f2f636f6465636f762e696f2f67682f73636865622f7961686f6f2d66696e616e63652d6170692f6272616e63682f352e782f67726170682f62616467652e737667)](https://app.codecov.io/gh/scheb/yahoo-finance-api/tree/5.x)[![Latest Stable Version](https://camo.githubusercontent.com/f6590b687530d3227a618a7c2f817445a69f4fa74f111ccbca51bae6d3542988/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73636865622f7961686f6f2d66696e616e63652d617069)](https://packagist.org/packages/scheb/yahoo-finance-api)[![Total Downloads](https://camo.githubusercontent.com/9a996b0ebb110af96c0330f91cdd97890e83a082d64bac325f7e619e286870c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73636865622f7961686f6f2d66696e616e63652d617069)](https://packagist.org/packages/scheb/yahoo-finance-api/stats)[![License](https://camo.githubusercontent.com/b151478163bd92f0ef5d789431418f33574f5acfd45d44d7ac40e95c0e90df78/68747470733a2f2f706f7365722e707567782e6f72672f73636865622f7961686f6f2d66696e616e63652d6170692f6c6963656e73652e737667)](https://packagist.org/packages/scheb/yahoo-finance-api)

[![Logo](doc/logo.svg)](doc/logo.svg)

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](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [Version Guidance](#version-guidance)
- [License](#license)
- [Contributing](#contributing)
- [Support Me](#support-me)

Installation
------------

[](#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": "^5"
    }
}
```

and then tell Composer to install the package:

```
composer update scheb/yahoo-finance-api
```

Usage
-----

[](#usage)

```
use Scheb\YahooFinanceApi\ApiClient;
use Scheb\YahooFinanceApi\ApiClientFactory;
use GuzzleHttp\Client;

// Create a new client from the factory
$client = ApiClientFactory::createApiClient();

// Or configure with options
$client = ApiClientFactory::createApiClient(
    clientOptions: [/* ... */], // Guzzle client options
    retries: 3,
    retryDelay: 1000, // milliseconds
);

// 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"));
```

Configuration
-------------

[](#configuration)

### User Agent

[](#user-agent)

You can customize the User-Agent header by passing it in the Guzzle client options:

```
$guzzleClientOptions = ['headers' => ['User-Agent' => 'MyApp/1.0']];
$client = ApiClientFactory::createApiClient($guzzleClientOptions);
```

### Using curl-impersonate

[](#using-curl-impersonate)

This library supports [curl-impersonate](https://github.com/lexiforest/curl-impersonate) to mimic real browser behavior. When using curl-impersonate, the library automatically removes the default User-Agent header to let curl-impersonate handle it.

To use curl-impersonate:

1. Install curl-impersonate on your system
    - Typically, you'd want to download the `libcurl-*` package for the respective system architecture and extract it
    - Follow the [Using libcurl-impersonate in PHP scripts](https://github.com/lexiforest/curl-impersonate/blob/main/docs/07_with_php.md) guide
2. When execution your application, set the required environment variables:

```
export LD_PRELOAD=/path/to/curl-impersonate/libcurl-impersonate.so
export CURL_IMPERSONATE=chrome136  # or another browser version
```

3. Create your API client normally - no additional configuration needed:

```
$client = ApiClientFactory::createApiClient();
```

The library will automatically detect the `CURL_IMPERSONATE` environment variable and configure the HTTP client accordingly.

### Retry Feature

[](#retry-feature)

The library includes a built-in retry mechanism that can automatically retry failed requests. Configure it when creating the client:

```
$client = ApiClientFactory::createApiClient(
    retries: 3,        // Number of retry attempts (default: 0)
    retryDelay: 1000,  // Delay between retries in milliseconds (default: 0)
);
```

When a request fails, the library will:

1. Wait for the specified delay
2. Renew the session context (fetch new set of cookies and crumb value)
3. Retry the request
4. Repeat until success or max retries reached

### Context Cache Feature

[](#context-cache-feature)

The library supports caching session contexts (cookies and crumb value) to improve performance and reduce HTTP requests. This is especially useful in high-traffic applications or when making multiple requests.

To use caching, you need a PSR-6 cache implementation, e.g. you could use `symfony/cache`:

```
composer require symfony/cache
```

Then configure the cache. In this example, a simple file-based cache is used:

```
use Scheb\YahooFinanceApi\ApiClientFactory;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

// File-based cache from symfony/cache
$cache = new FilesystemAdapter();

// Create API client with caching
$client = ApiClientFactory::createApiClient(
    cache: $cache,              // PSR-6 cache implementation
    cacheTtl: 3600,             // Cache TTL in seconds (optional, default: 3600)
    cacheKey: 'my_cache_key'    // Custom cache key (optional)
);
```

Version Guidance
----------------

[](#version-guidance)

VersionStatusPHP Version[1.x](https://github.com/scheb/yahoo-finance-api/tree/1.x)EOL&gt;= 5.3.0[2.x](https://github.com/scheb/yahoo-finance-api/tree/2.x)EOL&gt;= 5.6.0[3.x](https://github.com/scheb/yahoo-finance-api/tree/3.x)EOL&gt;= 5.6.0[4.x](https://github.com/scheb/yahoo-finance-api/tree/4.x)EOL&gt;= 7.1.3**[5.x](https://github.com/scheb/yahoo-finance-api/tree/5.x)**Maintained&gt;= 8.1.0License
-------

[](#license)

This library is available under the [MIT license](LICENSE).

Contributing
------------

[](#contributing)

Want to contribute to this project? See [CONTRIBUTING.md](CONTRIBUTING.md).

Support Me
----------

[](#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](https://paypal.me/ChristianScheb).

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance76

Regular maintenance activity

Popularity55

Moderate usage in the ecosystem

Community33

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~126 days

Recently: every ~61 days

Total

36

Last Release

75d ago

Major Versions

1.x-dev → v2.0.02017-08-10

v2.1.0 → v3.0.02017-11-14

2.x-dev → v3.1.02018-04-05

3.x-dev → v4.0.02020-06-18

4.x-dev → v5.0.02025-07-05

PHP version history (4 changes)v1.0.0PHP &gt;=5.3.0

v2.0.0PHP &gt;=5.6.0

v4.0.0PHP &gt;=7.1.3

v5.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/496658d46619a414a62b1e933fb7fc2e57eff4f0a4109f4cffc32093f57d65da?d=identicon)[scheb](/maintainers/scheb)

---

Top Contributors

[![scheb](https://avatars.githubusercontent.com/u/1259952?v=4)](https://github.com/scheb "scheb (203 commits)")[![CompoTypo](https://avatars.githubusercontent.com/u/26588145?v=4)](https://github.com/CompoTypo "CompoTypo (4 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (3 commits)")[![hackeresq](https://avatars.githubusercontent.com/u/16628119?v=4)](https://github.com/hackeresq "hackeresq (2 commits)")[![jrodriguesd](https://avatars.githubusercontent.com/u/100245095?v=4)](https://github.com/jrodriguesd "jrodriguesd (2 commits)")[![AbramovVyacheslav](https://avatars.githubusercontent.com/u/16228180?v=4)](https://github.com/AbramovVyacheslav "AbramovVyacheslav (1 commits)")[![Spomky](https://avatars.githubusercontent.com/u/1091072?v=4)](https://github.com/Spomky "Spomky (1 commits)")[![BenjaminPaap](https://avatars.githubusercontent.com/u/396685?v=4)](https://github.com/BenjaminPaap "BenjaminPaap (1 commits)")[![clind922](https://avatars.githubusercontent.com/u/3989064?v=4)](https://github.com/clind922 "clind922 (1 commits)")[![elminson](https://avatars.githubusercontent.com/u/2476286?v=4)](https://github.com/elminson "elminson (1 commits)")[![FabienVINCENT](https://avatars.githubusercontent.com/u/68119797?v=4)](https://github.com/FabienVINCENT "FabienVINCENT (1 commits)")

---

Tags

exchange-ratesfinancephpstock-marketstock-quotesstocksyahooyahoo-financeapifinanceyahoostock

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/scheb-yahoo-finance-api/health.svg)

```
[![Health](https://phpackages.com/badges/scheb-yahoo-finance-api/health.svg)](https://phpackages.com/packages/scheb-yahoo-finance-api)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[bunq/sdk_php

bunq PHP SDK

89222.7k2](/packages/bunq-sdk-php)[jeffreyhyer/alpaca-trade-api-php

PHP SDK for the Alpaca trade API

285.0k](/packages/jeffreyhyer-alpaca-trade-api-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
