refactor: migrate TrumpSignal to TypeScript monorepo and Pages Router
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
-- Baseline corresponding to legacy Alembic head 027.
|
||||
|
||||
-- Existing PostgreSQL databases must already have completed legacy migrations 001–027.
|
||||
|
||||
-- This file creates a fresh database; it does not rewrite existing financial data.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "posts" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"external_id" VARCHAR(64) NOT NULL UNIQUE,
|
||||
"text" TEXT NOT NULL,
|
||||
"source" VARCHAR(32) NOT NULL DEFAULT 'truth',
|
||||
"published_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
"sentiment" VARCHAR(16) NOT NULL DEFAULT 'neutral',
|
||||
"ai_confidence" INTEGER NOT NULL DEFAULT 0,
|
||||
"relevant" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
"price_impact_asset" VARCHAR(8),
|
||||
"price_impact_m5" DOUBLE PRECISION,
|
||||
"price_impact_m15" DOUBLE PRECISION,
|
||||
"price_impact_m1h" DOUBLE PRECISION,
|
||||
"price_at_post" DOUBLE PRECISION,
|
||||
"signal" VARCHAR(8),
|
||||
"ai_reasoning" TEXT,
|
||||
"prefilter_reason" VARCHAR(32),
|
||||
"analysis_version" VARCHAR(16),
|
||||
"target_asset" VARCHAR(16),
|
||||
"category" VARCHAR(24),
|
||||
"expected_move_pct" DOUBLE PRECISION,
|
||||
"invalidation_price" DOUBLE PRECISION,
|
||||
"created_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now())
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_posts_external_id ON "posts"("external_id");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "candles" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"asset" VARCHAR(8) NOT NULL,
|
||||
"timeframe" VARCHAR(4) NOT NULL,
|
||||
"time" BIGINT NOT NULL,
|
||||
"open" DOUBLE PRECISION NOT NULL,
|
||||
"high" DOUBLE PRECISION NOT NULL,
|
||||
"low" DOUBLE PRECISION NOT NULL,
|
||||
"close" DOUBLE PRECISION NOT NULL,
|
||||
"volume" DOUBLE PRECISION NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_candles_asset ON "candles"("asset");
|
||||
CREATE INDEX IF NOT EXISTS ix_candles_time ON "candles"("time");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_candle_asset_tf_time ON "candles"("asset","timeframe","time");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "bot_trades" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"asset" VARCHAR(8) NOT NULL,
|
||||
"side" VARCHAR(8) NOT NULL,
|
||||
"entry_price" DOUBLE PRECISION NOT NULL,
|
||||
"exit_price" DOUBLE PRECISION,
|
||||
"pnl_usd" DOUBLE PRECISION,
|
||||
"hold_seconds" INTEGER,
|
||||
"trigger_post_id" INTEGER REFERENCES "posts"("id"),
|
||||
"wallet_address" VARCHAR(64) NOT NULL,
|
||||
"opened_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now()),
|
||||
"closed_at" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"released_at" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"hl_order_id" VARCHAR(128),
|
||||
"size_usd" DOUBLE PRECISION,
|
||||
"leverage" INTEGER,
|
||||
"eff_take_profit_pct" DOUBLE PRECISION,
|
||||
"eff_stop_loss_pct" DOUBLE PRECISION,
|
||||
"eff_trailing_stop_pct" DOUBLE PRECISION,
|
||||
"eff_trailing_activate_pct" DOUBLE PRECISION,
|
||||
"eff_max_hold_hours" INTEGER,
|
||||
"eff_invalidation" VARCHAR(24),
|
||||
"eff_invalidation_price" DOUBLE PRECISION,
|
||||
"eff_min_hold_until_ts" DOUBLE PRECISION,
|
||||
"realized_partial_pnl_usd" DOUBLE PRECISION NOT NULL DEFAULT 0.0,
|
||||
"remaining_fraction" DOUBLE PRECISION NOT NULL DEFAULT 1.0,
|
||||
"derisk_steps_done" INTEGER NOT NULL DEFAULT 0,
|
||||
"base_size_usd" DOUBLE PRECISION,
|
||||
"addon_steps_done" INTEGER NOT NULL DEFAULT 0,
|
||||
"sys2_mode" VARCHAR(16),
|
||||
"grow_mode" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
"peak_gain_pct" DOUBLE PRECISION NOT NULL DEFAULT 0.0
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_bot_trades_trigger_post_id ON "bot_trades"("trigger_post_id");
|
||||
CREATE INDEX IF NOT EXISTS ix_bot_trades_wallet_address ON "bot_trades"("wallet_address");
|
||||
CREATE INDEX IF NOT EXISTS ix_bot_trades_wallet_closed ON "bot_trades"("wallet_address","closed_at");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "subscriptions" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"wallet_address" VARCHAR(64) NOT NULL UNIQUE,
|
||||
"hl_api_key" VARCHAR(256),
|
||||
"active" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
"subscribed_at" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"created_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now()),
|
||||
"leverage" INTEGER NOT NULL DEFAULT 3,
|
||||
"position_size_usd" DOUBLE PRECISION NOT NULL DEFAULT 20.0,
|
||||
"take_profit_pct" DOUBLE PRECISION,
|
||||
"stop_loss_pct" DOUBLE PRECISION,
|
||||
"min_confidence" INTEGER NOT NULL DEFAULT 80,
|
||||
"daily_budget_usd" DOUBLE PRECISION,
|
||||
"active_from" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"active_until" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"trailing_stop_pct" DOUBLE PRECISION,
|
||||
"trailing_activate_at_pct" DOUBLE PRECISION,
|
||||
"max_hold_hours" INTEGER NOT NULL DEFAULT 168,
|
||||
"manual_window_until" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"paper_mode" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
"circuit_breaker_tripped_at" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"circuit_breaker_reason" VARCHAR(32),
|
||||
"sys2_budget_pct" DOUBLE PRECISION NOT NULL DEFAULT 0.7,
|
||||
"sys2_cb_tripped_at" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"sys2_cb_reason" VARCHAR(32),
|
||||
"sys2_leverage" INTEGER,
|
||||
"sys2_mode" VARCHAR(16) NOT NULL DEFAULT 'standard',
|
||||
"auto_trade" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
"trump_enabled" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
"macro_enabled" BOOLEAN NOT NULL DEFAULT FALSE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_subscriptions_wallet_address ON "subscriptions"("wallet_address");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "kol_posts" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"kol_handle" VARCHAR(64) NOT NULL,
|
||||
"source" VARCHAR(16) NOT NULL,
|
||||
"external_id" VARCHAR(512) NOT NULL,
|
||||
"title" VARCHAR(512),
|
||||
"url" VARCHAR(512) NOT NULL,
|
||||
"published_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
"raw_text" TEXT NOT NULL,
|
||||
"content_hash" VARCHAR(64) NOT NULL,
|
||||
"summary" TEXT,
|
||||
"tickers_json" TEXT,
|
||||
"analyzed_at" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"analysis_model" VARCHAR(64),
|
||||
"analysis_version" VARCHAR(16),
|
||||
"tier" VARCHAR(16),
|
||||
"post_type" VARCHAR(16),
|
||||
"talks_vs_trades_flag" BOOLEAN DEFAULT FALSE,
|
||||
"sentiment" VARCHAR(16),
|
||||
"created_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now())
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_kol_posts_kol_handle ON "kol_posts"("kol_handle");
|
||||
CREATE INDEX IF NOT EXISTS ix_kol_posts_published_at ON "kol_posts"("published_at");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_kol_post_src_extid ON "kol_posts"("source","external_id");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "kol_wallets" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"handle" VARCHAR(64) NOT NULL,
|
||||
"chain" VARCHAR(16) NOT NULL,
|
||||
"address" VARCHAR(128) NOT NULL,
|
||||
"label" VARCHAR(128),
|
||||
"source_url" VARCHAR(256),
|
||||
"active" BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
"added_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now())
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_kol_wallets_handle ON "kol_wallets"("handle");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_kol_wallet_chain_addr ON "kol_wallets"("chain","address");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "kol_holdings_snapshots" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"wallet_id" INTEGER NOT NULL REFERENCES "kol_wallets"("id"),
|
||||
"snapshot_date" VARCHAR(10) NOT NULL,
|
||||
"holdings_json" TEXT NOT NULL,
|
||||
"total_usd" DOUBLE PRECISION,
|
||||
"source" VARCHAR(16) NOT NULL,
|
||||
"created_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now())
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_kol_holdings_snapshots_wallet_id ON "kol_holdings_snapshots"("wallet_id");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_kol_snapshot_wallet_date ON "kol_holdings_snapshots"("wallet_id","snapshot_date");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "kol_holding_changes" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"wallet_id" INTEGER NOT NULL REFERENCES "kol_wallets"("id"),
|
||||
"detected_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now()),
|
||||
"ticker" VARCHAR(32) NOT NULL,
|
||||
"change_type" VARCHAR(16) NOT NULL,
|
||||
"usd_before" DOUBLE PRECISION,
|
||||
"usd_after" DOUBLE PRECISION,
|
||||
"pct_change" DOUBLE PRECISION,
|
||||
"created_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now())
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_kol_holding_changes_wallet_id ON "kol_holding_changes"("wallet_id");
|
||||
CREATE INDEX IF NOT EXISTS ix_kol_holding_changes_detected_at ON "kol_holding_changes"("detected_at");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "kol_divergence" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"handle" VARCHAR(64) NOT NULL,
|
||||
"ticker" VARCHAR(32) NOT NULL,
|
||||
"post_id" INTEGER NOT NULL REFERENCES "kol_posts"("id"),
|
||||
"post_action" VARCHAR(16) NOT NULL,
|
||||
"post_conviction" DOUBLE PRECISION,
|
||||
"post_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
"change_id" INTEGER NOT NULL REFERENCES "kol_holding_changes"("id"),
|
||||
"onchain_action" VARCHAR(16) NOT NULL,
|
||||
"usd_before" DOUBLE PRECISION,
|
||||
"usd_after" DOUBLE PRECISION,
|
||||
"onchain_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
"signal_type" VARCHAR(16) NOT NULL,
|
||||
"direction" VARCHAR(8),
|
||||
"days_apart" DOUBLE PRECISION,
|
||||
"created_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now())
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_kol_divergence_handle ON "kol_divergence"("handle");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_kol_divergence_pair ON "kol_divergence"("post_id","change_id");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "telegram_bindings" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"wallet_address" VARCHAR(64),
|
||||
"chat_id" BIGINT NOT NULL UNIQUE,
|
||||
"tg_username" VARCHAR(64),
|
||||
"bound_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now()),
|
||||
"alerts_enabled" BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
"alert_trump" BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
"alert_btc_bottom" BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
"alert_funding" BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
"alert_kol_divergence" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
"min_confidence" INTEGER NOT NULL DEFAULT 70,
|
||||
"mute_from_hour" INTEGER,
|
||||
"mute_until_hour" INTEGER,
|
||||
"last_alert_at" TIMESTAMP WITHOUT TIME ZONE,
|
||||
"total_alerts_sent" INTEGER NOT NULL DEFAULT 0,
|
||||
"total_alerts_failed" INTEGER NOT NULL DEFAULT 0,
|
||||
"digest_enabled" BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
"digest_hour_utc" INTEGER NOT NULL DEFAULT 12,
|
||||
"last_digest_sent_at" TIMESTAMP WITHOUT TIME ZONE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_telegram_bindings_wallet_address ON "telegram_bindings"("wallet_address");
|
||||
CREATE INDEX IF NOT EXISTS ix_telegram_bindings_chat_id ON "telegram_bindings"("chat_id");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_telegram_wallet_nonnull ON telegram_bindings(wallet_address) WHERE wallet_address IS NOT NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "macro_snapshots" (
|
||||
"id" SERIAL PRIMARY KEY,
|
||||
"snapshot_date" DATE NOT NULL UNIQUE,
|
||||
"captured_at" TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('utc',now()),
|
||||
"ahr999" DOUBLE PRECISION,
|
||||
"altcoin_season_index" DOUBLE PRECISION,
|
||||
"fear_greed" INTEGER,
|
||||
"fear_greed_label" VARCHAR(32),
|
||||
"btc_dominance_pct" DOUBLE PRECISION,
|
||||
"eth_btc_ratio" DOUBLE PRECISION,
|
||||
"stablecoin_supply_usd" DOUBLE PRECISION,
|
||||
"etf_flow_net_usd_1d" DOUBLE PRECISION,
|
||||
"btc_open_interest_usd" DOUBLE PRECISION,
|
||||
"composite_score" DOUBLE PRECISION,
|
||||
"regime_label" VARCHAR(16),
|
||||
"raw_json" TEXT
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_macro_snapshots_snapshot_date ON "macro_snapshots"("snapshot_date");
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS signature_replays (signature_hash VARCHAR(64) PRIMARY KEY, expires_at BIGINT NOT NULL);
|
||||
CREATE INDEX IF NOT EXISTS ix_signature_replays_expiry ON signature_replays(expires_at);
|
||||
CREATE TABLE IF NOT EXISTS runtime_state (key TEXT PRIMARY KEY,value JSONB,updated_at TIMESTAMPTZ NOT NULL DEFAULT now());
|
||||
CREATE TABLE IF NOT EXISTS runtime_events (id SERIAL PRIMARY KEY,payload JSONB NOT NULL,created_at TIMESTAMPTZ NOT NULL DEFAULT now());
|
||||
CREATE TABLE IF NOT EXISTS live_prices (asset VARCHAR(16) PRIMARY KEY,price DOUBLE PRECISION NOT NULL,updated_at TIMESTAMPTZ NOT NULL DEFAULT now());
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@trumpsignal/database",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./schema": "./src/schema.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"pg": "^8.14.1",
|
||||
"drizzle-orm": "^0.44.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/pg": "^8.11.11"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import pg from 'pg'
|
||||
import { drizzle } from 'drizzle-orm/node-postgres'
|
||||
import * as schema from './schema'
|
||||
export * from './schema'
|
||||
export function createDatabase(connectionString: string) {
|
||||
const pool = new pg.Pool({ connectionString, max: 10 })
|
||||
const lockPool = new pg.Pool({ connectionString, max: 32 })
|
||||
return { db: drizzle(pool, { schema }), pool, lockPool }
|
||||
}
|
||||
@@ -0,0 +1,365 @@
|
||||
import { sql } from 'drizzle-orm'
|
||||
import {
|
||||
pgTable,
|
||||
jsonb,
|
||||
serial,
|
||||
integer,
|
||||
bigint,
|
||||
doublePrecision,
|
||||
boolean,
|
||||
text,
|
||||
varchar,
|
||||
timestamp,
|
||||
date,
|
||||
index,
|
||||
uniqueIndex,
|
||||
} from 'drizzle-orm/pg-core'
|
||||
|
||||
export const posts = pgTable(
|
||||
'posts',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
external_id: varchar('external_id', { length: 64 }).notNull().unique(),
|
||||
text: text('text').notNull(),
|
||||
source: varchar('source', { length: 32 }).notNull().default('truth'),
|
||||
published_at: timestamp('published_at', { mode: 'string', withTimezone: false }).notNull(),
|
||||
sentiment: varchar('sentiment', { length: 16 }).notNull().default('neutral'),
|
||||
ai_confidence: integer('ai_confidence').notNull().default(0),
|
||||
relevant: boolean('relevant').notNull().default(false),
|
||||
price_impact_asset: varchar('price_impact_asset', { length: 8 }),
|
||||
price_impact_m5: doublePrecision('price_impact_m5'),
|
||||
price_impact_m15: doublePrecision('price_impact_m15'),
|
||||
price_impact_m1h: doublePrecision('price_impact_m1h'),
|
||||
price_at_post: doublePrecision('price_at_post'),
|
||||
signal: varchar('signal', { length: 8 }),
|
||||
ai_reasoning: text('ai_reasoning'),
|
||||
prefilter_reason: varchar('prefilter_reason', { length: 32 }),
|
||||
analysis_version: varchar('analysis_version', { length: 16 }),
|
||||
target_asset: varchar('target_asset', { length: 16 }),
|
||||
category: varchar('category', { length: 24 }),
|
||||
expected_move_pct: doublePrecision('expected_move_pct'),
|
||||
invalidation_price: doublePrecision('invalidation_price'),
|
||||
created_at: timestamp('created_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
},
|
||||
(t) => [index('ix_posts_external_id').on(t.external_id)],
|
||||
)
|
||||
|
||||
export const candles = pgTable(
|
||||
'candles',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
asset: varchar('asset', { length: 8 }).notNull(),
|
||||
timeframe: varchar('timeframe', { length: 4 }).notNull(),
|
||||
time: bigint('time', { mode: 'number' }).notNull(),
|
||||
open: doublePrecision('open').notNull(),
|
||||
high: doublePrecision('high').notNull(),
|
||||
low: doublePrecision('low').notNull(),
|
||||
close: doublePrecision('close').notNull(),
|
||||
volume: doublePrecision('volume').notNull(),
|
||||
},
|
||||
(t) => [
|
||||
index('ix_candles_asset').on(t.asset),
|
||||
index('ix_candles_time').on(t.time),
|
||||
uniqueIndex('uq_candle_asset_tf_time').on(t.asset, t.timeframe, t.time),
|
||||
],
|
||||
)
|
||||
|
||||
export const bot_trades = pgTable(
|
||||
'bot_trades',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
asset: varchar('asset', { length: 8 }).notNull(),
|
||||
side: varchar('side', { length: 8 }).notNull(),
|
||||
entry_price: doublePrecision('entry_price').notNull(),
|
||||
exit_price: doublePrecision('exit_price'),
|
||||
pnl_usd: doublePrecision('pnl_usd'),
|
||||
hold_seconds: integer('hold_seconds'),
|
||||
trigger_post_id: integer('trigger_post_id').references(() => posts.id),
|
||||
wallet_address: varchar('wallet_address', { length: 64 }).notNull(),
|
||||
opened_at: timestamp('opened_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
closed_at: timestamp('closed_at', { mode: 'string', withTimezone: false }),
|
||||
released_at: timestamp('released_at', { mode: 'string', withTimezone: false }),
|
||||
hl_order_id: varchar('hl_order_id', { length: 128 }),
|
||||
size_usd: doublePrecision('size_usd'),
|
||||
leverage: integer('leverage'),
|
||||
eff_take_profit_pct: doublePrecision('eff_take_profit_pct'),
|
||||
eff_stop_loss_pct: doublePrecision('eff_stop_loss_pct'),
|
||||
eff_trailing_stop_pct: doublePrecision('eff_trailing_stop_pct'),
|
||||
eff_trailing_activate_pct: doublePrecision('eff_trailing_activate_pct'),
|
||||
eff_max_hold_hours: integer('eff_max_hold_hours'),
|
||||
eff_invalidation: varchar('eff_invalidation', { length: 24 }),
|
||||
eff_invalidation_price: doublePrecision('eff_invalidation_price'),
|
||||
eff_min_hold_until_ts: doublePrecision('eff_min_hold_until_ts'),
|
||||
realized_partial_pnl_usd: doublePrecision('realized_partial_pnl_usd').notNull().default(0.0),
|
||||
remaining_fraction: doublePrecision('remaining_fraction').notNull().default(1.0),
|
||||
derisk_steps_done: integer('derisk_steps_done').notNull().default(0),
|
||||
base_size_usd: doublePrecision('base_size_usd'),
|
||||
addon_steps_done: integer('addon_steps_done').notNull().default(0),
|
||||
sys2_mode: varchar('sys2_mode', { length: 16 }),
|
||||
grow_mode: boolean('grow_mode').notNull().default(false),
|
||||
peak_gain_pct: doublePrecision('peak_gain_pct').notNull().default(0.0),
|
||||
},
|
||||
(t) => [
|
||||
index('ix_bot_trades_trigger_post_id').on(t.trigger_post_id),
|
||||
index('ix_bot_trades_wallet_address').on(t.wallet_address),
|
||||
index('ix_bot_trades_wallet_closed').on(t.wallet_address, t.closed_at),
|
||||
],
|
||||
)
|
||||
|
||||
export const subscriptions = pgTable(
|
||||
'subscriptions',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
wallet_address: varchar('wallet_address', { length: 64 }).notNull().unique(),
|
||||
hl_api_key: varchar('hl_api_key', { length: 256 }),
|
||||
active: boolean('active').notNull().default(false),
|
||||
subscribed_at: timestamp('subscribed_at', { mode: 'string', withTimezone: false }),
|
||||
created_at: timestamp('created_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
leverage: integer('leverage').notNull().default(3),
|
||||
position_size_usd: doublePrecision('position_size_usd').notNull().default(20.0),
|
||||
take_profit_pct: doublePrecision('take_profit_pct'),
|
||||
stop_loss_pct: doublePrecision('stop_loss_pct'),
|
||||
min_confidence: integer('min_confidence').notNull().default(80),
|
||||
daily_budget_usd: doublePrecision('daily_budget_usd'),
|
||||
active_from: timestamp('active_from', { mode: 'string', withTimezone: false }),
|
||||
active_until: timestamp('active_until', { mode: 'string', withTimezone: false }),
|
||||
trailing_stop_pct: doublePrecision('trailing_stop_pct'),
|
||||
trailing_activate_at_pct: doublePrecision('trailing_activate_at_pct'),
|
||||
max_hold_hours: integer('max_hold_hours').notNull().default(168),
|
||||
manual_window_until: timestamp('manual_window_until', { mode: 'string', withTimezone: false }),
|
||||
paper_mode: boolean('paper_mode').notNull().default(false),
|
||||
circuit_breaker_tripped_at: timestamp('circuit_breaker_tripped_at', {
|
||||
mode: 'string',
|
||||
withTimezone: false,
|
||||
}),
|
||||
circuit_breaker_reason: varchar('circuit_breaker_reason', { length: 32 }),
|
||||
sys2_budget_pct: doublePrecision('sys2_budget_pct').notNull().default(0.7),
|
||||
sys2_cb_tripped_at: timestamp('sys2_cb_tripped_at', { mode: 'string', withTimezone: false }),
|
||||
sys2_cb_reason: varchar('sys2_cb_reason', { length: 32 }),
|
||||
sys2_leverage: integer('sys2_leverage'),
|
||||
sys2_mode: varchar('sys2_mode', { length: 16 }).notNull().default('standard'),
|
||||
auto_trade: boolean('auto_trade').notNull().default(false),
|
||||
trump_enabled: boolean('trump_enabled').notNull().default(false),
|
||||
macro_enabled: boolean('macro_enabled').notNull().default(false),
|
||||
},
|
||||
(t) => [index('ix_subscriptions_wallet_address').on(t.wallet_address)],
|
||||
)
|
||||
|
||||
export const kol_posts = pgTable(
|
||||
'kol_posts',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
kol_handle: varchar('kol_handle', { length: 64 }).notNull(),
|
||||
source: varchar('source', { length: 16 }).notNull(),
|
||||
external_id: varchar('external_id', { length: 512 }).notNull(),
|
||||
title: varchar('title', { length: 512 }),
|
||||
url: varchar('url', { length: 512 }).notNull(),
|
||||
published_at: timestamp('published_at', { mode: 'string', withTimezone: false }).notNull(),
|
||||
raw_text: text('raw_text').notNull(),
|
||||
content_hash: varchar('content_hash', { length: 64 }).notNull(),
|
||||
summary: text('summary'),
|
||||
tickers_json: text('tickers_json'),
|
||||
analyzed_at: timestamp('analyzed_at', { mode: 'string', withTimezone: false }),
|
||||
analysis_model: varchar('analysis_model', { length: 64 }),
|
||||
analysis_version: varchar('analysis_version', { length: 16 }),
|
||||
tier: varchar('tier', { length: 16 }),
|
||||
post_type: varchar('post_type', { length: 16 }),
|
||||
talks_vs_trades_flag: boolean('talks_vs_trades_flag').default(false),
|
||||
sentiment: varchar('sentiment', { length: 16 }),
|
||||
created_at: timestamp('created_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
},
|
||||
(t) => [
|
||||
index('ix_kol_posts_kol_handle').on(t.kol_handle),
|
||||
index('ix_kol_posts_published_at').on(t.published_at),
|
||||
uniqueIndex('uq_kol_post_src_extid').on(t.source, t.external_id),
|
||||
],
|
||||
)
|
||||
|
||||
export const kol_wallets = pgTable(
|
||||
'kol_wallets',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
handle: varchar('handle', { length: 64 }).notNull(),
|
||||
chain: varchar('chain', { length: 16 }).notNull(),
|
||||
address: varchar('address', { length: 128 }).notNull(),
|
||||
label: varchar('label', { length: 128 }),
|
||||
source_url: varchar('source_url', { length: 256 }),
|
||||
active: boolean('active').notNull().default(true),
|
||||
added_at: timestamp('added_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
},
|
||||
(t) => [
|
||||
index('ix_kol_wallets_handle').on(t.handle),
|
||||
uniqueIndex('uq_kol_wallet_chain_addr').on(t.chain, t.address),
|
||||
],
|
||||
)
|
||||
|
||||
export const kol_holdings_snapshots = pgTable(
|
||||
'kol_holdings_snapshots',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
wallet_id: integer('wallet_id')
|
||||
.notNull()
|
||||
.references(() => kol_wallets.id),
|
||||
snapshot_date: varchar('snapshot_date', { length: 10 }).notNull(),
|
||||
holdings_json: text('holdings_json').notNull(),
|
||||
total_usd: doublePrecision('total_usd'),
|
||||
source: varchar('source', { length: 16 }).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
},
|
||||
(t) => [
|
||||
index('ix_kol_holdings_snapshots_wallet_id').on(t.wallet_id),
|
||||
uniqueIndex('uq_kol_snapshot_wallet_date').on(t.wallet_id, t.snapshot_date),
|
||||
],
|
||||
)
|
||||
|
||||
export const kol_holding_changes = pgTable(
|
||||
'kol_holding_changes',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
wallet_id: integer('wallet_id')
|
||||
.notNull()
|
||||
.references(() => kol_wallets.id),
|
||||
detected_at: timestamp('detected_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
ticker: varchar('ticker', { length: 32 }).notNull(),
|
||||
change_type: varchar('change_type', { length: 16 }).notNull(),
|
||||
usd_before: doublePrecision('usd_before'),
|
||||
usd_after: doublePrecision('usd_after'),
|
||||
pct_change: doublePrecision('pct_change'),
|
||||
created_at: timestamp('created_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
},
|
||||
(t) => [
|
||||
index('ix_kol_holding_changes_wallet_id').on(t.wallet_id),
|
||||
index('ix_kol_holding_changes_detected_at').on(t.detected_at),
|
||||
],
|
||||
)
|
||||
|
||||
export const kol_divergence = pgTable(
|
||||
'kol_divergence',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
handle: varchar('handle', { length: 64 }).notNull(),
|
||||
ticker: varchar('ticker', { length: 32 }).notNull(),
|
||||
post_id: integer('post_id')
|
||||
.notNull()
|
||||
.references(() => kol_posts.id),
|
||||
post_action: varchar('post_action', { length: 16 }).notNull(),
|
||||
post_conviction: doublePrecision('post_conviction'),
|
||||
post_at: timestamp('post_at', { mode: 'string', withTimezone: false }).notNull(),
|
||||
change_id: integer('change_id')
|
||||
.notNull()
|
||||
.references(() => kol_holding_changes.id),
|
||||
onchain_action: varchar('onchain_action', { length: 16 }).notNull(),
|
||||
usd_before: doublePrecision('usd_before'),
|
||||
usd_after: doublePrecision('usd_after'),
|
||||
onchain_at: timestamp('onchain_at', { mode: 'string', withTimezone: false }).notNull(),
|
||||
signal_type: varchar('signal_type', { length: 16 }).notNull(),
|
||||
direction: varchar('direction', { length: 8 }),
|
||||
days_apart: doublePrecision('days_apart'),
|
||||
created_at: timestamp('created_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
},
|
||||
(t) => [
|
||||
index('ix_kol_divergence_handle').on(t.handle),
|
||||
uniqueIndex('uq_kol_divergence_pair').on(t.post_id, t.change_id),
|
||||
],
|
||||
)
|
||||
|
||||
export const telegram_bindings = pgTable(
|
||||
'telegram_bindings',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
wallet_address: varchar('wallet_address', { length: 64 }),
|
||||
chat_id: bigint('chat_id', { mode: 'number' }).notNull().unique(),
|
||||
tg_username: varchar('tg_username', { length: 64 }),
|
||||
bound_at: timestamp('bound_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
alerts_enabled: boolean('alerts_enabled').notNull().default(true),
|
||||
alert_trump: boolean('alert_trump').notNull().default(true),
|
||||
alert_btc_bottom: boolean('alert_btc_bottom').notNull().default(true),
|
||||
alert_funding: boolean('alert_funding').notNull().default(true),
|
||||
alert_kol_divergence: boolean('alert_kol_divergence').notNull().default(false),
|
||||
min_confidence: integer('min_confidence').notNull().default(70),
|
||||
mute_from_hour: integer('mute_from_hour'),
|
||||
mute_until_hour: integer('mute_until_hour'),
|
||||
last_alert_at: timestamp('last_alert_at', { mode: 'string', withTimezone: false }),
|
||||
total_alerts_sent: integer('total_alerts_sent').notNull().default(0),
|
||||
total_alerts_failed: integer('total_alerts_failed').notNull().default(0),
|
||||
digest_enabled: boolean('digest_enabled').notNull().default(true),
|
||||
digest_hour_utc: integer('digest_hour_utc').notNull().default(12),
|
||||
last_digest_sent_at: timestamp('last_digest_sent_at', { mode: 'string', withTimezone: false }),
|
||||
},
|
||||
(t) => [
|
||||
index('ix_telegram_bindings_wallet_address').on(t.wallet_address),
|
||||
index('ix_telegram_bindings_chat_id').on(t.chat_id),
|
||||
uniqueIndex('uq_telegram_wallet_nonnull')
|
||||
.on(t.wallet_address)
|
||||
.where(sql`${t.wallet_address} IS NOT NULL`),
|
||||
],
|
||||
)
|
||||
|
||||
export const macro_snapshots = pgTable(
|
||||
'macro_snapshots',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
snapshot_date: date('snapshot_date', { mode: 'string' }).notNull().unique(),
|
||||
captured_at: timestamp('captured_at', { mode: 'string', withTimezone: false })
|
||||
.notNull()
|
||||
.default(sql`timezone('utc', now())`),
|
||||
ahr999: doublePrecision('ahr999'),
|
||||
altcoin_season_index: doublePrecision('altcoin_season_index'),
|
||||
fear_greed: integer('fear_greed'),
|
||||
fear_greed_label: varchar('fear_greed_label', { length: 32 }),
|
||||
btc_dominance_pct: doublePrecision('btc_dominance_pct'),
|
||||
eth_btc_ratio: doublePrecision('eth_btc_ratio'),
|
||||
stablecoin_supply_usd: doublePrecision('stablecoin_supply_usd'),
|
||||
etf_flow_net_usd_1d: doublePrecision('etf_flow_net_usd_1d'),
|
||||
btc_open_interest_usd: doublePrecision('btc_open_interest_usd'),
|
||||
composite_score: doublePrecision('composite_score'),
|
||||
regime_label: varchar('regime_label', { length: 16 }),
|
||||
raw_json: text('raw_json'),
|
||||
},
|
||||
(t) => [index('ix_macro_snapshots_snapshot_date').on(t.snapshot_date)],
|
||||
)
|
||||
|
||||
export const signature_replays = pgTable(
|
||||
'signature_replays',
|
||||
{
|
||||
signature_hash: varchar('signature_hash', { length: 64 }).primaryKey(),
|
||||
expires_at: bigint('expires_at', { mode: 'number' }).notNull(),
|
||||
},
|
||||
(t) => [index('ix_signature_replays_expiry').on(t.expires_at)],
|
||||
)
|
||||
|
||||
export const runtime_state = pgTable('runtime_state', {
|
||||
key: text('key').primaryKey(),
|
||||
value: jsonb('value'),
|
||||
updated_at: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
export const runtime_events = pgTable('runtime_events', {
|
||||
id: serial('id').primaryKey(),
|
||||
payload: jsonb('payload').notNull(),
|
||||
created_at: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
export const live_prices = pgTable('live_prices', {
|
||||
asset: varchar('asset', { length: 16 }).primaryKey(),
|
||||
price: doublePrecision('price').notNull(),
|
||||
updated_at: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user