mab05k / oanda-client
Oanda v20 REST-API 的 PHP 客户端
v0.5.0
2023-06-03 23:09 UTC
Requires
- php: ^7.1.3|^8.2
- ext-json: *
- brick/math: ^0.8|^0.10|^0.11
- brick/money: ^0.4|^0.6|^0.8
- jms/serializer-bundle: ^3.5|^4.0|^5.0
- php-http/guzzle6-adapter: ^2.0
- php-http/httplug-bundle: ^1.7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14|^3.0
- http-interop/http-factory-guzzle: ^1.1
- monolog/monolog: ^1.24
- phake/phake: ^3.0|^4.0
- php-http/mock-client: ^1.2
- phpunit/phpunit: ^7.0|^9.0|^10.0
- symfony/browser-kit: ^4.2|^5.4|^6.0
- symfony/dotenv: ^4.2|^5.4|^6.0
- symfony/monolog-bundle: ^3.3
- symfony/yaml: ^4.2|^5.4|^6.0
- dev-master
- v0.5.0
- v0.4.0
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
- dev-chore/update-php-version
- dev-stream-endpoints
- dev-resettablePl-time
- dev-hotfix/trait-fqcn
- dev-hotfix/trade-closing-transaction-ids
- dev-hotfix/cancelled-time
- dev-bugfix/cancelled-order
- dev-update-dependenices
- dev-symfony-serializer
This package is auto-updated.
Last update: 2024-09-04 01:46:43 UTC
README
这是一个用于与 Oanda REST-V20 API 交互的 PHP 客户端库。该 API 考虑了灵活性,并支持使用多个 Oanda 账户。
贡献
如果您想帮助贡献,请访问贡献文档。
查看变更日志了解最近的更改。
端点
配置
配置使用标准 Symfony Bundle 配置完成
# config/bundles.php <?php return [ Mab05k\OandaClient\Bridge\Symfony\Bundle\BosOandaClientBundle::class => ['all' => true], Http\HttplugBundle\HttplugBundle::class => ['all' => true], JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], ];
# config/packages/oanda_client.yaml mab05k_oanda_client: hostname: https://api-fxpractice.oanda.com stream_hostname: https://stream-fxpractice.oanda.com path_prefix: /v3 accounts: - name: primary_account account_id: 000-000-0000000-000 account_secret: my_account_secret - name: secondary_account account_id: 000-000-0000000-001 account_secret: my_account_secret
前置扩展
当包由 Symfony 加载时,它将自动为您创建以下Httplug 配置。您可以根据自己的配置覆盖或扩展此配置。
# This is an example, and does not need to be manually added to your configuration files httplug: plugins: logger: logger: 'logger' clients: mab05k_oanda_client: factory: 'httplug.collector.factory.guzzle6' config: timeout: 3 plugins: - add_host: host: '%mab05k_oanda_client.hostname%' replace: true - add_path: path: '%mab05k_oanda_client.path_prefix%' - header_defaults: headers: Content-Type: 'application/json'
我们还为 JMS Serializer 设置了默认的 DateTime 格式,以匹配 Oanda 的 DateTime 格式
# This is an example, and does not need to be manually added to your configuration files jms_serializer: handlers: datetime: default_format: 'Y-m-d\TH:i:s.u???\Z'
身份验证
Oanda 客户端包根据您的配置处理发送授权头。默认情况下,它将使用配置中的第一个账户。如果您使用多个账户,您必须遵循多个账户部分中的文档。
使用
使用依赖注入将客户端注入到您的服务中
<?php namespace App\Service; use Mab05k\OandaClient\Client\AccountClient; class OandaAccountService { /** * @var AccountClient */ private $accountClient; public function __construct(AccountClient $accountClient) { $this->accountClient = $accountClient; } public function doSomethingWithAccount() { $account = $this->accountClient->account(); // do something and return the result... } }