Skip to content

Commit

Permalink
Merge pull request #21 from hhxsv5/master
Browse files Browse the repository at this point in the history
add Currency::getPrices()
  • Loading branch information
hhxsv5 authored Feb 21, 2019
2 parents 2d9d00a + 73b11c2 commit f4fb44a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/PublicApi/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,19 @@ public function getDetail($currency)
$response = $this->call(Request::METHOD_GET, '/api/v1/currencies/' . $currency);
return $response->getApiData();
}

/**
* Get fiat prices for currency
* @param string|null $base
* @param string|null $currencies
* @return array
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function getPrices($base = null, $currencies = null)
{
$response = $this->call(Request::METHOD_GET, '/api/v1/prices', compact('base', 'currencies'));
return $response->getApiData();
}
}
34 changes: 26 additions & 8 deletions tests/CurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ public function testGetList(Currency $api)
{
$currencies = $api->getList();
$this->assertInternalType('array', $currencies);
foreach ($currencies as $item) {
$this->assertArrayHasKey('name', $item);
$this->assertArrayHasKey('fullName', $item);
$this->assertArrayHasKey('currency', $item);
$this->assertArrayHasKey('precision', $item);
foreach ($currencies as $currency) {
$this->assertArrayHasKey('currency', $currency);
$this->assertArrayHasKey('name', $currency);
$this->assertArrayHasKey('fullName', $currency);
$this->assertArrayHasKey('precision', $currency);
$this->assertArrayHasKey('withdrawalMinSize', $currency);
$this->assertArrayHasKey('withdrawalMinFee', $currency);
$this->assertArrayHasKey('isWithdrawEnabled', $currency);
$this->assertArrayHasKey('isDepositEnabled', $currency);
}
}

Expand All @@ -46,13 +50,27 @@ public function testGetDetail(Currency $api)
{
$currency = $api->getDetail('BTC');
$this->assertInternalType('array', $currency);
$this->assertArrayHasKey('withdrawalMinFee', $currency);
$this->assertArrayHasKey('precision', $currency);
$this->assertArrayHasKey('currency', $currency);
$this->assertArrayHasKey('name', $currency);
$this->assertArrayHasKey('fullName', $currency);
$this->assertArrayHasKey('currency', $currency);
$this->assertArrayHasKey('precision', $currency);
$this->assertArrayHasKey('withdrawalMinSize', $currency);
$this->assertArrayHasKey('withdrawalMinFee', $currency);
$this->assertArrayHasKey('isWithdrawEnabled', $currency);
$this->assertArrayHasKey('isDepositEnabled', $currency);
}

/**
* @depends testNewCurrency
* @param Currency $api
* @throws \KuCoin\SDK\Exceptions\BusinessException
* @throws \KuCoin\SDK\Exceptions\HttpException
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
*/
public function testGetPrices(Currency $api)
{
$prices = $api->getPrices('USD', 'BTC,KCS');
$this->assertInternalType('array', $prices);
$this->assertNotEmpty($prices);
}
}
10 changes: 7 additions & 3 deletions tests/SymbolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function testGetTicker(Symbol $api)
$this->assertArrayHasKey('bestBidSize', $data);
$this->assertArrayHasKey('bestAsk', $data);
$this->assertArrayHasKey('bestAskSize', $data);
$this->assertArrayHasKey('time', $data);
}

/**
Expand All @@ -78,14 +79,14 @@ public function testGetAllTickers(Symbol $api)
$this->assertArrayHasKey('ticker', $data);
foreach ($data['ticker'] as $ticker) {
$this->assertArrayHasKey('symbol', $ticker);
$this->assertArrayHasKey('buy', $ticker);
$this->assertArrayHasKey('sell', $ticker);
// $this->assertArrayHasKey('buy', $ticker);
// $this->assertArrayHasKey('sell', $ticker);
// $this->assertArrayHasKey('changePrice', $ticker);
$this->assertArrayHasKey('changeRate', $ticker);
// $this->assertArrayHasKey('high', $ticker);
// $this->assertArrayHasKey('low', $ticker);
$this->assertArrayHasKey('vol', $ticker);
$this->assertArrayHasKey('last', $ticker);
// $this->assertArrayHasKey('last', $ticker);
}
}

Expand All @@ -103,6 +104,7 @@ public function testGetAggregatedPartOrderBook(Symbol $api)
$this->assertArrayHasKey('sequence', $data);
$this->assertArrayHasKey('bids', $data);
$this->assertArrayHasKey('asks', $data);
$this->assertArrayHasKey('time', $data);
}

/**
Expand All @@ -119,6 +121,7 @@ public function testGetAggregatedFullOrderBook(Symbol $api)
$this->assertArrayHasKey('sequence', $data);
$this->assertArrayHasKey('bids', $data);
$this->assertArrayHasKey('asks', $data);
$this->assertArrayHasKey('time', $data);
}

/**
Expand All @@ -135,6 +138,7 @@ public function testGetAtomicFullOrderBook(Symbol $api)
$this->assertArrayHasKey('sequence', $data);
$this->assertArrayHasKey('bids', $data);
$this->assertArrayHasKey('asks', $data);
$this->assertArrayHasKey('time', $data);
}


Expand Down

0 comments on commit f4fb44a

Please sign in to comment.