kucoin/kucoin-php-sdk

PHP SDK for KuCoin API

1.0.4 2019-02-18 06:26 UTC

README

The detailed document https://docs.kucoin.com.

Latest Version Build Status

Requirements

Dependency Requirement
PHP >=5.5.0 PHP7+ is better
guzzlehttp/guzzle ~6.0

Install

Install package via Composer.

composer require "kucoin/kucoin-php-sdk:~1.0.0"

Usage

  • Choose environment
Environment BaseUri
Production DEFAULT https://openapi-v2.kucoin.com
Sandbox https://openapi-sandbox.kucoin.com
// Switch to the sandbox environment
KuCoinApi::setBaseUri('https://openapi-sandbox.kucoin.com');
  • Example of API without authentication
use KuCoin\SDK\PublicApi\Time;

$api = new Time();
$timestamp = $api->timestamp();
var_dump($timestamp);
  • Example of API with authentication
use KuCoin\SDK\Auth;
use KuCoin\SDK\PrivateApi\Account;
use KuCoin\SDK\Exceptions\HttpException;
use KuCoin\SDK\Exceptions\BusinessException;

$auth = new Auth('key', 'secret', 'passphrase');
$api = new Account($auth);

try {
    $result = $api->getList(['type' => 'main']);
    var_dump($result);
} catch (HttpException $e) {
    var_dump($e->getMessage());
} catch (BusinessException $e) {
    var_dump($e->getMessage());
}
  • Example of WebSocket feed
use KuCoin\SDK\Auth;
use KuCoin\SDK\PrivateApi\WebSocketFeed;
use Ratchet\Client\WebSocket;
use React\EventLoop\LoopInterface;

$auth = new Auth('key', 'secret', 'passphrase');
$api = new WebSocketFeed($auth);

$query = ['connectId' => uniqid('', true)];
$channel = [
    'topic' => '/market/ticker:KCS-BTC',
    //'response' => true,
];

$api->subscribePublicChannel($query, $channel, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
    var_dump($message);
    
    // Stop loop
    // $loop->stop();
}, function ($code, $reason) {
    echo "OnClose: {$code} {$reason}\n";
});
  • API list
API Authentication
KuCoin\SDK\PrivateApi\Account YES
KuCoin\SDK\PrivateApi\Deposit YES
KuCoin\SDK\PrivateApi\Fill YES
KuCoin\SDK\PrivateApi\Order YES
KuCoin\SDK\PrivateApi\WebSocketFeed YES
KuCoin\SDK\PrivateApi\Withdrawal YES
KuCoin\SDK\PublicApi\Currency NO
KuCoin\SDK\PublicApi\Symbol NO
KuCoin\SDK\PublicApi\Time NO

Run tests

Modify your API key in phpunit.xml first.

composer test

License

MIT