cryptopupua/kuna-api

Kuna.io REST API php client

1.1.4 2021-07-14 06:22 UTC

This package is auto-updated.

Last update: 2023-03-12 21:05:39 UTC


README

SensioLabsInsight Build Status Coverage Status Latest Stable Version Total Downloads License

Kuna.io provides REST APIs that you can use to interact with platform programmatically.

This API client will help you interact with Kuna by REST API.

Table Of Contents

License

MIT License

Kuna REST API Reference

https://kuna.io/documents/api

Contributing

To create new endpoint - create issue or create pull request

Install

composer require cryptopupua/kuna-api 1.1.*

Usage

require __DIR__.'/vendor/autoload.php';

use cryptopupua\KunaApi\Api;
use cryptopupua\KunaApi\Exception\IncorrectResponseException;
use cryptopupua\KunaApi\KunaApi;
use cryptopupua\KunaApi\Model\History;
use cryptopupua\KunaApi\Model\MyAccount;
use cryptopupua\KunaApi\Model\Order;
use cryptopupua\KunaApi\Model\Ticker;


$api = new KunaApi(
    'https://kuna.io',
    'public key',
    'secret key'
);
$timestamp = $api->shared()->timestamp();

Mapping

Each endpoint response (exclude: timestamp) can be received as array or as object.

To use mapping response to object set parameter $mapping to true.

$issue = $api->signed()->activeOrders(Http::PAIR_ETHUAH, true);

// Result
[
    {
    class madmis\KunaApi\Model\Order {
        protected $id => 10003
        protected $side => "sell"
        protected $ordType => "limit"
        protected $price => 10000
        protected $avgPrice => 0
        protected $state => "wait"
        protected $market => "ethuah"
        protected $createdAt => DateTime
        protected $volume => 0.01
        protected $volume => 0.01
        protected $remainingVolume => 0.01
        protected $executedVolume => 0
        protected $tradesCount => 0
      }
    
    },
    ...
] 

Error handling

Each client request errors wrapped to custom exception madmis\ExchangeApi\Exception\ClientException

class madmis\ExchangeApi\Exception\ClientException {
  private $request => class GuzzleHttp\Psr7\Request
  private $response => NULL
  protected $message => "cURL error 7: Failed to connect to 127.0.0.1 port 8080: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)"
  ...
}

ClientException contains original request object and response object if response available

class madmis\ExchangeApi\Exception\ClientException {
  private $request => class GuzzleHttp\Psr7\Request 
  private $response => class GuzzleHttp\Psr7\Response {
    private $reasonPhrase => "Unauthorized"
    private $statusCode => 401
    ...
  }
  protected $message => "Client error: 401"
  ...  
}

So, to handle errors use try/catch

try {
    $api->signed()->activeOrders(Http::PAIR_ETHUAH, true);
} catch (madmis\ExchangeApi\Exception\ClientException $ex) {
    // any actions (log error, send email, ...) 
}

Running the tests

To run the tests, you'll need to install phpunit. Easiest way to do this is through composer.

composer install

Running Unit tests

php vendor/bin/phpunit -c phpunit.xml.dist

Library api

Shared resources (Public Kuna API)

Private resources (Private Kuna API)