Skip to content

Commit

Permalink
Merge pull request #103 from hhxsv5/master
Browse files Browse the repository at this point in the history
optimize tests && update sdk
  • Loading branch information
hhxsv5 authored Aug 2, 2021
2 parents 489d7a6 + f1b469b commit fddc9ae
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 48 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ go(function () {
| -------- | -------- | -------- |
| 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 |

Expand Down Expand Up @@ -273,6 +274,29 @@ go(function () {
| 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|

</details>

<details>
<summary>KuCoin\SDK\PrivateApi\StopOrder</summary>

| 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 |

</details>

<details>
<summary>KuCoin\SDK\PrivateApi\Symbol</summary>

| API | Authentication | Description |
| -------- | -------- | -------- |
| KuCoin\SDK\PrivateApi\Symbol::getAggregatedFullOrderBook() | NO | https://docs.kucoin.com/#get-full-order-book-aggregated |

</details>

Expand Down Expand Up @@ -323,8 +347,6 @@ go(function () {
| 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::getAggregatedFullOrderBook() | NO | https://docs.kucoin.com/#get-full-order-book-aggregated |
| KuCoin\SDK\PublicApi\Symbol::getAtomicFullOrderBook() | NO | https://docs.kucoin.com/#get-full-order-book-atomic |
| 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 |
Expand Down
4 changes: 2 additions & 2 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ abstract class Api
/**
* @var string SDK Version
*/
const VERSION = '1.1.21';
const VERSION = '1.1.22';

/**
* @var string SDK update date
*/
const UPDATE_DATE = '2021.03.02';
const UPDATE_DATE = '2021.08.02';

/**
* @var string
Expand Down
16 changes: 16 additions & 0 deletions src/PrivateApi/Deposit.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ public function getAddress($currency, $chain = null)
return $response->getApiData();
}

/**
* Get deposit addresses(V2)
* Get all deposit addresses for the currency you intend to deposit.
* If the returned data is empty, you may need to create a deposit address first.
* @param string $currency
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getAddresses($currency)
{
$response = $this->call(Request::METHOD_GET, '/api/v2/deposit-addresses', compact('currency'));
return $response->getApiData();
}

/**
* Get deposit list
* @param array $params
Expand Down
23 changes: 23 additions & 0 deletions src/PrivateApi/Symbol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace KuCoin\SDK\PrivateApi;

use KuCoin\SDK\Http\Request;
use KuCoin\SDK\KuCoinApi;

class Symbol extends KuCoinApi
{
/**
* Get full order book(aggregated) v3
* @param string $symbol
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getAggregatedFullOrderBook($symbol)
{
$response = $this->call(Request::METHOD_GET, '/api/v3/market/orderbook/level2', compact('symbol'));
return $response->getApiData();
}
}
7 changes: 5 additions & 2 deletions src/PublicApi/Symbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Class Symbol
* @package KuCoin\SDK\PublicApi
* @see https://docs.kucoin.com/#symbols
* @see https://docs.kucoin.com/#market-data
*/
class Symbol extends KuCoinApi
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public function getAllTickers()
*/
public function getAggregatedPartOrderBook($symbol, $depth = 20)
{
$response = $this->call(Request::METHOD_GET, '/api/v1/market/orderbook/level2_' . intval($depth), compact('symbol'));
$response = $this->call(Request::METHOD_GET, '/api/v1/market/orderbook/level2_' . (int)$depth, compact('symbol'));
return $response->getApiData();
}

Expand All @@ -75,6 +75,7 @@ public function getAggregatedPartOrderBook($symbol, $depth = 20)
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
* @deprecated Use v3 version: \KuCoin\SDK\PrivateApi\Symbol->getAggregatedFullOrderBook($symbol)
*/
public function getAggregatedFullOrderBook($symbol)
{
Expand All @@ -89,6 +90,7 @@ public function getAggregatedFullOrderBook($symbol)
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
* @deprecated
*/
public function getAtomicFullOrderBook($symbol)
{
Expand All @@ -103,6 +105,7 @@ public function getAtomicFullOrderBook($symbol)
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
* @deprecated
*/
public function getV2AtomicFullOrderBook($symbol)
{
Expand Down
5 changes: 2 additions & 3 deletions tests/AccountTest.php → tests/PrivateApi/AccountTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\ApiCode;
use KuCoin\SDK\Exceptions\BusinessException;
use KuCoin\SDK\PrivateApi\Account;

class AccountTest extends TestCase
{
protected $apiClass = Account::class;
protected $apiWithAuth = true;
protected $apiClass = Account::class;

/**
* @dataProvider apiProvider
Expand Down
31 changes: 25 additions & 6 deletions tests/DepositTest.php → tests/PrivateApi/DepositTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\Exceptions\BusinessException;
use KuCoin\SDK\PrivateApi\Deposit;

class DepositTest extends TestCase
{
protected $apiClass = Deposit::class;
protected $apiWithAuth = true;
protected $apiClass = Deposit::class;

/**
* @dataProvider apiProvider
Expand All @@ -20,6 +19,8 @@ class DepositTest extends TestCase
*/
public function testCreateAddress(Deposit $api)
{
$this->markTestSkipped();
return;
$address = $api->createAddress('BTC');
$this->assertInternalType('array', $address);
$this->assertArrayHasKey('address', $address);
Expand All @@ -36,10 +37,8 @@ public function testCreateAddress(Deposit $api)
*/
public function testGetAddress(Deposit $api)
{
$this->markTestSkipped();
return;
try {
$address = $api->getAddress('BTC');
$address = $api->getAddress('USDT');
if ($address !== null) {
$this->assertInternalType('array', $address);
$this->assertArrayHasKey('address', $address);
Expand All @@ -54,6 +53,26 @@ public function testGetAddress(Deposit $api)
}
}

/**
* @dataProvider apiProvider
* @param Deposit $api
* @return array|string
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetAddresses(Deposit $api)
{
$addresses = $api->getAddresses('USDT');
foreach ($addresses as $address) {
$this->assertInternalType('array', $address);
$this->assertArrayHasKey('address', $address);
$this->assertArrayHasKey('memo', $address);
$this->assertArrayHasKey('chain', $address);
$this->assertArrayHasKey('contractAddress', $address);
}
}

/**
* @dataProvider apiProvider
* @param Deposit $api
Expand Down
5 changes: 2 additions & 3 deletions tests/FillTest.php → tests/PrivateApi/FillTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\Fill;

class FillTest extends TestCase
{
protected $apiClass = Fill::class;
protected $apiWithAuth = true;
protected $apiClass = Fill::class;

/**
* @dataProvider apiProvider
Expand Down
5 changes: 2 additions & 3 deletions tests/MarginTest.php → tests/PrivateApi/MarginTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\Margin;

class MarginTest extends TestCase
{
protected $apiClass = Margin::class;
protected $apiWithAuth = true;
protected $apiClass = Margin::class;


/**
Expand Down
5 changes: 2 additions & 3 deletions tests/OrderTest.php → tests/PrivateApi/OrderTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\Order;

class OrderTest extends TestCase
{
protected $apiClass = Order::class;
protected $apiWithAuth = true;
protected $apiClass = Order::class;

/**
* @dataProvider apiProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\StopOrder;

class StopOrderTest extends TestCase
{
protected $apiClass = StopOrder::class;
protected $apiWithAuth = true;
protected $apiClass = StopOrder::class;

/**
* @dataProvider apiProvider
Expand Down
27 changes: 27 additions & 0 deletions tests/PrivateApi/SymbolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\Symbol;

class SymbolTest extends TestCase
{
protected $apiClass = Symbol::class;

/**
* @dataProvider apiProvider
* @param Symbol $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetAggregatedFullOrderBook(Symbol $api)
{
$data = $api->getAggregatedFullOrderBook('ETH-BTC');
$this->assertInternalType('array', $data);
$this->assertArrayHasKey('sequence', $data);
$this->assertArrayHasKey('bids', $data);
$this->assertArrayHasKey('asks', $data);
$this->assertArrayHasKey('time', $data);
}
}
8 changes: 8 additions & 0 deletions tests/PrivateApi/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace KuCoin\SDK\Tests\PrivateApi;

class TestCase extends \KuCoin\SDK\Tests\TestCase
{
protected $apiWithAuth = true;
}
5 changes: 2 additions & 3 deletions tests/TradeFeeTest.php → tests/PrivateApi/TradeFeeTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\TradeFee;

class TradeFeeTest extends TestCase
{
protected $apiClass = TradeFee::class;
protected $apiWithAuth = true;
protected $apiClass = TradeFee::class;

/**
* @dataProvider apiProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\WebSocketFeed;
use Ratchet\Client\WebSocket;
use React\EventLoop\LoopInterface;

class WebSocketFeedTest extends TestCase
{
protected $apiClass = WebSocketFeed::class;
protected $apiWithAuth = true;
protected $apiClass = WebSocketFeed::class;

/**
* @dataProvider apiProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace KuCoin\SDK\Tests;
namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\Withdrawal;

class WithdrawalTest extends TestCase
{
protected $apiClass = Withdrawal::class;
protected $apiWithAuth = true;
protected $apiClass = Withdrawal::class;

/**
* @dataProvider apiProvider
Expand Down
Loading

0 comments on commit fddc9ae

Please sign in to comment.