From c050829b3a028361b6ed0e062e513fb57d7b6aa9 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Mon, 16 Mar 2026 12:30:14 -0700 Subject: [PATCH] Feat: Split paper/live tracking, orderbook pricing --- lib/strategies/threshold.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/strategies/threshold.js b/lib/strategies/threshold.js index 19203b3..0185019 100644 --- a/lib/strategies/threshold.js +++ b/lib/strategies/threshold.js @@ -5,20 +5,24 @@ export class ThresholdStrategy extends BaseStrategy { super('threshold', { triggerPct: config.triggerPct || 65, betSize: config.betSize || 1, - cooldownMs: config.cooldownMs || 90000, + slippage: config.slippage || 3, + cooldownMs: config.cooldownMs || 30000, ...config }); - this.lastTradeTime = 0; - this.lastTradeTicker = null; + this._lastTrade = { + paper: { time: 0, ticker: null }, + live: { time: 0, ticker: null } + }; } - evaluate(state) { + evaluate(state, caller = 'paper') { if (!state || !this.enabled) return null; + const track = this._lastTrade[caller] || this._lastTrade.paper; const now = Date.now(); - if (now - this.lastTradeTime < this.config.cooldownMs) return null; - if (state.ticker === this.lastTradeTicker) return null; + if (now - track.time < this.config.cooldownMs) return null; + if (state.ticker === track.ticker) return null; const { yesPct, noPct } = state; const trigger = this.config.triggerPct; @@ -30,6 +34,7 @@ export class ThresholdStrategy extends BaseStrategy { strategy: this.name, side: 'no', price: noPct, + maxPrice: Math.min(noPct + this.config.slippage, 95), size: this.config.betSize, reason: `Yes at ${yesPct}% (≥${trigger}%), contrarian No at ${noPct}¢`, ticker: state.ticker @@ -39,6 +44,7 @@ export class ThresholdStrategy extends BaseStrategy { strategy: this.name, side: 'yes', price: yesPct, + maxPrice: Math.min(yesPct + this.config.slippage, 95), size: this.config.betSize, reason: `No at ${noPct}% (≥${trigger}%), contrarian Yes at ${yesPct}¢`, ticker: state.ticker @@ -46,8 +52,8 @@ export class ThresholdStrategy extends BaseStrategy { } if (signal) { - this.lastTradeTime = now; - this.lastTradeTicker = state.ticker; + track.time = now; + track.ticker = state.ticker; } return signal; @@ -56,7 +62,7 @@ export class ThresholdStrategy extends BaseStrategy { toJSON() { return { ...super.toJSON(), - lastTradeTicker: this.lastTradeTicker + lastTradeTicker: this._lastTrade.live.ticker || this._lastTrade.paper.ticker }; } }