├── 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 | [](https://travis-ci.org/ralouphie/getallheaders) 7 | [](https://coveralls.io/r/ralouphie/getallheaders?branch=master) 8 | [](https://packagist.org/packages/ralouphie/getallheaders) 9 | [](https://packagist.org/packages/ralouphie/getallheaders) 10 | [](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 |
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 |