From ae09a60637669e94c97dccdd43c0cc75251047a4 Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Wed, 14 Jun 2023 23:27:24 -0400 Subject: [PATCH] add basic endpoints --- src/index.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e029ebe..daf7af6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,53 @@ server.get('/ping', async (request, reply) => { return 'pong\n' }) +server.get('/option_quotes/underlyings', async (request, reply) => { + const underlyings = (await sql`SELECT DISTINCT "underlying" FROM "option_quote";`).map(x=>x.underlying); + reply.status(200).send(underlyings); +}) +server.get<{ + Params: {underlying:string, quote_date:string}, +}>('/option_quotes/:underlying/:quote_date', async (request, reply) => { + const options_quotes = await sql` + SELECT * + FROM "option_quote" + WHERE + "underlying" = ${request.params.underlying} + AND + "quote_date" = ${request.params.quote_date} + ORDER BY "strike";`; + reply.status(200).send(options_quotes); +}) +server.get<{ + Params: {underlying:string, quote_date:string}, +}>('/option_quotes/:underlying/:quote_date/strikes', async (request, reply) => { + const strikes = (await sql` + SELECT DISTINCT "strike" + FROM "option_quote" + WHERE + "underlying" = ${request.params.underlying} + AND + "quote_date" = ${request.params.quote_date} + ORDER BY "strike";` + ).map(x=>x.strike); + reply.status(200).send(strikes); +}) +server.get<{ + Params: {underlying:string, quote_date:string, strike:string}, +}>('/option_quotes/:underlying/:quote_date/:strike', async (request, reply) => { + const strikes = await sql` + SELECT * + FROM "option_quote" + WHERE + "underlying" = ${request.params.underlying} + AND + "quote_date" = ${request.params.quote_date} + AND + "strike" = ${request.params.strike} + ORDER BY "strike";`; + reply.status(200).send(strikes); +}) + server.listen({ port: 8234, host: '127.0.0.1' }, (err, address) => { if (err) { console.error(err) @@ -21,4 +68,4 @@ server.listen({ port: 8234, host: '127.0.0.1' }, (err, address) => { } console.log(`Server listening at ${address}`) }) -await sql.end({timeout:60}); \ No newline at end of file +//await sql.end({timeout:60}); \ No newline at end of file