大麦/alpha-vantage

简化版的Laravel Alpha Vantage API客户端

0.1.2 2019-02-27 05:17 UTC

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", ...
        ], ...
    ],
]
*/

安装

  1. 运行composer composer require d1am0nd/alpha-vantage
  2. 将您的Alpha Vantage API密钥添加到.env中,格式为AV_KEY={your key}

用法

API调用分为5个不同的组

以下描述的每个函数都是从相应的组中调用的,如示例所示。

以下描述的函数还接受一个额外的参数 array $params = [],如果需要,可以用来传递任何可选参数。

股票时间序列

文档 - https://www.alphavantage.co/documentation/#currency-exchange

示例 - 微软的历史月度股票数据

use AlphaVantage\Api;
// ...
public function monthlyData()
{
    return Api::stock()->monthly('MSFT');
}

可用方法

外汇

文档 - https://www.alphavantage.co/documentation/#currency-exchange

示例 - 欧元兑美元

use AlphaVantage\Api;
// ...
public function currencyExchangeRate()
{
    return Api::currency()->currencyExchangeRate('EUR', 'USD');
}

可用方法

数字货币与加密货币

文档说明 - https://www.alphavantage.co/documentation/#digital-currency

示例 - 比特币历史月度股价数据

use AlphaVantage\Api;
// ...
public function monthlyData()
{
    return Api::digitalCurrency()->monthly('BTC', 'USD');
}

可用方法

行业表现

文档说明 - 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',并带有文档中描述的附加参数 symbolintervalseries_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 文件。