Skip to content

Commit

Permalink
add borker summary test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniwebdev committed Oct 31, 2023
1 parent 7b0477e commit d18848e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/Resources/Broker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace GoAPI\IO\Resources;

class Broker {
public $code;
public $name;

public function __construct($code, $name)
{
$this->code = $code;
$this->name = $name;
}
}
46 changes: 46 additions & 0 deletions src/Resources/BrokerSummary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace GOAPI\IO\Resources;

class BrokerSummary
{
public Broker $broker;
public $code;
public $date;
public $side;
public $lot;
public $value;
public $transaction_type;
public $investor;
public $avg;
public $symbol;

public function __construct($code, $broker, $date, $side, $lot, $value, $transaction_type, $investor, $avg, $symbol)
{
$this->broker = new Broker($broker['code'], $broker['name']);
$this->code = $code;
$this->date = $date;
$this->side = $side;
$this->lot = $lot;
$this->value = $value;
$this->transaction_type = $transaction_type;
$this->investor = $investor;
$this->avg = $avg;
$this->symbol = $symbol;
}

static function fromArray($array) {

return new BrokerSummary(
$array['code'],
$array['broker'],
$array['date'],
$array['side'],
$array['lot'],
$array['value'],
$array['transaction_type'],
$array['investor'],
$array['avg'],
$array['symbol']
);
}
}
8 changes: 6 additions & 2 deletions src/Resources/StockPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StockPrice {
public $close;
public $volume;

function __construct($symbol, Company $company, $date, $open, $high, $low, $close, $volume) {
function __construct($symbol, Company|null $company, $date, $open, $high, $low, $close, $volume) {
$this->symbol = $symbol;
$this->company = $company;
$this->date = $date;
Expand All @@ -26,7 +26,11 @@ function __construct($symbol, Company $company, $date, $open, $high, $low, $clos
}

static function fromArray($array): StockPrice {
$company = Company::fromArray($array['company']);
$company = null;

if(isset($array['company'])) {
$company = Company::fromArray($array['company']);
}

return new self(
$array['symbol'],
Expand Down
14 changes: 10 additions & 4 deletions src/StockIDX.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public function getHistoricalData($symbol, $from = null, $to = null) {
if ($to) {
$params["to"] = $to;
}
return $this->makeRequest($endpoint, $params);

return (new Collection($this->makeRequest($endpoint)['data']['results']))->map(function($item) {
return \GOAPI\IO\Resources\StockPrice::fromArray($item);
});
}

public function getEIPOList() {
Expand All @@ -99,11 +102,14 @@ public function getEIPOList() {

public function getBrokerSummary($symbol, $date) {
$endpoint = "/{$symbol}/broker_summary";
$params = ["date" => $date];
return $this->makeRequest($endpoint, $params);
$params = ["date" => $date];

return (new Collection($this->makeRequest($endpoint, $params)['data']['results']))->map(function($item) {
return \GOAPI\IO\Resources\BrokerSummary::fromArray($item);
});
}

public function getStockIndicators($page = null, $date = null) {
public function getStockIndicators($page = 1, $date = null) {
$endpoint = "/indicators";
$params = [];
if ($page) {
Expand Down
21 changes: 17 additions & 4 deletions tests/StockIDXTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
$companies = $stockIDX->getCompanies();

expect($companies->count() > 0)->toBeTrue();
// expect($companies->values()[0] instanceof Company)->toBeTrue();
});

test('get stock price', function() use($client) {
Expand All @@ -31,14 +30,28 @@
$companies = $stockIDX->getStockPrices($symbols);

expect($companies->count() == count($symbols))->toBeTrue();
// expect($companies->values()[0] instanceof Company)->toBeTrue();
});

test('get stock historical price', function() use($client) {
$stockIDX = $client->createStockIDX();

$historical = $stockIDX->getHistoricalData('BBCA', from: date('Y-m-d', strtotime('-1 month')), to: date('Y-m-d'));

expect($historical instanceof \GOAPI\IO\Collection)->toBeTrue();
});

test('get stock trending', function() use($client) {
$stockIDX = $client->createStockIDX();

$results = $stockIDX->getTrendingStocks()->values();
expect($results)->toBeArray();
// expect($results[0] instanceof \GOAPI\IO\Resources\StockPriceChange)->toBeTrue();
// expect($companies->values()[0] instanceof Company)->toBeTrue();
});

test('get broker summary', function() use($client) {
$stockIDX = $client->createStockIDX();
$results = $stockIDX->getBrokerSummary('BBCA', '2023-10-30');



expect($results instanceof \GOAPI\IO\Collection)->toBeTrue();
});

0 comments on commit d18848e

Please sign in to comment.