alexdives/kuna-api-for-php

Kuna Exchange PHP API - https://kuna.io/documents/api

1.0 2021-03-18 09:13 UTC

This package is auto-updated.

Last update: 2024-12-18 18:54:14 UTC


README

<< Kuna API (php)

Kuna.io PHP API

GitHub issues GitHub stars

PHP Version Guzzle Version Packagist

WARNING! This is not a stable version!

PHP 7.3+ is required.

1. Install

You can add Kuna PHP API as a dependency using the composer.phar CLI:

# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add dependency
php composer.phar require AlexDives/kuna-api-for-php:^1.0

Alternatively, you can specify Kuna PHP API as a dependency in your project's existing composer.json file:

{
   "require": {
      "alexdives/kuna-api-for-php": "^1.0"
   }
}

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at getcomposer.org.

2. Public methods

2.1. Timestamp

use Kuna\Client;

$kuna = new Client();
$timestamp = $kuna->publicMethod()->timestamp(); //1466486485

2.2. Tickers

use Kuna\Client;
use Kuna\Constant;

$kuna = new Client();
$tickers = $kuna->publicMethod()->tickers(Constant::MARKET_BTCUAH);

print_r($tickers);

Result:

{
	"at":1466486520,
	"ticker":{
		"buy": 18001.0,
		"sell": 18939.0,
		"low": 18000.0,
		"high": 18999.0,
		"last": 18000.0,
		"vol": 1.6011
	}
}

2.3. Order book

use Kuna\Client;
use Kuna\Constant;

$kuna = new Client();
$orderBook = $kuna->publicMethod()->orderBook(Constant::MARKET_BTCUAH);

print_r($orderBook);

Result:

{
	"asks": [
		{
			"id": 1182,
			"side": "sell",
			"ord_type": "limit",
			"price": 18939.0,
			"avg_price": 0.0,
			"state": "wait",
			"market": "btcuah",
			"created_at": "2021-03-18T05:09:02Z",
			"volume": 0.0326,
			"remaining_volume": 0.0326,
			"executed_volume": 0.0,
			"trades_count":0
		}
	],

	"bids": [
		{
			"id": 1183,
			"side": "buy",
			"ord_type": "limit",
			"price": 18001.0,
			"avg_price": 0.0,
			"state": "wait",
			"market": "btcuah",
			"created_at": "2021-03-18T05:09:03Z",
			"volume": 0.0005,
			"remaining_volume": 0.0005,
			"executed_volume": 0.0,
			"trades_count": 0
		}
	]
}

2.4. Trades

use Kuna\Client;
use Kuna\Constant;

$kuna = new Client();
$trades = $kuna->publicMethod()->trades(Constant::MARKET_BTCUAH);

print_r($trades);

Result:

[
	{
		"id": 338,
		"price": 18000.0,
		"volume": 0.369,
		"funds": 6642.0,
		"market": "btcuah",
		"created_at": "2021-03-18T04:44:58Z",
		"side": null
	}
]

3. Private methods

use Kuna\Client;

$kuna = new Client([
	"publicKey" => "Your public key",
	"secretKey" => "Your secret key",
]);

$privateMethod = $kuna->privateMethod();

3.1. My profile

$me = $privateMethod->me();
print_r($me);

Result:

{
    "email": "example@email.com",
    "activated": true,
    "accounts": [
        {
	        "currency": "btc",
	        "balance": 12.4123,
	        "locked": 0.42
        },
        {
            "currency": "uah",
            "balance": 233519.52,
            "locked": 4981.315
        }
    ]
}

3.2. Create new Order

$orderMethod = $privateMethod->order();

/**
 * $price
 * $volume
 * $side
 * $market
 */
$newOrder = $orderMethod->create(18000, 0.1, Constant::SIDE_BUY, Constant::MARKET_BTCUAH);

print_r($newOrder);

Result:

{
    "id": 3091,
    "side": "buy",
    "ord_type": "market",
    "price": 18000,
    "avg_price": 0,
    "state": "wait",
    "market": "btcuah",
    "created_at": "2021-03-18T05:09:02Z",
    "volume": 0.1,
    "remaining_volume": 0.1,
    "executed_volume": 0,
    "trades_count": 0
}

3.3. Delete order

$orderMethod = $privateMethod->order();

/**
 * @property int $orderId
 */
$deletedOrder = $orderMethod->delete(3091);

print_r($deletedOrder);

Result:

{
    "id": 3091,
    "side": "buy",
    "ord_type": "market",
    "price": 18000,
    "avg_price": 18000,
    "state": "wait",
    "market": "btcuah",
    "created_at": "2021-03-18T05:09:02Z",
    "volume": 0.1,
    "remaining_volume": 0.05,
    "executed_volume": 0.05,
    "trades_count": 3
}

3.4. Active order list

$orderMethod = $privateMethod->order();

$orderList = $orderMethod->orderList(Constant::MARKET_BTCUAH);

print_r($orderList);

Result:

[
	{
	    "id": 3994,
	    "side": "buy",
	    "ord_type": "market",
	    "price": 29000,
	    "avg_price": 40000,
	    "state": "wait",
	    "market": "btcuah",
	    "created_at": "2021-03-18T05:09:02Z",
	    "volume": 0.8,
	    "remaining_volume": 0.109,
	    "executed_volume": 0.691,
	    "trades_count": 8
	}, {
	    "id": 40,
	    "side": "sell",
	    "ord_type": "market",
	    "price": 28000,
	    "avg_price": 29910,
	    "state": "wait",
	    "market": "btcuah",
	    "created_at": "2021-03-18T05:09:02Z",
	    "volume": 0.5,
	    "remaining_volume": 0.3,
	    "executed_volume": 0.2,
	    "trades_count": 10
	}
]