Feat: gate dip buys to first 6 minutes

This commit is contained in:
2026-03-16 14:27:25 -07:00
parent 10827a817c
commit 0cb4a082b1

View File

@@ -8,6 +8,8 @@ export class BullDipBuyer extends BaseStrategy {
betSize: config.betSize || 1, betSize: config.betSize || 1,
slippage: config.slippage || 3, slippage: config.slippage || 3,
cooldownMs: config.cooldownMs || 20000, cooldownMs: config.cooldownMs || 20000,
marketDurationMin: config.marketDurationMin || 15,
entryWindowMin: config.entryWindowMin || 6,
...config ...config
}); });
@@ -18,41 +20,49 @@ export class BullDipBuyer extends BaseStrategy {
} }
evaluate(state, caller = 'paper') { evaluate(state, caller = 'paper') {
if (!state || !this.enabled) return null; if (!state || !this.enabled || !state.closeTime) return null;
const track = this._lastTrade[caller] || this._lastTrade.paper; const track = this._lastTrade[caller] || this._lastTrade.paper;
const now = Date.now(); const now = Date.now();
if (now - track.time < this.config.cooldownMs) return null; if (now - track.time < this.config.cooldownMs) return null;
if (state.ticker === track.ticker) return null; if (state.ticker === track.ticker) return null;
const closeTs = new Date(state.closeTime).getTime();
const timeLeftMs = closeTs - now;
if (!Number.isFinite(timeLeftMs) || timeLeftMs <= 0) return null;
// Entry gate: only trade in first N minutes of each market cycle.
// With 15m markets: first 0-6m elapsed => roughly 15m down to 9m remaining.
const elapsedMin = (this.config.marketDurationMin * 60000 - timeLeftMs) / 60000;
if (elapsedMin < 0 || elapsedMin > this.config.entryWindowMin) return null;
const { yesPct } = state; const { yesPct } = state;
if (yesPct <= this.config.maxYesPrice && yesPct >= this.config.minYesPrice) { if (yesPct <= this.config.maxYesPrice && yesPct >= this.config.minYesPrice) {
// For live trading, require orderbook data — refuse to trade blind // For live trading, require orderbook data — refuse to trade blind
if (caller === 'live') { if (caller === 'live') {
const bestAsk = this._getBestYesAsk(state); const bestAsk = this._getBestYesAsk(state);
if (bestAsk == null) { if (bestAsk == null) return null;
return null;
}
// Verify the actual ask price is within our dip range + slippage // Verify the actual ask price is within our dip range + slippage
if (bestAsk > this.config.maxYesPrice + this.config.slippage) { if (bestAsk > this.config.maxYesPrice + this.config.slippage) return null;
return null;
}
// Don't let slippage push us above 50¢ — that's not a dip // Don't let slippage push us above 50¢ — that's not a dip
if (bestAsk > 50) { if (bestAsk > 50) return null;
return null;
}
} }
const maxPrice = Math.min(yesPct + this.config.slippage, this.config.maxYesPrice + this.config.slippage, 50); const maxPrice = Math.min(
yesPct + this.config.slippage,
this.config.maxYesPrice + this.config.slippage,
50
);
const bestAsk = this._getBestYesAsk(state); const bestAsk = this._getBestYesAsk(state);
let reason = `Bullish dip buy: Yes @ ${yesPct}¢`; let reason = `Bullish dip buy (t+${elapsedMin.toFixed(1)}m): Yes @ ${yesPct}¢`;
if (bestAsk != null) { if (bestAsk != null) {
if (bestAsk > maxPrice) { if (bestAsk > maxPrice) return null;
return null; reason = `Bullish dip buy (t+${elapsedMin.toFixed(1)}m): Yes @ ${yesPct}¢ (ask: ${bestAsk}¢)`;
}
reason = `Bullish dip buy: Yes @ ${yesPct}¢ (ask: ${bestAsk}¢)`;
} }
const signal = { const signal = {