mab05k / oanda-client
PHP Client for Oanda v20 REST-API
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: 2025-03-04 02:56:01 UTC
README
This is a PHP Client Library for interacting with the Oanda REST-V20 API. This API is designed with flexibility in mind, and supports using multiple Oanda Accounts.
Contributing
If you want to help contribute, please visit the Contributing documentation.
See the Changelog for recent changes.
Endpoints
Configuration
Configuration is done using Standard Symfony Bundle Configuration
# 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
Prepended Extensions
When the bundle is loaded by Symfony, it will automatically create the following Httplug Configuration for you. You are free to override or extend this config if you wish with your own configurations.
# 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'
We also set a default DateTime format for JMS Serializer to match the DateTime formatting from Oanda
# 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'
Authentication
The Oanda Client Bundle handles sending the Authorization headers for you based on your configuration. By default, it will use the first account in your configuration. If you are using multiple accounts, you must follow the documentation in the Multiple Accounts section.
Usage
Use Dependency Injection to inject the Clients into your Service
<?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... } }