kucoin/kucoin-futures-php-sdk
Composer 安装命令:
composer require kucoin/kucoin-futures-php-sdk
包简介
PHP SDK for KuCoin Futures API
README 文档
README
The detailed document https://docs.kucoin.com/futures/, in order to receive the latest API change notifications, please
Watchthis repository.
Requirements
| Dependency | Requirement |
|---|---|
| PHP | >=5.5.0 Recommend PHP7+ |
| guzzlehttp/guzzle | ^6.0|^7.0 |
Install
Install package via Composer.
composer require "kucoin/kucoin-futures-php-sdk:~1.0.0"
Usage
Choose environment
| Environment | BaseUri |
|---|---|
| Production | https://api-futures.kucoin.com(DEFAULT) |
use KuCoin\Futures\SDK\KuCoinFuturesApi; // Switch to the sandbox environment KuCoinFuturesApi::setBaseUri('https://api-sandbox-futures.kucoin.com');
Debug mode & logging
use KuCoin\Futures\SDK\KuCoinFuturesApi; // Debug mode will record the logs of API and WebSocket to files in the directory "KuCoinFuturesApi::getLogPath()" according to the minimum log level "KuCoinFuturesApi::getLogLevel()". KuCoinFuturesApi::setDebugMode(true); // Logging in your code // KuCoinFuturesApi::setLogPath('/tmp'); // KuCoinFuturesApi::setLogLevel(Monolog\Logger::DEBUG); KuCoinFuturesApi::getLogger()->debug("I'm a debug message");
Examples
See the test case for more examples.
Example of API without authentication
use KuCoin\Futures\SDK\PublicApi\Time; $api = new Time(); $timestamp = $api->timestamp(); var_dump($timestamp);
Example of API with authentication
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
use KuCoin\Futures\SDK\Auth; use KuCoin\Futures\SDK\PrivateApi\Account; use KuCoin\Futures\SDK\Exceptions\HttpException; use KuCoin\Futures\SDK\Exceptions\BusinessException; // 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->getOverview(); var_dump($result); } catch (HttpException $e) { var_dump($e->getMessage()); } catch (BusinessException $e) { var_dump($e->getMessage()); }
Example of WebSocket feed
use KuCoin\Futures\SDK\Auth; use KuCoin\Futures\SDK\KuCoinFuturesApi; use KuCoin\Futures\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 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 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('/contractMarket/ticker:ETHUSDTM'))); // Unsubscribe the channel // $ws->send(json_encode($api->createUnsubscribeMessage('/contractMarket/ticker:XBTUSDM'))); // Stop loop // $loop->stop(); }, function ($code, $reason) { echo "OnClose: {$code} {$reason}\n"; });
⚡️Coroutine HTTP client for asynchronous IO
See the benchmark, almost
20xfaster thancurl.
pecl install swoole composer require swlib/saber
use KuCoin\Futures\SDK\Auth; use KuCoin\Futures\SDK\Http\SwooleHttp; use KuCoin\Futures\SDK\KuCoinFuturesApi; use KuCoin\Futures\SDK\PrivateApi\Order; use KuCoin\Futures\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\Futures\SDK\PrivateApi\Account
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PrivateApi\Account::getOverview() | YES | https://docs.kucoin.com/futures/#account |
| KuCoin\Futures\SDK\PrivateApi\Account::getTransactionHistory() | YES | https://docs.kucoin.com/futures/#get-transaction-history |
| KuCoin\Futures\SDK\PrivateApi\Account::transferIn() | YES | deprecated |
| KuCoin\Futures\SDK\PrivateApi\Account::transferOut() | YES | deprecated https://docs.kucoin.com/futures/#transfer-funds-to-kucoin-main-account |
| KuCoin\Futures\SDK\PrivateApi\Account::transferOutV2() | YES | https://docs.kucoin.com/futures/#transfer-funds-to-kucoin-main-account-2 |
| KuCoin\Futures\SDK\PrivateApi\Account::cancelTransferOut() | YES | deprecated https://docs.kucoin.com/futures/#cancel-transfer-out-request |
| KuCoin\Futures\SDK\PrivateApi\Account::getTransferList() | YES | https://docs.kucoin.com/futures/#get-transfer-out-request-records |
| KuCoin\Futures\SDK\PrivateApi\Account::getSubApikey() | YES | https://docs.kucoin.com/futures/#get-sub-account-futures-api-list |
| KuCoin\Futures\SDK\PrivateApi\Account::createSubApikey() | YES | https://docs.kucoin.com/futures/#create-futures-apis-for-sub-account |
| KuCoin\Futures\SDK\PrivateApi\Account::modifySubApikey() | YES | https://docs.kucoin.com/futures/#modify-sub-account-futures-apis |
| KuCoin\Futures\SDK\PrivateApi\Account::deleteSubApikey() | YES | https://docs.kucoin.com/futures/#delete-sub-account-futures-apis |
| KuCoin\Futures\SDK\PrivateApi\Account::transferOutV3() | YES | https://docs.kucoin.com/futures/#transfer-to-main-or-trade-account |
KuCoin\Futures\SDK\PrivateApi\Deposit
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PrivateApi\Deposit::getAddress() | YES | https://docs.kucoin.com/futures/#get-deposit-address |
| KuCoin\Futures\SDK\PrivateApi\Deposit::getDeposits() | YES | https://docs.kucoin.com/futures/#get-deposit-list |
KuCoin\Futures\SDK\PrivateApi\Fill
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PrivateApi\Fill::getFills() | YES | https://docs.kucoin.com/futures/#get-fills |
| KuCoin\Futures\SDK\PrivateApi\Fill::getRecentList() | YES | https://docs.kucoin.com/futures/#recent-fills |
KuCoin\Futures\SDK\PrivateApi\Fee
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PrivateApi\Fee::getTradeFees() | YES | https://www.kucoin.com/docs/rest/funding/trade-fee/trading-pair-actual-fee-futures |
KuCoin\Futures\SDK\PrivateApi\Order
KuCoin\Futures\SDK\PrivateApi\Position
KuCoin\Futures\SDK\PrivateApi\WebSocketFeed
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PrivateApi\WebSocketFeed::getPublicServer() | NO | https://docs.kucoin.com/futures/#apply-connect-token |
| KuCoin\Futures\SDK\PrivateApi\WebSocketFeed::getPrivateServer() | YES | https://docs.kucoin.com/futures/#apply-connect-token |
| KuCoin\Futures\SDK\PrivateApi\WebSocketFeed::subscribePublicChannel() | NO | https://docs.kucoin.com/futures/#public-channels |
| KuCoin\Futures\SDK\PrivateApi\WebSocketFeed::subscribePublicChannels() | NO | https://docs.kucoin.com/futures/#public-channels |
| KuCoin\Futures\SDK\PrivateApi\WebSocketFeed::subscribePrivateChannel() | YES | https://docs.kucoin.com/futures/#private-channels |
| KuCoin\Futures\SDK\PrivateApi\WebSocketFeed::subscribePrivateChannels() | YES | https://docs.kucoin.com/futures/#private-channels |
KuCoin\Futures\SDK\PrivateApi\Withdrawal
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PrivateApi\Withdrawal::getQuotas() | YES | https://docs.kucoin.com/futures/#get-withdrawal-limit |
| KuCoin\Futures\SDK\PrivateApi\Withdrawal::getList() | YES | https://docs.kucoin.com/futures/#get-withdrawal-list |
| KuCoin\Futures\SDK\PrivateApi\Withdrawal::apply() | YES | https://docs.kucoin.com/futures/#withdraw-funds |
| KuCoin\Futures\SDK\PrivateApi\Withdrawal::cancel() | YES | https://docs.kucoin.com/futures/#cancel-withdrawal |
KuCoin\Futures\SDK\PrivateApi\RiskLimitLevel
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PrivateApi\RiskLimitLevel::getRiskLimitLevel | YES | https://docs.kucoin.com/futures/#obtain-futures-risk-limit-level |
| KuCoin\Futures\SDK\PrivateApi\RiskLimitLevel::changeRiskLimitLevel() | YES | https://docs.kucoin.com/futures/#adjust-risk-limit-level |
KuCoin\Futures\SDK\PublicApi\Symbol
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PublicApi\Symbol::getTicker() | NO | https://docs.kucoin.com/futures/#get-ticker |
| KuCoin\Futures\SDK\PublicApi\Symbol::getLevel2Snapshot() | NO | https://docs.kucoin.com/futures/#get-full-order-book-level-2 |
| KuCoin\Futures\SDK\PublicApi\Symbol::getLevel3Snapshot() | NO | https://docs.kucoin.com/futures/#get-full-order-book-level-3 |
| KuCoin\Futures\SDK\PublicApi\Symbol::getV2Level3Snapshot() | NO | https://docs.kucoin.com/futures/#get-full-order-book-level-3-v2 |
| KuCoin\Futures\SDK\PublicApi\Symbol::getLevel2Message() | NO | deprecated https://docs.kucoin.com/futures/##level-2-pulling-messages |
| KuCoin\Futures\SDK\PublicApi\Symbol::getLevel3Message() | NO | deprecated https://docs.kucoin.com/futures/##level-3-pulling-messages |
| KuCoin\Futures\SDK\PublicApi\Symbol::getTradeHistory() | NO | https://docs.kucoin.com/futures/#get-trade-histories |
| KuCoin\Futures\SDK\PublicApi\Symbol::getKLines() | NO | https://docs.kucoin.com/futures/?lang=en_US#get-k-line-data-of-contract |
| KuCoin\Futures\SDK\PublicApi\Symbol::getLevel2Depth20 | NO | https://docs.kucoin.com/futures/cn/#level-2-2 |
| KuCoin\Futures\SDK\PublicApi\Symbol::getLevel2Depth100 | NO | https://docs.kucoin.com/futures/cn/#level-2-2 |
| KuCoin\Futures\SDK\PublicApi\Symbol::getFundingRates | NO | https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-public-funding-history |
KuCoin\Futures\SDK\PublicApi\Contract
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PublicApi\Contract::getList() | NO | https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbols-list |
| KuCoin\Futures\SDK\PublicApi\Contract::getDetail() | NO | https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbol-detail |
| KuCoin\Futures\SDK\PublicApi\Contract::getAllTickers() | NO | https://www.kucoin.com/docs/rest/futures-trading/market-data/get-latest-ticker-for-all-contracts |
KuCoin\Futures\SDK\PublicApi\Time
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PublicApi\Time::timestamp() | NO | https://docs.kucoin.com/futures/#server-time |
KuCoin\Futures\SDK\PublicApi\Status
| API | Authentication | Description |
|---|---|---|
| KuCoin\Futures\SDK\PublicApi\Status::status() | NO | https://docs.kucoin.com/futures/#get-the-service-status |
Run tests
Modify your API key in
phpunit.xmlfirst.
# Add your API configuration items into the environmental variable first export API_BASE_URI=https://api-futures.kucoin.com export API_KEY=key export API_SECRET=secret export API_PASSPHRASE=passphrase export API_KEY_VERSION=2 export API_DEBUG_MODE=1 composer test
License
kucoin/kucoin-futures-php-sdk 适用场景与选型建议
kucoin/kucoin-futures-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.88k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2021 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sdk」 「futures」 「kucoin」 「kumex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kucoin/kucoin-futures-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kucoin/kucoin-futures-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kucoin/kucoin-futures-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A client for Barchart OnDemand market data.
A PSR-7 compatible library for making CRUD API endpoints
Simple Kraken Futures API Wrapper, written in PHP. Includes the basics and assumes you know your way around.
PHP SDK for DXtrade's Administrative and Trading REST API endpoints
A lightweight plain-PHP framework for database-backed CRUD APIs.
Modern, strongly-typed, PSR-compliant PHP client for the WeFact v2 API.
统计信息
- 总下载量: 1.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-08