{"id":15025299,"url":"https://github.com/ericoc/old-stock-quotes-php-lib","last_synced_at":"2025-10-03T23:32:08.077Z","repository":{"id":147419688,"uuid":"103041119","full_name":"ericoc/old-stock-quotes-php-lib","owner":"ericoc","description":"Stock Quote PHP Library","archived":true,"fork":false,"pushed_at":"2017-11-02T14:26:42.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-28T19:40:57.262Z","etag":null,"topics":["curl","deprecated","php-7","php-curl","php-library","php7","php70","phpredis","redis","redis-cache","stock-data","stock-market","stock-prices","stock-quotes","stockmarket","stocks","yahoo-finance","yahoo-finance-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericoc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-10T15:42:00.000Z","updated_at":"2023-01-28T21:17:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec1433ef-997e-4c96-8b09-6da91389fb66","html_url":"https://github.com/ericoc/old-stock-quotes-php-lib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericoc%2Fold-stock-quotes-php-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericoc%2Fold-stock-quotes-php-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericoc%2Fold-stock-quotes-php-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericoc%2Fold-stock-quotes-php-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericoc","download_url":"https://codeload.github.com/ericoc/old-stock-quotes-php-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235204448,"owners_count":18952326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curl","deprecated","php-7","php-curl","php-library","php7","php70","phpredis","redis","redis-cache","stock-data","stock-market","stock-prices","stock-quotes","stockmarket","stocks","yahoo-finance","yahoo-finance-api"],"created_at":"2024-09-24T20:02:01.345Z","updated_at":"2025-10-03T23:32:07.738Z","avatar_url":"https://github.com/ericoc.png","language":"PHP","readme":"\n# DEPRECATED\n\n## Unfortunately, this library is now deprecated.\n\nYahoo has disabled their YQL API for stock quotes. Currently, Yahoo is returning HTTP status codes of 999 with a message of \"`Requested denied`\".\n\n\t\"http-status-code\": \"999\"\n\t\"http-status-message\": \"Request denied\"\n\nThere is very little information as to *why* Yahoo chose to discontinue this API, but there is one note here:\n\n[https://forums.yahoo.net/t5/Yahoo-Finance-help/Receiving-Unable-to-process-request-at-this-time-error-999-lt/td-p/365013](https://forums.yahoo.net/t5/Yahoo-Finance-help/Receiving-Unable-to-process-request-at-this-time-error-999-lt/td-p/365013)\n\nIn any case, I had a lot of fun creating this library and learned a bunch. It was also the only time (*so far*!) that I have seriously used Redis in a personal project that I made public.\n\n### It was fun while it lasted!\n\n\n---\n\n# ~~Stock Quote PHP Library~~\n\n~~This was primarily a challenge to myself to create a PHP library/class that could look up stock quotes for stock symbols in a really efficient way. I wanted to avoid any unnecessary or extraneous HTTPS requests to whatever API I was using. The script uses [this Yahoo SQL API](https://developer.yahoo.com/yql/console/?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22YHOO%22%2C%22AAPL%22%2C%22GOOG%22%2C%22MSFT%22)\u0026env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys) (click the `Test` button...)~~\n\n~~The `stock_quotes` PHP class within [`stock_quotes.class.php`](stock_quotes.class.php) will only look up stock quotes that it does not already know, does so using a single HTTPS request for multiple stock symbols, and caches the stock quotes in Redis.~~\n\n## ~~Features~~\n\n* ~~Assuming you have nothing cached in Redis (by prior runs of the class/script for example), all of the stock symbols will be looked up using Yahoo's API and quotes will be retrieved.~~\n* ~~The stock quotes for each symbol being looked up are stored in the internal `$stock_quotes` array until the `stock_quotes` object is destroyed (like at the end of the script).~~\n* ~~The stock quotes are also stored (\"cached\") in Redis and automatically expire after `$redis_expire` seconds which is set in [`stock_quotes.class.php`](stock_quotes.class.php).~~\n* ~~Every call to the `get_stock_quotes()` method checks that there is not already a stock quote for each symbol within the internal `$stock_quotes` array as well as the Redis cache before hitting the Yahoo API to avoid any possibility of unnecessary HTTPS requests to the API.~~\n* ~~Furthermore, only a single HTTPS request is made to Yahoo API for each call to the `get_stock_quotes()` method (for any stock symbols which a quote is not known already) since a single HTTPS request can retrieve stock quotes for multiple stock symbols.~~\n\n## ~~Example~~\n\n~~Running the [`stock_quotes.php`](stock_quotes.php) demo will return something like the following (albeit with different numbers surely):~~\n\n\t$ php stock_quotes.php\n\tArray\n\t(\n\t    [INDU] =\u003e stdClass Object\n\t        (\n\t            [symbol] =\u003e INDU\n\t            [AverageDailyVolume] =\u003e\n\t            [Change] =\u003e +13.01\n\t            [DaysLow] =\u003e 21731.12\n\t            [DaysHigh] =\u003e 21846.63\n\t            [YearLow] =\u003e 17883.60\n\t            [YearHigh] =\u003e 22179.10\n\t            [MarketCapitalization] =\u003e\n\t            [LastTradePriceOnly] =\u003e 21797.79\n\t            [DaysRange] =\u003e 21731.12 - 21846.63\n\t            [Name] =\u003e Dow Jones Industrial Average\n\t            [Symbol] =\u003e INDU\n\t            [Volume] =\u003e 289404747\n\t            [StockExchange] =\u003e DJI\n\t        )\n\n\t    [^IXIC] =\u003e stdClass Object\n\t        (\n\t            [symbol] =\u003e ^IXIC\n\t            [AverageDailyVolume] =\u003e\n\t            [Change] =\u003e -37.6772\n\t            [DaysLow] =\u003e 6354.9556\n\t            [DaysHigh] =\u003e 6391.4087\n\t            [YearLow] =\u003e 5034.4102\n\t            [YearHigh] =\u003e 6460.8398\n\t            [MarketCapitalization] =\u003e\n\t            [LastTradePriceOnly] =\u003e 6360.1914\n\t            [DaysRange] =\u003e 6354.9556 - 6391.4087\n\t            [Name] =\u003e NASDAQ Composite\n\t            [Symbol] =\u003e ^IXIC\n\t            [Volume] =\u003e 1558104187\n\t            [StockExchange] =\u003e NIM\n\t        )\n\n\t    [^GSPC] =\u003e stdClass Object\n\t        (\n\t            [symbol] =\u003e ^GSPC\n\t            [AverageDailyVolume] =\u003e\n\t            [Change] =\u003e -3.67\n\t            [DaysLow] =\u003e 2459.40\n\t            [DaysHigh] =\u003e 2467.11\n\t            [YearLow] =\u003e 2083.79\n\t            [YearHigh] =\u003e 2490.87\n\t            [MarketCapitalization] =\u003e\n\t            [LastTradePriceOnly] =\u003e 2461.43\n\t            [DaysRange] =\u003e 2459.40 - 2467.11\n\t            [Name] =\u003e S\u0026P 500\n\t            [Symbol] =\u003e ^GSPC\n\t            [Volume] =\u003e 2003871859\n\t            [StockExchange] =\u003e SNP\n\t        )\n\n\t    [AAPL] =\u003e stdClass Object\n\t        (\n\t            [symbol] =\u003e AAPL\n\t            [AverageDailyVolume] =\u003e 27292000\n\t            [Change] =\u003e -2.63\n\t            [DaysLow] =\u003e 158.53\n\t            [DaysHigh] =\u003e 161.15\n\t            [YearLow] =\u003e 102.53\n\t            [YearHigh] =\u003e 164.94\n\t            [MarketCapitalization] =\u003e 819.36B\n\t            [LastTradePriceOnly] =\u003e 158.63\n\t            [DaysRange] =\u003e 158.53 - 161.15\n\t            [Name] =\u003e Apple Inc.\n\t            [Symbol] =\u003e AAPL\n\t            [Volume] =\u003e 28611535\n\t            [StockExchange] =\u003e NMS\n\t        )\n\n\t    [HPQ] =\u003e stdClass Object\n\t        (\n\t            [symbol] =\u003e HPQ\n\t            [AverageDailyVolume] =\u003e 10538500\n\t            [Change] =\u003e -0.16\n\t            [DaysLow] =\u003e 19.08\n\t            [DaysHigh] =\u003e 19.26\n\t            [YearLow] =\u003e 13.77\n\t            [YearHigh] =\u003e 19.78\n\t            [MarketCapitalization] =\u003e 32.14B\n\t            [LastTradePriceOnly] =\u003e 19.12\n\t            [DaysRange] =\u003e 19.08 - 19.26\n\t            [Name] =\u003e HP Inc.\n\t            [Symbol] =\u003e HPQ\n\t            [Volume] =\u003e 5177911\n\t            [StockExchange] =\u003e NYQ\n\t        )\n\n\t    [GOOG] =\u003e stdClass Object\n\t        (\n\t            [symbol] =\u003e GOOG\n\t            [AverageDailyVolume] =\u003e 1641720\n\t            [Change] =\u003e -9.45\n\t            [DaysLow] =\u003e 924.88\n\t            [DaysHigh] =\u003e 936.99\n\t            [YearLow] =\u003e 727.54\n\t            [YearHigh] =\u003e 988.25\n\t            [MarketCapitalization] =\u003e 641.95B\n\t            [LastTradePriceOnly] =\u003e 926.50\n\t            [DaysRange] =\u003e 924.88 - 936.99\n\t            [Name] =\u003e Alphabet Inc.\n\t            [Symbol] =\u003e GOOG\n\t            [Volume] =\u003e 1011538\n\t            [StockExchange] =\u003e NMS\n\t        )\n\n\t    [NOPE] =\u003e stdClass Object\n\t        (\n\t            [symbol] =\u003e NOPE\n\t            [AverageDailyVolume] =\u003e\n\t            [Change] =\u003e\n\t            [DaysLow] =\u003e\n\t            [DaysHigh] =\u003e\n\t            [YearLow] =\u003e\n\t            [YearHigh] =\u003e\n\t            [MarketCapitalization] =\u003e\n\t            [LastTradePriceOnly] =\u003e\n\t            [DaysRange] =\u003e\n\t            [Name] =\u003e\n\t            [Symbol] =\u003e NOPE\n\t            [Volume] =\u003e\n\t            [StockExchange] =\u003e\n\t        )\n\n\t    [SNAP] =\u003e stdClass Object\n\t        (\n\t            [symbol] =\u003e SNAP\n\t            [AverageDailyVolume] =\u003e 25914300\n\t            [Change] =\u003e +0.17\n\t            [DaysLow] =\u003e 15.10\n\t            [DaysHigh] =\u003e 15.80\n\t            [YearLow] =\u003e 11.28\n\t            [YearHigh] =\u003e 29.44\n\t            [MarketCapitalization] =\u003e 18.34B\n\t            [LastTradePriceOnly] =\u003e 15.32\n\t            [DaysRange] =\u003e 15.10 - 15.80\n\t            [Name] =\u003e Snap Inc.\n\t            [Symbol] =\u003e SNAP\n\t            [Volume] =\u003e 35956509\n\t            [StockExchange] =\u003e NYQ\n\t        )\n\n\t)\n\t===\n\t[MSFT] Microsoft Corporation | Change: $-0.36 / Low: $73.84 / High: $74.44\n\t[GOOG] Alphabet Inc. | Change: $-9.45 / Low: $924.88 / High: $936.99\n\t[YELP] Yelp Inc. | Change: $0.01 / Low: $43.41 / High: $44.25\n\t[SPLK] Splunk Inc. | Change: $-1.24 / Low: $67.12 / High: $68.76\n\n\n### ~~Explanation~~\n\n~~Per the output above, each key in the final `$quotes` (and `$quotes2`) array is a stock symbol with the value being an object containing that stock symbols quote.~~\n\n~~Some cool stuff is going on in the background here:~~\n\n* ~~In the example of [`stock_quotes.php`](stock_quotes.php), assuming Redis is empty, stock quotes are looked up at Yahoo for all of the requested stock symbols in `$quotes`:~~\n\t- ~~INDU~~\n\t- ~~\\^IXIC~~\n\t- ~~\\^GSPC~~\n\t- ~~AAPL~~\n\t- ~~HPQ~~\n\t- ~~GOOG~~\n\t- ~~NOPE~~\n\t- ~~SNAP~~\n* ~~However, in the second call to the `get_stock_quotes()` method via `$quotes2`, a quote for GOOG is already known within the internal `$stock_quotes` array so the Yahoo API is only contacted for these stock symbols:~~\n\t- ~~MSFT~~\n\t- ~~YELP~~\n\t- ~~SPLK~~\n* ~~If [`stock_quotes.php`](stock_quotes.php) was executed twice within `$redis_expire` seconds (before the stock quotes expired in Redis), no requests would be made to Yahoo at all. All of the stock quotes would already be known since they are available in Redis!~~\n\n\n### ~~Other Notes~~\n\n* ~~Even invalid stock symbols are cached in Redis and stored in the internal `$stock_quotes` array so that they will not be looked up using the Yahoo API unnecessarily.~~\n* ~~`$redis_expire` can be set to zero (`0`) in [`stock_quotes.class.php`](stock_quotes.class.php) to disable caching to Redis entirely.~~\n* ~~If a stock quote for a stock symbol is found within the `$stock_quotes` array or the Redis cache, it is not re-written to the Redis cache (so it will still expire at `$redis_expire` seconds from when it was _originally_ stored in Redis).~~\n\t- ~~This prevents very stale stock quote data from being served by Redis in case a single stock symbol is repeatedly being requested every few seconds (i.e. more often than `$redis_expire`).~~\n* ~~A handy bash one-liner to monitor stock quotes that are available in Redis along with their TTL:~~\n\n\t\twatch -n 2 'for x in $(echo \"keys *\" | redis-cli  | grep stocks_);do echo -n \"$x \" \u0026\u0026 echo \"ttl $x\" | redis-cli;done'\n\n\t- ~~If you change `$redis_key_prefix` to something other than `stocks_` in [`stock_quotes.class.php`](stock_quotes.class.php), adjust the above bash command appropriately~~\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericoc%2Fold-stock-quotes-php-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericoc%2Fold-stock-quotes-php-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericoc%2Fold-stock-quotes-php-lib/lists"}