reilag/kuna-api-php

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

2.1.0 2018-02-14 16:12 UTC

This package is not auto-updated.

Last update: 2024-04-27 17:03:49 UTC


README

<< Kuna API

Kuna Exchange PHP API

GitHub issues GitHub stars

PHP Version Guzzle Version Packagist

WARNING! This is not a stable version!

PHP 5.6+ is required.

If you do not want to use Composer or use version less than PHP 5.6 , you can use Simple API PHP Library

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 reilag/kuna-api-php:^1.0.1

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

{
   "require": {
      "reilag/kuna-api-php": "^1.0.1"
   }
}

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": "2016-06-21T05: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": "2016-06-21T05: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": "2016-06-21T04: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": "your_email@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": "2016-06-21T05: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": "2016-06-21T05: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": "2016-06-21T05: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": "2016-06-21T05:09:02Z",
	    "volume": 0.5,
	    "remaining_volume": 0.3,
	    "executed_volume": 0.2,
	    "trades_count": 10
	}
]