Skip to content

Commit ce6b793

Browse files
authored
Add options chain snapshot (#117)
* Add options chain snapshot * Include strike price filter params * Remove "previous_url" param Co-authored-by: Joe Dursun <[email protected]>
1 parent 2a67ddf commit ce6b793

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

src/rest/options/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ describe("[REST] Options", () => {
7777
.getCalls()[0]
7878
.args[0].should.eql("/v3/snapshot/options/AAPL/O:AAPL230616C00150000");
7979
});
80+
81+
it("snapshots - option chain /v3/snapshot/options/{underlyingAsset}", async () => {
82+
await options.snapshotOptionChain("AAPL");
83+
requestStub.callCount.should.eql(1);
84+
requestStub
85+
.getCalls()[0]
86+
.args[0].should.eql("/v3/snapshot/options/AAPL");
87+
});
8088
});

src/rest/options/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ import { previousClose } from "./previousClose";
1616
import { IOptionTrades, trades } from "./trades";
1717
import { IOptionsLastTrade, lastTrade } from "./lastTrade";
1818
import { IOptionQuotes, quotes } from "./quotes";
19-
import { IOptionsSnapshotContract, snapshotOptionContract } from "./snapshots";
19+
import {
20+
IOptionsSnapshotContract,
21+
IOptionsSnapshotChain,
22+
IOptionsChainQuery,
23+
snapshotOptionContract,
24+
snapshotOptionChain
25+
} from "./snapshots";
2026
import { ISummaries, ISummariesQuery } from "../stocks/summaries";
2127
import { summaries } from "./summaries";
2228

@@ -27,7 +33,13 @@ export {
2733
export { IOptionTrades } from "./trades";
2834
export { IOptionsLastTrade } from "./lastTrade";
2935
export { IOptionQuotes } from "./quotes";
30-
export { IOptionsSnapshotContract, snapshotOptionContract } from "./snapshots";
36+
export {
37+
IOptionsSnapshotContract,
38+
IOptionsSnapshotChain,
39+
IOptionsChainQuery,
40+
snapshotOptionContract,
41+
snapshotOptionChain,
42+
} from "./snapshots";
3143

3244
export interface IOptionsClient {
3345
aggregates: (
@@ -62,6 +74,10 @@ export interface IOptionsClient {
6274
underlyingAsset: string,
6375
optionContract: string
6476
) => Promise<IOptionsSnapshotContract>;
77+
snapshotOptionChain: (
78+
underlyingAsset: string,
79+
query?: IOptionsChainQuery
80+
) => Promise<IOptionsSnapshotChain>;
6581
}
6682

6783
export const optionsClient = (
@@ -77,6 +93,7 @@ export const optionsClient = (
7793
lastTrade: auth(apiKey, lastTrade, apiBase),
7894
quotes: auth(apiKey, quotes, apiBase),
7995
snapshotOptionContract: auth(apiKey, snapshotOptionContract, apiBase),
96+
snapshotOptionChain: auth(apiKey, snapshotOptionChain, apiBase),
8097
});
8198

8299
export default optionsClient;

src/rest/options/snapshots.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// CF: https://polygon.io/docs/options/get_v3_snapshot_options__underlyingAsset___optionContract
22

3-
import { get } from "../transport/request";
3+
import { get, IPolygonQuery } from "../transport/request";
44

55
export interface SnapshotDay {
66
change?: number;
@@ -68,6 +68,44 @@ export interface IOptionsSnapshotContract {
6868
results?: SnapshotInfo;
6969
}
7070

71+
// CF: https://polygon.io/docs/options/get_v3_snapshot_options__underlyingasset
72+
export interface IOptionsSnapshotChain {
73+
status?: string;
74+
request_id?: string;
75+
next_url?: string;
76+
results?: SnapshotInfo[];
77+
}
78+
79+
export interface IOptionsChainQuery extends IPolygonQuery {
80+
contract_type?: "call" | "put";
81+
expiration_date?: string;
82+
"expiration_date.lt"?: string;
83+
"expiration_date.lte"?: string;
84+
"expiration_date.gt"?: string;
85+
"expiration_date.gte"?: string;
86+
order?: "asc" | "desc";
87+
limit?: number;
88+
sort?: "ticker" | "expiration_date" | "strike_price";
89+
strike_price?: number;
90+
"strike_price.lt"?: number;
91+
"strike_price.lte"?: number;
92+
"strike_price.gt"?: number;
93+
"strike_price.gte"?: number;
94+
}
95+
96+
export const snapshotOptionChain = async (
97+
apiKey: string,
98+
apiBase: string,
99+
underlyingAsset: string,
100+
query?: IOptionsChainQuery
101+
): Promise<IOptionsSnapshotChain> =>
102+
get(
103+
`/v3/snapshot/options/${underlyingAsset}`,
104+
apiKey,
105+
apiBase,
106+
query
107+
);
108+
71109
export const snapshotOptionContract = async (
72110
apiKey: string,
73111
apiBase: string,

0 commit comments

Comments
 (0)