From 64321bbff64714cee344dc73b5b616fe4f2946ec Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Wed, 28 Jun 2023 21:48:15 -0400 Subject: [PATCH] Add "calendar prices" endpoint --- src/index.ts | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/index.ts b/src/index.ts index b660cff..bf2af4a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -91,32 +91,26 @@ server.get<{ 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); + const prices = await sql` + SELECT + "front_contract"."quote_date", + ("back_contract"."ask" - "front_contract"."bid") AS "price" + FROM + "option_quote" AS "front_contract" + INNER JOIN + "option_quote" AS "back_contract" + ON + "back_contract"."underlying" = "front_contract"."underlying" + AND "back_contract"."type" = "front_contract"."type" + AND "back_contract"."quote_date" = "front_contract"."quote_date" + AND "back_contract"."strike" = "front_contract"."strike" + AND "back_contract"."expiration" = ${request.params.back_expiration} + WHERE + "front_contract"."underlying" = ${request.params.underlying} + AND "front_contract"."type" = 'call' + AND "front_contract"."strike" = ${request.params.strike} + AND "front_contract"."expiration" = ${request.params.front_expiration}`; + reply.status(200).send(prices); }) server.listen({ port: 8234, host: '127.0.0.1' }, (err, address) => {