大麦/ alpha-vantage
简化版的Laravel Alpha Vantage API客户端
Requires
- php: ^7.0
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2024-09-27 18:32:10 UTC
README
这是一个用于简化从Alpha Vantage API获取金融数据的Laravel包。它是在Guzzle之上的一层抽象,旨在简化与Alpha Vantage API的连接。
文档
演示
获取历史数据
// Daily historical data for Bitcoin to USD $res = \AlphaVantage\Api::digitalCurrency()->daily('BTC', 'USD'); /* Returns [ "Meta Data": [ "1. Information": "Daily Prices and Volumes for Digital Currency", ... ], "Time Series (Digital Currency Daily)": [ "2018-01-03": [ "1a. open (USD)": "14782.09572045", ... ], "2018-01-02": [ "1a. open (USD)": "13514.39967186", ... ], ... ], ] */
安装
- 运行composer
composer require d1am0nd/alpha-vantage
- 将您的Alpha Vantage API密钥添加到.env中,格式为
AV_KEY={your key}
用法
API调用分为5个不同的组
Api::stock()
- 股票时间序列Api::currency()
- 外汇Api::digitalCurrency()
- 数字货币 & 加密货币Api::sector()
- 行业表现Api::general()
- 技术指标 & 其他
以下描述的每个函数都是从相应的组中调用的,如示例所示。
以下描述的函数还接受一个额外的参数 array $params = []
,如果需要,可以用来传递任何可选参数。
股票时间序列
文档 - https://www.alphavantage.co/documentation/#currency-exchange
示例 - 微软的历史月度股票数据
use AlphaVantage\Api; // ... public function monthlyData() { return Api::stock()->monthly('MSFT'); }
可用方法
intraday($symbol)
- https://www.alphavantage.co/documentation/#intradaydaily($symbol)
- https://www.alphavantage.co/documentation/#dailydailyAdjusted($symbol)
- https://www.alphavantage.co/documentation/#dailyadjweekly($symbol)
- https://www.alphavantage.co/documentation/#weeklyweeklyAdjusted($symbol)
- https://www.alphavantage.co/documentation/#weeklyadjmonthly($symbol)
- https://www.alphavantage.co/documentation/#monthlymonthlyAdjusted($symbol)
- https://www.alphavantage.co/documentation/#monthlyadjbatchStockQuotes(array $symbols)
- https://www.alphavantage.co/documentation/#batchquotesquote($symbol)
- https://www.alphavantage.co/documentation/#latestpricesearch($keywords)
- https://www.alphavantage.co/documentation/#symbolsearch
外汇
文档 - https://www.alphavantage.co/documentation/#currency-exchange
示例 - 欧元兑美元
use AlphaVantage\Api; // ... public function currencyExchangeRate() { return Api::currency()->currencyExchangeRate('EUR', 'USD'); }
可用方法
currencyExchangeRate($from, $to)
- https://www.alphavantage.co/documentation/#currency-exchangeintraday($from, $to, $interval)
- https://www.alphavantage.co/documentation/#fx-intradaydaily($from, $to)
- https://www.alphavantage.co/documentation/#fx-dailyweekly($from, $to)
- https://www.alphavantage.co/documentation/#fx-weeklymonthly($from, $to)
- https://www.alphavantage.co/documentation/#fx-monthly
数字货币与加密货币
文档说明 - https://www.alphavantage.co/documentation/#digital-currency
示例 - 比特币历史月度股价数据
use AlphaVantage\Api; // ... public function monthlyData() { return Api::digitalCurrency()->monthly('BTC', 'USD'); }
可用方法
intraday($symbol, $market)
- https://www.alphavantage.co/documentation/#currency-intradaydaily($symbol, $market)
- https://www.alphavantage.co/documentation/#currency-dailyweekly($symbol, $market)
- https://www.alphavantage.co/documentation/#currency-weeklymonthly($symbol, $market)
- https://www.alphavantage.co/documentation/#currency-monthly
行业表现
文档说明 - https://www.alphavantage.co/documentation/#sector-information
示例 - 行业表现
use AlphaVantage\Api; // ... public function sectorPerformances() { return Api::sector()->sectors(); }
可用方法
技术指标及其他
文档说明 - https://www.alphavantage.co/documentation/#technical-indicators
技术方法不是作为独立函数实现的。存在一个 Api::general()->query($funcName, array $params)
方法,它允许进行自定义查询。
示例 - MACDEXT
这将查询功能 'MACDEXT',并带有文档中描述的附加参数 symbol
、interval
和 series_type
,详情请见 https://www.alphavantage.co/documentation/#macdext
use AlphaVantage\Api; // ... public function technicalIndicators() { return Api::general()->query('MACDEXT', [ 'symbol' => 'MSFT', 'interval' => '15min', 'series_type' => 'high', ]); }
可用方法
query($functionName, array $parameters)
许可证
本项目采用 MIT 许可证 - 详细信息请参阅 LICENSE.md 文件。