diff --git a/src/server/backtest/grid.ts b/src/server/backtest/grid.ts index 3e1adfa..90580d2 100644 --- a/src/server/backtest/grid.ts +++ b/src/server/backtest/grid.ts @@ -118,7 +118,7 @@ export function runGridBacktest(candles15ByPair: Map, cfg: GridC const c4h = aggregateTf(c15, p.tfMs); return { pair, c4h, atr: atr(c4h, p.atrPeriod), adx: adx(c4h, p.atrPeriod), next4h: 0 }; }); - const byPair = new Map(contexts.map((c) => [c.pair, c])); + const byPair = new Map(contexts.map((c) => [c.pair, c])); const timeline: { ts: number; pair: Pair; candle: Candle }[] = []; for (const ctx of contexts) { @@ -126,7 +126,7 @@ export function runGridBacktest(candles15ByPair: Map, cfg: GridC if (candle.ts < cfg.tradeTo) timeline.push({ ts: candle.ts, pair: ctx.pair, candle }); } } - timeline.sort((a, b) => a.ts - b.ts || PAIRS.indexOf(a.pair) - PAIRS.indexOf(b.pair)); + timeline.sort((a, b) => a.ts - b.ts || PAIRS.indexOf(a.pair as (typeof PAIRS)[number]) - PAIRS.indexOf(b.pair as (typeof PAIRS)[number])); let lastEquityBucket = -1; diff --git a/src/server/backtest/runner.ts b/src/server/backtest/runner.ts index 71ea441..55eb1be 100644 --- a/src/server/backtest/runner.ts +++ b/src/server/backtest/runner.ts @@ -50,7 +50,7 @@ export function runBacktest(candles15ByPair: Map, cfg: BacktestC if (candle.ts < cfg.tradeTo) timeline.push({ ts: candle.ts, pair: ctx.pair, candle }); } } - timeline.sort((a, b) => a.ts - b.ts || PAIRS.indexOf(a.pair) - PAIRS.indexOf(b.pair)); + timeline.sort((a, b) => a.ts - b.ts || PAIRS.indexOf(a.pair as (typeof PAIRS)[number]) - PAIRS.indexOf(b.pair as (typeof PAIRS)[number])); const byPair = new Map(contexts.map((c) => [c.pair, c])); let lastEquityBucket = -1; diff --git a/src/server/live/grid-cycle.ts b/src/server/live/grid-cycle.ts index 0cf0d9f..fdbdb5a 100644 --- a/src/server/live/grid-cycle.ts +++ b/src/server/live/grid-cycle.ts @@ -98,7 +98,7 @@ export function processGridCycle( if (candle.ts > state.cursorTs) timeline.push({ ts: candle.ts, pair: ctx.pair, candle }); } } - timeline.sort((a, b) => a.ts - b.ts || PAIRS.indexOf(a.pair) - PAIRS.indexOf(b.pair)); + timeline.sort((a, b) => a.ts - b.ts || PAIRS.indexOf(a.pair as (typeof PAIRS)[number]) - PAIRS.indexOf(b.pair as (typeof PAIRS)[number])); const sell = (pair: Pair, ts: number, price: number, lot: GridLot, reason: ClosedTrade['exitReason']): void => { const fill = price * (1 - exec.slippage); diff --git a/src/server/live/process-cycle.ts b/src/server/live/process-cycle.ts index ce7bb7d..196e11e 100644 --- a/src/server/live/process-cycle.ts +++ b/src/server/live/process-cycle.ts @@ -82,7 +82,7 @@ export function processCycle( } return { pair, c4h, ind: computeIndicators(c4h, cfg.params), next4h }; }); - const byPair = new Map(contexts.map((c) => [c.pair, c])); + const byPair = new Map(contexts.map((c) => [c.pair, c])); const timeline: { ts: number; pair: Pair; candle: Candle }[] = []; for (const ctx of contexts) { @@ -90,7 +90,7 @@ export function processCycle( if (candle.ts > state.cursorTs) timeline.push({ ts: candle.ts, pair: ctx.pair, candle }); } } - timeline.sort((a, b) => a.ts - b.ts || PAIRS.indexOf(a.pair) - PAIRS.indexOf(b.pair)); + timeline.sort((a, b) => a.ts - b.ts || PAIRS.indexOf(a.pair as (typeof PAIRS)[number]) - PAIRS.indexOf(b.pair as (typeof PAIRS)[number])); let cursorTs = state.cursorTs; let lastEquityBucket = -1; diff --git a/src/server/scripts/backfill.ts b/src/server/scripts/backfill.ts index c80c563..d9ed5d2 100644 --- a/src/server/scripts/backfill.ts +++ b/src/server/scripts/backfill.ts @@ -1,4 +1,4 @@ -import { PAIRS } from '../types'; +import { ALL_PAIRS } from '../types'; import { fetchCandles } from '../market/cryptocom'; import { insertCandles, getCoverage } from '../market/candle-store'; import { sql } from '../db/client'; @@ -7,7 +7,7 @@ const M15 = 15 * 60 * 1000; const TARGET_MONTHS = 36; const since = Date.now() - TARGET_MONTHS * 30 * 24 * 60 * 60 * 1000; -for (const pair of PAIRS) { +for (const pair of ALL_PAIRS) { let endTs: number | undefined = undefined; let total = 0; let prevOldest: number | undefined = undefined; diff --git a/src/server/types.ts b/src/server/types.ts index 5d35099..275a481 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -8,4 +8,14 @@ export interface Candle { } export const PAIRS = ['BTC_USDT', 'ETH_USDT', 'SOL_USDT', 'XRP_USDT'] as const; -export type Pair = (typeof PAIRS)[number]; + +/** Handels-Universum der Trump-Engine (Schnittmenge Mapping × Crypto.com-USDT-Paare). */ +export const TRUMP_PAIRS = [ + 'BTC_USDT', 'ETH_USDT', 'SOL_USDT', 'XRP_USDT', + 'LINK_USDT', 'AAVE_USDT', 'ONDO_USDT', 'ENA_USDT', 'SUI_USDT', 'SEI_USDT', +] as const; + +export type Pair = (typeof PAIRS)[number] | (typeof TRUMP_PAIRS)[number]; + +/** Vereinigung beider Universen — für Candle-Backfill. */ +export const ALL_PAIRS: readonly Pair[] = [...new Set([...PAIRS, ...TRUMP_PAIRS])];