Skip to content

Commit d45cc74

Browse files
authored
Merge pull request #9 from MarketDataApp/fix-enum-values
Fix enum values
2 parents a063921 + 1e4d83b commit d45cc74

3 files changed

Lines changed: 60 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## v0.4.4-beta
4+
5+
Update options->option_chain to use enum values rather than the enum itself.
6+
7+
## v0.4.3-beta
8+
9+
Small bug fixes found from initial beta test
10+
11+
- Typo fixed Range::OUT_THE_MONEY > Range::OUT_OF_THE_MONEY
12+
- Corrected stocks->quotes() endpoint url
13+
- Changes OptionChain response to group strikes under expiration date
14+
315
## v0.4.2-beta
416

517
This library is now in **beta**. Feel free to try it out and report any bugs you find back here.

src/Endpoints/Options.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function option_chain(
227227
): OptionChains {
228228
return new OptionChains($this->client->execute(self::BASE_URL . "chain/$symbol", [
229229
'date' => $date,
230-
'expiration' => $expiration,
230+
'expiration' => $expiration instanceof Expiration ? $expiration->value : $expiration,
231231
'from' => $from,
232232
'to' => $to,
233233
'month' => $month,
@@ -238,8 +238,8 @@ public function option_chain(
238238
'nonstandard' => $non_standard,
239239
'dte' => $dte,
240240
'delta' => $delta,
241-
'side' => $side,
242-
'range' => $range,
241+
'side' => $side instanceof Side ? $side->value : $side,
242+
'range' => $range instanceof Range ? $range->value : $range,
243243
'strike' => $strike,
244244
'strikeLimit' => $strike_limit,
245245
'minBid' => $min_bid,

tests/Integration/OptionsTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use MarketDataApp\Endpoints\Responses\Options\Quote;
1212
use MarketDataApp\Endpoints\Responses\Options\Quotes;
1313
use MarketDataApp\Endpoints\Responses\Options\Strikes;
14+
use MarketDataApp\Enums\Expiration;
1415
use MarketDataApp\Enums\Side;
1516
use PHPUnit\Framework\TestCase;
1617

@@ -107,6 +108,50 @@ public function testOptionChain_success()
107108
$option_chain = array_pop($response->option_chains);
108109
$this->assertNotEmpty($option_chain);
109110

111+
// Verify each item in the response is an object of the correct type and has the correct values.
112+
$option_strike = array_pop($option_chain);
113+
$this->assertInstanceOf(OptionChainStrike::class, $option_strike);
114+
$this->assertEquals('string', gettype($option_strike->option_symbol));
115+
$this->assertEquals('string', gettype($option_strike->underlying));
116+
$this->assertInstanceOf(Carbon::class, $option_strike->expiration);
117+
$this->assertInstanceOf(Side::class, $option_strike->side);
118+
$this->assertEquals('double', gettype($option_strike->strike));
119+
$this->assertInstanceOf(Carbon::class, $option_strike->first_traded);
120+
$this->assertEquals('integer', gettype($option_strike->dte));
121+
$this->assertInstanceOf(Carbon::class, $option_strike->updated);
122+
$this->assertEquals('double', gettype($option_strike->bid));
123+
$this->assertEquals('integer', gettype($option_strike->bid_size));
124+
$this->assertEquals('double', gettype($option_strike->mid));
125+
$this->assertEquals('double', gettype($option_strike->ask));
126+
$this->assertEquals('integer', gettype($option_strike->ask_size));
127+
$this->assertTrue(in_array(gettype($option_strike->last), ['double', 'NULL']));
128+
$this->assertEquals('integer', gettype($option_strike->open_interest));
129+
$this->assertEquals('integer', gettype($option_strike->volume));
130+
$this->assertEquals('boolean', gettype($option_strike->in_the_money));
131+
$this->assertEquals('double', gettype($option_strike->intrinsic_value));
132+
$this->assertEquals('double', gettype($option_strike->extrinsic_value));
133+
$this->assertEquals('double', gettype($option_strike->implied_volatility));
134+
$this->assertTrue(in_array(gettype($option_strike->delta), ['double', 'NULL']));
135+
$this->assertEquals('double', gettype($option_strike->gamma));
136+
$this->assertEquals('double', gettype($option_strike->theta));
137+
$this->assertEquals('double', gettype($option_strike->vega));
138+
$this->assertEquals('double', gettype($option_strike->rho));
139+
$this->assertEquals('double', gettype($option_strike->underlying_price));
140+
}
141+
public function testOptionChain_expirationEnum_success()
142+
{
143+
$response = $this->client->options->option_chain(
144+
symbol: 'AAPL',
145+
expiration: Expiration::ALL,
146+
side: Side::CALL,
147+
);
148+
149+
// Verify that the response is an object of the correct type.
150+
$this->assertInstanceOf(OptionChains::class, $response);
151+
$this->assertNotEmpty($response->option_chains);
152+
$option_chain = array_pop($response->option_chains);
153+
$this->assertNotEmpty($option_chain);
154+
110155
// Verify each item in the response is an object of the correct type and has the correct values.
111156
$option_strike = array_pop($option_chain);
112157
$this->assertInstanceOf(OptionChainStrike::class, $option_strike);

0 commit comments

Comments
 (0)