Skip to content

Commit 38676c8

Browse files
committed
Add remaining endpoint Options>quotes and update Read.me and CHANGELOG
1 parent bb0826c commit 38676c8

8 files changed

Lines changed: 371 additions & 77 deletions

File tree

CHANGELOG.md

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

3+
## v0.4.0-alpha
4+
5+
- Completed remaining endpoints:
6+
- Options
7+
- expirations
8+
- lookup
9+
- strikes
10+
- option_chain
11+
- quotes
12+
- Utilities
13+
- api_status
14+
- headers
15+
- Mutual Funds
16+
- candles
17+
- Markets
18+
- status
19+
320
## v0.3.0-alpha
421

522
- Completed Stocks endpoints: earnings, news.

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,19 @@ $candles = $client->mutual_funds->candles(
5252
);
5353

5454
// Options
55-
$expirations = $client->options->expirations();
56-
$lookup = $client->options->lookup()
57-
$strikes = $client->options->strikes();
55+
$expirations = $client->options->expirations('AAPL');
56+
$lookup = $client->options->lookup('AAPL 7/28/23 $200 Call');
57+
$strikes = $client->options->strikes(
58+
symbol: 'AAPL',
59+
expiration: Carbon::parse('2023-01-20'),
60+
date: Carbon::parse('2023-01-03'),
61+
);
5862
$option_chain = $client->options->option_chain(
5963
symbol: 'AAPL',
6064
expiration: Carbon::parse('2025-01-17'),
6165
side: Side::CALL,
6266
);
63-
$quotes = $client->options->quotes();
67+
$quotes = $client->options->quotes('AAPL250117C00150000');
6468

6569
// Utilities
6670
$status = $client->utilities->api_status();

src/Endpoints/Options.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ public function __construct($client)
4444
public function expirations(string $symbol, int $strike = null, Carbon $date = null): Expirations
4545
{
4646
// Stub
47-
return new Expirations($this->client->execute(self::BASE_URL . "options/expirations/$symbol", [
48-
'date' => $date,
49-
'strike' => $strike,
50-
]));
47+
return new Expirations($this->client->execute(self::BASE_URL . "options/expirations/$symbol",
48+
compact('strike', 'date')));
5149
}
5250

5351
/**
@@ -85,10 +83,8 @@ public function lookup(string $input): Lookup
8583
public function strikes(string $symbol, Carbon $expiration = null, Carbon $date = null): Strikes
8684
{
8785
// Stub
88-
return new Strikes($this->client->execute(self::BASE_URL . "options/strikes/$symbol", [
89-
'expiration' => $expiration,
90-
'date' => $date,
91-
]));
86+
return new Strikes($this->client->execute(self::BASE_URL . "options/strikes/$symbol",
87+
compact('expiration', 'date')));
9288
}
9389

9490
/**
@@ -259,9 +255,30 @@ public function option_chain(
259255
]));
260256
}
261257

262-
public function quotes(): Quotes
258+
/**
259+
* Get a current or historical end of day quote for a single options contract.
260+
*
261+
* @param string $option_symbol The option symbol (as defined by the OCC) for the option you wish to lookup. Use the
262+
* current OCC option symbol format, even for historic options that quoted before the format change in 2010.
263+
*
264+
* @param Carbon|null $date Use to lookup a historical end of day quote from a specific trading day. If no date is
265+
* specified the quote will be the most current price available during market hours. When the market is closed the
266+
* quote will be from the last trading day.
267+
*
268+
* @param Carbon|null $from Use to lookup a series of end of day quotes. From is the oldest (leftmost) date to
269+
* return (inclusive). If from/to is not specified the quote will be the most current price available during market
270+
* hours. When the market is closed the quote will be from the last trading day.
271+
*
272+
* @param Carbon|null $to Use to lookup a series of end of day quotes. From is the newest (rightmost) date to return
273+
* (exclusive). If from/to is not specified the quote will be the most current price available during market hours.
274+
* When the market is closed the quote will be from the last trading day.
275+
*
276+
* @throws ApiException|GuzzleException
277+
*/
278+
public function quotes(string $option_symbol, Carbon $date = null, Carbon $from = null, Carbon $to = null): Quotes
263279
{
264280
// Stub
265-
return new Quotes();
281+
return new Quotes($this->client->execute(self::BASE_URL . "options/quotes/$option_symbol/",
282+
compact('date', 'from', 'to')));
266283
}
267284
}

src/Endpoints/Responses/Options/OptionChain.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class OptionChain
99
{
1010

1111
// The option symbol according to OCC symbology.
12-
public string $symbol;
12+
public string $option_symbol;
1313

1414
// The ticker symbol of the underlying security.
1515
public string $underlying;
@@ -87,7 +87,7 @@ class OptionChain
8787
public Carbon $updated;
8888

8989
public function __construct(
90-
string $symbol,
90+
string $option_symbol,
9191
string $underlying,
9292
Carbon $expiration,
9393
Side $side,
@@ -114,7 +114,7 @@ public function __construct(
114114
float $rho,
115115
Carbon $updated,
116116
) {
117-
$this->symbol = $symbol;
117+
$this->option_symbol = $option_symbol;
118118
$this->underlying = $underlying;
119119
$this->expiration = $expiration;
120120
$this->side = $side;

src/Endpoints/Responses/Options/OptionChains.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@ public function __construct(object $response)
2929
case 'ok':
3030
for ($i = 0; $i < count($response->optionSymbol); $i++) {
3131
$this->option_chains[] = new OptionChain(
32-
$response->optionSymbol[$i],
33-
$response->underlying[$i],
34-
Carbon::parse($response->expiration[$i]),
35-
Side::from($response->side[$i]),
36-
$response->strike[$i],
37-
Carbon::parse($response->firstTraded[$i]),
38-
$response->dte[$i],
39-
$response->ask[$i],
40-
$response->askSize[$i],
41-
$response->bid[$i],
42-
$response->bidSize[$i],
43-
$response->mid[$i],
44-
$response->last[$i],
45-
$response->volume[$i],
46-
$response->openInterest[$i],
47-
$response->underlyingPrice[$i],
48-
$response->inTheMoney[$i],
49-
$response->intrinsicValue[$i],
50-
$response->extrinsicValue[$i],
51-
$response->iv[$i],
52-
$response->delta[$i],
53-
$response->gamma[$i],
54-
$response->theta[$i],
55-
$response->vega[$i],
56-
$response->rho[$i],
57-
Carbon::parse($response->updated[$i]),
32+
option_symbol: $response->optionSymbol[$i],
33+
underlying: $response->underlying[$i],
34+
expiration: Carbon::parse($response->expiration[$i]),
35+
side: Side::from($response->side[$i]),
36+
strike: $response->strike[$i],
37+
first_traded: Carbon::parse($response->firstTraded[$i]),
38+
dte: $response->dte[$i],
39+
ask: $response->ask[$i],
40+
ask_size: $response->askSize[$i],
41+
bid: $response->bid[$i],
42+
bid_size: $response->bidSize[$i],
43+
mid: $response->mid[$i],
44+
last: $response->last[$i],
45+
volume: $response->volume[$i],
46+
open_interest: $response->openInterest[$i],
47+
underlying_price: $response->underlyingPrice[$i],
48+
in_the_money: $response->inTheMoney[$i],
49+
intrinsic_value: $response->intrinsicValue[$i],
50+
extrinsic_value: $response->extrinsicValue[$i],
51+
implied_volatility: $response->iv[$i],
52+
delta: $response->delta[$i],
53+
gamma: $response->gamma[$i],
54+
theta: $response->theta[$i],
55+
vega: $response->vega[$i],
56+
rho: $response->rho[$i],
57+
updated: Carbon::parse($response->updated[$i]),
5858
);
5959
}
6060
break;
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
3+
namespace MarketDataApp\Endpoints\Responses\Options;
4+
5+
use Carbon\Carbon;
6+
7+
class Quote
8+
{
9+
10+
// The option symbol according to OCC symbology.
11+
public string $option_symbol;
12+
13+
// The ask price.
14+
public float $ask;
15+
16+
// The number of contracts offered at the ask price.
17+
public int $ask_size;
18+
19+
// The bid price.
20+
public float $bid;
21+
22+
// The number of contracts offered at the bid price.
23+
public int $bid_size;
24+
25+
// The midpoint price between the ask and the bid, also known as the mark price.
26+
public float $mid;
27+
28+
// The last price negotiated for this option contract at the time of this quote.
29+
public float $last;
30+
31+
// The number of contracts negotiated during the trading day at the time of this quote.
32+
public int $volume;
33+
34+
// The total number of contracts that have not yet been settled at the time of this quote.
35+
public int $open_interest;
36+
37+
// The last price of the underlying security at the time of this quote.
38+
public float $underlying_price;
39+
40+
// Specifies whether the option contract was in the money true or false at the time of this quote.
41+
public bool $in_the_money;
42+
43+
// The intrinsic value of the option.
44+
public float $intrinsic_value;
45+
46+
// The extrinsic value of the option.
47+
public float $extrinsic_value;
48+
49+
// The implied volatility of the option.
50+
public float $implied_volatility;
51+
52+
// The delta of the option.
53+
public float $delta;
54+
55+
// The gamma of the option.
56+
public float $gamma;
57+
58+
// The theta of the option.
59+
public float $theta;
60+
61+
// The vega of the option.
62+
public float $vega;
63+
64+
// The rho of the option.
65+
public float $rho;
66+
67+
// The date and time of this quote snapshot in Unix time.
68+
public Carbon $updated;
69+
70+
public function __construct(
71+
string $option_symbol,
72+
float $ask,
73+
int $ask_size,
74+
float $bid,
75+
int $bid_size,
76+
float $mid,
77+
float $last,
78+
int $volume,
79+
int $open_interest,
80+
float $underlying_price,
81+
bool $in_the_money,
82+
float $intrinsic_value,
83+
float $extrinsic_value,
84+
float $implied_volatility,
85+
float $delta,
86+
float $gamma,
87+
float $theta,
88+
float $vega,
89+
float $rho,
90+
Carbon $updated,
91+
) {
92+
$this->option_symbol = $option_symbol;
93+
$this->ask = $ask;
94+
$this->ask_size = $ask_size;
95+
$this->bid = $bid;
96+
$this->bid_size = $bid_size;
97+
$this->mid = $mid;
98+
$this->last = $last;
99+
$this->volume = $volume;
100+
$this->open_interest = $open_interest;
101+
$this->underlying_price = $underlying_price;
102+
$this->in_the_money = $in_the_money;
103+
$this->intrinsic_value = $intrinsic_value;
104+
$this->extrinsic_value = $extrinsic_value;
105+
$this->implied_volatility = $implied_volatility;
106+
$this->delta = $delta;
107+
$this->gamma = $gamma;
108+
$this->theta = $theta;
109+
$this->vega = $vega;
110+
$this->rho = $rho;
111+
$this->updated = $updated;
112+
}
113+
}

src/Endpoints/Responses/Options/Quotes.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,65 @@
22

33
namespace MarketDataApp\Endpoints\Responses\Options;
44

5+
use Carbon\Carbon;
6+
57
class Quotes
68
{
9+
10+
// Status will always be ok when there is data for the quote requested.
11+
public string $status;
12+
13+
// Time of the next quote if there is no data in the requested period, but there is data in a subsequent period.
14+
public Carbon $next_time;
15+
16+
// Time of the previous quote if there is no data in the requested period, but there is data in a previous period.
17+
public Carbon $prev_time;
18+
19+
/** @var Quote[] $quotes */
20+
public array $quotes = [];
21+
22+
public function __construct(object $response)
23+
{
24+
// Convert the response to this object.
25+
$this->status = $response->s;
26+
27+
switch ($this->status) {
28+
case 'ok':
29+
for ($i = 0; $i < count($response->optionSymbol); $i++) {
30+
$this->quotes[] = new Quote(
31+
option_symbol: $response->optionSymbol[$i],
32+
ask: $response->ask[$i],
33+
ask_size: $response->askSize[$i],
34+
bid: $response->bid[$i],
35+
bid_size: $response->bidSize[$i],
36+
mid: $response->mid[$i],
37+
last: $response->last[$i],
38+
volume: $response->volume[$i],
39+
open_interest: $response->openInterest[$i],
40+
underlying_price: $response->underlyingPrice[$i],
41+
in_the_money: $response->inTheMoney[$i],
42+
intrinsic_value: $response->intrinsicValue[$i],
43+
extrinsic_value: $response->extrinsicValue[$i],
44+
implied_volatility: $response->iv[$i],
45+
delta: $response->delta[$i],
46+
gamma: $response->gamma[$i],
47+
theta: $response->theta[$i],
48+
vega: $response->vega[$i],
49+
rho: $response->rho[$i],
50+
updated: Carbon::parse($response->updated[$i]),
51+
);
52+
}
53+
break;
54+
55+
case 'no_data':
56+
if (isset($response->nextTime)) {
57+
$this->next_time = Carbon::parse($response->nextTime);
58+
}
59+
60+
if (isset($response->prevTime)) {
61+
$this->prev_time = Carbon::parse($response->prevTime);
62+
}
63+
break;
64+
}
65+
}
766
}

0 commit comments

Comments
 (0)