TypeScript futures bot for Binance USD-M, Bybit linear, and OKX swap markets. Strategy logic is exchange-agnostic; each venue is wrapped behind a normalized adapter.
Market Data ──► Strategy ──► Risk ──► Execution ──► Exchange Adapter
│ │ │ │
└──────────────┴─────────┴──────────┴──► State Store
| Layer | Responsibility |
|---|---|
| Market data | WebSocket tickers, order books, funding, fills |
| Strategy | Momentum breakout + funding bias → normalized signals |
| Risk | Kelly sizing (stake-math), leverage cap, daily loss kill switch, cooldowns |
| Execution | Entry + stop-loss + take-profit order lifecycle |
| State store | Positions, PnL, signals, kill-switch (extend with Redis/PostgreSQL) |
cp .env.example .env
npm install
npm run paper # paper + testnet (default)Switch exchange via EXCHANGE=binance|bybit|okx in .env.
import { computeFuturesKellyStake } from './risk/position-sizing.js';
const stakeUsd = computeFuturesKellyStake({
winProbability: 0.58,
riskRewardRatio: 2,
bankroll: 10_000,
maxStakeUsd: 500,
minStakeUsd: 10,
kellyFraction: 0.5, // half-Kelly
});| Exchange | REST | WebSocket | Notes |
|---|---|---|---|
| Binance | /fapi/v1/* |
fstream.binance.com |
reduceOnly, hedge positionSide |
| Bybit | /v5/* |
v5 public/private linear | Unified account, strict position mode |
| OKX | /api/v5/* |
v5 public/private | BTC-USDT-SWAP instId, demo via x-simulated-trading |
All adapters implement ExchangeAdapter and return normalized NormalizedOrder, Position, Ticker, etc.
- Max leverage (default 5×, below exchange max)
- Max position notional
- Daily loss kill switch
- Consecutive API error kill switch
- Per-symbol cooldown
- Half-Kelly stake sizing with min/max bounds
- Redis — distributed locks, live state cache
- PostgreSQL — trades, signals, audit log (see
StatePersistenceinsrc/state/store.ts) - Kafka/RabbitMQ — async signal → execution pipeline
| Command | Description |
|---|---|
npm run build |
Compile TypeScript |
npm run dev |
Run with tsx |
npm run paper |
Paper trading mode |
npm start |
Run compiled dist/index.js |
- Binance USD-M on testnet with
PAPER_TRADING=true - Validate WebSocket feeds and order lifecycle
- Tune risk limits and Kelly fraction
- Enable live keys only after sustained paper results
- Add Bybit / OKX by changing
EXCHANGE
This software is for educational purposes. Futures trading carries substantial risk of loss. Test thoroughly on testnet/paper before using real funds.