Feat: Base strategy interface for all strategies

This commit is contained in:
2026-03-15 13:08:42 -07:00
parent d1683eaa11
commit 72d313f286

39
lib/strategies/base.js Normal file
View File

@@ -0,0 +1,39 @@
/**
* Base strategy class. All strategies extend this.
*
* Strategies receive market state updates and emit trade signals.
* Signals are { side: 'yes'|'no', price: number, size: number, reason: string }
*/
export class BaseStrategy {
constructor(name, config = {}) {
this.name = name;
this.config = config;
this.enabled = true;
this.mode = 'paper'; // 'paper' | 'live'
}
/**
* Called on every market state update.
* Return a signal object or null.
*/
evaluate(marketState) {
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
};
}
}