Add "calendar prices" endpoint

master
Avraham Sakal 2 years ago
parent 1dc5b11f03
commit 64321bbff6

@ -91,32 +91,26 @@ server.get<{
server.get<{ server.get<{
Params: {underlying:string, strike:string, front_expiration:string, back_expiration:string, }, Params: {underlying:string, strike:string, front_expiration:string, back_expiration:string, },
}>('/option_quotes/:underlying/:strike/:front_expiration/:back_expiration', async (request, reply) => { }>('/option_quotes/:underlying/:strike/:front_expiration/:back_expiration', async (request, reply) => {
const strikes = await sql` const prices = await sql`
SELECT SELECT
"front"."quote_date", "front_contract"."quote_date",
("back"."bid" - "front"."ask") AS "calendar_price" ("back_contract"."ask" - "front_contract"."bid") AS "price"
FROM "option_quote" AS "front" FROM
INNER JOIN "option_quote" AS "back" "option_quote" AS "front_contract"
ON INNER JOIN
"front"."type" = "back"."type" "option_quote" AS "back_contract"
AND ON
"front"."underlying" = "back"."underlying" "back_contract"."underlying" = "front_contract"."underlying"
AND AND "back_contract"."type" = "front_contract"."type"
"front"."strike" = "back"."strike" AND "back_contract"."quote_date" = "front_contract"."quote_date"
AND AND "back_contract"."strike" = "front_contract"."strike"
"front"."quote_date" = "back"."quote_date" AND "back_contract"."expiration" = ${request.params.back_expiration}
AND WHERE
"back"."expiration" = ${request.params.back_expiration} "front_contract"."underlying" = ${request.params.underlying}
WHERE AND "front_contract"."type" = 'call'
"front"."type" = 'call' AND "front_contract"."strike" = ${request.params.strike}
AND AND "front_contract"."expiration" = ${request.params.front_expiration}`;
"front"."underlying" = ${request.params.underlying} reply.status(200).send(prices);
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) => { server.listen({ port: 8234, host: '127.0.0.1' }, (err, address) => {

Loading…
Cancel
Save