A lightweight PHP API client for the IX-API.
To install, run composer require dant89/ix-api-client
in the root of your project or add dant89/ix-api-client
to your composer.json.
View the tagged versions to choose between v1
and v2
implementations of this client.
"require": {
"dant89/ix-api-client": "^LATEST_VERSION_TAG"
}
Use your provided key / secret credentials for the given implementor URL to return and then set a bearer token:
use Dant89\IXAPIClient\Client;
// Create base client
$client = new Client(IXAPI_URL);
// Get a bearer token from key / secret
$response = $client->getHttpClient(HttpClientType::AUTH)
->postAuthToken(IXAPI_KEY, IXAPI_SECRET);
// Check for valid response status
if ($response->getStatus() === 200) {
$client->setBearerToken($response->getContent()['access_token']);
}
With the bearer token set, you can return data from all endpoints that require authentication.
Get Product Offerings:
// Query for products
$response = $client->getHttpClient(HttpClientType::PRODUCT_OFFERINGS)
->get();
// Check for valid response and set the array of products
if ($response->getStatus() === 200) {
$productOfferings = $response->getContent();
}
Method Support and Filters:
All base clients have support for get
, delete
, post
, patch
.
Additional methods are available where supported, for example getStatistics
, getLoa
.
$singleItem = $client->getHttpClient(HttpClientType::CONTACTS)
->get('item-uuid')
->getContent();
$filteredItems = $client->getHttpClient(HttpClientType::CONTACTS)
->get(null, ['managing_account' => 'uuid-123'])
->getContent();
$response = $client->getHttpClient(HttpClientType::CONTACTS)
->post([
'managing_account' => 'uuid-123',
'consuming_account' => 'uuid-456',
'name' => 'sample contact',
]);
$client->getHttpClient(HttpClientType::CONTACTS)
->patch('item-uuid', [
'name' => 'renamed sample contact',
]);
$client->getHttpClient(HttpClientType::CONTACTS)
->delete('item-uuid');
// Query for connections timeseries data
$timeseries = $client->getHttpClient(HttpClientType::CONNECTIONS)
->getStatisticTimeseries('connection-123-uuid', '30d')
->getContent();
You will need to contact an exchange to create an API key / secret combination and find out the URL of their IX-API implementation.
Q. The IX-API is OpenAPI 3 compliant, why don't I just create a client using a tool such as Swagger Codegen?
A. Please do! This client is intended to be very lightweight and something you can use to jump in, build on and experiment with. Clients generated by automated tools, such as Swagger Codegen can have more depth and functionality that you may find your application requires.
Contributions to the client are welcome, to contribute please:
- Fork this repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new pull request