feat: Schema für Trump-Engine (trump_events, trump_positions, trump_signal_state)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 07:49:21 +00:00
parent 43b5ed10bd
commit 13cf694673
5 changed files with 867 additions and 1 deletions

View File

@@ -111,3 +111,39 @@ export const backtestRuns = pgTable('backtest_runs', {
config: jsonb('config').notNull(),
result: jsonb('result').notNull(),
});
/** „Trump kauft"-Events (on-chain Transfers in Watchlist-Wallets, Truth-Social-Erwähnungen). */
export const trumpEvents = pgTable(
'trump_events',
{
id: serial('id').primaryKey(),
source: text('source').notNull(), // 'onchain' | 'truth'
token: text('token').notNull(), // Symbol, z. B. 'WBTC', 'TRX'
instrument: varchar('instrument', { length: 16 }), // null = nicht auf Crypto.com handelbar
eventTs: timestamp('event_ts', { withTimezone: true }).notNull(),
ref: text('ref').notNull(), // Tx-Hash bzw. Post-URL
notionalUsd: doublePrecision('notional_usd'), // nur onchain
consumedAt: timestamp('consumed_at', { withTimezone: true }), // null = noch nicht von der Engine verarbeitet
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
},
(t) => [uniqueIndex('trump_events_source_ref_token').on(t.source, t.ref, t.token)],
);
/** Offene Positionen der Trump-Engine (Zeit-Exit, kein Stop). */
export const trumpPositions = pgTable('trump_positions', {
pair: varchar('pair', { length: 16 }).primaryKey(),
qty: doublePrecision('qty').notNull(),
entryTs: timestamp('entry_ts', { withTimezone: true }).notNull(),
entryPrice: doublePrecision('entry_price').notNull(),
entryCost: doublePrecision('entry_cost').notNull(),
riskAmount: doublePrecision('risk_amount').notNull(), // = entryCost → r = Return auf Einsatz
exitDueTs: timestamp('exit_due_ts', { withTimezone: true }).notNull(),
eventId: integer('event_id').notNull(),
});
/** Cursor des On-Chain-Pollers (letzter vollständig gescannter Block). */
export const trumpSignalState = pgTable('trump_signal_state', {
id: integer('id').primaryKey(), // immer 1
lastBlock: integer('last_block').notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
});

View File

@@ -31,7 +31,7 @@ export interface ClosedTrade {
qty: number;
pnl: number;
r: number;
exitReason: 'trailing_stop' | 'end_of_data' | 'rotation' | 'grid_tp' | 'grid_stop';
exitReason: 'trailing_stop' | 'end_of_data' | 'rotation' | 'grid_tp' | 'grid_stop' | 'trump_hold';
side: 'long' | 'short';
}