add dev envs; add lookbackPeriod
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
CLICKHOUSE_HOST=http://localhost:8123
|
||||
LISTEN_PORT=3005
|
||||
+2
-1
@@ -12,7 +12,8 @@
|
||||
"@clickhouse/client": "^0.2.7",
|
||||
"@sinclair/typebox": "^0.32.5",
|
||||
"@trpc/server": "^10.45.0",
|
||||
"cors": "^2.8.5"
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.17",
|
||||
|
||||
Generated
+8
@@ -17,6 +17,9 @@ dependencies:
|
||||
cors:
|
||||
specifier: ^2.8.5
|
||||
version: 2.8.5
|
||||
dotenv:
|
||||
specifier: ^16.4.1
|
||||
version: 16.4.1
|
||||
|
||||
devDependencies:
|
||||
'@types/cors':
|
||||
@@ -386,6 +389,11 @@ packages:
|
||||
object-keys: 1.1.1
|
||||
dev: true
|
||||
|
||||
/dotenv@16.4.1:
|
||||
resolution: {integrity: sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ==}
|
||||
engines: {node: '>=12'}
|
||||
dev: false
|
||||
|
||||
/error-ex@1.3.2:
|
||||
resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==}
|
||||
dependencies:
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
if(process.env.NODE_DEV==="development"){
|
||||
dotenv.config({ path:"../.env.development" });
|
||||
}
|
||||
|
||||
export default null;
|
||||
+17
-4
@@ -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'));
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user