sukhrobnurali/alphavantage-sdk
Composer 安装命令:
composer require sukhrobnurali/alphavantage-sdk
包简介
A lightweight PHP API wrapper for Alpha Vantage.
README 文档
README
AlphaVantage SDK is a lightweight PHP wrapper for the Alpha Vantage Stock Market API.
It allows you to quickly integrate real-time stock prices, trends, and historical data into your applications with minimal setup. Whether you're building a financial dashboard, tracking market trends, or simply exploring stock data, this SDK makes it easy to access all the Alpha Vantage endpoints in a clean, modern, and dependency-free way.
Table of Contents
Features
- Full Range Endpoints: Access Time Series, Technical Indicators, Forex, and Cryptocurrency data.
- JSON Responses: Designed to work with JSON only.
- Dependency-Free HTTP Client: Uses an inbuilt cURL-based HTTP client.
- Modern PHP Practices: Built for PHP 8.1+ with strict typing, PSR-4 autoloading, and PSR-12 coding standards.
- Robust Error Handling: Custom exceptions for handling API errors and invalid responses.
- Comprehensive Testing: Includes PHPUnit tests to ensure core functionalities remain stable.
Requirements
- PHP: Version 8.1 or later.
- cURL: Enabled in PHP for HTTP requests.
Installation
Install the package via Composer:
composer require sukhrobnurali/alphavantage-sdk
Usage
The following examples show how to use the different endpoints provided by the SDK.
1. Initialization
Begin by including Composer’s autoloader and initializing the client with your API key:
<?php require 'vendor/autoload.php'; use AlphaVantage\Client; $apiKey = 'YOUR_ALPHA_VANTAGE_API_KEY'; $client = new Client($apiKey);
2. Time Series Data
Retrieve intraday stock data for Microsoft (MSFT) at a 5-minute interval:
<?php $intradayData = $client->timeSeries()->intraday('MSFT', '5min'); print_r($intradayData);
3. Technical Indicators
Fetch Simple Moving Average (SMA) data for Microsoft (MSFT):
<?php $smaData = $client->technicalIndicator()->get('SMA', [ 'symbol' => 'MSFT', 'interval' => 'daily', 'time_period' => 10, 'series_type' => 'close' ]); print_r($smaData);
4. Forex Data
Get the real-time exchange rate from USD to EUR:
<?php $exchangeRate = $client->forex()->getExchangeRate('USD', 'EUR'); print_r($exchangeRate);
5. Cryptocurrency Data
Retrieve daily cryptocurrency data for Bitcoin (BTC) in USD:
<?php $cryptoData = $client->crypto()->daily('BTC', 'USD'); print_r($cryptoData);
API Documentation
Time Series Endpoints
-
Intraday Data
- Method:
TimeSeriesEndpoint::intraday(string $symbol, string $interval, string $outputSize = 'compact') - Description: Retrieves intraday time series data for a specified stock symbol.
- Method:
-
Daily Data
- Method:
TimeSeriesEndpoint::daily(string $symbol, string $outputSize = 'compact') - Description: Retrieves daily time series data for a specified stock symbol.
- Method:
-
Weekly Data
- Method:
TimeSeriesEndpoint::weekly(string $symbol) - Description: Retrieves weekly time series data for a specified stock symbol.
- Method:
-
Monthly Data
- Method:
TimeSeriesEndpoint::monthly(string $symbol) - Description: Retrieves monthly time series data for a specified stock symbol.
- Method:
Technical Indicator Endpoints
- Technical Indicator Data
- Method:
TechnicalIndicatorEndpoint::get(string $indicator, array $params) - Description: Retrieves technical indicator data based on the specified indicator (e.g., SMA, EMA) and parameters.
- Method:
Forex Endpoints
-
Exchange Rate
- Method:
ForexEndpoint::getExchangeRate(string $fromCurrency, string $toCurrency) - Description: Retrieves the real-time exchange rate between two currencies.
- Method:
-
Intraday Forex Data
- Method:
ForexEndpoint::intraday(string $fromCurrency, string $toCurrency, string $interval) - Description: Retrieves intraday forex data for a given currency pair.
- Method:
Cryptocurrency Endpoints
-
Daily Data
- Method:
CryptoEndpoint::daily(string $symbol, string $market) - Description: Retrieves daily digital currency data for the specified cryptocurrency and market.
- Method:
-
Weekly Data
- Method:
CryptoEndpoint::weekly(string $symbol, string $market) - Description: Retrieves weekly digital currency data for the specified cryptocurrency and market.
- Method:
-
Monthly Data
- Method:
CryptoEndpoint::monthly(string $symbol, string $market) - Description: Retrieves monthly digital currency data for the specified cryptocurrency and market.
- Method:
Testing
Run the test suite using Composer:
composer test
The package includes PHPUnit tests that ensure all core functionalities and error handling mechanisms work as expected.
Contributing
Contributions are welcome! To contribute:
- Fork the repository.
- Create a branch for your feature or bug fix.
- Commit your changes with clear, descriptive messages.
- Submit a Pull Request detailing your changes.
Please adhere to the coding standards (PSR-12) and include tests for new features or bug fixes.
License
This project is licensed under the MIT License.
For any questions or further assistance, please open an issue in the repository.
sukhrobnurali/alphavantage-sdk 适用场景与选型建议
sukhrobnurali/alphavantage-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 02 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sukhrobnurali/alphavantage-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sukhrobnurali/alphavantage-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-09