mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-16 21:41:02 +00:00
Feat: Base strategy interface for all strategies
This commit is contained in:
39
lib/strategies/base.js
Normal file
39
lib/strategies/base.js
Normal 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
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user