Git Product home page Git Product logo

kucoin-php-sdk's Introduction

PHP SDK for KuCoin API

The detailed document https://docs.kucoin.com, in order to receive the latest API change notifications, please Watch this repository.

Latest Version PHP Version Build Status Total Downloads License

Requirements

Dependency Requirement
PHP >=5.5.0 Recommend PHP7+
guzzlehttp/guzzle ^6.0|^7.0

Install

Install package via Composer.

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

Usage

Choose environment

Environment BaseUri
Production https://api.kucoin.com
// Switch to the sandbox environment
KuCoinApi::setBaseUri('https://api.kucoin.com');

Debug mode & logging

// Debug mode will record the logs of API and WebSocket to files in the directory "KuCoinApi::getLogPath()" according to the minimum log level "KuCoinApi::getLogLevel()".
KuCoinApi::setDebugMode(true);

// Logging in your code
// KuCoinApi::setLogPath('/tmp');
// KuCoinApi::setLogLevel(Monolog\Logger::DEBUG);
KuCoinApi::getLogger()->debug("I'm a debug message");

Examples

See the test case for more examples.

Example of API without authentication

use KuCoin\SDK\PublicApi\Time;

$api = new Time();
$timestamp = $api->timestamp();
var_dump($timestamp);
Note

To reinforce the security of the API, KuCoin upgraded the API key to version 2.0, the validation logic has also been changed. It is recommended to create(https://www.kucoin.com/account/api) and update your API key to version 2.0. The API key of version 1.0 will be still valid until May 1, 2021

Example of API with authentication

use KuCoin\SDK\PrivateApi\Account;
use KuCoin\SDK\Exceptions\HttpException;
use KuCoin\SDK\Exceptions\BusinessException;
use KuCoin\SDK\Auth;

// Auth version v2 (recommend)
$auth = new Auth('key', 'secret', 'passphrase', Auth::API_KEY_VERSION_V2);
// Auth version v1
// $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\Factory;
use React\EventLoop\LoopInterface;

$auth = null;
// Need to pass the Auth parameter when subscribing to a private channel($api->subscribePrivateChannel()).
// $auth = new Auth('key', 'secret', 'passphrase');
$api = new WebSocketFeed($auth);

// Use a custom event loop instance if you like
//$loop = Factory::create();
//$loop->addPeriodicTimer(1, function () {
//    var_dump(date('Y-m-d H:i:s'));
//});
//$api->setLoop($loop);

$query = ['connectId' => uniqid('', true)];
$channels = [
    ['topic' => '/market/ticker:KCS-BTC'], // Subscribe multiple channels
    ['topic' => '/market/ticker:ETH-BTC'],
];

$api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
    var_dump($message);

    // Subscribe another channel
    // $ws->send(json_encode($api->createSubscribeMessage('/market/ticker:LTC-BTC')));

    // Unsubscribe the channel
    // $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC')));

    // Stop loop
    // $loop->stop();
}, function ($code, $reason) {
    echo "OnClose: {$code} {$reason}\n";
});

Add custom options

use KuCoin\SDK\PublicApi\Time;

$api = new Time(null, new GuzzleHttp([
    'curl' => [ // custom cURL options: https://www.php.net/manual/en/function.curl-setopt
        CURLOPT_TCP_NODELAY => true, // Disable TCP's Nagle algorithm, which tries to minimize the number of small packets on the network.
        // ...
    ],
]));
$timestamp = $api->timestamp();
var_dump($timestamp);
use KuCoin\SDK\Auth;
use KuCoin\SDK\Http\GuzzleHttp;
use KuCoin\SDK\KuCoinApi;
use KuCoin\SDK\PrivateApi\WebSocketFeed;
use Ratchet\Client\WebSocket;
use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;

$api = new WebSocketFeed(
    null,
    new GuzzleHttp([
        'curl' => [ // Custom cURL options: https://www.php.net/manual/en/function.curl-setopt
            CURLOPT_TCP_NODELAY => true, // Disable TCP's Nagle algorithm, which tries to minimize the number of small packets on the network.
            // ...
        ],
    ])
);
$query = ['connectId' => uniqid('', true)];
$channels = [
    ['topic' => '/market/ticker:KCS-BTC'],
    ['topic' => '/market/ticker:ETH-BTC'],
];
$options = ['tcp' => ['tcp_nodelay' => true]]; // Custom socket context options: https://www.php.net/manual/zh/context.socket
$api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
    var_dump($message);
}, function ($code, $reason) {
    echo "OnClose: {$code} {$reason}\n";
}, $options);

⚡️Coroutine HTTP client for asynchronous IO

See the benchmark, almost 20x faster than curl.

pecl install swoole
composer require swlib/saber
use KuCoin\SDK\Auth;
use KuCoin\SDK\Http\SwooleHttp;
use KuCoin\SDK\KuCoinApi;
use KuCoin\SDK\PrivateApi\Order;
use KuCoin\SDK\PublicApi\Time;

// Require PHP 7.1+ and Swoole 2.1.2+
// Require running in cli mode

go(function () {
    $api = new Time(null, new SwooleHttp);
    $timestamp = $api->timestamp();
    var_dump($timestamp);
});

go(function () {
    // Auth version v2 (recommend)
    $auth = new Auth('key', 'secret', 'passphrase', Auth::API_KEY_VERSION_V2);
    // Auth version v1
    // $auth = new Auth('key', 'secret', 'passphrase');
    $api = new Order($auth, new SwooleHttp);
    // Create 50 orders CONCURRENTLY in 1 second
    for ($i = 0; $i < 50; $i++) {
        go(function () use ($api, $i) {
            $order = [
                'clientOid' => uniqid(),
                'price'     => '1',
                'size'      => '1',
                'symbol'    => 'BTC-USDT',
                'type'      => 'limit',
                'side'      => 'buy',
                'remark'    => 'ORDER#' . $i,
            ];
            try {
                $result = $api->create($order);
                var_dump($result);
            } catch (\Throwable $e) {
                var_dump($e->getMessage());
            }
        });
    }
});

API list

KuCoin\SDK\PrivateApi\Account
API Authentication Description
KuCoin\SDK\PrivateApi\Account::create() YES https://docs.kucoin.com/#create-an-account
KuCoin\SDK\PrivateApi\Account::getList() YES https://docs.kucoin.com/#list-accounts
KuCoin\SDK\PrivateApi\Account::getDetail() YES https://docs.kucoin.com/#get-an-account
KuCoin\SDK\PrivateApi\Account::getLedgers() YES DEPRECATED https://docs.kucoin.com/#get-account-ledgers-deprecated
KuCoin\SDK\PrivateApi\Account::getHolds() YES https://docs.kucoin.com/#get-holds
KuCoin\SDK\PrivateApi\Account::innerTransfer() YES DEPRECATED https://docs.kucoin.com/#inner-transfer
KuCoin\SDK\PrivateApi\Account::innerTransferV2() YES https://docs.kucoin.com/#inner-transfer
KuCoin\SDK\PrivateApi\Account::getSubAccountUsers() YES https://docs.kucoin.com/#get-user-info-of-all-sub-accounts
KuCoin\SDK\PrivateApi\Account::getSubAccountDetail() YES https://docs.kucoin.com/#get-account-balance-of-a-sub-account
KuCoin\SDK\PrivateApi\Account::getSubAccountList() YES https://docs.kucoin.com/#get-the-aggregated-balance-of-all-sub-accounts-of-the-current-user
KuCoin\SDK\PrivateApi\Account::subTransfer() YES DEPRECATED https://docs.kucoin.com/#transfer-between-master-account-and-sub-account
KuCoin\SDK\PrivateApi\Account::subTransferV2() YES https://docs.kucoin.com/#transfer-between-master-user-and-sub-user
KuCoin\SDK\PrivateApi\Account::getLedgersV2() YES https://docs.kucoin.com/#get-account-ledgers
KuCoin\SDK\PrivateApi\Account::getSubUserV2() YES https://docs.kucoin.com/#get-paginated-list-of-sub-accounts
KuCoin\SDK\PrivateApi\Account::getUserinfoV2() YES https://docs.kucoin.com/#get-account-summary-info-v2
KuCoin\SDK\PrivateApi\Account::createSubUserV2() YES https://docs.kucoin.com/#create-sub-account-v2
KuCoin\SDK\PrivateApi\Account::createSubUserApiKey() YES https://docs.kucoin.com/#create-spot-apis-for-sub-account
KuCoin\SDK\PrivateApi\Account::getSubUserApiKey() YES https://docs.kucoin.com/#get-sub-account-spot-api-list
KuCoin\SDK\PrivateApi\Account::updateSubUserApiKey() YES https://docs.kucoin.com/#modify-sub-account-spot-apis
KuCoin\SDK\PrivateApi\Account::deleteSubUserApiKey() YES https://docs.kucoin.com/#delete-sub-account-spot-apis
KuCoin\SDK\PrivateApi\Account::getSubAccountListV2() YES https://docs.kucoin.com/#get-paginated-sub-account-information
KuCoin\SDK\PrivateApi\Account::getAccountTransferable() YES https://docs.kucoin.com/#get-the-transferable
KuCoin\SDK\PrivateApi\Account::getHfLedgersV2() YES https://docs.kucoin.com/spot-hf/#account-ledger-in-high-frequency-trading-accounts
KuCoin\SDK\PrivateApi\Deposit
API Authentication Description
KuCoin\SDK\PrivateApi\Deposit::createAddress() YES https://docs.kucoin.com/#create-deposit-address
KuCoin\SDK\PrivateApi\Deposit::getAddress() YES https://docs.kucoin.com/#get-deposit-address
KuCoin\SDK\PrivateApi\Deposit::getAddresses() YES https://docs.kucoin.com/#get-deposit-addresses-v2
KuCoin\SDK\PrivateApi\Deposit::getDeposits() YES https://docs.kucoin.com/#get-deposit-list
KuCoin\SDK\PrivateApi\Deposit::getV1Deposits() YES https://docs.kucoin.com/#get-v1-historical-deposits-list
KuCoin\SDK\PrivateApi\TradeFee
API Authentication Description
KuCoin\SDK\PrivateApi\TradeFee::getBaseFee() YES https://docs.kucoin.com/#basic-user-fee
KuCoin\SDK\PrivateApi\TradeFee::getTradeFees() YES https://docs.kucoin.com/#actual-fee-rate-of-the-trading-pair
KuCoin\SDK\PrivateApi\Symbol
API Authentication Description
KuCoin\SDK\PrivateApi\Symbol::getAggregatedFullOrderBook() NO DEPRECATEDhttps://docs.kucoin.com/#get-full-order-book-aggregated
KuCoin\SDK\PrivateApi\Order
API Authentication Description
KuCoin\SDK\PrivateApi\Order::create() YES https://docs.kucoin.com/#place-a-new-order
KuCoin\SDK\PrivateApi\Order::createMulti() YES https://docs.kucoin.com/#place-bulk-orders
KuCoin\SDK\PrivateApi\Order::cancel() YES https://docs.kucoin.com/#cancel-an-order
KuCoin\SDK\PrivateApi\Order::cancelAll() YES https://docs.kucoin.com/#cancel-all-orders
KuCoin\SDK\PrivateApi\Order::getList() YES https://docs.kucoin.com/#list-orders
KuCoin\SDK\PrivateApi\Order::getV1List() YES DEPRECATEDhttps://docs.kucoin.com/#get-v1-historical-orders-list
KuCoin\SDK\PrivateApi\Order::getDetail() YES https://docs.kucoin.com/#get-an-order
KuCoin\SDK\PrivateApi\Order::getRecentList() YES https://docs.kucoin.com/#recent-orders
KuCoin\SDK\PrivateApi\Order::createMarginOrder() YES https://docs.kucoin.com/#place-a-margin-order
KuCoin\SDK\PrivateApi\Order::cancelByClientOid() YES https://docs.kucoin.com/#cancel-single-order-by-clientoid
KuCoin\SDK\PrivateApi\Order::getDetailByClientOid() YES https://docs.kucoin.com/#get-single-active-order-by-clientoid
KuCoin\SDK\PrivateApi\Order::hfCreate() YES https://docs.kucoin.com/spot-hf/#place-hf-order
KuCoin\SDK\PrivateApi\Order::hfSyncCreate() YES https://docs.kucoin.com/spot-hf/#sync-place-hf-order
KuCoin\SDK\PrivateApi\Order::hfCreateMulti() YES https://docs.kucoin.com/spot-hf/#place-multiple-hf-orders
KuCoin\SDK\PrivateApi\Order::hfSyncCreateMulti() YES https://docs.kucoin.com/spot-hf/#sync-place-multiple-hf-orders
KuCoin\SDK\PrivateApi\Order::hfModify() YES https://docs.kucoin.com/spot-hf/#modify-order
KuCoin\SDK\PrivateApi\Order::hfCancel() YES https://docs.kucoin.com/spot-hf/#cancel-orders-by-orderid
KuCoin\SDK\PrivateApi\Order::hfSyncCancel() YES https://docs.kucoin.com/spot-hf/#sync-cancel-orders-by-orderid
KuCoin\SDK\PrivateApi\Order::hfCancelByClientOid() YES https://docs.kucoin.com/spot-hf/#cancel-order-by-clientoid
KuCoin\SDK\PrivateApi\Order::hfSyncCancelByClientOid() YES https://docs.kucoin.com/spot-hf/#sync-cancel-orders-by-clientoid
KuCoin\SDK\PrivateApi\Order::hfSyncCancelSize() YES https://docs.kucoin.com/spot-hf/#cancel-specified-number-of-orders-by-orderid
KuCoin\SDK\PrivateApi\Order::hfSyncCancelAll() YES https://docs.kucoin.com/spot-hf/#cancel-all-hf-orders-by-symbol
KuCoin\SDK\PrivateApi\Order::getActiveOrderList() YES https://docs.kucoin.com/spot-hf/#obtain-list-of-active-hf-orders
KuCoin\SDK\PrivateApi\Order::getActiveSymbols() YES https://docs.kucoin.com/spot-hf/#obtain-list-of-symbol-with-active-hf-orders
KuCoin\SDK\PrivateApi\Order::getDoneOrderList() YES https://docs.kucoin.com/spot-hf/#obtain-list-of-filled-hf-orders
KuCoin\SDK\PrivateApi\Order::getHfDetail() YES https://docs.kucoin.com/spot-hf/#details-of-a-single-hf-order
KuCoin\SDK\PrivateApi\Order::getHfDetailByClientOid() YES https://docs.kucoin.com/spot-hf/#obtain-details-of-a-single-hf-order-using-clientoid
KuCoin\SDK\PrivateApi\Order::hfAutoCancel() YES https://docs.kucoin.com/spot-hf/#hf-auto-cancel-setting
KuCoin\SDK\PrivateApi\Order::getHfAutoCancel() YES https://docs.kucoin.com/spot-hf/#hf-auto-cancel-order-setting-query
KuCoin\SDK\PrivateApi\Order::getHfFills() YES https://docs.kucoin.com/spot-hf/#hf-transaction-records
KuCoin\SDK\PrivateApi\Order::hfCancelAll() YES https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/cancel-all-hf-orders
KuCoin\SDK\PrivateApi\Order::createHfMarginOrder() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/place-hf-order
KuCoin\SDK\PrivateApi\Order::cancelMarginHfOrder() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/cancel-hf-order-by-orderid
KuCoin\SDK\PrivateApi\Order::cancelMarginHfOrderByClientOid() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/cancel-hf-order-by-clientoid
KuCoin\SDK\PrivateApi\Order::cancelAllMarginHfOrder() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/cancel-all-hf-orders-by-symbol
KuCoin\SDK\PrivateApi\Order::getMarginHfActiveOrders() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/get-active-hf-orders-list
KuCoin\SDK\PrivateApi\Order::getMarginHfFilledOrders() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/get-hf-filled-list
KuCoin\SDK\PrivateApi\Order::getMarginHfDetail() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/get-hf-order-details-by-orderid
KuCoin\SDK\PrivateApi\Order::getMarginHfDetailByClientOid() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/get-hf-order-details-by-clientoid
KuCoin\SDK\PrivateApi\Order::getMarginHfFills() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/get-hf-transaction-records
KuCoin\SDK\PrivateApi\OrderTest
API Authentication Description
KuCoin\SDK\PrivateApi\Order::createTest() YES https://www.kucoin.com/docs/rest/spot-trading/orders/place-order-test
KuCoin\SDK\PrivateApi\Order::hfCreateTest() YES https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/place-hf-order-test
KuCoin\SDK\PrivateApi\Order::createMarginTestOrder() YES https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/place-hf-order-test
KuCoin\SDK\PrivateApi\OcoOrder
API Authentication Description
KuCoin\SDK\PrivateApi\OcoOrder::create() YES https://www.kucoin.com/docs/rest/spot-trading/oco-order/place-order
KuCoin\SDK\PrivateApi\OcoOrder::cancel() YES https://www.kucoin.com/docs/rest/spot-trading/oco-order/cancel-order-by-orderid
KuCoin\SDK\PrivateApi\OcoOrder::cancelByClientOid() YES https://www.kucoin.com/docs/rest/spot-trading/oco-order/cancel-order-by-clientoid
KuCoin\SDK\PrivateApi\OcoOrder::cancelMulti() YES https://www.kucoin.com/docs/rest/spot-trading/oco-order/cancel-multiple-orders
KuCoin\SDK\PrivateApi\OcoOrder::getDetail() YES https://www.kucoin.com/docs/rest/spot-trading/oco-order/get-order-info-by-orderid
KuCoin\SDK\PrivateApi\OcoOrder::getDetailByClientOid() YES https://www.kucoin.com/docs/rest/spot-trading/oco-order/get-order-info-by-clientoid
KuCoin\SDK\PrivateApi\OcoOrder::getList() YES https://www.kucoin.com/docs/rest/spot-trading/oco-order/get-order-list
KuCoin\SDK\PrivateApi\Earn
API Authentication Description
KuCoin\SDK\PrivateApi\Earn::getSavingProducts() YES https://www.kucoin.com/docs/rest/earn/kucoin-earn/get-earn-savings-products
KuCoin\SDK\PrivateApi\Earn::getPromotionProducts() YES https://www.kucoin.com/docs/rest/earn/kucoin-earn/get-earn-limited-time-promotion-products
KuCoin\SDK\PrivateApi\Earn::getStakingProducts() YES https://www.kucoin.com/docs/rest/earn/staking/get-earn-staking-products
KuCoin\SDK\PrivateApi\Earn::getEthStakingProducts() YES https://www.kucoin.com/docs/rest/earn/staking/get-earn-eth-staking-products
KuCoin\SDK\PrivateApi\Earn::getKcsStakingProducts() YES https://www.kucoin.com/docs/rest/earn/staking/get-earn-kcs-staking-products
KuCoin\SDK\PrivateApi\Earn::subscribe() YES https://www.kucoin.com/docs/rest/earn/general/subscribe-to-earn-fixed-income-products
KuCoin\SDK\PrivateApi\Earn::redeemPreview() YES https://www.kucoin.com/docs/rest/earn/general/get-earn-redeem-preview-by-holding-id
KuCoin\SDK\PrivateApi\Earn::redeem() YES https://www.kucoin.com/docs/rest/earn/general/redeem-by-earn-holding-id
KuCoin\SDK\PrivateApi\Earn::getHoldAssets() YES https://www.kucoin.com/docs/rest/earn/kucoin-earn/get-earn-fixed-income-current-holdings
KuCoin\SDK\PrivateApi\StopOrder
API Authentication Description
KuCoin\SDK\PrivateApi\StopOrder::create() YES https://docs.kucoin.com/#place-a-new-order-2
KuCoin\SDK\PrivateApi\StopOrder::cancel() YES https://docs.kucoin.com/#cancel-an-order-2
KuCoin\SDK\PrivateApi\StopOrder::cancelBatch() YES https://docs.kucoin.com/#cancel-orders
KuCoin\SDK\PrivateApi\StopOrder::getList() YES https://docs.kucoin.com/#list-stop-orders
KuCoin\SDK\PrivateApi\StopOrder::getDetail() YES https://docs.kucoin.com/#get-single-order-info
KuCoin\SDK\PrivateApi\StopOrder::getDetailByClientOid() YES https://docs.kucoin.com/#get-single-order-by-clientoid
KuCoin\SDK\PrivateApi\StopOrder::cancelByClientOid() YES https://docs.kucoin.com/#cancel-single-order-by-clientoid-2
KuCoin\SDK\PrivateApi\Fill
API Authentication Description
KuCoin\SDK\PrivateApi\Fill::getList() YES https://docs.kucoin.com/#list-fills
KuCoin\SDK\PrivateApi\Fill::getRecentList() YES https://docs.kucoin.com/#recent-fills
KuCoin\SDK\PrivateApi\WebSocketFeed
API Authentication Description
KuCoin\SDK\PrivateApi\WebSocketFeed::getPublicServer() NO https://docs.kucoin.com/#apply-connect-token
KuCoin\SDK\PrivateApi\WebSocketFeed::getPrivateServer() YES https://docs.kucoin.com/#apply-connect-token
KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePublicChannel() NO https://docs.kucoin.com/#public-channels
KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePublicChannels() NO https://docs.kucoin.com/#public-channels
KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePrivateChannel() YES https://docs.kucoin.com/#private-channels
KuCoin\SDK\PrivateApi\WebSocketFeed::subscribePrivateChannels() YES https://docs.kucoin.com/#private-channels
KuCoin\SDK\PrivateApi\Withdrawal
API Authentication Description
KuCoin\SDK\PrivateApi\Withdrawal::getQuotas() YES https://docs.kucoin.com/#get-withdrawal-quotas
KuCoin\SDK\PrivateApi\Withdrawal::getList() YES https://docs.kucoin.com/#get-withdrawals-list
KuCoin\SDK\PrivateApi\Withdrawal::getV1List() YES https://docs.kucoin.com/#get-v1-historical-withdrawals-list
KuCoin\SDK\PrivateApi\Withdrawal::apply() YES https://docs.kucoin.com/#apply-withdraw
KuCoin\SDK\PrivateApi\Withdrawal::cancel() YES https://docs.kucoin.com/#cancel-withdrawal
KuCoin\SDK\PublicApi\Currency
API Authentication Description
KuCoin\SDK\PublicApi\Currency::getList() NO https://docs.kucoin.com/#get-currencies
KuCoin\SDK\PublicApi\Currency::getDetail() NO https://docs.kucoin.com/#get-currency-detail
KuCoin\SDK\PublicApi\Currency::getPrices() NO https://docs.kucoin.com/#get-fiat-price
KuCoin\SDK\PublicApi\Currency::getV2Detail() NO https://docs.kucoin.com/#get-currency-detail-recommend
KuCoin\SDK\PublicApi\Symbol
API Authentication Description
KuCoin\SDK\PublicApi\Symbol::getList() NO DEPRECATED https://docs.kucoin.com/#get-symbols-list-deprecated
KuCoin\SDK\PublicApi\Symbol::getTicker() NO https://docs.kucoin.com/#get-ticker
KuCoin\SDK\PublicApi\Symbol::getAllTickers() NO https://docs.kucoin.com/#get-all-tickers
KuCoin\SDK\PublicApi\Symbol::getAggregatedPartOrderBook() NO https://docs.kucoin.com/#get-part-order-book-aggregated
KuCoin\SDK\PublicApi\Symbol::getTradeHistories() NO https://docs.kucoin.com/#get-trade-histories
KuCoin\SDK\PublicApi\Symbol::getKLines() NO https://docs.kucoin.com/#get-klines
KuCoin\SDK\PublicApi\Symbol::get24HStats() NO https://docs.kucoin.com/#get-24hr-stats
KuCoin\SDK\PublicApi\Symbol::getMarkets() NO https://docs.kucoin.com/#get-market-list
KuCoin\SDK\PublicApi\Symbol::getListV2() NO https://docs.kucoin.com/#get-symbols-list
KuCoin\SDK\PrivateApi\Margin
API Authentication Description
KuCoin\SDK\PrivateApi\Margin::getMarkPrice() YES https://docs.kucoin.com/#margin-info
KuCoin\SDK\PrivateApi\Margin::getConfig() YES https://docs.kucoin.com/#get-margin-configuration-info
KuCoin\SDK\PrivateApi\Margin::getAccount() YES https://docs.kucoin.com/#get-margin-account
KuCoin\SDK\PrivateApi\Margin::borrow() YES DEPRECATED https://docs.kucoin.com/#post-borrow-order
KuCoin\SDK\PrivateApi\Margin::getBorrow() YES DEPRECATED https://docs.kucoin.com/#get-borrow-order
KuCoin\SDK\PrivateApi\Margin::getOutstanding() YES DEPRECATED https://docs.kucoin.com/#get-repay-record
KuCoin\SDK\PrivateApi\Margin::getRepayRecord() YES DEPRECATED https://docs.kucoin.com/#get-repayment-record
KuCoin\SDK\PrivateApi\Margin::repayAll() YES DEPRECATED https://docs.kucoin.com/#one-click-repayment
KuCoin\SDK\PrivateApi\Margin::repaySingle() YES DEPRECATED https://docs.kucoin.com/#repay-a-single-order
KuCoin\SDK\PrivateApi\Margin::lend() YES DEPRECATED https://docs.kucoin.com/#post-lend-order
KuCoin\SDK\PrivateApi\Margin::cancelLend() YES DEPRECATED https://docs.kucoin.com/#cancel-lend-order
KuCoin\SDK\PrivateApi\Margin::setAutoLend() YES DEPRECATED https://docs.kucoin.com/#set-auto-lend
KuCoin\SDK\PrivateApi\Margin::getLendActive() YES DEPRECATED https://docs.kucoin.com/#get-active-order
KuCoin\SDK\PrivateApi\Margin::getLendDone() YES DEPRECATED https://docs.kucoin.com/#get-lent-history
KuCoin\SDK\PrivateApi\Margin::getUnsettled() YES DEPRECATED https://docs.kucoin.com/#get-active-lend-order-list
KuCoin\SDK\PrivateApi\Margin::getSettled() YES DEPRECATED https://docs.kucoin.com/#get-settled-lend-order-history
KuCoin\SDK\PrivateApi\Margin::getLendAssets() YES DEPRECATED https://docs.kucoin.com/#get-account-lend-record
KuCoin\SDK\PrivateApi\Margin::getMarket() YES DEPRECATED https://docs.kucoin.com/#lending-market-data
KuCoin\SDK\PrivateApi\Margin::getTradeLast() YES DEPRECATED https://docs.kucoin.com/#margin-trade-data
KuCoin\SDK\PrivateApi\Margin::getEtfInfo() YES https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-leveraged-token-info
KuCoin\SDK\PrivateApi\Margin::borrowV3() YES https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/margin-borrowing
KuCoin\SDK\PrivateApi\Margin::repayV3() YES https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/repayment
KuCoin\SDK\PrivateApi\Margin::getBorrowV3() YES https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/get-margin-borrowing-history
KuCoin\SDK\PrivateApi\Margin::getRepayV3() YES https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/get-repayment-history
KuCoin\SDK\PrivateApi\Margin::getInterestV3() YES https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/get-cross-isolated-margin-interest-records
KuCoin\SDK\PrivateApi\Lend
API Authentication Description
KuCoin\SDK\PrivateApi\Lend::getCurrencies() YES https://www.kucoin.com/docs/rest/margin-trading/lending-market-v3-/get-currency-information
KuCoin\SDK\PrivateApi\Lend::getMarketInterestRate() YES https://www.kucoin.com/docs/rest/margin-trading/lending-market-v3-/get-interest-rates
KuCoin\SDK\PrivateApi\Lend::purchase() YES https://www.kucoin.com/docs/rest/margin-trading/lending-market-v3-/subscription
KuCoin\SDK\PrivateApi\Lend::redeem() YES https://www.kucoin.com/docs/rest/margin-trading/lending-market-v3-/redemption
KuCoin\SDK\PrivateApi\Lend::purchaseUpdate() YES https://www.kucoin.com/docs/rest/margin-trading/lending-market-v3-/modify-subscription-orders
KuCoin\SDK\PrivateApi\Lend::getRedeemOrders() YES https://www.kucoin.com/docs/rest/margin-trading/lending-market-v3-/get-redemption-orders
KuCoin\SDK\PrivateApi\Lend::getPurchaseOrders() YES https://www.kucoin.com/docs/rest/margin-trading/lending-market-v3-/get-subscription-orders
KuCoin\SDK\PrivateApi\IsolatedMargin
API Authentication Description
KuCoin\SDK\PrivateApi\IsolatedMargin::getSymbols() YES https://docs.kucoin.com/#query-isolated-margin-trading-pair-configuration
KuCoin\SDK\PrivateApi\IsolatedMargin::getAccountList() YES https://docs.kucoin.com/#query-isolated-margin-account-info
KuCoin\SDK\PrivateApi\IsolatedMargin::getAccountDetail() YES https://docs.kucoin.com/#query-single-isolated-margin-account-info
KuCoin\SDK\PrivateApi\IsolatedMargin::borrow() YES DEPRECATED https://docs.kucoin.com/#isolated-margin-borrowing
KuCoin\SDK\PrivateApi\IsolatedMargin::getOutstanding() YES DEPRECATED https://docs.kucoin.com/#query-outstanding-repayment-records
KuCoin\SDK\PrivateApi\IsolatedMargin::getRepaid() YES DEPRECATED https://docs.kucoin.com/#query-repayment-records
KuCoin\SDK\PrivateApi\IsolatedMargin::repayAll() YES DEPRECATED https://docs.kucoin.com/#quick-repayment
KuCoin\SDK\PrivateApi\IsolatedMargin::repaySingle() YES DEPRECATED https://docs.kucoin.com/#single-repayment
KuCoin\SDK\PublicApi\Time
API Authentication Description
KuCoin\SDK\PublicApi\Time::timestamp() NO https://docs.kucoin.com/#server-time
KuCoin\SDK\PublicApi\ServiceStatus
API Authentication Description
KuCoin\SDK\PublicApi\ServiceStatus::getStatus() NO https://docs.kucoin.com/#service-status

Run tests

Modify your API key in phpunit.xml first.

# Add your API configuration items into the environmental variable first
export API_BASE_URI=https://api.kucoin.com
export API_KEY=key
export API_SECRET=secret
export API_PASSPHRASE=passphrase
export API_KEY_VERSION=2

composer test

License

MIT

kucoin-php-sdk's People

Contributors

artisan-liu avatar c2s avatar fieyum avatar hhxsv5 avatar ive20 avatar purekid avatar sh7ning avatar viaweb3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kucoin-php-sdk's Issues

SDK not recognized after installing through composer

Using Visual Studio 2019, I install the kucoin php api through composer but when running a simple server time test, I cant get it to recognize the library. Keep getting 'Uncaught Error: Class 'KuCoin\SDK\PublicApi\Time' not found in C...

Steps:

  1. New Visual Studio php project

  2. Install kucoin\kucoin-php-sdk using composer...ver 1.1.21 installs fine

  3. Run simple time test

     `<?php
     
     use KuCoin\SDK\PublicApi\Time;
     
     $api = new Time();
     $timestamp = $api->timestamp();
     var_dump($timestamp);`
    
  4. Run and get 'Uncaught Error: Class 'KuCoin\SDK\PublicApi\Time' not found in C...

When I change views and drill down, the time folder is there but the folder hierarchy is different. Are we supposed to manually change that for each file?

Using WS message in event loop

I have 3 questions here...

  1. I'm trying to figure out how to pass the message received by the WS to the event loop, see code below.
  2. Is this the right way to handle ws messages asynchronously? I notice delays with the more topics I subscribe to.
  3. My IDE is showing that React Factory is deprecated, are there plans to stop usages of it in the future?
        $loop = Factory::create();
        $loop->addPeriodicTimer(1, function($message) {
           var_dump('loop: ' . date('Y-m-d H:i:s'));
           var_dump($message);
        });
        $api->setLoop($loop);

        $api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use(&$exchange, &$interval, &$results) {
            // $loop->run();
            // print $message['data']['symbol'] . PHP_EOL;

            }
        }, function ($code, $reason) {
            echo "OnClose: {$code} {$reason}\n";
        });

React Event loop

How would I go about using the websocketfeed to get

['topic' => '/market/ticker:XHV-USDT']
['topic' => '/market/ticker:XHV-USDT'],
['topic' => '/spotMarket/tradeOrders'],
['topic' => '/account/balance']

into a single event loop, is there any example that covers having these 4 items push, having one call to the api->subscribePrivateChannels seems to block the next...

Proxy to KuCoin API

Hi,
Our codebase is behind a firewall.
This SDK is using Guzzle and the question is how can proxy these requests?

withdrawal applay error

hi

after set memo in send xrp

[API]Failure: api code is NOT 200000, POST /api/v1/withdrawals with body={"clientOid":"6139b4edd27c27.88823947","currency":"XRP","address":"rDt7d2bf2CSKzTFug2etkhbr8yQjbZtLE7","memo":"25802","amount":21.2,"isInner":false,"chain":""}, respond code=400100 message="request parameter illegal" body={"code":"400100","msg":"request parameter illegal"}

Close socket

Hi,

Using webSocket feed, is there any way to close previously opened sockets? or to check if there is already a previous connection?

Im sorry, a question section would be nice, this is not really a issue 🙄

Thanks!

Order size increment invalid

may size = 0.693

[API]Failure: api code is NOT 200000, POST /api/v1/orders with body={"clientOid":"615d681b3f8c44.66488972","side":"buy","symbol":"SOL-USDT","type":"market","size":0.6930000000000001}, respond code=400100 message="Order size increment invalid." body={"code":"400100","msg":"Order size increment invalid."}

Q: How can set the type of starting an order? (LONG or SHORT)

<?php
// ....
$order = [
    'clientOid' => uniqid(),
    'price'     => '1',
    'size'      => '1',
    'symbol'    => 'BTC-USDT',
    'type'      => 'limit',
    'side'      => 'sell',
    'remark'    => 'ORDER#' . time(),
];
try {
    $result = $api->create($order);
    var_dump($result);
} catch (\Throwable $e) {
    var_dump($e->getMessage());
}

Here, I am trying to start order with the SELL type.

Does everything correct and my code should work? or do I miss understanding something?

Does this only work in FEATURES mode? not normal mode?

Any kind of help is welcome. Thanks in advance.

Uncaught Swoole\Error: API must be called in the coroutine in

Hello,

So I've been trying to execute the order function, but I am getting this error:
PHP Fatal error: Uncaught Swoole\Error: API must be called in the coroutine in .../vendor/react/event-loop/src/StreamSelectLoop.php:290

It is weird because I can query the websocket and everything, but not when trying to run this code:

go(function () use ($priceUSDT, $amountUSDTAfterFee) {
                $auth = new Auth('**********', '****', "********", Auth::API_KEY_VERSION_V2);
                $api = new Order($auth, new SwooleHttp);

                go(function () use ($api, $priceUSDT, $amountUSDTAfterFee) {
                    try {
                        $result = $api->create([
                            'clientOid' => uniqid(),
                            'price' => $priceUSDT,
                            'size' => $amountUSDTAfterFee,
                            'symbol' => "{$this->workOnCurrency}-USDT",
                            'type' => 'market',
                            'side' => 'buy',
                        ]);
                        var_dump($result);
                    } catch (\Throwable $e) {
                        var_dump($e->getMessage());
                    }
                });
            });

I did installed the following, as mentioned in the docs:

composer require "kucoin/kucoin-php-sdk:~1.1.0"
pecl install swoole
composer require swlib/saber

Can you guys help pls

currency get detail on another chain

$detail = Kucoin::currency()->getDetail('ETH', 'KCC');

array:12 [▼ "currency" => "ETH" "name" => "ETH" "fullName" => "Ethereum" "precision" => 8 "confirms" => 1 "contractAddress" => "" "withdrawalMinSize" => "0.01" "withdrawalMinFee" => "0.004" "isWithdrawEnabled" => true "isDepositEnabled" => true "isMarginEnabled" => true "isDebitEnabled" => true ]

$detail = Kucoin::currency()->getDetail('ETH');

array:12 [▼ "currency" => "ETH" "name" => "ETH" "fullName" => "Ethereum" "precision" => 8 "confirms" => 12 "contractAddress" => "" "withdrawalMinSize" => "0.01" "withdrawalMinFee" => "0.004" "isWithdrawEnabled" => true "isDepositEnabled" => true "isMarginEnabled" => true "isDebitEnabled" => true ]

The withdrawalMinFee did not change

PHP Fatal error: Uncaught RuntimeException: Unable to set stream resource to non-blocking mode

Hi guys!
When I try to use WebSocket feed in coroutine, I get an error:

PHP Fatal error: Uncaught RuntimeException: Unable to set stream resource to non-blocking mode in .../vendor/react/stream/src/WritableResourceStream.php:35

<?php
include_once 'vendor/autoload.php';
use KuCoin\SDK\Auth;
use KuCoin\SDK\PrivateApi\WebSocketFeed;
use Ratchet\Client\WebSocket;
use React\EventLoop\LoopInterface;

Swoole\Runtime::enableCoroutine();

$api = new WebSocketFeed(null);

$query = ['connectId' => uniqid('', true)];

$channels = [
    ['topic' => '/market/ticker:ETH-BTC'],
];

go(function() use ($api, $query, $channels) {
    $api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) {
        var_dump($message);
        $loop->stop();
    }, function ($code, $reason) {});
});

My OS: Centos 7
PHP 7.1.16

WebSocket

Is there a way to add subscription without restart the call?
In the same way the createUnsubscribeMessage does.
Thanks

Order remark

"done" and "filled" order updates received via websocket feed do not contain the order remark.

Fatal error: Uncaught Error: Class 'Swoole\Runtime' not found

Unfortunately this SDK does not work :(.

I tried to run sdk order method but it gave me the below error. I have installed all the dependencies using composer. My php version is 7.1.29.

$order = [
                'clientOid' => $order_id,
                'price'     => $price,
                'size'      => $size,
                'symbol'    => $symbol,
                'type'      => $type,
                'side'      => $side,
                'remark'    => 'ORDER#' . $order_id,
            ];
 $api = new Order($auth, new SwooleHttp);
  try {
                $result = $api->create($order);
                var_dump($result);
            } catch (\Throwable $e) {
                var_dump($e->getMessage());
            }
PHP Fatal error:  Uncaught Error: Class 'Swoole\Runtime' not found in /opt/kucoin/vendor/kucoin/kucoin-php-sdk/src/Http/SwooleHttp.php:19
Stack trace:
#0 /opt/kucoin/bot.php(60): KuCoin\SDK\Http\SwooleHttp->__construct()
#1 {main}
  thrown in /opt/kucoin/vendor/kucoin/kucoin-php-sdk/src/Http/SwooleHttp.php on line 19

Compatibility issue on a 32-bit system

Hello,

I just tried implementing your basic example for getting the list of wallets (using the code of your "Account.php".

Now when I try to run it, I get this error:

string(236) "[HTTP]Failure: status code is NOT 200, GET /api/v1/accounts?type=main with body=[], respond code=400 body={"code":"400001","msg":"Please check the header of your request for KC-API-KEY, KC-API-SIGN, KC-API-TIMESTAMP, KC-API-PASSPHRASE"}"

The docs say that:

All REST requests must contain the following headers:

KC-API-KEY The api key as a string.
KC-API-SIGN The base64-encoded signature (see Signing a Message).
KC-API-TIMESTAMP A timestamp for your request.
KC-API-PASSPHRASE The passphrase you specified when creating the API key.

Does this mean, that your sdk is not working anymore, because I can't to the message signing thing?

"Order size increment invalid" when using decimals.

Hello,

So, I've been working for a while using the SDK and I noted that there is a problem when trying to use decimals. Also I noted this happens also in other of your libraries. Here is an example:

ccxt/ccxt#1846 (comment)

Also, in that thread it mentions a catalogue of valid decimal points, can you please provide it?

Thanks

Request:

{
   "clientOid":"60eb7238e742b",
   "size":"3258.921114",
   "symbol":"ADA-USDT",
   "type":"MARKET",
   "side":"sell",
   "timeInForce":"IOC"
}

Response:
{"code":"400100","msg":"Order size increment invalid."}

Class 'Kucoin\SDK\Auth' not found

I am trying api with laravel and i am getting the auth not found error. I have checked the directory and file is there. I am not sure why it is not picking up. Any help will be great.

$auth = new Auth($this->api_key, $this->api_secret, $this->passphrase, Auth::API_KEY_VERSION_V2);

many sockets issue

how can i do when i want a lots of Private Channels per user for each api?

multiple deposits

hi
in this api i can only one address for each coin like BTC
so my users in website should have unique deposit address for BTC
otherwise how can I check who has deposit?
they all have same deposit address!

Bumbing guzzle

Any change of getting support for Guzzle HTTP 7?

Laravel 8 is now requiring Guzzle 7 ("guzzlehttp/guzzle": "^7.0.1"), and that is causing a few issues with this SDK. Currently I have downgraded Guzzle in Laravel and it seems to be working, but it would be great if the SDK could get official support for it.

Issue with GuzzleHttp\Psr7\uri_for() function at WebSocketFeed

There is a problem with the GuzzleHttp library. It needs to be updated on the component! It crashes very badly!

[2021-12-22 09:36:04] production.ERROR: Call to undefined function GuzzleHttp\Psr7\uri_for() {"exception":"[object] (Error(code: 0): Call to undefined function GuzzleHttp\Psr7\uri_for() at /var/app/current/vendor/ratchet/pawl/src/Connector.php:126)
[stacktrace]
#0 /var/app/current/vendor/ratchet/pawl/src/Connector.php(38): Ratchet\Client\Connector->generateRequest('wss://ws-api.ku...', Array, Array)
#1 /var/app/current/vendor/kucoin/kucoin-php-sdk/src/PrivateApi/WebSocketFeed.php(138): Ratchet\Client\Connector->__invoke('wss://ws-api.ku...')
#2 /var/app/current/vendor/kucoin/kucoin-php-sdk/src/PrivateApi/WebSocketFeed.php(229): KuCoin\SDK\PrivateApi\WebSocketFeed->subscribeChannels(Array, Array, Object(Closure), NULL, Array)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.