mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-17 05:51:02 +00:00
Feat: Threshold strategy — contrarian bet at extremes
This commit is contained in:
70
lib/strategies/threshold.js
Normal file
70
lib/strategies/threshold.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { BaseStrategy } from './base.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Threshold (Contrarian) Strategy
|
||||||
|
*
|
||||||
|
* Logic:
|
||||||
|
* - If one side goes above a high threshold (e.g. 65%), bet the other.
|
||||||
|
* - Fixed bet size — no progression.
|
||||||
|
* - Simple mean-reversion assumption for short-term BTC markets.
|
||||||
|
*/
|
||||||
|
export class ThresholdStrategy extends BaseStrategy {
|
||||||
|
constructor(config = {}) {
|
||||||
|
super('threshold', {
|
||||||
|
triggerPct: config.triggerPct || 65,
|
||||||
|
betSize: config.betSize || 1,
|
||||||
|
cooldownMs: config.cooldownMs || 90000,
|
||||||
|
...config
|
||||||
|
});
|
||||||
|
|
||||||
|
this.lastTradeTime = 0;
|
||||||
|
this.lastTradeTicker = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate(state) {
|
||||||
|
if (!state || !this.enabled) return null;
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
if (now - this.lastTradeTime < this.config.cooldownMs) return null;
|
||||||
|
if (state.ticker === this.lastTradeTicker) return null;
|
||||||
|
|
||||||
|
const { yesPct, noPct } = state;
|
||||||
|
const trigger = this.config.triggerPct;
|
||||||
|
|
||||||
|
let signal = null;
|
||||||
|
|
||||||
|
if (yesPct >= trigger) {
|
||||||
|
signal = {
|
||||||
|
strategy: this.name,
|
||||||
|
side: 'no',
|
||||||
|
price: noPct,
|
||||||
|
size: this.config.betSize,
|
||||||
|
reason: `Yes at ${yesPct}% (≥${trigger}%), contrarian No at ${noPct}¢`,
|
||||||
|
ticker: state.ticker
|
||||||
|
};
|
||||||
|
} else if (noPct >= trigger) {
|
||||||
|
signal = {
|
||||||
|
strategy: this.name,
|
||||||
|
side: 'yes',
|
||||||
|
price: yesPct,
|
||||||
|
size: this.config.betSize,
|
||||||
|
reason: `No at ${noPct}% (≥${trigger}%), contrarian Yes at ${yesPct}¢`,
|
||||||
|
ticker: state.ticker
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signal) {
|
||||||
|
this.lastTradeTime = now;
|
||||||
|
this.lastTradeTicker = state.ticker;
|
||||||
|
}
|
||||||
|
|
||||||
|
return signal;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJSON() {
|
||||||
|
return {
|
||||||
|
...super.toJSON(),
|
||||||
|
lastTradeTicker: this.lastTradeTicker
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user