finazon / finazon-grpc-php
Finazon gRPC 客户端库 for PHP
v1.2.1
2024-05-28 09:40 UTC
Requires
- php: ^7.4|^8.0
- ext-grpc: *
- ext-protobuf: *
- google/common-protos: ^4.5
- google/protobuf: ^3.25
- grpc/grpc: ^1.57
This package is auto-updated.
Last update: 2024-08-28 10:06:48 UTC
README
这是 Finazon 的官方 PHP 库,提供访问
- 数据集列表、发布者、市场和股票代码。
- 市场数据:股票快照、时间序列、交易和技术指标。
- 来自特定数据集的数据,如 Benzinga、Binance、Crypto、Forex、SEC 和 SIP。
🔑 API密钥 是必需的。如果您还没有,请在此注册。
要求
确保您有 PHP 7.4 或更高版本。
安装
使用Composer添加包
composer require finazon/finazon-grpc-php
🔗 在Packagist上查看包。
更新到最新版本
composer update finazon/finazon-grpc-php
快速入门
1. 设置新项目
mkdir hello-finazon && cd hello-finazon
composer init --name="example/hello-finazon" --no-interaction
composer require finazon/finazon-grpc-php
2. 创建 time_series.php
脚本
<?php require 'vendor/autoload.php'; use Finazon\Grpc\Api\GetTimeSeriesRequest; use Finazon\Grpc\Api\TimeSeries; use Finazon\Grpc\Exception\RequestException; use Finazon\Grpc\Service\TimeSeriesService; // Load last OHLCV candles for AAPL $service = new TimeSeriesService('your_api_key'); $request = new GetTimeSeriesRequest(); $request->setDataset('sip_non_pro') ->setTicker('AAPL') ->setInterval('1h') ->setPageSize(10); try { $response = $service->getTimeSeries($request); echo 'Last AAPL OHLCV data' . PHP_EOL; foreach ($response->getResult() as $t) { /** @var Timeseries $t */ echo sprintf( '%s - %s, %s, %s, %s, %s %s', $t->getTimestamp(), $t->getOpen(), $t->getHigh(), $t->getLow(), $t->getClose(), $t->getVolume(), PHP_EOL, ); } } catch (RequestException $e) { echo sprintf('Received error, code: %s, message: %s%s', $e->getCode(), $e->getMessage(), PHP_EOL); }
3. 输入您的 API 密钥
将 'your_api_key'
替换为您的实际密钥。
4. 运行脚本
php time_series.php
📝 预期输出
Last AAPL OHLCV data
1709582400 - 175.325, 175.5, 174.95, 175.1, 14962271
1709578800 - 174.2, 175.645, 173.98, 175.325, 8209663
1709575200 - 174.05, 174.505, 173.79, 174.205, 7869144
1709571600 - 174.1112, 174.7, 174.01, 174.05, 7365810
1709568000 - 174.835, 175.895, 174.1, 174.1201, 8672800
1709564400 - 174.96, 175.929, 173.9, 174.83, 14265584
1709560800 - 176.15, 176.9, 174.62, 174.97, 13824038
1709323200 - 179.9312, 179.97, 179.415, 179.695, 7701993
1709319600 - 179.315, 180.22, 179.31, 180.005, 6668926
1709316000 - 178.515, 179.39, 178.33, 179.32, 6103415
👀 查看完整示例和其他示例这里
RPC 支持
以下表格概述了支持的 RPC 调用
以下是如何使用 service
和 request
对象的示例
<?php require 'vendor/autoload.php'; use Finazon\Grpc\Api\RpcNameRequest; use Finazon\Grpc\Service\ServiceNameService; # ... $service = new ServiceNameService('your_api_key'); $request = new RpcNameRequest(); $response = service->rpcName($request);
文档
深入了解我们的官方文档。
示例
在示例目录中探索实际场景。
支持
保持更新
贡献
- 分叉并克隆:
$ git clone https://github.com/finazon-io/finazon-grpc-php.git
。 - 创建分支:
$ cd finazon-grpc-php && git checkout -b my-feature
。 - 提交更改并进行测试。
- 推送您的分支并提交带有详细描述的拉取请求。
有关贡献的更多指导,请参阅 GitHub 上的GitHub 文档。
许可证
本项目采用 MIT 许可证。有关更多详细信息,请参阅本存储库中的 LICENSE.txt
文件。