Skip to content

Commit

Permalink
Merge pull request #18 from minasm/master
Browse files Browse the repository at this point in the history
Extend Exchanges API to use Symbol List and Delisted Symbols List
  • Loading branch information
radicalloop authored Sep 2, 2024
2 parents 3af5d69 + 9bc0dfd commit 5060a42
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 19 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
50 changes: 42 additions & 8 deletions src/Api/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Exchange extends EodClient
{
use Actionable;

/**
* url segment for exchange api
*
Expand All @@ -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;
}
}
40 changes: 32 additions & 8 deletions tests/ExchangeTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use Dotenv\Dotenv;
use PHPUnit\Framework\TestCase;
use RadicalLoop\Eod\Config;
use RadicalLoop\Eod\Eod;
Expand All @@ -7,13 +9,14 @@
class ExchangeTest extends TestCase
{
protected $exchange; //comment
private $root;


protected function setUp(): void
{
parent::setUp();
$this->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();
}

Expand All @@ -30,17 +33,18 @@ 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]);
$this->assertArrayHasKey('Country', $data[0]);
$this->assertArrayHasKey('Exchange', $data[0]);
$this->assertArrayHasKey('Currency', $data[0]);
$this->assertArrayHasKey('Type', $data[0]);
$this->assertArrayHasKey('Isin', $data[0]);

}

/** @test **/
Expand Down Expand Up @@ -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);
}
}
5 changes: 4 additions & 1 deletion tests/StockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use PHPUnit\Framework\TestCase;
use RadicalLoop\Eod\Config;
use RadicalLoop\Eod\Eod;
use Dotenv\Dotenv;

class StockTest extends TestCase
{
Expand All @@ -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();
}

Expand Down

0 comments on commit 5060a42

Please sign in to comment.