Skip to content

Commit

Permalink
Merge branch 'release/1.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ersin-demirtas committed Jul 13, 2021
2 parents d311f11 + 3b09f8f commit dd14ca3
Show file tree
Hide file tree
Showing 61 changed files with 1,721 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/Rest/Crypto/Aggregates.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Aggregates extends RestResource
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function get($tickerSymbol, $multiplier, $from, $to, $timespan = 'days', $params = [])
public function get($tickerSymbol, $multiplier, $from, $to, $timespan = 'day', $params = [])
{
return $this->_get('/v2/aggs/ticker/' . $tickerSymbol . '/range/' . $multiplier . '/' . $timespan . '/' . $from . '/' . $to, $params);
}
Expand Down
10 changes: 7 additions & 3 deletions src/Rest/Crypto/DailyOpenClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace PolygonIO\Rest\Crypto;

use PolygonIO\Rest\Common\Mappers;
use PolygonIO\Rest\RestResource;
use \PolygonIO\Rest\Common\Mappers;

/**
* Class DailyOpenClose
Expand Down Expand Up @@ -35,11 +35,15 @@ public function get($from, $to, $date): array
protected function mapper(array $response): array
{
if (array_key_exists('openTrades', $response)) {
$response['openTrades'] = array_map(Mappers::cryptoTick, $response['openTrades']);
$response['openTrades'] = array_map(function($ticker) {
return Mappers::cryptoTick($ticker);
}, $response['openTrades']);
}

if (array_key_exists('closingTrades', $response)) {
$response['closingTrades'] = array_map(Mappers::cryptoTick, $response['closingTrades']);
$response['closingTrades'] = array_map(function ($ticker) {
return Mappers::cryptoTick($ticker);
}, $response['closingTrades']);
}

return $response;
Expand Down
6 changes: 2 additions & 4 deletions src/Rest/Crypto/GroupedDaily.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ class GroupedDaily extends RestResource

/**
* @param $date
* @param string $locale
* @param string $market
* @param array $params
*
* @return array
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function get($date, $locale = 'US', $market = 'CRYPTO', $params = []): array
public function get($date, array $params = []): array
{
return $this->_get('/v2/aggs/grouped/locale/' . $locale . '/market/' . $market . '/' . $date, $params);
return $this->_get('/v2/aggs/grouped/locale/global/market/crypto/' . $date, $params);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Rest/Crypto/SnapshotGainersLosers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SnapshotGainersLosers extends RestResource
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function get($direction = 'gainers'): array
public function get(string $direction = 'gainers'): array
{
return $this->_get('/v2/snapshot/locale/global/markets/crypto/' . $direction);
}
Expand All @@ -34,7 +34,7 @@ protected function mapper(array $response): array
{
$response['tickers'] = array_map(
function ($ticker) {
return Mappers::snapshotTicker($ticker);
return Mappers::snapshotCryptoTicker($ticker);
},
$response['tickers']
);
Expand Down
10 changes: 5 additions & 5 deletions tests/Rest/Crypto/AggregatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

use PHPUnit\Framework\TestCase;
use PolygonIO\Rest\Crypto\Aggregates;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class AggregatesTest extends TestCase
{
use MocksHttp;
use LoadsStub;

public function testAggregatesCloseGetCall()
{
$requestsContainer = [];

$previousClose = new Aggregates('fake-api-key');
$previousClose->httpClient = $this->getHttpMock(
$requestsContainer, [
'results' => [],
]
$requestsContainer, $this->loadJsonStubFile('api/v2/aggs/ticker/AAPL/range/1/day/2020-10-14/2020-10-15.json')
);

$previousClose->get('AAPL', 1, '2018-2-2', '2019-2-2');
$previousClose->get('AAPL', 1, '2020-10-14', '2020-10-15');

$this->assertPath($requestsContainer, '/v2/aggs/ticker/AAPL/range/1/days/2018-2-2/2019-2-2');
$this->assertPath($requestsContainer, '/v2/aggs/ticker/AAPL/range/1/day/2020-10-14/2020-10-15');
}
}
6 changes: 5 additions & 1 deletion tests/Rest/Crypto/CryptoExchangesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
namespace PolygonIO\Tests\Rest\Crypto;

use PolygonIO\Rest\Crypto\CryptoExchanges;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class CryptoExchangesTest extends \PHPUnit\Framework\TestCase
{
use MocksHttp;
use LoadsStub;

public function testCryptoExchangesGetCall()
{
$requestsContainer = [];

$cryptoExchanges = new CryptoExchanges('fake-api-key');
$cryptoExchanges->httpClient = $this->getHttpMock($requestsContainer);
$cryptoExchanges->httpClient = $this->getHttpMock(
$requestsContainer, $this->loadJsonStubFile('api/v1/meta/crypto-exchanges.json')
);

$cryptoExchanges->get();

Expand Down
11 changes: 8 additions & 3 deletions tests/Rest/Crypto/DailyOpenCloseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
namespace PolygonIO\Tests\Rest\Crypto;

use PolygonIO\Rest\Crypto\DailyOpenClose;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class DailyOpenCloseTest extends \PHPUnit\Framework\TestCase
{
use MocksHttp;
use LoadsStub;

public function testDailyOpenCloseGetCall()
{
$requestsContainer = [];

$dailyOpenClose = new DailyOpenClose('fake-api-key');
$dailyOpenClose->httpClient = $this->getHttpMock($requestsContainer);
$dailyOpenClose->httpClient = $this->getHttpMock(
$requestsContainer,
$this->loadJsonStubFile('api/v1/open-close/crypto/BTC/USD/2020-10-14.json')
);

$dailyOpenClose->get('BTC', 'ETH', '2018-2-2');
$dailyOpenClose->get('BTC', 'USD', '2020-10-14');

$this->assertPath($requestsContainer, '/v1/open-close/crypto/BTC/ETH/2018-2-2');
$this->assertPath($requestsContainer, '/v1/open-close/crypto/BTC/USD/2020-10-14');
}
}
10 changes: 5 additions & 5 deletions tests/Rest/Crypto/GroupedDailyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
namespace PolygonIO\Tests\Rest\Crypto;

use PolygonIO\Rest\Crypto\GroupedDaily;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class GroupedDailyTest extends \PHPUnit\Framework\TestCase
{
use MocksHttp;
use LoadsStub;

public function testGroupedDailyGetCall()
{
$requestsContainer = [];

$groupedDaily = new GroupedDaily('fake-api-key');
$groupedDaily->httpClient = $this->getHttpMock(
$requestsContainer, [
'results' => [],
]
$requestsContainer, $this->loadJsonStubFile('api/v2/aggs/grouped/locale/global/market/crypto/2020-10-14.json')
);

$groupedDaily->get('2019-2-2');
$groupedDaily->get('2020-10-14');

$this->assertPath($requestsContainer, '/v2/aggs/grouped/locale/US/market/CRYPTO/2019-2-2');
$this->assertPath($requestsContainer, '/v2/aggs/grouped/locale/global/market/crypto/2020-10-14');
}
}
10 changes: 5 additions & 5 deletions tests/Rest/Crypto/HistoricCryptoTradeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
namespace PolygonIO\Tests\Rest\Crypto;

use PolygonIO\Rest\Crypto\HistoricCryptoTrade;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class HistoricCryptoTradeTest extends \PHPUnit\Framework\TestCase
{
use MocksHttp;
use LoadsStub;

public function testHistoricCryptoTradeGetCall()
{
$requestsContainer = [];

$historicCryptoTrade = new HistoricCryptoTrade('fake-api-key');
$historicCryptoTrade->httpClient = $this->getHttpMock(
$requestsContainer, [
'ticks' => [],
]
$requestsContainer, $this->loadJsonStubFile('api/v1/historic/crypto/BTC/USD/2020-10-14.json')
);

$historicCryptoTrade->get('BTC', 'ETH', '2018-2-2');
$historicCryptoTrade->get('BTC', 'USD', '2020-10-14');

$this->assertPath($requestsContainer, '/v1/historic/crypto/BTC/ETH/2018-2-2');
$this->assertPath($requestsContainer, '/v1/historic/crypto/BTC/USD/2020-10-14');
}
}
11 changes: 8 additions & 3 deletions tests/Rest/Crypto/LastTradeForCryptoPairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
namespace PolygonIO\Tests\Rest\Crypto;

use PolygonIO\Rest\Crypto\LastTradeForCryptoPair;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class LastTradeForCryptoPairTest extends \PHPUnit\Framework\TestCase
{
use MocksHttp;
use LoadsStub;

public function testLastTradeForCryptoPairGetCall()
{
$requestsContainer = [];

$lastTradeForCryptoPair = new LastTradeForCryptoPair('fake-api-key');
$lastTradeForCryptoPair->httpClient = $this->getHttpMock($requestsContainer);
$lastTradeForCryptoPair->httpClient = $this->getHttpMock(
$requestsContainer,
$this->loadJsonStubFile('api/v1/last/crypto/BTC/USD.json')
);

$lastTradeForCryptoPair->get('BTC', 'ETH');
$lastTradeForCryptoPair->get('BTC', 'USD');

$this->assertPath($requestsContainer, '/v1/last/crypto/BTC/ETH');
$this->assertPath($requestsContainer, '/v1/last/crypto/BTC/USD');
}
}
6 changes: 3 additions & 3 deletions tests/Rest/Crypto/PreviousCloseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
namespace PolygonIO\Tests\Rest\Crypto;

use PolygonIO\Rest\Crypto\PreviousClose;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class PreviousCloseTest extends \PHPUnit\Framework\TestCase
{
use MocksHttp;
use LoadsStub;

public function testPreviousCloseGetCall()
{
$requestsContainer = [];

$previousClose = new PreviousClose('fake-api-key');
$previousClose->httpClient = $this->getHttpMock(
$requestsContainer, [
'results' => [],
]
$requestsContainer, $this->loadJsonStubFile('api/v2/aggs/ticker/AAPL/prev.json')
);

$previousClose->get('AAPL');
Expand Down
7 changes: 4 additions & 3 deletions tests/Rest/Crypto/SnapshotAllTickersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
namespace PolygonIO\Tests\Rest\Crypto;

use PolygonIO\Rest\Crypto\SnapshotAllTickers;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class SnapshotAllTickersTest extends \PHPUnit\Framework\TestCase
{
use MocksHttp;
use LoadsStub;

public function testSnapshotAllTickersGetCall()
{
$requestsContainer = [];

$snapshotAllTickers = new SnapshotAllTickers('fake-api-key');
$snapshotAllTickers->httpClient = $this->getHttpMock(
$requestsContainer, [
'tickers' => [],
]
$requestsContainer,
$this->loadJsonStubFile('api/v2/snapshot/locale/global/markets/crypto/tickers.json')
);

$snapshotAllTickers->get();
Expand Down
7 changes: 4 additions & 3 deletions tests/Rest/Crypto/SnapshotGainersLosersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use PHPUnit\Framework\TestCase;
use PolygonIO\Rest\Crypto\SnapshotGainersLosers;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

class SnapshotGainersLosersTest extends TestCase
{
use MocksHttp;
use LoadsStub;

public function testSnapshotGainersLosersGetCall()
{
$requestsContainer = [];

$snapshotGainersLosers = new SnapshotGainersLosers('fake-api-key');
$snapshotGainersLosers->httpClient = $this->getHttpMock(
$requestsContainer, [
'tickers' => [],
]
$requestsContainer,
$this->loadJsonStubFile('api/v2/snapshot/locale/global/markets/crypto/gainers.json')
);

$snapshotGainersLosers->get();
Expand Down
2 changes: 1 addition & 1 deletion tests/Rest/Stocks/HistoricTradesV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testHistoricTradesV2GetCall()

$historicTradesV2 = new HistoricTradesV2('fake-api-key');
$historicTradesV2->httpClient = $this->getHttpMock(
$requestsContainer, $this->loadJsonStubFile('api/v2/ticks/stocks/trades.json')
$requestsContainer, $this->loadJsonStubFile('api/v2/ticks/stocks/AAPL/2020-10-14.json')
);

$historicTradesV2->get('AAPL', '2019-2-2');
Expand Down
13 changes: 13 additions & 0 deletions tests/stubs/api/v1/conversion/AUD/USD.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"status": "success",
"last": {
"bid": 1.3672596,
"ask": 1.3673344,
"exchange": 48,
"timestamp": 1605555313000
},
"from": "AUD",
"to": "USD",
"initialAmount": 100,
"converted": 73.14
}
34 changes: 34 additions & 0 deletions tests/stubs/api/v1/historic/crypto/BTC/USD/2020-10-14.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"day": "2020-10-14T00:00:00.000Z",
"map": {
"c": "conditions",
"p": "price",
"s": "size",
"t": "timestamp",
"x": "exchange"
},
"msLatency": 1,
"status": "success",
"symbol": "BTC-USD",
"ticks": [
{
"s": 0.00188217,
"p": 15482.89,
"x": 1,
"t": 1604880000067,
"c": [
2
]
},
{
"s": 0.00161739,
"p": 15482.11,
"x": 1,
"t": 1604880000167,
"c": [
2
]
}
],
"type": "crypto"
}
Loading

0 comments on commit dd14ca3

Please sign in to comment.