Add "calendar prices" endpoint

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

@ -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`
const prices = 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}
"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"."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);
"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) => {

Loading…
Cancel
Save