apexbot 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +307 -0
- package/dist/adapters/manifold.js +166 -0
- package/dist/adapters/telegram.js +133 -0
- package/dist/agent/agentManager.js +315 -0
- package/dist/backtest/backtester.js +24 -0
- package/dist/channels/channelManager.js +72 -0
- package/dist/channels/discord.js +136 -0
- package/dist/channels/telegram.js +186 -0
- package/dist/cli/index.js +838 -0
- package/dist/core/eventBus.js +33 -0
- package/dist/decisionEngine.js +69 -0
- package/dist/eventBus.js +21 -0
- package/dist/gateway/dashboard.js +1009 -0
- package/dist/gateway/index.js +303 -0
- package/dist/index.js +195 -0
- package/dist/math/ev.js +25 -0
- package/dist/math/kelly.js +24 -0
- package/dist/rateLimiter.js +42 -0
- package/dist/safety/failsafe.js +32 -0
- package/dist/safety/llmChecker.js +148 -0
- package/dist/sessions/sessionManager.js +120 -0
- package/dist/strategy/arbitrage.js +151 -0
- package/package.json +78 -0
- package/scripts/install.ps1 +114 -0
- package/scripts/install.sh +146 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core Event Bus - typed events for the entire system
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.once = exports.emit = exports.off = exports.on = void 0;
|
|
10
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
11
|
+
// Typed event emitter
|
|
12
|
+
class TypedEventEmitter {
|
|
13
|
+
emitter = new eventemitter3_1.default();
|
|
14
|
+
on(event, listener) {
|
|
15
|
+
this.emitter.on(event, listener);
|
|
16
|
+
}
|
|
17
|
+
off(event, listener) {
|
|
18
|
+
this.emitter.off(event, listener);
|
|
19
|
+
}
|
|
20
|
+
emit(event, data) {
|
|
21
|
+
this.emitter.emit(event, data);
|
|
22
|
+
}
|
|
23
|
+
once(event, listener) {
|
|
24
|
+
this.emitter.once(event, listener);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Singleton instance
|
|
28
|
+
const bus = new TypedEventEmitter();
|
|
29
|
+
exports.on = bus.on.bind(bus);
|
|
30
|
+
exports.off = bus.off.bind(bus);
|
|
31
|
+
exports.emit = bus.emit.bind(bus);
|
|
32
|
+
exports.once = bus.once.bind(bus);
|
|
33
|
+
exports.default = bus;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DecisionEngine = void 0;
|
|
7
|
+
const ev_1 = require("./math/ev");
|
|
8
|
+
const kelly_1 = require("./math/kelly");
|
|
9
|
+
const rateLimiter_1 = __importDefault(require("./rateLimiter"));
|
|
10
|
+
const failsafe_1 = __importDefault(require("./safety/failsafe"));
|
|
11
|
+
const eventBus_1 = require("./eventBus");
|
|
12
|
+
class DecisionEngine {
|
|
13
|
+
cfg;
|
|
14
|
+
bankroll;
|
|
15
|
+
limiter;
|
|
16
|
+
failsafe;
|
|
17
|
+
constructor(cfg) {
|
|
18
|
+
this.cfg = cfg;
|
|
19
|
+
this.bankroll = cfg.bankroll;
|
|
20
|
+
this.limiter = new rateLimiter_1.default(cfg.rateLimitCapacity, cfg.rateLimitRatePerSec);
|
|
21
|
+
this.failsafe = new failsafe_1.default(cfg.failsafe, this.bankroll);
|
|
22
|
+
(0, eventBus_1.on)('market:update', (m) => this.onMarketUpdate(m));
|
|
23
|
+
}
|
|
24
|
+
placeOrder(marketId, side, stake) {
|
|
25
|
+
if (!this.limiter.tryRemove(1)) {
|
|
26
|
+
(0, eventBus_1.emit)('strategy:alert', `rate_limited:${marketId}`);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
// Placeholder: integrate Manifold API here (authenticated requests)
|
|
30
|
+
const order = { marketId, side, stake, ts: Date.now() };
|
|
31
|
+
(0, eventBus_1.emit)('order:placed', order);
|
|
32
|
+
return order;
|
|
33
|
+
}
|
|
34
|
+
onMarketUpdate(m) {
|
|
35
|
+
// Basic flow:
|
|
36
|
+
// 1) get model probability (from tick or internal model)
|
|
37
|
+
const prob = m.probModel ?? 0.5;
|
|
38
|
+
const price = m.price;
|
|
39
|
+
// 2) compute EV for buy
|
|
40
|
+
const ev = (0, ev_1.expectedValueForBuy)(price, prob);
|
|
41
|
+
if (ev <= 0)
|
|
42
|
+
return; // no edge
|
|
43
|
+
// 3) compute Kelly fraction and stake
|
|
44
|
+
const fKelly = (0, kelly_1.kellyFraction)(price, prob);
|
|
45
|
+
const f = Math.min(1, fKelly * this.cfg.riskMultiplier);
|
|
46
|
+
const rawStake = this.bankroll * f;
|
|
47
|
+
const stake = Math.max(this.cfg.minStake, Math.min(this.cfg.maxStake, rawStake));
|
|
48
|
+
// 4) check failsafe
|
|
49
|
+
const shouldStop = this.failsafe.shouldStop(this.bankroll);
|
|
50
|
+
if (shouldStop.stop) {
|
|
51
|
+
(0, eventBus_1.emit)('strategy:alert', `failsafe:stop:${shouldStop.reason}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// 5) place order
|
|
55
|
+
const order = this.placeOrder(m.marketId, 'buy', stake);
|
|
56
|
+
return order;
|
|
57
|
+
}
|
|
58
|
+
// call when an order fills / result known
|
|
59
|
+
onTradeResult(pnl) {
|
|
60
|
+
this.bankroll += pnl;
|
|
61
|
+
this.failsafe.onTradeResult(this.bankroll, pnl);
|
|
62
|
+
(0, eventBus_1.emit)('strategy:alert', `trade_result:pnl=${pnl.toFixed(4)} bankroll=${this.bankroll.toFixed(4)}`);
|
|
63
|
+
}
|
|
64
|
+
getBankroll() {
|
|
65
|
+
return this.bankroll;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.DecisionEngine = DecisionEngine;
|
|
69
|
+
exports.default = DecisionEngine;
|
package/dist/eventBus.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.bus = void 0;
|
|
7
|
+
exports.emit = emit;
|
|
8
|
+
exports.on = on;
|
|
9
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
10
|
+
exports.bus = new eventemitter3_1.default();
|
|
11
|
+
// typed emitter usage helper
|
|
12
|
+
function emit(ev, payload) {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
exports.bus.emit(ev, payload);
|
|
16
|
+
}
|
|
17
|
+
function on(ev, cb) {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
exports.bus.on(ev, cb);
|
|
20
|
+
}
|
|
21
|
+
exports.default = exports.bus;
|