From e0e7182ac5ab4987aa181f5a1c7aeeb7191d066b Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Mon, 26 Jun 2023 00:46:54 -0400 Subject: [PATCH] add prices-over-time endpoint --- src/index.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/index.ts b/src/index.ts index 477a8a0..b660cff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,6 +88,36 @@ server.get<{ ).map(x=>x.expiration); reply.status(200).send(expirations); }) +server.get<{ + Params: {underlying:string, strike:string, front_expiration:string, back_expiration:string, }, +}>('/option_quotes/:underlying/:strike/:front_expiration/:back_expiration', async (request, reply) => { + const strikes = await sql` + SELECT + "front"."quote_date", + ("back"."bid" - "front"."ask") AS "calendar_price" + FROM "option_quote" AS "front" + INNER JOIN "option_quote" AS "back" + ON + "front"."type" = "back"."type" + AND + "front"."underlying" = "back"."underlying" + AND + "front"."strike" = "back"."strike" + AND + "front"."quote_date" = "back"."quote_date" + AND + "back"."expiration" = ${request.params.back_expiration} + WHERE + "front"."type" = 'call' + AND + "front"."underlying" = ${request.params.underlying} + AND + "front"."strike" = ${request.params.strike} + AND + "front"."expiration" = ${request.params.front_expiration} + ORDER BY "quote_date";`; + reply.status(200).send(strikes); +}) server.listen({ port: 8234, host: '127.0.0.1' }, (err, address) => { if (err) {