madmis / kuna-api
Kuna.io REST API php client
Requires
- php: ^7.1
- doctrine/annotations: ^1.4
- madmis/exchange-api: ^0.1
- symfony/options-resolver: ^3.3
Requires (Dev)
- phpunit/phpunit: ^6.2
- symfony/console: ^3.3
This package is auto-updated.
Last update: 2024-10-19 21:57:23 UTC
README
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
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)
-
$timestamp = $api->shared()->timestamp();
-
$tickers = $api->shared()->tickers('btcuah');
-
$orders = $api->shared()->orderBook('btcuah');
-
$orders = $api->shared()->asksOrderBook('btcuah');
-
$orders = $api->shared()->bidsOrderBook('btcuah');
-
$orders = $api->shared()->tradesHistory('btcuah');
Private resources (Private Kuna API)
-
Information About the User and Assets
$orders = $api->signed()->me();
-
Order Placing - create BUY order
$orders = $api->signed()->createBuyOrder('btcuah', 1.00, 350000, true);
-
Order Placing - create SELL order
$orders = $api->signed()->createSellOrder('btcuah', 1.00, 420000, true);
-
$orders = $api->signed()->cancelOrder(124578, true);
-
$orders = $api->signed()->activeOrders('btcuah', true);
-
$orders = $api->signed()->myHistory('btcuah', true);