Feat: Split paper/live tracking, orderbook pricing

This commit is contained in:
2026-03-16 12:30:14 -07:00
parent 7ba25a1eaa
commit c050829b3a

View File

@@ -5,20 +5,24 @@ export class ThresholdStrategy extends BaseStrategy {
super('threshold', { super('threshold', {
triggerPct: config.triggerPct || 65, triggerPct: config.triggerPct || 65,
betSize: config.betSize || 1, betSize: config.betSize || 1,
cooldownMs: config.cooldownMs || 90000, slippage: config.slippage || 3,
cooldownMs: config.cooldownMs || 30000,
...config ...config
}); });
this.lastTradeTime = 0; this._lastTrade = {
this.lastTradeTicker = null; paper: { time: 0, ticker: null },
live: { time: 0, ticker: null }
};
} }
evaluate(state) { evaluate(state, caller = 'paper') {
if (!state || !this.enabled) return null; if (!state || !this.enabled) return null;
const track = this._lastTrade[caller] || this._lastTrade.paper;
const now = Date.now(); const now = Date.now();
if (now - this.lastTradeTime < this.config.cooldownMs) return null; if (now - track.time < this.config.cooldownMs) return null;
if (state.ticker === this.lastTradeTicker) return null; if (state.ticker === track.ticker) return null;
const { yesPct, noPct } = state; const { yesPct, noPct } = state;
const trigger = this.config.triggerPct; const trigger = this.config.triggerPct;
@@ -30,6 +34,7 @@ export class ThresholdStrategy extends BaseStrategy {
strategy: this.name, strategy: this.name,
side: 'no', side: 'no',
price: noPct, price: noPct,
maxPrice: Math.min(noPct + this.config.slippage, 95),
size: this.config.betSize, size: this.config.betSize,
reason: `Yes at ${yesPct}% (≥${trigger}%), contrarian No at ${noPct}¢`, reason: `Yes at ${yesPct}% (≥${trigger}%), contrarian No at ${noPct}¢`,
ticker: state.ticker ticker: state.ticker
@@ -39,6 +44,7 @@ export class ThresholdStrategy extends BaseStrategy {
strategy: this.name, strategy: this.name,
side: 'yes', side: 'yes',
price: yesPct, price: yesPct,
maxPrice: Math.min(yesPct + this.config.slippage, 95),
size: this.config.betSize, size: this.config.betSize,
reason: `No at ${noPct}% (≥${trigger}%), contrarian Yes at ${yesPct}¢`, reason: `No at ${noPct}% (≥${trigger}%), contrarian Yes at ${yesPct}¢`,
ticker: state.ticker ticker: state.ticker
@@ -46,8 +52,8 @@ export class ThresholdStrategy extends BaseStrategy {
} }
if (signal) { if (signal) {
this.lastTradeTime = now; track.time = now;
this.lastTradeTicker = state.ticker; track.ticker = state.ticker;
} }
return signal; return signal;
@@ -56,7 +62,7 @@ export class ThresholdStrategy extends BaseStrategy {
toJSON() { toJSON() {
return { return {
...super.toJSON(), ...super.toJSON(),
lastTradeTicker: this.lastTradeTicker lastTradeTicker: this._lastTrade.live.ticker || this._lastTrade.paper.ticker
}; };
} }
} }