krivov / yahoo-finance-api
用于访问雅虎财经数据的PHP库
v4.0.0
2024-07-07 12:49 UTC
Requires
- php: >=8.1.3
- ext-json: *
- guzzlehttp/guzzle: ^6.0|^7.0
Requires (Dev)
- escapestudios/symfony2-coding-standard: ^3.9
- friendsofphp/php-cs-fixer: ^3.59
- phpunit/phpunit: ^7.5 || ^8 || ^9
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^3.11|^4.0
README
这是一个雅虎财经API的PHP客户端。
由于YQL API已于2017年11月停止使用,此客户端现在使用非官方API端点进行报价、搜索和历史数据。
警告:这些非官方API可能不稳定,并且随时可能会中断。此外,您可能违反了雅虎的服务条款。因此,请自行承担风险使用。
安装
通过Composer下载
php composer.phar require scheb/yahoo-finance-api
或者您也可以直接将包添加到composer.json中
{ "require": { "scheb/yahoo-finance-api": "^3.0" } }
然后告诉Composer安装包
php composer.phar update scheb/yahoo-finance-api
使用
use Scheb\YahooFinanceApi\ApiClient; use Scheb\YahooFinanceApi\ApiClientFactory; use GuzzleHttp\Client; // Create a new client from the factory $client = ApiClientFactory::createApiClient(); // Or use your own Guzzle client and pass it in $options = [/*...*/]; $guzzleClient = new Client($options); $client = ApiClientFactory::createApiClient($guzzleClient); // Returns an array of Scheb\YahooFinanceApi\Results\SearchResult $searchResult = $client->search("Apple"); // Returns an array of Scheb\YahooFinanceApi\Results\HistoricalData $historicalData = $client->getHistoricalData("AAPL", ApiClient::INTERVAL_1_DAY, new \DateTime("-14 days"), new \DateTime("today")); // Returns Scheb\YahooFinanceApi\Results\Quote $exchangeRate = $client->getExchangeRate("USD", "EUR"); // Returns an array of Scheb\YahooFinanceApi\Results\Quote $exchangeRates = $client->getExchangeRates([ ["USD", "EUR"], ["EUR", "USD"], ]); // Returns Scheb\YahooFinanceApi\Results\Quote $quote = $client->getQuote("AAPL"); // Returns an array of Scheb\YahooFinanceApi\Results\Quote $quotes = $client->getQuotes(["AAPL", "GOOG"]);
贡献
欢迎您通过贡献此库,通过在问题部分创建拉取请求或功能请求。对于拉取请求,请遵循以下指南
- Symfony代码风格
- 请添加/更新测试用例
- 测试方法应命名为
[方法]_[场景]_[预期结果]
要运行测试套件,请使用composer install
安装依赖,然后执行bin/phpunit
。
许可协议
此包可在MIT许可协议下使用。