Skip to content

Commit

Permalink
Merge pull request #15 from fieyum/master
Browse files Browse the repository at this point in the history
api upgrade update
  • Loading branch information
hhxsv5 authored Jan 15, 2024
2 parents ec44ba6 + 0a57632 commit 61f72e1
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ go(function () {
| KuCoin\Futures\SDK\PrivateApi\Order::getDetail() | YES | https://docs.kucoin.com/futures/#get-details-of-a-single-order |
| KuCoin\Futures\SDK\PrivateApi\Order::getDetailByClientOid() | YES | https://docs.kucoin.com/futures/#get-details-of-a-single-order |
| KuCoin\Futures\SDK\PrivateApi\Order::getOpenOrderStatistics() | YES | https://docs.kucoin.com/futures/#active-order-value-calculation |
| KuCoin\Futures\SDK\PrivateApi\Order::cancelByClientOid() | YES | https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-order-by-clientoid|

</details>
<details>
Expand Down Expand Up @@ -311,6 +312,7 @@ go(function () {
| 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 |

</details>

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.0.22';
const VERSION = '1.0.23';

/**
* @var string SDK update date
*/
const UPDATE_DATE = '2023.07.17';
const UPDATE_DATE = '2024.01.05';

/**
* @var string
Expand Down
19 changes: 19 additions & 0 deletions src/PrivateApi/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace KuCoin\Futures\SDK\PrivateApi;

use KuCoin\Futures\SDK\Exceptions\BusinessException;
use KuCoin\Futures\SDK\Exceptions\HttpException;
use KuCoin\Futures\SDK\Exceptions\InvalidApiUriException;
use KuCoin\Futures\SDK\Http\Request;
use KuCoin\Futures\SDK\KuCoinFuturesApi;

Expand Down Expand Up @@ -164,4 +167,20 @@ public function getDetailByClientOid($clientOid)
$response = $this->call(Request::METHOD_GET, '/api/v1/orders/' . $clientOid, ['clientOid' => $clientOid]);
return $response->getApiData();
}

/**
* Cancel Order by clientOid.
*
* @param $clientOid
* @param $symbol
* @return array
* @throws BusinessException
* @throws HttpException
* @throws InvalidApiUriException
*/
public function cancelByClientOid($clientOid, $symbol)
{
$response = $this->call(Request::METHOD_DELETE, '/api/v1/orders/client-order/' . $clientOid, ['symbol' => $symbol]);
return $response->getApiData();
}
}
18 changes: 18 additions & 0 deletions src/PublicApi/Symbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,22 @@ public function getLevel2Depth100($symbol)
$response = $this->call(Request::METHOD_GET, '/api/v1/level2/depth100', ['symbol' => $symbol]);
return $response->getApiData();
}

/**
* Get Public Funding History.
*
* @param $symbol
* @param $from
* @param $to
* @return mixed|null
* @throws \KuCoin\Futures\SDK\Exceptions\BusinessException
* @throws \KuCoin\Futures\SDK\Exceptions\HttpException
* @throws \KuCoin\Futures\SDK\Exceptions\InvalidApiUriException
*/
public function getFundingRates($symbol, $from, $to)
{
$params = compact('symbol', 'from', 'to');
$response = $this->call(Request::METHOD_GET, '/api/v1/contract/funding-rates', $params);
return $response->getApiData();
}
}
29 changes: 29 additions & 0 deletions tests/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,33 @@ public function testGetDetailByClientOid(Order $api)
$this->assertArrayHasKey('updatedAt', $order);
$this->assertArrayHasKey('orderTime', $order);
}

/**
* @dataProvider apiProvider
* @param Order $api
* @throws \KuCoin\Futures\SDK\Exceptions\BusinessException
* @throws \KuCoin\Futures\SDK\Exceptions\HttpException
* @throws \KuCoin\Futures\SDK\Exceptions\InvalidApiUriException
*/
public function testCancelByClientOid($api)
{
$clientId = uniqid();
$symbol = 'DOTUSDTM';
$order = [
'clientOid' => $clientId,
'type' => 'limit',
'side' => 'buy',
'symbol' => $symbol,
'leverage' => 5,
'remark' => 'test cancel order',

'price' => 6,
'size' => 1,
];

$api->create($order);
$result = $api->cancelByClientOid($clientId, $symbol);
$this->assertInternalType('array', $result);
$this->assertArrayHasKey('clientOid', $result);
}
}
22 changes: 22 additions & 0 deletions tests/SymbolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,26 @@ public function testGetLevel2Depth100(Symbol $api)
$this->assertInternalType('array', $data['asks']);
$this->assertInternalType('array', $data['bids']);
}

/**
* @dataProvider apiProvider
* @param Symbol $api
* @return void
* @throws \KuCoin\Futures\SDK\Exceptions\BusinessException
* @throws \KuCoin\Futures\SDK\Exceptions\HttpException
* @throws \KuCoin\Futures\SDK\Exceptions\InvalidApiUriException
*/
public function testGetFundingRates(Symbol $api)
{
$from = strtotime(date('Y-m-d', time() - 86400));
$to = $from + 86400;
$data = $api->getFundingRates('ETHUSDTM', $from * 1000, $to * 1000);
$this->assertInternalType('array', $data);
foreach ($data as $item) {
$this->assertInternalType('array', $item);
$this->assertArrayHasKey('symbol', $item);
$this->assertArrayHasKey('fundingRate', $item);
$this->assertArrayHasKey('timepoint', $item);
}
}
}

0 comments on commit 61f72e1

Please sign in to comment.