Skip to content

Commit

Permalink
fix for historix trades v2 mapping issue for #14
Browse files Browse the repository at this point in the history
  • Loading branch information
ersin-demirtas committed Jul 13, 2021
1 parent 9b4875d commit d311f11
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Rest/Stocks/HistoricTradesV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ protected function mapper(array $response): array
'tapeWhereTheTradeOccured' => 'z',
];

$response['ticks'] = array_map(
function ($tick) {
$response['results'] = array_map(
function ($result) {

return $tick;
return $result;
},
$response['ticks']
$response['results']
);

return $response;
Expand Down
27 changes: 27 additions & 0 deletions tests/Concerns/LoadsStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php


namespace PolygonIO\Tests\Concerns;

trait LoadsStub
{
/**
* Loads stub files, from stubs folder.
*
* @param string $filePath
*
* @return mixed
*/
public function loadStubFile(string $filePath)
{
return file_get_contents(__DIR__ . '/../stubs/' . $filePath);
}

/*
* Loads json stub files from stubs folder and parses into an array.
*/
public function loadJsonStubFile(string $filePath)
{
return json_decode($this->loadStubFile($filePath), true);
}
}
6 changes: 3 additions & 3 deletions tests/Rest/Stocks/HistoricTradesV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
namespace PolygonIO\Tests\Rest\Stocks;

use PolygonIO\Rest\Stocks\HistoricTradesV2;
use PolygonIO\Tests\Concerns\LoadsStub;
use PolygonIO\Tests\Helpers\MocksHttp;

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

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

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

$historicTradesV2->get('AAPL', '2019-2-2');
Expand Down
90 changes: 90 additions & 0 deletions tests/stubs/api/v2/ticks/stocks/trades.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"ticker": "AAPL",
"results_count": 2,
"db_latency": 11,
"success": true,
"results": [
{
"t": 1517562000016036600,
"y": 1517562000015577000,
"q": 1063,
"i": "1",
"x": 11,
"s": 100,
"c": [
12,
41
],
"p": 171.55,
"z": 3
},
{
"t": 1517562000016038100,
"y": 1517562000015577600,
"q": 1064,
"i": "2",
"x": 11,
"s": 100,
"c": [
12,
41
],
"p": 171.55,
"z": 3
}
],
"map": {
"I": {
"name": "orig_id",
"type": "string"
},
"x": {
"name": "exchange",
"type": "int"
},
"p": {
"name": "price",
"type": "float64"
},
"i": {
"name": "id",
"type": "string"
},
"e": {
"name": "correction",
"type": "int"
},
"r": {
"name": "trf_id",
"type": "int"
},
"t": {
"name": "sip_timestamp",
"type": "int64"
},
"y": {
"name": "participant_timestamp",
"type": "int64"
},
"f": {
"name": "trf_timestamp",
"type": "int64"
},
"q": {
"name": "sequence_number",
"type": "int64"
},
"c": {
"name": "conditions",
"type": "int"
},
"s": {
"name": "size",
"type": "int"
},
"z": {
"name": "tape",
"type": "int"
}
}
}

0 comments on commit d311f11

Please sign in to comment.