This is simple future trading bot for Binance USD-M, Bybit linear and OKX swap markets: binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot binance trading bot
Multi-Exchange Futures Trading Bot
A production-style TypeScript futures trading bot supporting Binance USD-M, Bybit Linear, and OKX Swap markets with exchange-agnostic architecture, Kelly position sizing, and institutional-grade risk management.
Features
- โก Multi-exchange architecture
- ๐ Momentum breakout strategy
- ๐ฐ Kelly Criterion position sizing
- ๐ก Advanced risk management
- ๐ Exchange-agnostic execution engine
- ๐ Funding rate awareness
- ๐ Stop-loss & take-profit lifecycle
- ๐จ Daily loss kill switch
- ๐ API failure circuit breaker
- ๐ Structured logging
- ๐ Production-ready TypeScript codebase
Supported Exchanges
| Exchange | Market | | ---------- | ---------------- | | ๐ก Binance | USD-M Futures | | โซ Bybit | Linear Perpetual | | โช OKX | USDT Swap |
Switch exchanges simply by changing:
EXCHANGE=binance
or
EXCHANGE=bybit
or
EXCHANGE=okx
No strategy code needs to change.
Strategy
The trading engine follows a modular pipeline.
Market Data
โ
โผ
Momentum Strategy
โ
โผ
Funding Bias Filter
โ
โผ
Kelly Position Sizing
โ
โผ
Risk Validation
โ
โผ
Execution Engine
โ
โผ
Exchange Adapter
โ
โผ
Portfolio & State Store
Each layer has a single responsibility, making the system easy to extend and maintain.
Architecture
Market Data
โ
โผ
Strategy Engine
โ
โผ
Risk Management
โ
โผ
Execution Engine
โ
โโโโโโโโโโโโโผโโโโโโโโโโโโโ
โผ โผ โผ
Binance Bybit OKX
โ โ โ
โโโโโโโโโโโโโดโโโโโโโโโโโโโ
โ
โผ
State Store
Every exchange implements the same normalized interface.
The strategy never communicates directly with exchange-specific APIs.
Risk Management
The trading engine includes multiple independent safety systems.
- Kelly-based position sizing
- Maximum leverage limits
- Maximum position notional
- Daily loss kill switch
- Consecutive API error protection
- Per-symbol cooldown timers
- Minimum and maximum position sizing
- Funding-aware execution
Kelly Position Sizing
Position sizing uses STAKE-MATH.
import { computeFuturesKellyStake } from "./risk/position-sizing.js";
const stakeUsd = computeFuturesKellyStake({ winProbability: 0.58, riskRewardRatio: 2, bankroll: 10000, maxStakeUsd: 500, minStakeUsd: 10, kellyFraction: 0.5 });
Inputs include:
- Win probability
- Risk/Reward ratio
- Current bankroll
- Fractional Kelly
- Minimum stake
- Maximum stake
Exchange Adapters
Every supported exchange is normalized behind a common interface.
| Exchange | REST | WebSocket | Notes | | -------- | ------------ | --------------------- | ---------------------- | | Binance | /fapi/v1/* | fstream.binance.com | Hedge mode, reduceOnly | | Bybit | /v5/* | V5 Public & Private | Unified Account | | OKX | /api/v5/* | V5 Public & Private | Demo & Production |
Adapters return normalized objects including:
- Orders
- Positions
- Tickers
- Funding Rates
- Balances
- Fills
Project Structure
src/
โโโ strategy/ โ โโโ Momentum breakout
โโโ market/ โ โโโ WebSocket market data
โโโ execution/ โ โโโ Order lifecycle
โโโ risk/ โ โโโ Kelly sizing & protection
โโโ exchange/ โ โโโ Binance โ โโโ Bybit โ โโโ OKX
โโโ state/ โ โโโ Portfolio & persistence
โโโ util/ โ โโโ Logging & helpers
โโโ index.ts
Quick Start
cp .env.example .env
npm install
npm run paper
Paper trading is enabled by default.
Switch exchanges through:
EXCHANGE=binance
or
EXCHANGE=bybit
or
EXCHANGE=okx
Available Scripts
| Command | Description | | --------------- | ------------------------ | | npm run build | Compile TypeScript | | npm run dev | Run with tsx | | npm run paper | Paper trading | | npm start | Run compiled application |
My Recommendation
If you're building automated trading systems:
- start with paper trading
- verify every signal manually
- validate execution under different market conditions
- backtest before deploying live capital
- increase position size gradually
- never trade with money you cannot afford to lose
Happy Trading โค๏ธ
Contributing
Contributions are welcome.
Whether you're interested in:
- quantitative trading
- exchange integrations
- TypeScript
- distributed systems
- software architecture
- performance optimization
Disclaimer
This repository is provided for educational purposes only.
Nothing contained here should be interpreted as financial advice.
Futures trading carries substantial financial risk and the potential for significant losses.
Always validate strategies through extensive backtesting and paper trading before deploying real capital.
Never risk funds you cannot afford to lose.
Built with โค๏ธ for quantitative traders and TypeScript developers.
If this repository helped you learn something new, consider giving it a โญ.