├── vendor ├── .gitignore ├── autoload.php ├── composer │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_files.php │ ├── autoload_psr4.php │ ├── LICENSE │ ├── autoload_static.php │ ├── autoload_real.php │ ├── installed.json │ └── ClassLoader.php └── ralouphie │ └── getallheaders │ ├── composer.json │ ├── LICENSE │ ├── README.md │ └── src │ └── getallheaders.php ├── composer.json ├── example └── index.php ├── src └── YF.php ├── readme.md └── composer.lock /vendor/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | -------------------------------------------------------------------------------- /vendor/autoload.php: -------------------------------------------------------------------------------- 1 | =5.6" 13 | }, 14 | "require-dev": { 15 | "phpunit/phpunit": "^5 || ^6.5", 16 | "php-coveralls/php-coveralls": "^2.1" 17 | }, 18 | "autoload": { 19 | "files": ["src/getallheaders.php"] 20 | }, 21 | "autoload-dev": { 22 | "psr-4": { 23 | "getallheaders\\Tests\\": "tests/" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/composer/autoload_files.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php', 10 | 'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php', 11 | 'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php', 12 | '37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php', 13 | ); 14 | -------------------------------------------------------------------------------- /vendor/composer/autoload_psr4.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/src'), 10 | 'Scheb\\YahooFinanceApi\\' => array($vendorDir . '/scheb/yahoo-finance-api/src'), 11 | 'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'), 12 | 'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'), 13 | 'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'), 14 | 'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'), 15 | ); 16 | -------------------------------------------------------------------------------- /vendor/composer/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) Nils Adermann, Jordi Boggiano 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is furnished 9 | to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /vendor/ralouphie/getallheaders/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Ralph Khattar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/ralouphie/getallheaders/README.md: -------------------------------------------------------------------------------- 1 | getallheaders 2 | ============= 3 | 4 | PHP `getallheaders()` polyfill. Compatible with PHP >= 5.3. 5 | 6 | [![Build Status](https://travis-ci.org/ralouphie/getallheaders.svg?branch=master)](https://travis-ci.org/ralouphie/getallheaders) 7 | [![Coverage Status](https://coveralls.io/repos/ralouphie/getallheaders/badge.png?branch=master)](https://coveralls.io/r/ralouphie/getallheaders?branch=master) 8 | [![Latest Stable Version](https://poser.pugx.org/ralouphie/getallheaders/v/stable.png)](https://packagist.org/packages/ralouphie/getallheaders) 9 | [![Latest Unstable Version](https://poser.pugx.org/ralouphie/getallheaders/v/unstable.png)](https://packagist.org/packages/ralouphie/getallheaders) 10 | [![License](https://poser.pugx.org/ralouphie/getallheaders/license.png)](https://packagist.org/packages/ralouphie/getallheaders) 11 | 12 | 13 | This is a simple polyfill for [`getallheaders()`](http://www.php.net/manual/en/function.getallheaders.php). 14 | 15 | ## Install 16 | 17 | For PHP version **`>= 5.6`**: 18 | 19 | ``` 20 | composer require ralouphie/getallheaders 21 | ``` 22 | 23 | For PHP version **`< 5.6`**: 24 | 25 | ``` 26 | composer require ralouphie/getallheaders "^2" 27 | ``` 28 | -------------------------------------------------------------------------------- /vendor/ralouphie/getallheaders/src/getallheaders.php: -------------------------------------------------------------------------------- 1 | 'Content-Type', 16 | 'CONTENT_LENGTH' => 'Content-Length', 17 | 'CONTENT_MD5' => 'Content-Md5', 18 | ); 19 | 20 | foreach ($_SERVER as $key => $value) { 21 | if (substr($key, 0, 5) === 'HTTP_') { 22 | $key = substr($key, 5); 23 | if (!isset($copy_server[$key]) || !isset($_SERVER[$key])) { 24 | $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', $key)))); 25 | $headers[$key] = $value; 26 | } 27 | } elseif (isset($copy_server[$key])) { 28 | $headers[$copy_server[$key]] = $value; 29 | } 30 | } 31 | 32 | if (!isset($headers['Authorization'])) { 33 | if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { 34 | $headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; 35 | } elseif (isset($_SERVER['PHP_AUTH_USER'])) { 36 | $basic_pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; 37 | $headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $basic_pass); 38 | } elseif (isset($_SERVER['PHP_AUTH_DIGEST'])) { 39 | $headers['Authorization'] = $_SERVER['PHP_AUTH_DIGEST']; 40 | } 41 | } 42 | 43 | return $headers; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php', 11 | 'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php', 12 | 'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php', 13 | '37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php', 14 | ); 15 | 16 | public static $prefixLengthsPsr4 = array ( 17 | 'g' => 18 | array ( 19 | 'gauss314\\yahoo_finance\\' => 23, 20 | ), 21 | 'S' => 22 | array ( 23 | 'Scheb\\YahooFinanceApi\\' => 22, 24 | ), 25 | 'P' => 26 | array ( 27 | 'Psr\\Http\\Message\\' => 17, 28 | ), 29 | 'G' => 30 | array ( 31 | 'GuzzleHttp\\Psr7\\' => 16, 32 | 'GuzzleHttp\\Promise\\' => 19, 33 | 'GuzzleHttp\\' => 11, 34 | ), 35 | ); 36 | 37 | public static $prefixDirsPsr4 = array ( 38 | 'gauss314\\yahoo_finance\\' => 39 | array ( 40 | 0 => __DIR__ . '/../..' . '/src', 41 | ), 42 | 'Scheb\\YahooFinanceApi\\' => 43 | array ( 44 | 0 => __DIR__ . '/..' . '/scheb/yahoo-finance-api/src', 45 | ), 46 | 'Psr\\Http\\Message\\' => 47 | array ( 48 | 0 => __DIR__ . '/..' . '/psr/http-message/src', 49 | ), 50 | 'GuzzleHttp\\Psr7\\' => 51 | array ( 52 | 0 => __DIR__ . '/..' . '/guzzlehttp/psr7/src', 53 | ), 54 | 'GuzzleHttp\\Promise\\' => 55 | array ( 56 | 0 => __DIR__ . '/..' . '/guzzlehttp/promises/src', 57 | ), 58 | 'GuzzleHttp\\' => 59 | array ( 60 | 0 => __DIR__ . '/..' . '/guzzlehttp/guzzle/src', 61 | ), 62 | ); 63 | 64 | public static function getInitializer(ClassLoader $loader) 65 | { 66 | return \Closure::bind(function () use ($loader) { 67 | $loader->prefixLengthsPsr4 = ComposerStaticInit808e166fdec32112e1514bdc06900bbc::$prefixLengthsPsr4; 68 | $loader->prefixDirsPsr4 = ComposerStaticInit808e166fdec32112e1514bdc06900bbc::$prefixDirsPsr4; 69 | 70 | }, null, ClassLoader::class); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vendor/composer/autoload_real.php: -------------------------------------------------------------------------------- 1 | = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); 27 | if ($useStaticLoader) { 28 | require_once __DIR__ . '/autoload_static.php'; 29 | 30 | call_user_func(\Composer\Autoload\ComposerStaticInit808e166fdec32112e1514bdc06900bbc::getInitializer($loader)); 31 | } else { 32 | $map = require __DIR__ . '/autoload_namespaces.php'; 33 | foreach ($map as $namespace => $path) { 34 | $loader->set($namespace, $path); 35 | } 36 | 37 | $map = require __DIR__ . '/autoload_psr4.php'; 38 | foreach ($map as $namespace => $path) { 39 | $loader->setPsr4($namespace, $path); 40 | } 41 | 42 | $classMap = require __DIR__ . '/autoload_classmap.php'; 43 | if ($classMap) { 44 | $loader->addClassMap($classMap); 45 | } 46 | } 47 | 48 | $loader->register(true); 49 | 50 | if ($useStaticLoader) { 51 | $includeFiles = Composer\Autoload\ComposerStaticInit808e166fdec32112e1514bdc06900bbc::$files; 52 | } else { 53 | $includeFiles = require __DIR__ . '/autoload_files.php'; 54 | } 55 | foreach ($includeFiles as $fileIdentifier => $file) { 56 | composerRequire808e166fdec32112e1514bdc06900bbc($fileIdentifier, $file); 57 | } 58 | 59 | return $loader; 60 | } 61 | } 62 | 63 | function composerRequire808e166fdec32112e1514bdc06900bbc($fileIdentifier, $file) 64 | { 65 | if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { 66 | require $file; 67 | 68 | $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /example/index.php: -------------------------------------------------------------------------------- 1 | getHistorical($symbol, $time_ago); 16 | /* 17 | Array 18 | ( 19 | [0] => Array 20 | ( 21 | [date] => 2019-10-04 22 | [open] => 21.950001 23 | [high] => 22.9 24 | [low] => 21.950001 25 | [close] => 22.9 26 | [adjClose] => 22.9 27 | [volume] => 277948 28 | ) 29 | 30 | .... 31 | .... 32 | 33 | [59] => Array 34 | ( 35 | [date] => 2020-01-03 36 | [open] => 25.5 37 | [high] => 25.549999 38 | [low] => 24.5 39 | [close] => 24.950001 40 | [adjClose] => 24.950001 41 | [volume] => 229283 42 | ) 43 | ) 44 | */ 45 | 46 | 47 | /* 48 | ********************************************** 49 | GET FOREX PAIRS 50 | ********************************************** 51 | */ 52 | $currency_1="USD"; 53 | $currency_2="ARS"; 54 | //$fx = $yf->getFX($currency_1,$currency_2); 55 | 56 | /* 57 | Array 58 | ( 59 | [symbol] => USDARS=X 60 | [date] => 2020-01-04 5:55:51 61 | [bid] => 59.729 62 | [ask] => 59.734 63 | [high] => 59.73 64 | [low] => 59.729 65 | [open] => 59.73 66 | [previous] => 59.729 67 | [price] => 59.729 68 | ) 69 | */ 70 | 71 | 72 | /* 73 | ********************************************** 74 | GET CURRENT QUOTE AND DATA 75 | ********************************************** 76 | */ 77 | $symbol = "YPF"; 78 | // $quote = $yf->getQuote($symbol); 79 | 80 | /* 81 | Array 82 | ( 83 | [symbol] => YPF 84 | [price] => 11.16 85 | [date] => 2020-01-03 21:02:00 86 | [book] => Array 87 | ( 88 | [bidSize] => 31 89 | [bid] => 11.14 90 | [ask] => 11.57 91 | [askSize] => 9 92 | ) 93 | 94 | [today] => Array 95 | ( 96 | [high] => 11.49 97 | [low] => 10.86 98 | [open] => 11.24 99 | [previousDay] => 11.26 100 | [volume] => 2732642 101 | [change] => -0.10000038 102 | [changePercent] => -0.8881029 103 | ) 104 | 105 | [AfterMarket] => Array 106 | ( 107 | [price] => 11.0746 108 | [change] => -0.08539963 109 | [changePercent] => -0.76522964 110 | [lastTrade] => 2020-01-03 21:26:02 111 | ) 112 | 113 | [financials] => Array 114 | ( 115 | [name] => YPF Sociedad Anonima 116 | [mktCap] => 4389372928 117 | [sharesOutstanding] => 393312992 118 | [volumeAvg3Month] => 2095557 119 | [bookValue] => 33.975 120 | [eps12Month] => 3.125 121 | [dividendRate] => 0.089 122 | [dividendYield] => 0.007904085 123 | ) 124 | 125 | [stats] => Array 126 | ( 127 | [SMA50] => 10.16606 128 | [SMA200] => 11.737482 129 | [1yrHigh] => 18.73 130 | [1yrHighChangePercent] => -0.40416443 131 | [1yrLow] => 8.04 132 | [1yrLowChangePercent] => 0.38805968 133 | ) 134 | 135 | ) 136 | */ 137 | 138 | 139 | 140 | /* 141 | ********************************************** 142 | GET CONTRACTS EXPIRATIONS DATES 143 | ********************************************** 144 | */ 145 | 146 | $symbol="YPF"; 147 | //$expirations = $yf->getExpirations($symbol); 148 | /* 149 | Array 150 | ( 151 | [0] => Array 152 | ( 153 | [unix] => 1578614400 154 | [days] => 6 155 | [expiration] => 2020-01-10 156 | ) 157 | 158 | ... 159 | ... 160 | 161 | [9] => Array 162 | ( 163 | [unix] => 1642723200 164 | [days] => 748 165 | [expiration] => 2022-01-21 166 | ) 167 | ) 168 | */ 169 | 170 | 171 | /* 172 | ********************************************** 173 | GET CONTRACTS DETAIL 174 | ********************************************** 175 | */ 176 | 177 | $symbol="AAPL"; 178 | //$expirations = $yf->getExpirations($symbol); 179 | //$contracts = $yf->getContracts($symbol,$expirations[0]['unix']); 180 | 181 | /* 182 | Array 183 | ( 184 | [0] => Array 185 | ( 186 | [symbol] => AAPL 187 | [spot] => 297.43 188 | [expiration] => 2020-01-10 189 | [strike] => 230 190 | [otm_abs] => 22.67 191 | [call_contract] => AAPL200110C00230000 192 | [call_bid] => 67.85 193 | [call_ask] => 69.6 194 | [call_lastPrice] => 68.99 195 | [call_volume] => 18 196 | [call_openInterest] => 0 197 | [call_lastTradeDateUNIX] => 1578069878 198 | [call_lastTradeDate] => 2020-01-03 199 | [put_contract] => AAPL200110P00230000 200 | [put_bid] => 0.02 201 | [put_ask] => 0.03 202 | [put_lastPrice] => 0.03 203 | [put_volume] => 6 204 | [put_openInterest] => 0 205 | [put_lastTradeDateUNIX] => 1578061990 206 | [put_lastTradeDate] => 2020-01-03 207 | [IV] => 95.9 208 | ) 209 | 210 | ... 211 | ... 212 | 213 | [37] => Array 214 | ( 215 | [symbol] => AAPL 216 | [spot] => 297.43 217 | [expiration] => 2020-01-10 218 | [strike] => 350 219 | [otm_abs] => 17.67 220 | [call_contract] => AAPL200110C00350000 221 | [call_bid] => 0.02 222 | [call_ask] => 0.03 223 | [call_lastPrice] => 0.05 224 | [call_volume] => 405 225 | [call_openInterest] => 0 226 | [call_lastTradeDateUNIX] => 1578084931 227 | [call_lastTradeDate] => 2020-01-03 228 | [put_contract] => AAPL200110P00350000 229 | [put_bid] => 51 230 | [put_ask] => 51.85 231 | [put_lastPrice] => 51.7 232 | [put_volume] => 2 233 | [put_openInterest] => 0 234 | [put_lastTradeDateUNIX] => 1577983464 235 | [put_lastTradeDate] => 2020-01-02 236 | [IV] => 45.31 237 | ) 238 | ) 239 | */ 240 | 241 | ?> 242 | -------------------------------------------------------------------------------- /src/YF.php: -------------------------------------------------------------------------------- 1 | 0)? round(array_sum($array)/count($array),$decimales) : NULL; 12 | return $prom; 13 | } 14 | 15 | public function diasEntre($fecha_i,$fecha_f) 16 | { 17 | $dias = (strtotime($fecha_i)-strtotime($fecha_f))/86400; 18 | $dias = abs($dias); $dias = floor($dias); 19 | return $dias; 20 | } 21 | 22 | 23 | public function getHistorical($symbol,$time_ago){ 24 | /* 25 | Constantes intervalos: se puede incluir funcionalidad de datos por semana o por mes a futuro 26 | INTERVAL_1_DAY 27 | INTERVAL_1_WEEK 28 | INTERVAL_1_MONTH 29 | */ 30 | $time_ago = "-".$time_ago; 31 | $client = ApiClientFactory::createApiClient(); 32 | $historicalData = $client->getHistoricalData($symbol, ApiClient::INTERVAL_1_DAY, new \DateTime($time_ago), new \DateTime("today")); 33 | 34 | foreach ($historicalData as $key => $value) { 35 | $ret[$key]['date']=date_format($value->getDate(), 'Y-m-d'); 36 | $ret[$key]['open']=$value->getOpen(); 37 | $ret[$key]['high']=$value->getHigh(); 38 | $ret[$key]['low']=$value->getLow(); 39 | $ret[$key]['close']=$value->getClose(); 40 | $ret[$key]['adjClose']=$value->getAdjClose(); 41 | $ret[$key]['volume']=$value->getVolume(); 42 | } 43 | return $ret; 44 | } 45 | 46 | 47 | public function getFX($currency_1,$currency_2){ 48 | $client = ApiClientFactory::createApiClient(); 49 | $exchangeRates = $client->getExchangeRate($currency_1,$currency_2); 50 | $ret['symbol']=$exchangeRates->getSymbol(); 51 | $ret['date']=date_format($exchangeRates->getRegularMarketTime(), 'Y-m-d G:i:s'); 52 | $ret['bid']=$exchangeRates->getBid(); 53 | $ret['ask']=$exchangeRates->getAsk(); 54 | $ret['high']=$exchangeRates->getRegularMarketDayHigh(); 55 | $ret['low']=$exchangeRates->getRegularMarketDayLow(); 56 | $ret['open']=$exchangeRates->getRegularMarketOpen(); 57 | $ret['previousDay']=$exchangeRates->getregularMarketPreviousClose(); 58 | $ret['price']=$exchangeRates->getRegularMarketPrice(); 59 | return $ret; 60 | } 61 | 62 | public function getQuote($symbol){ 63 | $client = ApiClientFactory::createApiClient(); 64 | $quote = $client->getQuote($symbol); 65 | 66 | $ret['symbol']=$quote->getSymbol(); 67 | $ret['price']=$quote->getRegularMarketPrice(); 68 | $ret['date']=date_format($quote->getRegularMarketTime(), 'Y-m-d G:i:s'); 69 | 70 | $ret['book']['bidSize']=$quote->getBidSize(); 71 | $ret['book']['bid']=$quote->getBid(); 72 | $ret['book']['ask']=$quote->getAsk(); 73 | $ret['book']['askSize']=$quote->getAskSize(); 74 | 75 | $ret['today']['high']=$quote->getRegularMarketDayHigh(); 76 | $ret['today']['low']=$quote->getRegularMarketDayLow(); 77 | $ret['today']['open']=$quote->getRegularMarketOpen(); 78 | $ret['today']['previousDay']=$quote->getregularMarketPreviousClose(); 79 | $ret['today']['volume']=$quote->getRegularMarketVolume(); 80 | $ret['today']['change']=$quote->getRegularMarketChange(); 81 | $ret['today']['changePercent']=$quote->getRegularMarketChangePercent(); 82 | 83 | if ($quote->getPostMarketTime()) { 84 | $ret['AfterMarket']['price']=$quote->getPostMarketPrice(); 85 | $ret['AfterMarket']['change']=$quote->getPostMarketChange(); 86 | $ret['AfterMarket']['changePercent']=$quote->getPostMarketChangePercent(); 87 | $ret['AfterMarket']['lastTrade']=date_format($quote->getPostMarketTime(), 'Y-m-d G:i:s'); 88 | } 89 | $ret['financials']['name']=$quote->getShortName(); 90 | $ret['financials']['mktCap']=$quote->getMarketCap(); 91 | $ret['financials']['sharesOutstanding']=$quote->getSharesOutstanding(); 92 | $ret['financials']['volumeAvg3Month']=$quote->getAverageDailyVolume3Month(); 93 | $ret['financials']['bookValue']=$quote->getBookValue(); 94 | $ret['financials']['eps12Month']=$quote->getEpsTrailingTwelveMonths(); 95 | $ret['financials']['dividendRate']=$quote->getTrailingAnnualDividendRate(); 96 | $ret['financials']['dividendYield']=$quote->getTrailingAnnualDividendYield(); 97 | 98 | $ret['stats']['SMA50']=$quote->getFiftyDayAverage(); 99 | $ret['stats']['SMA200']=$quote->getTwoHundredDayAverage(); 100 | $ret['stats']['1yrHigh']=$quote->getFiftyTwoWeekHigh(); 101 | $ret['stats']['1yrHighChangePercent']=$quote->getFiftyTwoWeekHighChangePercent(); 102 | $ret['stats']['1yrLow']=$quote->getFiftyTwoWeekLow(); 103 | $ret['stats']['1yrLowChangePercent']=$quote->getFiftyTwoWeekLowChangePercent(); 104 | 105 | return $ret; 106 | } 107 | 108 | public function getExpirations($symbol){ 109 | $hoyUNIX=date("U"); 110 | $url="https://es.finance.yahoo.com/quote/$symbol/options"; 111 | $dataWEB=file_get_contents($url); 112 | $vencimientos_unix=json_decode(explode(',"hasMiniOptions"',explode('expirationDates":', $dataWEB)[1])[0],true); 113 | foreach ($vencimientos_unix as $key => $value) { 114 | $vencimientos[$key]['unix']=$value; 115 | $vencimientos[$key]['days'] = round(($value-$hoyUNIX)/(24*3600)); 116 | $vencimientos[$key]['expiration']=date("Y-m-d", strtotime(date("Y-m-d",$value).' + 1 days')); 117 | } 118 | return $vencimientos; 119 | } 120 | 121 | public function getContracts($symbol,$expiration){ 122 | $url="https://es.finance.yahoo.com/quote/$symbol/options?date=$expiration&straddle=true&p=$symbol"; 123 | $dataWEB=file_get_contents($url); 124 | $spot = explode('',explode('Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)" data-reactid="34">', $dataWEB)[1])[0]; 125 | $spot = str_replace(",", ".", $spot); 126 | $cadena=explode('{"call.change', $dataWEB); 127 | $rta=[]; 128 | foreach ($cadena as $key => $value) { 129 | if ($key>0) { 130 | $reg='{"call.change'.$value; 131 | $reg=substr($reg,0, -1); 132 | $r=json_decode($reg,true); 133 | $rta[]=$r; 134 | } 135 | } 136 | foreach ($rta as $key => $value) { 137 | if (count($value)==0) { 138 | $inicio=$key; 139 | break(1); 140 | } 141 | } 142 | $rtaOk=[]; 143 | foreach ($rta as $key => $value) { 144 | if ($key>$inicio) { 145 | $rtaOk[]=$value; 146 | } 147 | } 148 | $result['spot']=$spot; 149 | $result['cadena']=array_filter($rtaOk); 150 | 151 | $resultForm = $this->formatearCadena($result['cadena'],$symbol,$expiration,$result['spot']); 152 | return $resultForm; 153 | } 154 | 155 | 156 | public function formatearCadena($cadena,$simbolo,$vencimiento,$spot){ 157 | foreach ($cadena as $key => $value) { 158 | $otm_abs=abs(($value['strike']['raw']/$spot-1)*100); 159 | if ($otm_abs<30 && isset($value['put.contractSymbol']) && isset($value['call.contractSymbol'])) { 160 | $strike=$value['strike']['raw']; 161 | $rta[$strike]['symbol']=$simbolo; 162 | $rta[$strike]['spot']=$spot; 163 | $rta[$strike]['expiration']=date("Y-m-d",strtotime(date("Y-m-d",$vencimiento)."+ 1 day")); 164 | $rta[$strike]['strike']=$value['strike']['raw']; 165 | $rta[$strike]['otm_abs']=round($otm_abs,2); 166 | $rta[$strike]['call_contract']=$value['call.contractSymbol']; 167 | $rta[$strike]['call_bid']=$value['call.bid']['raw']; 168 | $rta[$strike]['call_ask']=$value['call.ask']['raw']; 169 | $rta[$strike]['call_lastPrice']=$value['call.lastPrice']['raw']; 170 | $call_iv=round($value['call.impliedVolatility']['raw']*100,2); 171 | $call_iv=($call_iv>0)? $call_iv : NULL; 172 | $rta[$strike]['call_volume']= (isset($value['call.volume']['raw']))? $value['call.volume']['raw'] : NULL; 173 | $rta[$strike]['call_openInterest']=$value['call.openInterest']['raw']; 174 | $rta[$strike]['call_lastTradeDateUNIX']=$value['call.lastTradeDate']['raw']; 175 | $rta[$strike]['call_lastTradeDate']=$value['call.lastTradeDate']['fmt']; 176 | $rta[$strike]['put_contract']=$value['put.contractSymbol']; 177 | $rta[$strike]['put_bid']=$value['put.bid']['raw']; 178 | $rta[$strike]['put_ask']=$value['put.ask']['raw']; 179 | $rta[$strike]['put_lastPrice']=$value['put.lastPrice']['raw']; 180 | $put_iv=round($value['put.impliedVolatility']['raw']*100,2); 181 | $put_iv=($put_iv>0)? $put_iv : NULL; 182 | $rta[$strike]['put_volume']= (isset($value['put.volume']['raw']))? $value['put.volume']['raw'] : NULL; 183 | $rta[$strike]['put_openInterest']=$value['put.openInterest']['raw']; 184 | $rta[$strike]['put_lastTradeDateUNIX']=$value['put.lastTradeDate']['raw']; 185 | $rta[$strike]['put_lastTradeDate']=$value['put.lastTradeDate']['fmt']; 186 | $rta[$strike]['IV']=$this->promedio([$call_iv,$put_iv]); 187 | 188 | $call_mkt=($rta[$strike]['call_bid']+$rta[$strike]['call_ask'])/2; 189 | $put_mkt=($rta[$strike]['put_bid']+$rta[$strike]['put_ask'])/2; 190 | $tiempo = $this->diasEntre(date("Y-m-d"),$vencimiento['vencimiento']) / 365; 191 | } 192 | } 193 | if ($rta) { 194 | return array_values($rta); 195 | }else { 196 | return NULL; 197 | } 198 | } 199 | 200 | 201 | 202 | } 203 | ?> 204 | -------------------------------------------------------------------------------- /vendor/composer/installed.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "guzzlehttp/guzzle", 4 | "version": "6.5.x-dev", 5 | "version_normalized": "6.5.9999999.9999999-dev", 6 | "source": { 7 | "type": "git", 8 | "url": "https://github.com/guzzle/guzzle.git", 9 | "reference": "400cefd25a23a3098486bfb52685b5367a464171" 10 | }, 11 | "dist": { 12 | "type": "zip", 13 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/400cefd25a23a3098486bfb52685b5367a464171", 14 | "reference": "400cefd25a23a3098486bfb52685b5367a464171", 15 | "shasum": "" 16 | }, 17 | "require": { 18 | "ext-json": "*", 19 | "guzzlehttp/promises": "^1.0", 20 | "guzzlehttp/psr7": "^1.6.1", 21 | "php": ">=5.5" 22 | }, 23 | "require-dev": { 24 | "ext-curl": "*", 25 | "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", 26 | "psr/log": "^1.1" 27 | }, 28 | "suggest": { 29 | "ext-intl": "Required for Internationalized Domain Name (IDN) support", 30 | "psr/log": "Required for using the Log middleware" 31 | }, 32 | "time": "2019-12-30T04:52:42+00:00", 33 | "type": "library", 34 | "extra": { 35 | "branch-alias": { 36 | "dev-master": "6.5-dev" 37 | } 38 | }, 39 | "installation-source": "source", 40 | "autoload": { 41 | "psr-4": { 42 | "GuzzleHttp\\": "src/" 43 | }, 44 | "files": [ 45 | "src/functions_include.php" 46 | ] 47 | }, 48 | "notification-url": "https://packagist.org/downloads/", 49 | "license": [ 50 | "MIT" 51 | ], 52 | "authors": [ 53 | { 54 | "name": "Michael Dowling", 55 | "email": "mtdowling@gmail.com", 56 | "homepage": "https://github.com/mtdowling" 57 | } 58 | ], 59 | "description": "Guzzle is a PHP HTTP client library", 60 | "homepage": "http://guzzlephp.org/", 61 | "keywords": [ 62 | "client", 63 | "curl", 64 | "framework", 65 | "http", 66 | "http client", 67 | "rest", 68 | "web service" 69 | ] 70 | }, 71 | { 72 | "name": "guzzlehttp/promises", 73 | "version": "dev-master", 74 | "version_normalized": "9999999-dev", 75 | "source": { 76 | "type": "git", 77 | "url": "https://github.com/guzzle/promises.git", 78 | "reference": "ac2529fc650684c5cd687e2b462d046cdbed556e" 79 | }, 80 | "dist": { 81 | "type": "zip", 82 | "url": "https://api.github.com/repos/guzzle/promises/zipball/ac2529fc650684c5cd687e2b462d046cdbed556e", 83 | "reference": "ac2529fc650684c5cd687e2b462d046cdbed556e", 84 | "shasum": "" 85 | }, 86 | "require": { 87 | "php": ">=5.6" 88 | }, 89 | "require-dev": { 90 | "phpunit/phpunit": "^5.7.27 || ^7.5" 91 | }, 92 | "time": "2019-12-17T17:19:17+00:00", 93 | "type": "library", 94 | "extra": { 95 | "branch-alias": { 96 | "dev-master": "1.4-dev" 97 | } 98 | }, 99 | "installation-source": "source", 100 | "autoload": { 101 | "psr-4": { 102 | "GuzzleHttp\\Promise\\": "src/" 103 | }, 104 | "files": [ 105 | "src/functions_include.php" 106 | ] 107 | }, 108 | "notification-url": "https://packagist.org/downloads/", 109 | "license": [ 110 | "MIT" 111 | ], 112 | "authors": [ 113 | { 114 | "name": "Michael Dowling", 115 | "email": "mtdowling@gmail.com", 116 | "homepage": "https://github.com/mtdowling" 117 | } 118 | ], 119 | "description": "Guzzle promises library", 120 | "keywords": [ 121 | "promise" 122 | ] 123 | }, 124 | { 125 | "name": "guzzlehttp/psr7", 126 | "version": "1.x-dev", 127 | "version_normalized": "1.9999999.9999999.9999999-dev", 128 | "source": { 129 | "type": "git", 130 | "url": "https://github.com/guzzle/psr7.git", 131 | "reference": "c291e45d40e638815990004e5f7ee367c2b752e9" 132 | }, 133 | "dist": { 134 | "type": "zip", 135 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/c291e45d40e638815990004e5f7ee367c2b752e9", 136 | "reference": "c291e45d40e638815990004e5f7ee367c2b752e9", 137 | "shasum": "" 138 | }, 139 | "require": { 140 | "php": ">=5.4.0", 141 | "psr/http-message": "~1.0", 142 | "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" 143 | }, 144 | "provide": { 145 | "psr/http-message-implementation": "1.0" 146 | }, 147 | "require-dev": { 148 | "ext-zlib": "*", 149 | "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" 150 | }, 151 | "suggest": { 152 | "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" 153 | }, 154 | "time": "2019-12-21T15:35:40+00:00", 155 | "type": "library", 156 | "extra": { 157 | "branch-alias": { 158 | "dev-master": "1.6-dev" 159 | } 160 | }, 161 | "installation-source": "source", 162 | "autoload": { 163 | "psr-4": { 164 | "GuzzleHttp\\Psr7\\": "src/" 165 | }, 166 | "files": [ 167 | "src/functions_include.php" 168 | ] 169 | }, 170 | "notification-url": "https://packagist.org/downloads/", 171 | "license": [ 172 | "MIT" 173 | ], 174 | "authors": [ 175 | { 176 | "name": "Michael Dowling", 177 | "email": "mtdowling@gmail.com", 178 | "homepage": "https://github.com/mtdowling" 179 | }, 180 | { 181 | "name": "Tobias Schultze", 182 | "homepage": "https://github.com/Tobion" 183 | } 184 | ], 185 | "description": "PSR-7 message implementation that also provides common utility methods", 186 | "keywords": [ 187 | "http", 188 | "message", 189 | "psr-7", 190 | "request", 191 | "response", 192 | "stream", 193 | "uri", 194 | "url" 195 | ] 196 | }, 197 | { 198 | "name": "psr/http-message", 199 | "version": "dev-master", 200 | "version_normalized": "9999999-dev", 201 | "source": { 202 | "type": "git", 203 | "url": "https://github.com/php-fig/http-message.git", 204 | "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4" 205 | }, 206 | "dist": { 207 | "type": "zip", 208 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", 209 | "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", 210 | "shasum": "" 211 | }, 212 | "require": { 213 | "php": ">=5.3.0" 214 | }, 215 | "time": "2019-08-29T13:16:46+00:00", 216 | "type": "library", 217 | "extra": { 218 | "branch-alias": { 219 | "dev-master": "1.0.x-dev" 220 | } 221 | }, 222 | "installation-source": "source", 223 | "autoload": { 224 | "psr-4": { 225 | "Psr\\Http\\Message\\": "src/" 226 | } 227 | }, 228 | "notification-url": "https://packagist.org/downloads/", 229 | "license": [ 230 | "MIT" 231 | ], 232 | "authors": [ 233 | { 234 | "name": "PHP-FIG", 235 | "homepage": "http://www.php-fig.org/" 236 | } 237 | ], 238 | "description": "Common interface for HTTP messages", 239 | "homepage": "https://github.com/php-fig/http-message", 240 | "keywords": [ 241 | "http", 242 | "http-message", 243 | "psr", 244 | "psr-7", 245 | "request", 246 | "response" 247 | ] 248 | }, 249 | { 250 | "name": "ralouphie/getallheaders", 251 | "version": "3.0.3", 252 | "version_normalized": "3.0.3.0", 253 | "source": { 254 | "type": "git", 255 | "url": "https://github.com/ralouphie/getallheaders.git", 256 | "reference": "120b605dfeb996808c31b6477290a714d356e822" 257 | }, 258 | "dist": { 259 | "type": "zip", 260 | "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", 261 | "reference": "120b605dfeb996808c31b6477290a714d356e822", 262 | "shasum": "" 263 | }, 264 | "require": { 265 | "php": ">=5.6" 266 | }, 267 | "require-dev": { 268 | "php-coveralls/php-coveralls": "^2.1", 269 | "phpunit/phpunit": "^5 || ^6.5" 270 | }, 271 | "time": "2019-03-08T08:55:37+00:00", 272 | "type": "library", 273 | "installation-source": "dist", 274 | "autoload": { 275 | "files": [ 276 | "src/getallheaders.php" 277 | ] 278 | }, 279 | "notification-url": "https://packagist.org/downloads/", 280 | "license": [ 281 | "MIT" 282 | ], 283 | "authors": [ 284 | { 285 | "name": "Ralph Khattar", 286 | "email": "ralph.khattar@gmail.com" 287 | } 288 | ], 289 | "description": "A polyfill for getallheaders." 290 | }, 291 | { 292 | "name": "scheb/yahoo-finance-api", 293 | "version": "dev-master", 294 | "version_normalized": "9999999-dev", 295 | "source": { 296 | "type": "git", 297 | "url": "https://github.com/scheb/yahoo-finance-api.git", 298 | "reference": "9a7b39e3d97a268577594ef51bddb285fbb0d93a" 299 | }, 300 | "dist": { 301 | "type": "zip", 302 | "url": "https://api.github.com/repos/scheb/yahoo-finance-api/zipball/9a7b39e3d97a268577594ef51bddb285fbb0d93a", 303 | "reference": "9a7b39e3d97a268577594ef51bddb285fbb0d93a", 304 | "shasum": "" 305 | }, 306 | "require": { 307 | "ext-json": "*", 308 | "guzzlehttp/guzzle": "^6.0", 309 | "php": ">=5.6.0" 310 | }, 311 | "require-dev": { 312 | "phpunit/phpunit": "^5.7 || ^6.5" 313 | }, 314 | "time": "2019-12-21T13:02:42+00:00", 315 | "type": "library", 316 | "installation-source": "source", 317 | "autoload": { 318 | "psr-4": { 319 | "Scheb\\YahooFinanceApi\\": "src/" 320 | } 321 | }, 322 | "notification-url": "https://packagist.org/downloads/", 323 | "license": [ 324 | "MIT" 325 | ], 326 | "authors": [ 327 | { 328 | "name": "Christian Scheb", 329 | "email": "me@christianscheb.de" 330 | } 331 | ], 332 | "description": "PHP library for accessing Yahoo Finance data", 333 | "homepage": "https://github.com/scheb/yahoo-finance-api", 334 | "keywords": [ 335 | "api", 336 | "finance", 337 | "stock", 338 | "yahoo" 339 | ] 340 | } 341 | ] 342 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Yahoo Finance non oficial SDK 2 |

3 | Total Downloads 4 | License 5 |

6 | 7 | Since APIs have been discontinued in November 2017, this client is using non-official API endpoints for quotes, search and historical data. 8 | 9 | **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. 10 | 11 | 12 | # Installation 13 | 14 | ```shell 15 | $ composer require "floda/yahoo_finance" 16 | ``` 17 |
18 | 19 | # Usage 20 | 21 | If your project has not an autoloder, just include once this line: 22 | ```php 23 | require_once __DIR__ . "/../vendor/autoload.php"; 24 | ``` 25 | 26 | For Laravel 5, Symfony, just instance object and use functions 27 | 28 |
29 | 30 | ## Historical Data 31 | 32 | ```php 33 | Argentina -> Buenos Aires Stock Exchange (BYMA) 43 | 44 | $time_ago = "3 months"; //you can use xx days, xx weeks, xx months, xx years, etc 45 | 46 | $historical = $yf->getHistorical($symbol, $time_ago); 47 | /* 48 | Array 49 | ( 50 | [0] => Array 51 | ( 52 | [date] => 2019-10-04 53 | [open] => 21.950001 54 | [high] => 22.9 55 | [low] => 21.950001 56 | [close] => 22.9 57 | [adjClose] => 22.9 58 | [volume] => 277948 59 | ) 60 | 61 | .... 62 | .... 63 | 64 | [59] => Array 65 | ( 66 | [date] => 2020-01-03 67 | [open] => 25.5 68 | [high] => 25.549999 69 | [low] => 24.5 70 | [close] => 24.950001 71 | [adjClose] => 24.950001 72 | [volume] => 229283 73 | ) 74 | ) 75 | */ 76 | 77 | ``` 78 | 79 |
80 | 81 | ## All Exchanges 82 | 83 | |Sufix|Country|City|Sufix|Country|City| 84 | | :------------- | :------------- | :------------- | :------------- | :------------- | :------------- | 85 | |.BA|Argentina|Buenos Aires (BYMA)|.NS|India|National of India| 86 | |.VI|Austria|Vienna|.JK|Indonesia|Indonesia (IDX)| 87 | |.AX|Australia|Australian (ASX)|.IR|Ireland|Euronext Dublin| 88 | |.BR|Belgium|Euronext Brussels|.TA|Israel|Tel Aviv| 89 | |.SA|Brazil|Sao Paolo (BOVESPA)|.TI|Italy|EuroTLX| 90 | |.CN|Canada|Canadian Securities|.MI|Italy|Italian| 91 | |.NE|Canada|NEO Exchange|.T|Japan|Tokyo| 92 | |.TO|Canada|Toronto (TSX)|.RG|Latvia|Nasdaq OMX Riga| 93 | |.V|Canada|TSX Venture Exchange (TSXV)|.VS|Lithuania|Nasdaq OMX Vilnius| 94 | |.SN|Chile|Santiago|.KL|Malaysia|Malaysian| 95 | |.SS|China|Shanghai|.MX|Mexico|Mexico (BMV)| 96 | |.SZ|China|Shenzhen|.AS|Netherlands|Euronext Amsterdam| 97 | |.PR|Czech Republic|Prague Index|.NZ|New Zealand|New Zealand (NZX)| 98 | |.CO|Denmark|Nasdaq OMX Copenhagen|.OL|Norway|Oslo| 99 | |.CA|Egypt|Egyptian Index (EGID)|.LS|Portugal|Euronext Lisbon| 100 | |.TL|Estonia|Nasdaq OMX Tallinn|.QA|Qatar|Qatar| 101 | |.HE|Finland|Nasdaq OMX Helsinki|.ME|Russia|Moscow Exchange (MOEX)| 102 | |.NX|France|Euronext|.SI|Singapore|Singapore (SGX)| 103 | |.PA|France|Euronext Paris|.JO|South Africa|Johannesburg| 104 | |.BE|Germany|Berlin|.KS|South Korea|Korea| 105 | |.BM|Germany|Bremen|.KQ|South Korea|KOSDAQ| 106 | |.DU|Germany|Dusseldorf|.MC|Spain|Madrid SE C.A.T.S.| 107 | |.F|Germany|Frankfurt|.SAU|Saudi Arabia|Saudi (Tadawul)| 108 | |.HM|Germany|Hamburg|.ST|Sweden|Nasdaq OMX Stockholm| 109 | |.HA|Germany|Hanover|.SW|Switzerland|Swiss Exchange (SIX)| 110 | |.MU|Germany|Munich|.TWO|Taiwan|Taiwan OTC Exchange| 111 | |.SG|Germany|Stuttgart|.TW|Taiwan|Taiwan (TWSE)| 112 | |.DE|Germany|Deutsche Boerse XETRA|.BK|Thailand (SET)| 113 | |.AT|Greece|Athens (ATHEX)|.IS|Turkey|Borsa İstanbul| 114 | |.HK|Hong Kong|Hong Kong (HKEX)|.L|United Kingdom|London| 115 | |.BD|Hungary|Budapest|.IL|United Kingdom|London| 116 | |.IC|Iceland|Nasdaq OMX Iceland|.CR|Venezuela|Caracas| 117 | |.BO|India|Bombay| 118 | 119 | 120 |
121 | 122 | ## FOREX PAIRS 123 | 124 | ```php 125 | getFX($currency_1,$currency_2); 135 | 136 | /* 137 | Array 138 | ( 139 | [symbol] => USDARS=X 140 | [date] => 2020-01-04 5:55:51 141 | [bid] => 59.729 142 | [ask] => 59.734 143 | [high] => 59.73 144 | [low] => 59.729 145 | [open] => 59.73 146 | [previous] => 59.729 147 | [price] => 59.729 148 | ) 149 | */ 150 | 151 | ``` 152 | 153 |
154 | 155 | ## Quote, Order Book, AfterMarket Prices, Financial & Stats 156 | 157 | ```php 158 | getQuote($symbol); 167 | 168 | /* 169 | Array 170 | ( 171 | [symbol] => YPF 172 | [price] => 11.16 173 | [date] => 2020-01-03 21:02:00 174 | [book] => Array 175 | ( 176 | [bidSize] => 31 177 | [bid] => 11.14 178 | [ask] => 11.57 179 | [askSize] => 9 180 | ) 181 | 182 | [today] => Array 183 | ( 184 | [high] => 11.49 185 | [low] => 10.86 186 | [open] => 11.24 187 | [previousDay] => 11.26 188 | [volume] => 2732642 189 | [change] => -0.10000038 190 | [changePercent] => -0.8881029 191 | ) 192 | 193 | [AfterMarket] => Array 194 | ( 195 | [price] => 11.0746 196 | [change] => -0.08539963 197 | [changePercent] => -0.76522964 198 | [lastTrade] => 2020-01-03 21:26:02 199 | ) 200 | 201 | [financials] => Array 202 | ( 203 | [name] => YPF Sociedad Anonima 204 | [mktCap] => 4389372928 205 | [sharesOutstanding] => 393312992 206 | [volumeAvg3Month] => 2095557 207 | [bookValue] => 33.975 208 | [eps12Month] => 3.125 209 | [dividendRate] => 0.089 210 | [dividendYield] => 0.007904085 211 | ) 212 | 213 | [stats] => Array 214 | ( 215 | [SMA50] => 10.16606 216 | [SMA200] => 11.737482 217 | [1yrHigh] => 18.73 218 | [1yrHighChangePercent] => -0.40416443 219 | [1yrLow] => 8.04 220 | [1yrLowChangePercent] => 0.38805968 221 | ) 222 | 223 | ) 224 | */ 225 | 226 | 227 | ``` 228 | 229 |
230 | 231 | ## Symbol - Expiration Dates 232 | 233 | ```php 234 | getExpirations($symbol); 243 | /* 244 | Array 245 | ( 246 | [0] => Array 247 | ( 248 | [unix] => 1578614400 249 | [days] => 6 250 | [expiration] => 2020-01-10 251 | ) 252 | 253 | ... 254 | ... 255 | 256 | [9] => Array 257 | ( 258 | [unix] => 1642723200 259 | [days] => 748 260 | [expiration] => 2022-01-21 261 | ) 262 | ) 263 | */ 264 | 265 | 266 | ``` 267 | 268 |
269 | 270 | ## Symbol - Expiration - Option Chain 271 | 272 | ```php 273 | getExpirations($symbol); 282 | $contracts = $yf->getContracts($symbol,$expirations[0]['unix']); 283 | 284 | /* 285 | Array 286 | ( 287 | [0] => Array 288 | ( 289 | [symbol] => AAPL 290 | [spot] => 297.43 291 | [expiration] => 2020-01-10 292 | [strike] => 230 293 | [otm_abs] => 22.67 294 | [call_contract] => AAPL200110C00230000 295 | [call_bid] => 67.85 296 | [call_ask] => 69.6 297 | [call_lastPrice] => 68.99 298 | [call_volume] => 18 299 | [call_openInterest] => 0 300 | [call_lastTradeDateUNIX] => 1578069878 301 | [call_lastTradeDate] => 2020-01-03 302 | [put_contract] => AAPL200110P00230000 303 | [put_bid] => 0.02 304 | [put_ask] => 0.03 305 | [put_lastPrice] => 0.03 306 | [put_volume] => 6 307 | [put_openInterest] => 0 308 | [put_lastTradeDateUNIX] => 1578061990 309 | [put_lastTradeDate] => 2020-01-03 310 | [IV] => 95.9 311 | ) 312 | 313 | ... 314 | ... 315 | 316 | [37] => Array 317 | ( 318 | [symbol] => AAPL 319 | [spot] => 297.43 320 | [expiration] => 2020-01-10 321 | [strike] => 350 322 | [otm_abs] => 17.67 323 | [call_contract] => AAPL200110C00350000 324 | [call_bid] => 0.02 325 | [call_ask] => 0.03 326 | [call_lastPrice] => 0.05 327 | [call_volume] => 405 328 | [call_openInterest] => 0 329 | [call_lastTradeDateUNIX] => 1578084931 330 | [call_lastTradeDate] => 2020-01-03 331 | [put_contract] => AAPL200110P00350000 332 | [put_bid] => 51 333 | [put_ask] => 51.85 334 | [put_lastPrice] => 51.7 335 | [put_volume] => 2 336 | [put_openInterest] => 0 337 | [put_lastTradeDateUNIX] => 1577983464 338 | [put_lastTradeDate] => 2020-01-02 339 | [IV] => 45.31 340 | ) 341 | ) 342 | */ 343 | 344 | 345 | ``` 346 | 347 |
348 | 349 | # Configuration 350 | 351 | It doesnt need any configuration line 352 | 353 | Enjoy it! :heart: 354 | 355 | 356 |
357 | 358 | # Credits 359 | 360 | [scheb/yahoo-finance-api](https://github.com/scheb/yahoo-finance-api) 361 | 362 |
363 | 364 | # License 365 | 366 | [MIT](https://github.com/gauss314/yahoo_finance/blob/master/LICENSE) 367 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "9dfe2860e1a03290e8b9559214eb75f9", 8 | "packages": [ 9 | { 10 | "name": "guzzlehttp/guzzle", 11 | "version": "6.5.x-dev", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/guzzle/guzzle.git", 15 | "reference": "400cefd25a23a3098486bfb52685b5367a464171" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/400cefd25a23a3098486bfb52685b5367a464171", 20 | "reference": "400cefd25a23a3098486bfb52685b5367a464171", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "ext-json": "*", 25 | "guzzlehttp/promises": "^1.0", 26 | "guzzlehttp/psr7": "^1.6.1", 27 | "php": ">=5.5" 28 | }, 29 | "require-dev": { 30 | "ext-curl": "*", 31 | "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", 32 | "psr/log": "^1.1" 33 | }, 34 | "suggest": { 35 | "ext-intl": "Required for Internationalized Domain Name (IDN) support", 36 | "psr/log": "Required for using the Log middleware" 37 | }, 38 | "type": "library", 39 | "extra": { 40 | "branch-alias": { 41 | "dev-master": "6.5-dev" 42 | } 43 | }, 44 | "autoload": { 45 | "psr-4": { 46 | "GuzzleHttp\\": "src/" 47 | }, 48 | "files": [ 49 | "src/functions_include.php" 50 | ] 51 | }, 52 | "notification-url": "https://packagist.org/downloads/", 53 | "license": [ 54 | "MIT" 55 | ], 56 | "authors": [ 57 | { 58 | "name": "Michael Dowling", 59 | "email": "mtdowling@gmail.com", 60 | "homepage": "https://github.com/mtdowling" 61 | } 62 | ], 63 | "description": "Guzzle is a PHP HTTP client library", 64 | "homepage": "http://guzzlephp.org/", 65 | "keywords": [ 66 | "client", 67 | "curl", 68 | "framework", 69 | "http", 70 | "http client", 71 | "rest", 72 | "web service" 73 | ], 74 | "time": "2019-12-30T04:52:42+00:00" 75 | }, 76 | { 77 | "name": "guzzlehttp/promises", 78 | "version": "dev-master", 79 | "source": { 80 | "type": "git", 81 | "url": "https://github.com/guzzle/promises.git", 82 | "reference": "ac2529fc650684c5cd687e2b462d046cdbed556e" 83 | }, 84 | "dist": { 85 | "type": "zip", 86 | "url": "https://api.github.com/repos/guzzle/promises/zipball/ac2529fc650684c5cd687e2b462d046cdbed556e", 87 | "reference": "ac2529fc650684c5cd687e2b462d046cdbed556e", 88 | "shasum": "" 89 | }, 90 | "require": { 91 | "php": ">=5.6" 92 | }, 93 | "require-dev": { 94 | "phpunit/phpunit": "^5.7.27 || ^7.5" 95 | }, 96 | "type": "library", 97 | "extra": { 98 | "branch-alias": { 99 | "dev-master": "1.4-dev" 100 | } 101 | }, 102 | "autoload": { 103 | "psr-4": { 104 | "GuzzleHttp\\Promise\\": "src/" 105 | }, 106 | "files": [ 107 | "src/functions_include.php" 108 | ] 109 | }, 110 | "notification-url": "https://packagist.org/downloads/", 111 | "license": [ 112 | "MIT" 113 | ], 114 | "authors": [ 115 | { 116 | "name": "Michael Dowling", 117 | "email": "mtdowling@gmail.com", 118 | "homepage": "https://github.com/mtdowling" 119 | } 120 | ], 121 | "description": "Guzzle promises library", 122 | "keywords": [ 123 | "promise" 124 | ], 125 | "time": "2019-12-17T17:19:17+00:00" 126 | }, 127 | { 128 | "name": "guzzlehttp/psr7", 129 | "version": "1.x-dev", 130 | "source": { 131 | "type": "git", 132 | "url": "https://github.com/guzzle/psr7.git", 133 | "reference": "c291e45d40e638815990004e5f7ee367c2b752e9" 134 | }, 135 | "dist": { 136 | "type": "zip", 137 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/c291e45d40e638815990004e5f7ee367c2b752e9", 138 | "reference": "c291e45d40e638815990004e5f7ee367c2b752e9", 139 | "shasum": "" 140 | }, 141 | "require": { 142 | "php": ">=5.4.0", 143 | "psr/http-message": "~1.0", 144 | "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" 145 | }, 146 | "provide": { 147 | "psr/http-message-implementation": "1.0" 148 | }, 149 | "require-dev": { 150 | "ext-zlib": "*", 151 | "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" 152 | }, 153 | "suggest": { 154 | "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" 155 | }, 156 | "type": "library", 157 | "extra": { 158 | "branch-alias": { 159 | "dev-master": "1.6-dev" 160 | } 161 | }, 162 | "autoload": { 163 | "psr-4": { 164 | "GuzzleHttp\\Psr7\\": "src/" 165 | }, 166 | "files": [ 167 | "src/functions_include.php" 168 | ] 169 | }, 170 | "notification-url": "https://packagist.org/downloads/", 171 | "license": [ 172 | "MIT" 173 | ], 174 | "authors": [ 175 | { 176 | "name": "Michael Dowling", 177 | "email": "mtdowling@gmail.com", 178 | "homepage": "https://github.com/mtdowling" 179 | }, 180 | { 181 | "name": "Tobias Schultze", 182 | "homepage": "https://github.com/Tobion" 183 | } 184 | ], 185 | "description": "PSR-7 message implementation that also provides common utility methods", 186 | "keywords": [ 187 | "http", 188 | "message", 189 | "psr-7", 190 | "request", 191 | "response", 192 | "stream", 193 | "uri", 194 | "url" 195 | ], 196 | "time": "2019-12-21T15:35:40+00:00" 197 | }, 198 | { 199 | "name": "psr/http-message", 200 | "version": "dev-master", 201 | "source": { 202 | "type": "git", 203 | "url": "https://github.com/php-fig/http-message.git", 204 | "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4" 205 | }, 206 | "dist": { 207 | "type": "zip", 208 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", 209 | "reference": "efd67d1dc14a7ef4fc4e518e7dee91c271d524e4", 210 | "shasum": "" 211 | }, 212 | "require": { 213 | "php": ">=5.3.0" 214 | }, 215 | "type": "library", 216 | "extra": { 217 | "branch-alias": { 218 | "dev-master": "1.0.x-dev" 219 | } 220 | }, 221 | "autoload": { 222 | "psr-4": { 223 | "Psr\\Http\\Message\\": "src/" 224 | } 225 | }, 226 | "notification-url": "https://packagist.org/downloads/", 227 | "license": [ 228 | "MIT" 229 | ], 230 | "authors": [ 231 | { 232 | "name": "PHP-FIG", 233 | "homepage": "http://www.php-fig.org/" 234 | } 235 | ], 236 | "description": "Common interface for HTTP messages", 237 | "homepage": "https://github.com/php-fig/http-message", 238 | "keywords": [ 239 | "http", 240 | "http-message", 241 | "psr", 242 | "psr-7", 243 | "request", 244 | "response" 245 | ], 246 | "time": "2019-08-29T13:16:46+00:00" 247 | }, 248 | { 249 | "name": "ralouphie/getallheaders", 250 | "version": "3.0.3", 251 | "source": { 252 | "type": "git", 253 | "url": "https://github.com/ralouphie/getallheaders.git", 254 | "reference": "120b605dfeb996808c31b6477290a714d356e822" 255 | }, 256 | "dist": { 257 | "type": "zip", 258 | "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", 259 | "reference": "120b605dfeb996808c31b6477290a714d356e822", 260 | "shasum": "" 261 | }, 262 | "require": { 263 | "php": ">=5.6" 264 | }, 265 | "require-dev": { 266 | "php-coveralls/php-coveralls": "^2.1", 267 | "phpunit/phpunit": "^5 || ^6.5" 268 | }, 269 | "type": "library", 270 | "autoload": { 271 | "files": [ 272 | "src/getallheaders.php" 273 | ] 274 | }, 275 | "notification-url": "https://packagist.org/downloads/", 276 | "license": [ 277 | "MIT" 278 | ], 279 | "authors": [ 280 | { 281 | "name": "Ralph Khattar", 282 | "email": "ralph.khattar@gmail.com" 283 | } 284 | ], 285 | "description": "A polyfill for getallheaders.", 286 | "time": "2019-03-08T08:55:37+00:00" 287 | }, 288 | { 289 | "name": "scheb/yahoo-finance-api", 290 | "version": "dev-master", 291 | "source": { 292 | "type": "git", 293 | "url": "https://github.com/scheb/yahoo-finance-api.git", 294 | "reference": "9a7b39e3d97a268577594ef51bddb285fbb0d93a" 295 | }, 296 | "dist": { 297 | "type": "zip", 298 | "url": "https://api.github.com/repos/scheb/yahoo-finance-api/zipball/9a7b39e3d97a268577594ef51bddb285fbb0d93a", 299 | "reference": "9a7b39e3d97a268577594ef51bddb285fbb0d93a", 300 | "shasum": "" 301 | }, 302 | "require": { 303 | "ext-json": "*", 304 | "guzzlehttp/guzzle": "^6.0", 305 | "php": ">=5.6.0" 306 | }, 307 | "require-dev": { 308 | "phpunit/phpunit": "^5.7 || ^6.5" 309 | }, 310 | "type": "library", 311 | "autoload": { 312 | "psr-4": { 313 | "Scheb\\YahooFinanceApi\\": "src/" 314 | } 315 | }, 316 | "notification-url": "https://packagist.org/downloads/", 317 | "license": [ 318 | "MIT" 319 | ], 320 | "authors": [ 321 | { 322 | "name": "Christian Scheb", 323 | "email": "me@christianscheb.de" 324 | } 325 | ], 326 | "description": "PHP library for accessing Yahoo Finance data", 327 | "homepage": "https://github.com/scheb/yahoo-finance-api", 328 | "keywords": [ 329 | "api", 330 | "finance", 331 | "stock", 332 | "yahoo" 333 | ], 334 | "time": "2019-12-21T13:02:42+00:00" 335 | } 336 | ], 337 | "packages-dev": [], 338 | "aliases": [], 339 | "minimum-stability": "dev", 340 | "stability-flags": { 341 | "scheb/yahoo-finance-api": 20 342 | }, 343 | "prefer-stable": false, 344 | "prefer-lowest": false, 345 | "platform": [], 346 | "platform-dev": [] 347 | } 348 | -------------------------------------------------------------------------------- /vendor/composer/ClassLoader.php: -------------------------------------------------------------------------------- 1 | 7 | * Jordi Boggiano 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Composer\Autoload; 14 | 15 | /** 16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. 17 | * 18 | * $loader = new \Composer\Autoload\ClassLoader(); 19 | * 20 | * // register classes with namespaces 21 | * $loader->add('Symfony\Component', __DIR__.'/component'); 22 | * $loader->add('Symfony', __DIR__.'/framework'); 23 | * 24 | * // activate the autoloader 25 | * $loader->register(); 26 | * 27 | * // to enable searching the include path (eg. for PEAR packages) 28 | * $loader->setUseIncludePath(true); 29 | * 30 | * In this example, if you try to use a class in the Symfony\Component 31 | * namespace or one of its children (Symfony\Component\Console for instance), 32 | * the autoloader will first look for the class under the component/ 33 | * directory, and it will then fallback to the framework/ directory if not 34 | * found before giving up. 35 | * 36 | * This class is loosely based on the Symfony UniversalClassLoader. 37 | * 38 | * @author Fabien Potencier 39 | * @author Jordi Boggiano 40 | * @see http://www.php-fig.org/psr/psr-0/ 41 | * @see http://www.php-fig.org/psr/psr-4/ 42 | */ 43 | class ClassLoader 44 | { 45 | // PSR-4 46 | private $prefixLengthsPsr4 = array(); 47 | private $prefixDirsPsr4 = array(); 48 | private $fallbackDirsPsr4 = array(); 49 | 50 | // PSR-0 51 | private $prefixesPsr0 = array(); 52 | private $fallbackDirsPsr0 = array(); 53 | 54 | private $useIncludePath = false; 55 | private $classMap = array(); 56 | private $classMapAuthoritative = false; 57 | private $missingClasses = array(); 58 | private $apcuPrefix; 59 | 60 | public function getPrefixes() 61 | { 62 | if (!empty($this->prefixesPsr0)) { 63 | return call_user_func_array('array_merge', $this->prefixesPsr0); 64 | } 65 | 66 | return array(); 67 | } 68 | 69 | public function getPrefixesPsr4() 70 | { 71 | return $this->prefixDirsPsr4; 72 | } 73 | 74 | public function getFallbackDirs() 75 | { 76 | return $this->fallbackDirsPsr0; 77 | } 78 | 79 | public function getFallbackDirsPsr4() 80 | { 81 | return $this->fallbackDirsPsr4; 82 | } 83 | 84 | public function getClassMap() 85 | { 86 | return $this->classMap; 87 | } 88 | 89 | /** 90 | * @param array $classMap Class to filename map 91 | */ 92 | public function addClassMap(array $classMap) 93 | { 94 | if ($this->classMap) { 95 | $this->classMap = array_merge($this->classMap, $classMap); 96 | } else { 97 | $this->classMap = $classMap; 98 | } 99 | } 100 | 101 | /** 102 | * Registers a set of PSR-0 directories for a given prefix, either 103 | * appending or prepending to the ones previously set for this prefix. 104 | * 105 | * @param string $prefix The prefix 106 | * @param array|string $paths The PSR-0 root directories 107 | * @param bool $prepend Whether to prepend the directories 108 | */ 109 | public function add($prefix, $paths, $prepend = false) 110 | { 111 | if (!$prefix) { 112 | if ($prepend) { 113 | $this->fallbackDirsPsr0 = array_merge( 114 | (array) $paths, 115 | $this->fallbackDirsPsr0 116 | ); 117 | } else { 118 | $this->fallbackDirsPsr0 = array_merge( 119 | $this->fallbackDirsPsr0, 120 | (array) $paths 121 | ); 122 | } 123 | 124 | return; 125 | } 126 | 127 | $first = $prefix[0]; 128 | if (!isset($this->prefixesPsr0[$first][$prefix])) { 129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; 130 | 131 | return; 132 | } 133 | if ($prepend) { 134 | $this->prefixesPsr0[$first][$prefix] = array_merge( 135 | (array) $paths, 136 | $this->prefixesPsr0[$first][$prefix] 137 | ); 138 | } else { 139 | $this->prefixesPsr0[$first][$prefix] = array_merge( 140 | $this->prefixesPsr0[$first][$prefix], 141 | (array) $paths 142 | ); 143 | } 144 | } 145 | 146 | /** 147 | * Registers a set of PSR-4 directories for a given namespace, either 148 | * appending or prepending to the ones previously set for this namespace. 149 | * 150 | * @param string $prefix The prefix/namespace, with trailing '\\' 151 | * @param array|string $paths The PSR-4 base directories 152 | * @param bool $prepend Whether to prepend the directories 153 | * 154 | * @throws \InvalidArgumentException 155 | */ 156 | public function addPsr4($prefix, $paths, $prepend = false) 157 | { 158 | if (!$prefix) { 159 | // Register directories for the root namespace. 160 | if ($prepend) { 161 | $this->fallbackDirsPsr4 = array_merge( 162 | (array) $paths, 163 | $this->fallbackDirsPsr4 164 | ); 165 | } else { 166 | $this->fallbackDirsPsr4 = array_merge( 167 | $this->fallbackDirsPsr4, 168 | (array) $paths 169 | ); 170 | } 171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 172 | // Register directories for a new namespace. 173 | $length = strlen($prefix); 174 | if ('\\' !== $prefix[$length - 1]) { 175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 176 | } 177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 178 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 179 | } elseif ($prepend) { 180 | // Prepend directories for an already registered namespace. 181 | $this->prefixDirsPsr4[$prefix] = array_merge( 182 | (array) $paths, 183 | $this->prefixDirsPsr4[$prefix] 184 | ); 185 | } else { 186 | // Append directories for an already registered namespace. 187 | $this->prefixDirsPsr4[$prefix] = array_merge( 188 | $this->prefixDirsPsr4[$prefix], 189 | (array) $paths 190 | ); 191 | } 192 | } 193 | 194 | /** 195 | * Registers a set of PSR-0 directories for a given prefix, 196 | * replacing any others previously set for this prefix. 197 | * 198 | * @param string $prefix The prefix 199 | * @param array|string $paths The PSR-0 base directories 200 | */ 201 | public function set($prefix, $paths) 202 | { 203 | if (!$prefix) { 204 | $this->fallbackDirsPsr0 = (array) $paths; 205 | } else { 206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 207 | } 208 | } 209 | 210 | /** 211 | * Registers a set of PSR-4 directories for a given namespace, 212 | * replacing any others previously set for this namespace. 213 | * 214 | * @param string $prefix The prefix/namespace, with trailing '\\' 215 | * @param array|string $paths The PSR-4 base directories 216 | * 217 | * @throws \InvalidArgumentException 218 | */ 219 | public function setPsr4($prefix, $paths) 220 | { 221 | if (!$prefix) { 222 | $this->fallbackDirsPsr4 = (array) $paths; 223 | } else { 224 | $length = strlen($prefix); 225 | if ('\\' !== $prefix[$length - 1]) { 226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 227 | } 228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 229 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 230 | } 231 | } 232 | 233 | /** 234 | * Turns on searching the include path for class files. 235 | * 236 | * @param bool $useIncludePath 237 | */ 238 | public function setUseIncludePath($useIncludePath) 239 | { 240 | $this->useIncludePath = $useIncludePath; 241 | } 242 | 243 | /** 244 | * Can be used to check if the autoloader uses the include path to check 245 | * for classes. 246 | * 247 | * @return bool 248 | */ 249 | public function getUseIncludePath() 250 | { 251 | return $this->useIncludePath; 252 | } 253 | 254 | /** 255 | * Turns off searching the prefix and fallback directories for classes 256 | * that have not been registered with the class map. 257 | * 258 | * @param bool $classMapAuthoritative 259 | */ 260 | public function setClassMapAuthoritative($classMapAuthoritative) 261 | { 262 | $this->classMapAuthoritative = $classMapAuthoritative; 263 | } 264 | 265 | /** 266 | * Should class lookup fail if not found in the current class map? 267 | * 268 | * @return bool 269 | */ 270 | public function isClassMapAuthoritative() 271 | { 272 | return $this->classMapAuthoritative; 273 | } 274 | 275 | /** 276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled. 277 | * 278 | * @param string|null $apcuPrefix 279 | */ 280 | public function setApcuPrefix($apcuPrefix) 281 | { 282 | $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; 283 | } 284 | 285 | /** 286 | * The APCu prefix in use, or null if APCu caching is not enabled. 287 | * 288 | * @return string|null 289 | */ 290 | public function getApcuPrefix() 291 | { 292 | return $this->apcuPrefix; 293 | } 294 | 295 | /** 296 | * Registers this instance as an autoloader. 297 | * 298 | * @param bool $prepend Whether to prepend the autoloader or not 299 | */ 300 | public function register($prepend = false) 301 | { 302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend); 303 | } 304 | 305 | /** 306 | * Unregisters this instance as an autoloader. 307 | */ 308 | public function unregister() 309 | { 310 | spl_autoload_unregister(array($this, 'loadClass')); 311 | } 312 | 313 | /** 314 | * Loads the given class or interface. 315 | * 316 | * @param string $class The name of the class 317 | * @return bool|null True if loaded, null otherwise 318 | */ 319 | public function loadClass($class) 320 | { 321 | if ($file = $this->findFile($class)) { 322 | includeFile($file); 323 | 324 | return true; 325 | } 326 | } 327 | 328 | /** 329 | * Finds the path to the file where the class is defined. 330 | * 331 | * @param string $class The name of the class 332 | * 333 | * @return string|false The path if found, false otherwise 334 | */ 335 | public function findFile($class) 336 | { 337 | // class map lookup 338 | if (isset($this->classMap[$class])) { 339 | return $this->classMap[$class]; 340 | } 341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { 342 | return false; 343 | } 344 | if (null !== $this->apcuPrefix) { 345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit); 346 | if ($hit) { 347 | return $file; 348 | } 349 | } 350 | 351 | $file = $this->findFileWithExtension($class, '.php'); 352 | 353 | // Search for Hack files if we are running on HHVM 354 | if (false === $file && defined('HHVM_VERSION')) { 355 | $file = $this->findFileWithExtension($class, '.hh'); 356 | } 357 | 358 | if (null !== $this->apcuPrefix) { 359 | apcu_add($this->apcuPrefix.$class, $file); 360 | } 361 | 362 | if (false === $file) { 363 | // Remember that this class does not exist. 364 | $this->missingClasses[$class] = true; 365 | } 366 | 367 | return $file; 368 | } 369 | 370 | private function findFileWithExtension($class, $ext) 371 | { 372 | // PSR-4 lookup 373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 374 | 375 | $first = $class[0]; 376 | if (isset($this->prefixLengthsPsr4[$first])) { 377 | $subPath = $class; 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { 379 | $subPath = substr($subPath, 0, $lastPos); 380 | $search = $subPath . '\\'; 381 | if (isset($this->prefixDirsPsr4[$search])) { 382 | $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { 384 | if (file_exists($file = $dir . $pathEnd)) { 385 | return $file; 386 | } 387 | } 388 | } 389 | } 390 | } 391 | 392 | // PSR-4 fallback dirs 393 | foreach ($this->fallbackDirsPsr4 as $dir) { 394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 395 | return $file; 396 | } 397 | } 398 | 399 | // PSR-0 lookup 400 | if (false !== $pos = strrpos($class, '\\')) { 401 | // namespaced class name 402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 404 | } else { 405 | // PEAR-like class name 406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 407 | } 408 | 409 | if (isset($this->prefixesPsr0[$first])) { 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 411 | if (0 === strpos($class, $prefix)) { 412 | foreach ($dirs as $dir) { 413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 414 | return $file; 415 | } 416 | } 417 | } 418 | } 419 | } 420 | 421 | // PSR-0 fallback dirs 422 | foreach ($this->fallbackDirsPsr0 as $dir) { 423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 424 | return $file; 425 | } 426 | } 427 | 428 | // PSR-0 include paths. 429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 430 | return $file; 431 | } 432 | 433 | return false; 434 | } 435 | } 436 | 437 | /** 438 | * Scope isolated include. 439 | * 440 | * Prevents access to $this/self from included files. 441 | */ 442 | function includeFile($file) 443 | { 444 | include $file; 445 | } 446 | --------------------------------------------------------------------------------