rocketfellows/tinkoff-invest-v1-method-get-dividends

v1.0.0 2022-06-26 21:21 UTC

This package is not auto-updated.

Last update: 2024-09-17 06:24:39 UTC


README

Code Coverage Badge

该组件是对接收证券分红支付事件的方法的包装。

提供一组函数,用于接收不同查询参数的分红。

德意志银行swagger定义 https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_GetDividends

组件内容

该组件由两个基本部分组成

  • rocketfellows\TinkoffInvestV1MethodGetDividends\DividendsService - 获取证券分红列表的直接目标服务
  • 适配器 - 实现接收证券分红的适配器

DividendsService

DividendsService - 提供请求证券分红列表的函数的服务。

函数列表及其合约

  • getAll - 以证券的figi值作为输入参数,返回Dividends元组,抛出SourceFaultExceptionIncorrectInputsFaultException
  • getBeforeDate - 输入参数为证券的figi值和截至登记日(record_date)的日期,包括必要进行搜索的日期,返回Dividends元组,抛出SourceFaultExceptionIncorrectInputsFaultException
  • getByPeriod - 输入参数为证券的figi值和注册日固定日期范围,在其中进行搜索,返回Dividends元组,抛出SourceFaultExceptionIncorrectInputsFaultException
/**
 * @throws SourceFaultException
 * @throws IncorrectInputsFaultException
 */
public function getAll(string $figi): Dividends;

/**
 * @throws SourceFaultException
 * @throws IncorrectInputsFaultException
 */
public function getBeforeDate(string $figi, DateTime $dateTime): Dividends;

/**
 * @throws IncorrectInputsFaultException
 * @throws SourceFaultException
 */
public function getByPeriod(string $figi, DateTime $fromDateTime, DateTime $toDateTime): Dividends;

Figi - 证券标识符。

Dividends - 定义 - rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividends,不可变Dividend类型对象的元组。

Dividend - 定义 - rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend,描述证券的分红数据,方案定义在此 https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_GetDividends

DividendsServiceException - 定义 - rocketfellows\TinkoffInvestV1MethodGetDividends\exceptions\DividendsServiceException,此组件的基异常抽象类。

IncorrectInputsFaultException - 定义 - rocketfellows\TinkoffInvestV1Common\exceptions\faults\IncorrectInputsFaultException,如果搜索证券分红的输入数据不正确时抛出的异常,例如搜索figi不存在证券。

SourceFaultException - 定义 - rocketfellows\TinkoffInvestV1Common\exceptions\faults\SourceFaultException,如果tinkoff投资API的服务器端发生错误时抛出的异常。

DividendsRequestInterface - 定义 - rocketfellows\TinkoffInvestV1MethodGetDividends\DividendsRequestInterface,与DividendsService服务一起工作以从各种来源接收证券分红数据的接口。必须由适配器实现该接口,例如rest、soap、gRpc等适配器。

/**
* @throws IncorrectInputsFaultException
* @throws SourceFaultException
*/
public function requestAll(string $figi): Dividends;

/**
* @throws IncorrectInputsFaultException
* @throws SourceFaultException
*/
public function requestToDate(string $figi, DateTime $toDateTime): Dividends;

/**
* @throws IncorrectInputsFaultException
* @throws SourceFaultException
*/
public function requestByPeriod(string $figi, DateTime $fromDateTime, DateTime $toDateTime): Dividends;

适配器

到目前为止,在https://tinkoff.github.io/investAPI/swagger-ui/#/InstrumentsService/InstrumentsService_GetDividends的swagger文件中描述的REST API是获取证券分红支付信息的数据源。因此,在组件框架内,实现了实现rocketfellows\TinkoffInvestV1MethodGetDividends\DividendsRequestInterface接口的REST API适配器。

您可以随意实现其他适配器以获取分红数据。

到目前为止实现适配器列表

  • REST

REST适配器

一个实现了接口 rocketfellows\TinkoffInvestV1MethodGetDividends\DividendsRequestInterface - rocketfellows\TinkoffInvestV1MethodGetDividends\adapters\rest\DividendsRequestService 的 REST API 适配器类

该类实现了接口的所有合同,包括输入、输出和异常。

适配器使用低级抽象来获取股息数据 rocketfellows\TinkoffInvestV1InstrumentsRestClient\GetDividendsInterface 作为依赖,这是一个由 rocketfellows/tinkoff-invest-v1-instruments-rest-client 组件提供的接口,组件链接:https://github.com/rocketfellows/tinkoff-invest -v1-instruments-rest-client

REST API 适配器使用示例

为了开始使用该服务接收股息支付数据,您需要配置以下内容

  • 低级 REST API 客户端 rocketfellows\TinkoffInvestV1RestClient\Client
  • 定义 rocketfellows\TinkoffInvestV1InstrumentsRestClient\GetDividendsInterface 接口的实现
  • rocketfellows\TinkoffInvestV1InstrumentsRestClient\GetDividendsInterface 接口的实现传递给 rocketfellows\TinkoffInvestV1MethodGetDividends\adapters\rest\DividendsRequestService
  • rocketfellows\TinkoffInvestV1MethodGetDividends\DividendsService 的实现(即 rocketfellows\TinkoffInvestV1MethodGetDividends\adapters\rest\DividendsRequestService 适配器的 REST API 实现)作为依赖项传递给 rocketfellows\TinkoffInvestV1MethodGetDividends\DividendsRequestInterface 接口

当然,您也可以通过您的 DI 容器完成所有这些初步设置。

配置示例

$client = new \rocketfellows\TinkoffInvestV1RestClient\Client(
    (
        new \rocketfellows\TinkoffInvestV1RestClient\ClientConfig(
            'https://invest-public-api.tinkoff.ru/rest',
            <your_access_token>
        )
    ),
    new \GuzzleHttp\Client()
);

$instrumentsService = new \rocketfellows\TinkoffInvestV1InstrumentsRestClient\InstrumentsService($client);

$dividendsRequestService = new \rocketfellows\TinkoffInvestV1MethodGetDividends\adapters\rest\DividendsRequestService($instrumentsService);

服务函数调用示例

$dividends = $dividendsService->getByPeriod(
    'BBG004730RP0',
    new DateTime('2022-05-24T15:38:52.283Z'),
    new DateTime('2022-08-24T15:38:52.283Z'),
);

var_dump($dividends);

输出

object(rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividends)#35 (2) {
  ["data":protected]=>
  array(1) {
    [0]=>
    object(rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend)#38 (10) {
      ["dividendNet":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      object(rocketfellows\TinkoffInvestV1Common\models\MoneyValue)#36 (3) {
        ["currency":"rocketfellows\TinkoffInvestV1Common\models\MoneyValue":private]=>
        object(arslanimamutdinov\ISOStandard4217\Currency)#23 (3) {
          ["name":"arslanimamutdinov\ISOStandard4217\Currency":private]=>
          string(13) "Russian ruble"
          ["alpha3":"arslanimamutdinov\ISOStandard4217\Currency":private]=>
          string(3) "RUB"
          ["numericCode":"arslanimamutdinov\ISOStandard4217\Currency":private]=>
          string(3) "643"
        }
        ["units":"rocketfellows\TinkoffInvestV1Common\models\MoneyValue":private]=>
        int(52)
        ["nano":"rocketfellows\TinkoffInvestV1Common\models\MoneyValue":private]=>
        int(530000000)
      }
      ["closePrice":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      object(rocketfellows\TinkoffInvestV1Common\models\MoneyValue)#33 (3) {
        ["currency":"rocketfellows\TinkoffInvestV1Common\models\MoneyValue":private]=>
        object(arslanimamutdinov\ISOStandard4217\Currency)#26 (3) {
          ["name":"arslanimamutdinov\ISOStandard4217\Currency":private]=>
          string(13) "Russian ruble"
          ["alpha3":"arslanimamutdinov\ISOStandard4217\Currency":private]=>
          string(3) "RUB"
          ["numericCode":"arslanimamutdinov\ISOStandard4217\Currency":private]=>
          string(3) "643"
        }
        ["units":"rocketfellows\TinkoffInvestV1Common\models\MoneyValue":private]=>
        int(296)
        ["nano":"rocketfellows\TinkoffInvestV1Common\models\MoneyValue":private]=>
        int(0)
      }
      ["yieldValue":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      object(rocketfellows\TinkoffInvestV1Common\models\Quotation)#24 (2) {
        ["units":"rocketfellows\TinkoffInvestV1Common\models\Quotation":private]=>
        int(17)
        ["nano":"rocketfellows\TinkoffInvestV1Common\models\Quotation":private]=>
        int(750000000)
      }
      ["paymentDate":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      NULL
      ["declaredDate":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      object(DateTime)#22 (3) {
        ["date"]=>
        string(26) "2022-06-30 00:00:00.000000"
        ["timezone_type"]=>
        int(2)
        ["timezone"]=>
        string(1) "Z"
      }
      ["lastBuyDate":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      object(DateTime)#37 (3) {
        ["date"]=>
        string(26) "2022-07-18 00:00:00.000000"
        ["timezone_type"]=>
        int(2)
        ["timezone"]=>
        string(1) "Z"
      }
      ["recordDate":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      object(DateTime)#30 (3) {
        ["date"]=>
        string(26) "2022-07-20 00:00:00.000000"
        ["timezone_type"]=>
        int(2)
        ["timezone"]=>
        string(1) "Z"
      }
      ["createdAt":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      object(DateTime)#39 (3) {
        ["date"]=>
        string(26) "2022-06-26 02:04:44.658320"
        ["timezone_type"]=>
        int(2)
        ["timezone"]=>
        string(1) "Z"
      }
      ["dividendType":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      string(0) ""
      ["regularity":"rocketfellows\TinkoffInvestV1MethodGetDividends\models\Dividend":private]=>
      string(0) ""
    }
  }
  ["position"]=>
  int(0)
}

贡献

欢迎提出拉取请求。如果有重大更改,请首先为讨论打开一个问题。

请确保根据需要更新测试。