cryptopupua/kuna-api REST API php client

1.1.4 2021-07-14 06:22 UTC

This package is auto-updated.

Last update: 2024-04-12 23:27:58 UTC


SensioLabsInsight Build Status Coverage Status Latest Stable Version Total Downloads License 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


MIT License

Kuna REST API Reference


To create new endpoint - create issue or create pull request


composer require cryptopupua/kuna-api 1.1.*


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(
    'public key',
    'secret key'
$timestamp = $api->shared()->timestamp();


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 port 8080: Connection refused (see"

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)