rocketfellows / tinkoff-invest-v1-instruments-rest-client
v1.0.1
2022-06-21 21:39 UTC
Requires
- php: >=7.4
- rocketfellows/tinkoff-invest-v1-rest-client: 1.0.2
Requires (Dev)
- phpstan/phpstan: ^0.12.90
- phpunit/phpunit: ^8.5
- squizlabs/php_codesniffer: 3.6.2
This package is not auto-updated.
Last update: 2024-09-25 08:30:11 UTC
README
对 tinkoff invest v1 工具服务进行简单实现的库。目前提供以下方法:
- GetDividends - https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_GetDividends
- GetCountries - https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_GetCountries
- GetBondCoupons - https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_GetBondCoupons
- GetAssets - https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_GetAssets
- FindInstrument - https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_FindInstrument
- BondBy - https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_BondBy
方法接口
- \rocketfellows\TinkoffInvestV1InstrumentsRestClient\GetDividendsInterface
- \rocketfellows\TinkoffInvestV1InstrumentsRestClient\GetCountriesInterface
- \rocketfellows\TinkoffInvestV1InstrumentsRestClient\GetBondCouponsInterface
- \rocketfellows\TinkoffInvestV1InstrumentsRestClient\GetAssetsInterface
- \rocketfellows\TinkoffInvestV1InstrumentsRestClient\FindInstrumentInterface
- \rocketfellows\TinkoffInvestV1InstrumentsRestClient\BondByInterface
将方法接口实现聚合到 \rocketfellows\TinkoffInvestV1InstrumentsRestClient\InstrumentsService。
为了遵循接口分离原则,你应该将特定的接口作为依赖项注入,并通过容器(DI)定义实现。
安装
composer require rocketfellows/tinkoff-invest-v1-instruments-rest-client
方法合同定义
组件方法接受一个数组作为参数,而原始数组也作为输出值。
方法抛出以下类型的异常
- \rocketfellows\TinkoffInvestV1RestClient\exceptions\request\ClientException
- \rocketfellows\TinkoffInvestV1RestClient\exceptions\request\ServerException
- \rocketfellows\TinkoffInvestV1RestClient\exceptions\request\HttpClientException
组件依赖项
"rocketfellows/tinkoff-invest-v1-rest-client": "1.0.1" - 作为通用 HTTP 客户端。
使用示例
通用 HTTP 客户端配置
$client = new Client( ( new ClientConfig( 'https://invest-public-api.tinkoff.ru/rest', <your_access_token> ) ), new \GuzzleHttp\Client() );
工具服务配置(或通过 DI 的接口特定方法配置)
$instrumentsService = new InstrumentsService($client);
获取股息方法调用示例
$dividends = $instrumentsService->getDividends([ "figi" => "BBG004730RP0", "from" => "2022-05-28T15:38:52.283Z", "to" => '2022-08-18T15:38:52.283Z', ])
返回值
Array ( [dividends] => Array ( [0] => Array ( [dividendNet] => Array ( [currency] => rub [units] => 52 [nano] => 530000000 ) [declaredDate] => 2022-06-30T00:00:00Z [lastBuyDate] => 2022-07-18T00:00:00Z [dividendType] => [recordDate] => 2022-07-20T00:00:00Z [regularity] => [closePrice] => Array ( [currency] => rub [units] => 306 [nano] => 500000000 ) [yieldValue] => Array ( [units] => 17 [nano] => 140000000 ) [createdAt] => 2022-06-10T02:05:32.707197Z ) ) )
贡献
欢迎提交拉取请求。如果有重大更改,请先提交一个问题进行讨论。
请确保适当地更新测试。