Skip to content

Commit

Permalink
Merge pull request #141 from fieyum/master
Browse files Browse the repository at this point in the history
feat: update version
  • Loading branch information
hhxsv5 authored Nov 12, 2024
2 parents e55cfe9 + d50f01d commit eedadf7
Show file tree
Hide file tree
Showing 15 changed files with 464 additions and 43 deletions.
104 changes: 63 additions & 41 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.32';
const VERSION = '1.1.33';

/**
* @var string SDK update date
*/
const UPDATE_DATE = '2024.07.04';
const UPDATE_DATE = '2024.11.12';

/**
* @var string
Expand Down
4 changes: 4 additions & 0 deletions src/Enums/AccountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ class AccountType
const MAIN = 'MAIN';

const TRADE = 'TRADE';

const MARGIN_TRADE = 'MARGIN_TRADE';

const MARGIN_ISOLATED_TRADE = 'MARGIN_ISOLATED_TRADE';
}
35 changes: 35 additions & 0 deletions src/PrivateApi/Affiliate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace KuCoin\SDK\PrivateApi;

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

/**
*
* Class Affiliate
* @package KuCoin\SDK\PrivateApi
*
* @see https://www.kucoin.com/docs/rest/affiliate/get-affiliate-user-rebate-information
*
*/
class Affiliate extends KuCoinApi
{
/**
*
* This endpoint allows getting affiliate user rebate information.
*
* @param $date
* @param $offset
* @param $maxCount
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getInviterStatistics($date, $offset = 1, $maxCount = 10)
{
$parameters = compact('date', 'offset', 'maxCount');
return $this->call(Request::METHOD_GET, '/api/v2/affiliate/inviter/statistics', $parameters)->getApiData();
}
}
35 changes: 35 additions & 0 deletions src/PrivateApi/Margin.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,39 @@ public function getInterestV3(array $params, array $pagination = [])
$response = $this->call(Request::METHOD_GET, '/api/v3/margin/interest', $params + $pagination);
return $response->getApiData();
}

/**
* This endpoint allows querying the configuration of cross margin trading pairs.
*
* @param $symbol
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getSymbolV3($symbol = '')
{
$response = $this->call(Request::METHOD_GET, '/api/v3/margin/symbols', ['symbol' => $symbol]);
return $response->getApiData();
}

/**
* This endpoint allows modifying the leverage multiplier for cross margin or isolated margin.
*
* @param $leverage
* @param $symbol
* @param $isIsolated
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function modifyLeverageMultiplierV3($leverage, $symbol = '', $isIsolated = false)
{
$response = $this->call(Request::METHOD_POST,
'/api/v3/position/update-user-leverage',
compact('leverage', 'symbol', 'isIsolated')
);
return $response->getApiData();
}
}
15 changes: 15 additions & 0 deletions src/PrivateApi/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,19 @@ public function createMarginTestOrder(array $order)
$response = $this->call(Request::METHOD_POST, '/api/v3/hf/margin/order/test', $order);
return $response->getApiData();
}

/**
* This endpoint allows users to query all trading pairs with active orders.
*
* @param $tradeType
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getMarginHfActiveSymbols($tradeType)
{
$response = $this->call(Request::METHOD_GET, '/api/v3/hf/margin/order/active/symbols', ['tradeType' => $tradeType]);
return $response->getApiData();
}
}
45 changes: 45 additions & 0 deletions src/PrivateApi/VipLend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace KuCoin\SDK\PrivateApi;

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

/**
*
* Class VipLend
* @package KuCoin\SDK\PrivateApi
*
* @see https://www.kucoin.com/docs/rest/vip-lending/introduction
*
*/
class VipLend extends KuCoinApi
{
/**
* This endpoint is only for querying accounts that are currently involved in loans.
*
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getLoan()
{
$response = $this->call(Request::METHOD_GET, '/api/v1/otc-loan/loan');
return $response->getApiData();
}

/**
* This endpoint is only for querying accounts that are currently involved in off-exchange funding and loans.
*
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getAccounts()
{
$response = $this->call(Request::METHOD_GET, '/api/v1/otc-loan/accounts');
return $response->getApiData();
}
}
27 changes: 27 additions & 0 deletions src/PublicApi/Margin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace KuCoin\SDK\PublicApi;

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

/**
* Class Margin
* @package KuCoin\SDK\PublicApi
* @see https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-all-margin-trading-pairs-mark-prices
*/
class Margin extends KuCoinApi
{
/**
* This endpoint returns the current mark prices for all margin trading pairs.
*
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getSymbolsMarkPrice()
{
return $this->call(Request::METHOD_GET, '/api/v3/mark-price/all-symbols')->getApiData();
}
}
14 changes: 14 additions & 0 deletions src/PublicApi/Symbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,18 @@ public function getListV2($market = null)
$response = $this->call(Request::METHOD_GET, '/api/v2/symbols', compact('market'));
return $response->getApiData();
}

/**
* Request via this endpoint to get detail currency pairs for trading. If you want to get the market information of the trading symbol, please use Get All Tickers.
*
* @param $symbol
* @return mixed|null
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getV2SymbolDetail($symbol)
{
return $this->call(Request::METHOD_GET, '/api/v2/symbols/' . $symbol)->getApiData();
}
}
27 changes: 27 additions & 0 deletions tests/PrivateApi/AffiliateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\Enums\AccountType;
use KuCoin\SDK\PrivateApi\Affiliate;
use KuCoin\SDK\PrivateApi\Earn;

class AffiliateTest extends TestCase
{
protected $apiClass = Affiliate::class;

/**
* @dataProvider apiProvider
*
* @param Affiliate $api
* @return void
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetInviterStatistics(Affiliate $api)
{
$statistics = $api->getInviterStatistics(date('Ymd', strtotime('-10 day')));
$this->assertInternalType('array', $statistics);
}
}
61 changes: 61 additions & 0 deletions tests/PrivateApi/MarginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,65 @@ public function testGetInterestV3(Margin $api)
$this->assertArrayHasKey('createdTime', $item);
}
}

/**
* @dataProvider apiProvider
*
* @param Margin $api
* @return void
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetSymbolV3(Margin $api)
{
$symbols = $api->getSymbolV3();
$this->assertInternalType('array', $symbols);
$this->assertArrayHasKey('items', $symbols);
$assertCallable = function ($item) {
$this->assertArrayHasKey('symbol', $item);
$this->assertArrayHasKey('name', $item);
$this->assertArrayHasKey('enableTrading', $item);
$this->assertArrayHasKey('market', $item);
$this->assertArrayHasKey('baseCurrency', $item);
$this->assertArrayHasKey('quoteCurrency', $item);
$this->assertArrayHasKey('baseIncrement', $item);
$this->assertArrayHasKey('baseMinSize', $item);
$this->assertArrayHasKey('quoteIncrement', $item);
$this->assertArrayHasKey('quoteMinSize', $item);
$this->assertArrayHasKey('baseMaxSize', $item);
$this->assertArrayHasKey('quoteMaxSize', $item);
$this->assertArrayHasKey('priceIncrement', $item);
$this->assertArrayHasKey('feeCurrency', $item);
$this->assertArrayHasKey('priceLimitRate', $item);
$this->assertArrayHasKey('minFunds', $item);
};
foreach ($symbols['items'] as $item) {
$assertCallable($item);
}

$symbol = $symbols['items'][0]['symbol'];
$singleSymbol = $api->getSymbolV3($symbol);
foreach ($singleSymbol['items'] as $item) {
$assertCallable($item);
}
}

/**
* @dataProvider apiProvider
*
* @param Margin $api
* @return void
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testModifyLeverageMultiplierV3(Margin $api)
{
$symbol = $api->getSymbolV3()['items'][0]['symbol'];
$result = $api->modifyLeverageMultiplierV3(2, $symbol, true);
$this->assertNull($result);
$api->modifyLeverageMultiplierV3(3);
$this->assertNull($result);
}
}
20 changes: 20 additions & 0 deletions tests/PrivateApi/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\Enums\AccountType;
use KuCoin\SDK\PrivateApi\Order;
use KuCoin\SDK\PublicApi\Symbol;

Expand Down Expand Up @@ -1347,4 +1348,23 @@ public function testMarginHfCreate(Order $api)
$this->assertInternalType('array', $data);
$this->assertArrayHasKey('orderId', $data);
}

/**
* @dataProvider apiProvider
*
* @param Order $api
* @return void
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetMarginHfActiveSymbols(Order $api)
{
$activeIsolatedSymbols = $api->getMarginHfActiveSymbols(AccountType::MARGIN_ISOLATED_TRADE);
$this->assertArrayHasKey('symbolSize', $activeIsolatedSymbols);
$this->assertArrayHasKey('symbols', $activeIsolatedSymbols);
$activeSymbols = $api->getMarginHfActiveSymbols(AccountType::MARGIN_TRADE);
$this->assertArrayHasKey('symbolSize', $activeSymbols);
$this->assertArrayHasKey('symbols', $activeSymbols);
}
}
53 changes: 53 additions & 0 deletions tests/PrivateApi/VipLendTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace KuCoin\SDK\Tests\PrivateApi;

use KuCoin\SDK\PrivateApi\VipLend;

class VipLendTest extends TestCase
{
protected $apiClass = VipLend::class;

/**
* @dataProvider apiProvider
*
* @param VipLend $api
* @return void
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetLoan(VipLend $api)
{
$result = $api->getLoan();
$this->assertInternalType('array', $result);
$this->assertArrayHasKey('orders', $result);
$this->assertArrayHasKey('ltv', $result);
$this->assertArrayHasKey('totalMarginAmount', $result);
$this->assertArrayHasKey('transferMarginAmount', $result);
$this->assertArrayHasKey('margins', $result);
}

/**
* @dataProvider apiProvider
*
* @param VipLend $api
* @return void
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetAccounts(VipLend $api)
{
$result = $api->getAccounts();
$this->assertInternalType('array', $result);
foreach ($result as $item) {
$this->assertArrayHasKey('uid', $item);
$this->assertArrayHasKey('marginCcy', $item);
$this->assertArrayHasKey('marginQty', $item);
$this->assertArrayHasKey('marginFactor', $item);
$this->assertArrayHasKey('accountType', $item);
$this->assertArrayHasKey('isParent', $item);
}
}
}
Loading

0 comments on commit eedadf7

Please sign in to comment.