calendar optimizer page works
This commit is contained in:
+15
-30
@@ -49,6 +49,7 @@ const appRouter = router({
|
||||
DISTINCT(asOfDate) as asOfDate
|
||||
FROM option_contracts
|
||||
WHERE symbol = '${underlying}'
|
||||
ORDER BY asOfDate
|
||||
`)
|
||||
).map(({ asOfDate }) => asOfDate);
|
||||
}),
|
||||
@@ -66,10 +67,11 @@ const appRouter = router({
|
||||
return (
|
||||
await query<{ expirationDate: string }>(`
|
||||
SELECT
|
||||
DISTINCT(expirationDate)
|
||||
DISTINCT(expirationDate) as expirationDate
|
||||
FROM option_contracts
|
||||
WHERE symbol = '${underlying}'
|
||||
AND asOfDate = '${asOfDate}'
|
||||
ORDER BY expirationDate
|
||||
`)
|
||||
).map(({ expirationDate }) => expirationDate);
|
||||
}),
|
||||
@@ -88,11 +90,12 @@ const appRouter = router({
|
||||
return (
|
||||
await query<{ strike: string }>(`
|
||||
SELECT
|
||||
DISTINCT(strike)
|
||||
DISTINCT(strike) as strike
|
||||
FROM option_contracts
|
||||
WHERE symbol = '${underlying}'
|
||||
AND asOfDate = '${asOfDate}'
|
||||
AND expirationDate = '${expirationDate}'
|
||||
ORDER BY strike
|
||||
`)
|
||||
).map(({ strike }) => strike);
|
||||
}),
|
||||
@@ -106,25 +109,16 @@ const appRouter = router({
|
||||
)
|
||||
.query(async (opts) => {
|
||||
const { underlying } = opts.input;
|
||||
return (
|
||||
await query<[number, number]>(
|
||||
`
|
||||
return await query<{ x: number; y: number }>(
|
||||
`
|
||||
SELECT
|
||||
toUnixTimestamp(tsStart),
|
||||
open
|
||||
toUnixTimestamp(tsStart) as x,
|
||||
open as y
|
||||
FROM stock_aggregates
|
||||
WHERE symbol = '${underlying}'
|
||||
ORDER BY tsStart ASC
|
||||
`,
|
||||
"JSONCompactEachRow"
|
||||
)
|
||||
).reduce(
|
||||
(columns, row) => {
|
||||
columns[0].push(row[0]);
|
||||
columns[1].push(row[1]);
|
||||
return columns;
|
||||
},
|
||||
[[], []]
|
||||
"JSONEachRow"
|
||||
);
|
||||
}),
|
||||
getOpensForOptionContract: publicProcedure
|
||||
@@ -139,12 +133,11 @@ const appRouter = router({
|
||||
)
|
||||
.query(async (opts) => {
|
||||
const { underlying, expirationDate, strike } = opts.input;
|
||||
return (
|
||||
await query<[number, number]>(
|
||||
`
|
||||
return await query<{ x: number; y: number }>(
|
||||
`
|
||||
SELECT
|
||||
toUnixTimestamp(tsStart),
|
||||
open
|
||||
toUnixTimestamp(tsStart) as x,
|
||||
open as y
|
||||
FROM option_aggregates
|
||||
WHERE symbol = '${underlying}'
|
||||
AND expirationDate = '${expirationDate}'
|
||||
@@ -152,15 +145,7 @@ const appRouter = router({
|
||||
AND type = 'call'
|
||||
ORDER BY tsStart ASC
|
||||
`,
|
||||
"JSONCompactEachRow"
|
||||
)
|
||||
).reduce(
|
||||
(columns, row) => {
|
||||
columns[0].push(row[0]);
|
||||
columns[1].push(row[1]);
|
||||
return columns;
|
||||
},
|
||||
[[], []]
|
||||
"JSONEachRow"
|
||||
);
|
||||
}),
|
||||
getHistoricalCalendarPrices: publicProcedure
|
||||
|
||||
Reference in New Issue
Block a user