Files
KalBot/lib/strategies/dont-doubt-bull.js

55 lines
1.5 KiB
JavaScript

import { BaseStrategy } from './base.js';
export class DontDoubtBullStrategy extends BaseStrategy {
constructor(config = {}) {
super('dont-doubt-bull', {
minYesPct: config.minYesPct || 30,
maxYesPct: config.maxYesPct || 40,
betSize: config.betSize || 2,
slippage: config.slippage || 3,
cooldownMs: config.cooldownMs || 20000,
...config
});
this._lastTrade = {
paper: { time: 0, ticker: null },
live: { time: 0, ticker: null }
};
}
evaluate(state, caller = 'paper') {
if (!state || !this.enabled || !state.closeTime) return null;
const track = this._lastTrade[caller] || this._lastTrade.paper;
const now = Date.now();
if (now - track.time < this.config.cooldownMs) return null;
if (state.ticker === track.ticker) return null;
const timeLeftMs = new Date(state.closeTime).getTime() - now;
const minsLeft = timeLeftMs / 60000;
if (minsLeft > 14 || minsLeft < 10) return null;
const { yesPct } = state;
if (yesPct >= this.config.minYesPct && yesPct <= this.config.maxYesPct) {
const maxPrice = Math.min(yesPct + this.config.slippage, 95);
const signal = {
strategy: this.name,
side: 'yes',
price: yesPct,
maxPrice,
size: this.config.betSize,
reason: `Early Bullish Dip: ${minsLeft.toFixed(1)}m left, Yes @ ${yesPct}¢`,
ticker: state.ticker
};
track.time = now;
track.ticker = state.ticker;
return signal;
}
return null;
}
}