Skip to content

Commit

Permalink
Merge pull request #132 from fieyum/master
Browse files Browse the repository at this point in the history
phpsdk api upgrade update
  • Loading branch information
hhxsv5 authored Jan 15, 2024
2 parents d58b79d + 3a199e0 commit 8486124
Show file tree
Hide file tree
Showing 9 changed files with 633 additions and 164 deletions.
355 changes: 193 additions & 162 deletions README.md

Large diffs are not rendered by default.

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.28';
const VERSION = '1.1.29';

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

/**
* @var string
Expand Down
13 changes: 13 additions & 0 deletions src/PrivateApi/Margin.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,17 @@ public function getStrategyRiskLimit(string $marginModel)
$response = $this->call(Request::METHOD_GET, '/api/v1/risk/limit/strategy', ['marginModel' => $marginModel]);
return $response->getApiData();
}

/**
* This interface returns leveraged token information.
*
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getEtfInfo()
{
return $this->call(Request::METHOD_GET, '/api/v3/etf/info')->getApiData();
}
}
132 changes: 132 additions & 0 deletions src/PrivateApi/OcoOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

namespace KuCoin\SDK\PrivateApi;

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

/**
* Class OcoOrder
* @package KuCoin\SDK\PrivateApi
* @see https://www.kucoin.com/docs/rest/spot-trading/oco-order/introduction
*/
class OcoOrder extends KuCoinApi
{
/**
* Place a new order.
*
* @param array $order
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function create(array $order)
{
return $this->call(Request::METHOD_POST, '/api/v3/oco/order', $order)->getApiData();
}

/**
* Cancel Order by orderId.
*
* @param $orderId
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function cancel($orderId)
{
return $this->call(Request::METHOD_DELETE, '/api/v3/oco/order/' . $orderId)->getApiData();
}

/**
* Cancel an order by clientOid.
*
* @param $clientOid
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function cancelByClientOid($clientOid)
{
return $this->call(Request::METHOD_DELETE, '/api/v3/oco/client-order/' . $clientOid)->getApiData();
}

/**
* Cancel Multiple Orders.
*
* @param string $symbol trading pair. If not passed, the oco orders of all symbols will be canceled by default.
* @param array $orderIds Specify the order number, there can be multiple orders, separated by commas. If not passed, all oco orders will be canceled by default.
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function cancelMulti($symbol = '', array $orderIds = [])
{
return $this->call(Request::METHOD_DELETE, '/api/v3/oco/orders', [
'symbol' => $symbol,
'orderIds' => implode(',', $orderIds),
])->getApiData();
}

/**
* Get Order Info by orderId.
*
* @param $orderId
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getDetail($orderId)
{
return $this->call(Request::METHOD_GET, '/api/v3/oco/order/' . $orderId)->getApiData();
}

/**
* Get Order Detail by orderId.
*
* @param $orderId
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getOrderDetail($orderId)
{
return $this->call(Request::METHOD_GET, '/api/v3/oco/order/details/' . $orderId)->getApiData();
}

/**
* Get Order Info by clientOid.
*
* @param $clientOid
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getDetailByClientOid($clientOid)
{
return $this->call(Request::METHOD_GET, '/api/v3/oco/client-order/' . $clientOid)->getApiData();
}

/**
*
* Get Order List.
*
* @param array $params
* @param array $pagination
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getList(array $params = [], array $pagination = [])
{
return $this->call(Request::METHOD_GET, '/api/v3/oco/orders', $params + $pagination)->getApiData();
}
}
13 changes: 13 additions & 0 deletions src/PrivateApi/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,17 @@ public function getHfFills(array $params)
$response = $this->call(Request::METHOD_GET, '/api/v1/hf/fills', $params);
return $response->getApiData();
}

/**
* Cancel all HF orders.
*
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function hfCancelAll()
{
return $this->call(Request::METHOD_DELETE, '/api/v1/hf/orders/cancelAll')->getApiData();
}
}
25 changes: 25 additions & 0 deletions tests/PrivateApi/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,29 @@ public function testGetHfLedgersV2(Account $api)
$this->assertArrayHasKey('context', $item);
}
}

/**
* @dataProvider apiProvider
*
* @param Account $api
* @return void
* @throws BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testFlexTransfer(Account $api)
{
$params = [
'clientOid' => uniqid(),
'type' => 'INTERNAL',
'currency' => "USDT",
'amount' => '1',
'fromAccountType' => 'MAIN',
'toAccountType' => 'CONTRACT',
];

$data = $api->flexTransfer($params);
$this->assertInternalType('array', $data);
$this->assertArrayHasKey('orderId', $data);
}
}
21 changes: 21 additions & 0 deletions tests/PrivateApi/MarginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,25 @@ public function testGetStrategyRiskLimit(Margin $api)
$this->assertArrayHasKey('precision', $data[0]);
}
}


/**
* @dataProvider apiProvider
* @param Margin $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetEtfInfo(Margin $api)
{
$data = $api->getEtfInfo();
foreach ($data as $item) {
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('netAsset', $item);
$this->assertArrayHasKey('targetLeverage', $item);
$this->assertArrayHasKey('actualLeverage', $item);
$this->assertArrayHasKey('issuedSize', $item);
$this->assertArrayHasKey('basket', $item);
}
}
}
Loading

0 comments on commit 8486124

Please sign in to comment.