Files
KalBot/lib/strategies/base.js

45 lines
1.2 KiB
JavaScript

/**
* Base strategy class. All strategies extend this.
*
* Strategies receive market state updates and emit trade signals.
* Signals are { side: 'yes'|'no', price: number, maxPrice: number, size: number, reason: string }
*
* `price` = ideal/target price in cents
* `maxPrice` = maximum acceptable fill price (slippage tolerance)
*/
export class BaseStrategy {
constructor(name, config = {}) {
this.name = name;
this.config = config;
this.enabled = true;
this.mode = 'paper';
}
/**
* Called on every market state update.
* @param {object} marketState - includes yesPct, noPct, orderbook, ticker, closeTime, etc.
* @param {string} caller - 'paper' | 'live' — so strategies can track per-caller state
* Return a signal object or null.
*/
evaluate(marketState, caller = 'paper') {
throw new Error(`${this.name}: evaluate() not implemented`);
}
/**
* Called when a market settles. Useful for strategies that
* need to know outcomes (like Martingale).
*/
onSettlement(result, tradeHistory) {
// Override in subclass if needed
}
toJSON() {
return {
name: this.name,
enabled: this.enabled,
mode: this.mode,
config: this.config
};
}
}