From 29015e5a0b89953f0357f4f23f8c62b0d75cf8de Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Sun, 18 Jun 2023 14:39:50 -0400 Subject: [PATCH] add `expirations` endpoint --- src/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/index.ts b/src/index.ts index 22df570..4c551ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,6 +74,20 @@ server.get<{ ORDER BY "strike";`; reply.status(200).send(strikes); }) +server.get<{ + Params: {underlying:string, quote_date:string}, +}>('/option_quotes/:underlying/:quote_date/expirations', async (request, reply) => { + const expirations = (await sql` + SELECT DISTINCT "expiration" + FROM "option_quote" + WHERE + "underlying" = ${request.params.underlying} + AND + "quote_date" = ${request.params.quote_date} + ORDER BY "expiration";` + ).map(x=>x.expiration); + reply.status(200).send(expirations); +}) server.listen({ port: 8234, host: '127.0.0.1' }, (err, address) => { if (err) {