diff --git a/composer.json b/composer.json index 4423170..67a5c1a 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,10 @@ } }, "require-dev": { - "phpunit/phpunit": "^8.0", - "mikey179/vfsstream": "^1.6" + "phpunit/phpunit": "^10.0", + "mikey179/vfsstream": "^1.6", + "vlucas/phpdotenv": "^5.6", + "ext-json": "*" }, "extra": { "laravel": { diff --git a/src/Api/Exchange.php b/src/Api/Exchange.php index d84a935..fe531b0 100644 --- a/src/Api/Exchange.php +++ b/src/Api/Exchange.php @@ -7,6 +7,7 @@ class Exchange extends EodClient { use Actionable; + /** * url segment for exchange api * @@ -17,41 +18,74 @@ class Exchange extends EodClient /** * Set Get Exchange Symbols api * url : https://eodhistoricaldata.com/knowledgebase/list-symbols-exchange/ - * @param string $symbol - * @param array $params + * + * @param string $symbol + * @param array $params * @return Exchange */ public function symbol($symbol, $params = []) { $this->setParams($symbol, $params); + return $this; } /** * Set Multiple Tickers api * url: https://eodhistoricaldata.com/knowledgebase/multiple-tickers-download/ - * @param string $symbol - * @param array $params + * + * @param string $symbol + * @param array $params * @return Exchange */ public function multipleTicker($symbol, $params = []) { $this->urlSegment = '/eod-bulk-last-day'; $this->setParams($symbol, $params); + return $this; } - - /** + + /** * Get exchange details api * url: https://eodhistoricaldata.com/financial-apis/exchanges-api-trading-hours-and-holidays/ - * @param string $symbol - * @param array $params + * + * @param string $symbol + * @param array $params * @return Exchange */ public function details($symbol, $params = []) { $this->urlSegment = '/exchange-details'; $this->setParams($symbol, $params); + + return $this; + } + + /** + * Get the full list of supported exchanges symbols with names, codes, operating MICs, country, and currency + * url: https://eodhd.com/financial-apis/exchanges-api-list-of-tickers-and-trading-hours + */ + public function list(string $exchange, array $params = []): self + { + $this->urlSegment = '/exchange-symbol-list'; + $this->setParams($exchange, $params); + + return $this; + } + + /** + * Get the list of inactive (delisted) tickers from an exchange + * url: https://eodhd.com/financial-apis/delisted-stock-companies-data + */ + public function delisted(string $exchange, array $params = []): self + { + $this->urlSegment = '/exchange-symbol-list'; + + $params = array_merge($params, ['delisted' => 1]); + + $this->setParams($exchange, $params); + return $this; } } diff --git a/tests/ExchangeTest.php b/tests/ExchangeTest.php index c6491f3..2df4fbe 100644 --- a/tests/ExchangeTest.php +++ b/tests/ExchangeTest.php @@ -1,4 +1,6 @@ root = vfsStream::setup('storage'); - $apiToken = getenv('API_TOKEN'); + $dotenv = Dotenv::createImmutable(__DIR__ . '/..'); + $dotenv->load(); + $apiToken = $_ENV['API_TOKEN']; $this->exchange = (new Eod(new Config($apiToken)))->exchange(); } @@ -30,10 +33,9 @@ public function exchange_symbol() $content = $this->exchange->symbol('US')->json(); $data = json_decode($content, true); - $this->assertTrue(is_array($data)); - $this->assertNotEmpty($data); + $this->assertIsArray($data); - $this->assertCount(6, $data[0]); + $this->assertCount(7, $data[0]); $this->assertArrayHasKey('Code', $data[0]); $this->assertArrayHasKey('Name', $data[0]); @@ -41,6 +43,8 @@ public function exchange_symbol() $this->assertArrayHasKey('Exchange', $data[0]); $this->assertArrayHasKey('Currency', $data[0]); $this->assertArrayHasKey('Type', $data[0]); + $this->assertArrayHasKey('Isin', $data[0]); + } /** @test **/ @@ -75,14 +79,34 @@ public function save_file() $content = $this->root->getChild('test.csv')->getContent(); $this->assertNotEmpty($content); } - + /** @test **/ public function details() { $content = $this->exchange->details('US')->json(); $data = json_decode($content, true); - + $this->assertTrue(is_array($data)); $this->assertNotEmpty($data); } + + /** @test **/ + public function it_lists_exchanges() + { + $content = $this->exchange->list('LSE')->json(); + $data = json_decode($content, true); + + $this->assertIsArray($data); + $this->assertNotEmpty($data); + } + + /** @test **/ + public function it_lists_delisted_exchanges() + { + $content = $this->exchange->delisted('LSE')->json(); + $data = json_decode($content, true); + + $this->assertIsArray($data); + $this->assertNotEmpty($data); + } } diff --git a/tests/StockTest.php b/tests/StockTest.php index 63c5f01..4076765 100644 --- a/tests/StockTest.php +++ b/tests/StockTest.php @@ -2,6 +2,7 @@ use PHPUnit\Framework\TestCase; use RadicalLoop\Eod\Config; use RadicalLoop\Eod\Eod; +use Dotenv\Dotenv; class StockTest extends TestCase { @@ -10,7 +11,9 @@ class StockTest extends TestCase protected function setUp(): void { parent::setUp(); - $apiToken = getenv('API_TOKEN'); + $dotenv = Dotenv::createImmutable(__DIR__ . '/..'); + $dotenv->load(); + $apiToken = $_ENV['API_TOKEN']; $this->stock = (new Eod(new Config($apiToken)))->stock(); }