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.
MIT License
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(
'https://kuna.io',
'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
}
},
...
]
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, ...)
}
To run the tests, you'll need to install phpunit. Easiest way to do this is through composer.
composer install
php vendor/bin/phpunit -c phpunit.xml.dist
-
$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');
-
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);