PHP code example of madmis / kuna-api

1. Go to this page and download the library: Download madmis/kuna-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

madmis / kuna-api example snippets




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();

$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
      }
    
    },
    ...
] 

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)"
  ...
}

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"
  ...  
}

try {
    $api->signed()->activeOrders(Http::PAIR_ETHUAH, true);
} catch (madmis\ExchangeApi\Exception\ClientException $ex) {
    // any actions (log error, send email, ...) 
}

    $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');
   

     $orders = $api->signed()->me();
   

     $orders = $api->signed()->createBuyOrder('btcuah', 1.00, 350000, true);
   

     $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);