Refactor: Register new strategies in worker

This commit is contained in:
2026-03-15 20:44:34 -07:00
parent caca6d29b6
commit 2948312619

View File

@@ -3,6 +3,10 @@ import { PaperEngine } from './lib/paper/engine.js';
import { MartingaleStrategy } from './lib/strategies/martingale.js'; import { MartingaleStrategy } from './lib/strategies/martingale.js';
import { MartingaleAlphaStrategy } from './lib/strategies/martingale-alpha.js'; import { MartingaleAlphaStrategy } from './lib/strategies/martingale-alpha.js';
import { ThresholdStrategy } from './lib/strategies/threshold.js'; import { ThresholdStrategy } from './lib/strategies/threshold.js';
import { BullDipBuyer } from './lib/strategies/bull-dip-buyer.js';
import { SniperReversalStrategy } from './lib/strategies/sniper-reversal.js';
import { MomentumRiderStrategy } from './lib/strategies/momentum-rider.js';
import { DontDoubtBullStrategy } from './lib/strategies/dont-doubt-bull.js';
import { getMarket } from './lib/kalshi/rest.js'; import { getMarket } from './lib/kalshi/rest.js';
import { db } from './lib/db.js'; import { db } from './lib/db.js';
import { notify } from './lib/notify.js'; import { notify } from './lib/notify.js';
@@ -19,10 +23,15 @@ async function main() {
const paper = new PaperEngine(1000); const paper = new PaperEngine(1000);
await paper.init(); await paper.init();
// Load all 7 strategies!
const strategies = [ const strategies = [
new MartingaleStrategy({ threshold: 70, baseBet: 1, maxDoublings: 5 }), new MartingaleStrategy({ threshold: 70, baseBet: 1, maxDoublings: 5 }),
new MartingaleAlphaStrategy({ minPct: 40, maxPct: 60, baseBet: 1, maxRounds: 3 }), new MartingaleAlphaStrategy({ minPct: 40, maxPct: 60, baseBet: 1, maxRounds: 3 }),
new ThresholdStrategy({ triggerPct: 65, betSize: 1 }) new ThresholdStrategy({ triggerPct: 65, betSize: 1 }),
new BullDipBuyer({ maxYesPrice: 45, minYesPrice: 15, betSize: 2 }),
new SniperReversalStrategy({ triggerPct: 95, minsLeft: 3, betSize: 1 }),
new MomentumRiderStrategy({ triggerPct: 75, betSize: 2 }),
new DontDoubtBullStrategy({ minYesPct: 30, maxYesPct: 40, betSize: 2 })
]; ];
for (const s of strategies) { for (const s of strategies) {
@@ -33,7 +42,6 @@ async function main() {
let latestMarketState = null; let latestMarketState = null;
// Handles markets that rotated BEFORE Kalshi posted the final result
async function processOrphans() { async function processOrphans() {
if (paper._resetting) return; if (paper._resetting) return;
try { try {
@@ -54,7 +62,6 @@ async function main() {
} }
} }
// Check orphans immediately on startup, then every 60 seconds
await processOrphans(); await processOrphans();
setInterval(processOrphans, 60000); setInterval(processOrphans, 60000);
@@ -72,9 +79,6 @@ async function main() {
for (const strategy of strategies) { for (const strategy of strategies) {
if (!strategy.enabled) continue; if (!strategy.enabled) continue;
// FIX: Prevent parallel betting!
// If the strategy has an unresolved position in limbo, it MUST wait.
// This protects the strict mathematical sequence of Martingale systems.
const acct = paper._getAccount(strategy.name); const acct = paper._getAccount(strategy.name);
if (acct.openPositions.size > 0) { if (acct.openPositions.size > 0) {
continue; continue;
@@ -114,14 +118,14 @@ async function main() {
); );
} }
} else { } else {
console.log(`[Worker] Result for ${ticker} pending. Background poller will handle it when Kalshi publishes the outcome.`); console.log(`[Worker] Result for ${ticker} pending.`);
} }
writeState(latestMarketState, paper, strategies); writeState(latestMarketState, paper, strategies);
}); });
await tracker.start(); await tracker.start();
await notify('🤖 Kalbot Worker started!', 'Kalbot Online', 'low', 'robot,green_circle'); await notify('🤖 Kalbot Worker started with 7 strats!', 'Kalbot Online', 'low', 'robot,green_circle');
heartbeatTimer = setInterval(() => { heartbeatTimer = setInterval(() => {
writeState(latestMarketState, paper, strategies); writeState(latestMarketState, paper, strategies);