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.
If you want to help contribute, please visit the Contributing documentation.
See the Changelog for recent changes.
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
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'
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.
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...
}
}