|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import _ from './env';
|
|
|
|
|
import { publicProcedure, router } from './trpc.js';
|
|
|
|
|
import { query } from './clickhouse.js';
|
|
|
|
|
import { createHTTPHandler, createHTTPServer } from '@trpc/server/adapters/standalone';
|
|
|
|
|
import { createHTTPHandler } from '@trpc/server/adapters/standalone';
|
|
|
|
|
import cors from 'cors';
|
|
|
|
|
import { Object as ObjectT, String as StringT, TSchema, Number as NumberT } from '@sinclair/typebox';
|
|
|
|
|
import { TypeCompiler } from '@sinclair/typebox/compiler';
|
|
|
|
@ -140,15 +141,19 @@ const appRouter = router({
|
|
|
|
|
getHistoricalStockQuoteChartData: publicProcedure
|
|
|
|
|
.input(RpcType(ObjectT({
|
|
|
|
|
underlying:StringT(),
|
|
|
|
|
lookbackPeriodStart:StringT(),
|
|
|
|
|
lookbackPeriodEnd:StringT(),
|
|
|
|
|
})))
|
|
|
|
|
.query(async (opts)=>{
|
|
|
|
|
const {underlying, } = opts.input;
|
|
|
|
|
const { underlying, lookbackPeriodStart, lookbackPeriodEnd } = opts.input;
|
|
|
|
|
return (await query<[number,number]>(`
|
|
|
|
|
SELECT
|
|
|
|
|
toUnixTimestamp(tsStart) as x,
|
|
|
|
|
open as y
|
|
|
|
|
FROM stock_aggregates
|
|
|
|
|
WHERE symbol = '${underlying}'
|
|
|
|
|
AND tsStart >= '${lookbackPeriodStart} 00:00:00'
|
|
|
|
|
AND tsStart <= '${lookbackPeriodEnd} 00:00:00'
|
|
|
|
|
ORDER BY x ASC
|
|
|
|
|
`,'JSONEachRow'));
|
|
|
|
|
}),
|
|
|
|
@ -159,9 +164,11 @@ const appRouter = router({
|
|
|
|
|
daysBetweenFrontAndBackExpiration:NumberT(),
|
|
|
|
|
strikePercentageFromUnderlyingPriceRangeMin:NumberT(),
|
|
|
|
|
strikePercentageFromUnderlyingPriceRangeMax:NumberT(),
|
|
|
|
|
lookbackPeriodStart:StringT(),
|
|
|
|
|
lookbackPeriodEnd:StringT(),
|
|
|
|
|
})))
|
|
|
|
|
.query(async (opts)=>{
|
|
|
|
|
const {underlying, daysToFrontExpiration, daysBetweenFrontAndBackExpiration, strikePercentageFromUnderlyingPriceRangeMin, strikePercentageFromUnderlyingPriceRangeMax, } = opts.input;
|
|
|
|
|
const {underlying, daysToFrontExpiration, daysBetweenFrontAndBackExpiration, strikePercentageFromUnderlyingPriceRangeMin, strikePercentageFromUnderlyingPriceRangeMax, lookbackPeriodStart, lookbackPeriodEnd, } = opts.input;
|
|
|
|
|
return (await query<[number,number]>(`
|
|
|
|
|
SELECT
|
|
|
|
|
toUnixTimestamp(tsStart) as x,
|
|
|
|
@ -172,6 +179,8 @@ const appRouter = router({
|
|
|
|
|
AND strikePercentageFromUnderlyingPrice >= ${strikePercentageFromUnderlyingPriceRangeMin}
|
|
|
|
|
AND strikePercentageFromUnderlyingPrice <= ${strikePercentageFromUnderlyingPriceRangeMax}
|
|
|
|
|
AND daysBetweenFrontAndBackExpiration = ${daysBetweenFrontAndBackExpiration}
|
|
|
|
|
AND tsStart >= '${lookbackPeriodStart} 00:00:00'
|
|
|
|
|
AND tsStart <= '${lookbackPeriodEnd} 00:00:00'
|
|
|
|
|
`,'JSONEachRow'));
|
|
|
|
|
}),
|
|
|
|
|
getHistoricalCalendarExitQuoteChartData: publicProcedure
|
|
|
|
@ -179,9 +188,11 @@ const appRouter = router({
|
|
|
|
|
underlying:StringT(),
|
|
|
|
|
daysToFrontExpiration:NumberT(),
|
|
|
|
|
daysBetweenFrontAndBackExpiration:NumberT(),
|
|
|
|
|
lookbackPeriodStart:StringT(),
|
|
|
|
|
lookbackPeriodEnd:StringT(),
|
|
|
|
|
})))
|
|
|
|
|
.query(async (opts)=>{
|
|
|
|
|
const {underlying, daysToFrontExpiration, daysBetweenFrontAndBackExpiration, } = opts.input;
|
|
|
|
|
const {underlying, daysToFrontExpiration, daysBetweenFrontAndBackExpiration, lookbackPeriodStart, lookbackPeriodEnd, } = opts.input;
|
|
|
|
|
return (await query<[number,number]>(`
|
|
|
|
|
SELECT
|
|
|
|
|
FLOOR(strikePercentageFromUnderlyingPrice, 1) as x,
|
|
|
|
@ -192,6 +203,8 @@ const appRouter = router({
|
|
|
|
|
AND strikePercentageFromUnderlyingPrice >= -5.0
|
|
|
|
|
AND strikePercentageFromUnderlyingPrice <= 5.0
|
|
|
|
|
AND daysBetweenFrontAndBackExpiration = ${daysBetweenFrontAndBackExpiration}
|
|
|
|
|
AND tsStart >= '${lookbackPeriodStart} 00:00:00'
|
|
|
|
|
AND tsStart <= '${lookbackPeriodEnd} 00:00:00'
|
|
|
|
|
ORDER BY x ASC
|
|
|
|
|
`,'JSONEachRow'));
|
|
|
|
|
}),
|
|
|
|
|