add basic endpoints
This commit is contained in:
+48
-1
@@ -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});
|
||||
//await sql.end({timeout:60});
|
||||
Reference in New Issue
Block a user