Skip to content

Latest commit

 

History

History
115 lines (80 loc) · 3.58 KB

README.md

File metadata and controls

115 lines (80 loc) · 3.58 KB

IX-API PHP Client

Latest Stable Version Github Issues

A lightweight PHP API client for the IX-API.

Installation

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"
}

Usage

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();

Authentication

You will need to contact an exchange to create an API key / secret combination and find out the URL of their IX-API implementation.

Questions

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

Contributions to the client are welcome, to contribute please:

  1. Fork this repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new pull request