Sio Bot is a Bun + TypeScript trading bot built around a modular runtime, configurable strategy stack, paper/live exchange adapters, a backtesting engine, and an optimizer for searching strategy parameters. It relies on the sio-Nexus project for realtime and historical market data over Unix sockets: sergi-io/sio-nexus.
This project is licensed under the GNU General Public License v3.0 only. See LICENSE.
The project is organized to support three main workflows:
- realtime trading in paper mode or live mode
- offline backtesting and configuration optimization
- post-trade reporting through a generated trading journal
- Connects to sio-Nexus for market data and historical klines
- Runs a configurable strategy pipeline with TA, risk, order, and position managers
- Supports paper trading with persisted local state
- Supports live execution on Phemex
- Runs backtests on historical data
- Optimizes bot configuration with brute force or a genetic algorithm
- Generates a static HTML trading journal from recorded position history
- Includes terminal dashboards for indicators and Nexus data
High-level runtime flow:
- Load
.envandbot-config.json - Choose exchange adapter:
PaperTradeExchangefor realtime paper tradingPhemexExchangefor live tradingFakeExchangefor backtests
- Warm up kline buffers from Nexus/history
- Feed klines into the TA manager
- Evaluate enter/exit strategies
- Apply risk rules and sizing
- Open/close positions and persist results
- Regenerate the journal when positions are closed
Core modules:
src/siobot/: main runtime orchestrationsrc/strategies/: enter and exit strategy implementationssrc/risk/: leverage, sizing, and stop/risk controlssrc/exchanges/: Phemex, paper-trade, fake exchange, Nexus clientssrc/ta/: indicator implementations and terminal dashboardsrc/backtester/: backtest runner, reports, optimizersrc/journal/: static journal generationsrc/utils/db/: SQLite persistence for paper-trade state and position history
- Bun
- A running
sio-nexusinstance from sergi-io/sio-nexus - Unix socket access to Nexus query and aggregate feeds
- Phemex API credentials if you want to trade live
- Install dependencies:
bun install- Create your local environment file:
cp .env-sample .env- Review and update:
bot-config.json- Nexus socket paths
- Telegram settings
- paper-trade or live-trade settings
- backtest date range
-
Start sio-Nexus.
-
Run the bot in paper mode:
bun run devBy default, paper mode is controlled by SIOBOT_PAPER_TRADE_ENABLED=true in .env.
Set it to false only when you are ready to use live exchange execution.
The bot reads configuration from two places:
.env: environment, logging, exchange credentials, journal, sockets, deploy settingsbot-config.json: trading symbol, timeframes, strategy toggles, optimizer weights, risk limits
Important environment variables:
SIOBOT_PAPER_TRADE_ENABLEDSIOBOT_PAPER_TRADE_INITIAL_BALANCESIOBOT_EXCHANGE_ID(phemexorbitget)SIOBOT_PHEMEX_API_IDSIOBOT_PHEMEX_API_SECRETSIOBOT_BITGET_API_KEYSIOBOT_BITGET_API_SECRETSIOBOT_BITGET_PASSWORDSIOBOT_BITGET_TESTNET_ENABLEDSIOBOT_BACK_TEST_DATE_STARTSIOBOT_BACK_TEST_DATE_ENDSIOBOT_LOG_ENABLEDSIOBOT_LOG_LEVELSIOBOT_JOURNAL_DIRSIOBOT_NEXUS_AGGR_SOCKET_PATHSIOBOT_NEXUS_QUERY_SOCKET_PATH
Important bot-config.json fields:
assetSymboltimeFramesFromNexustimeFrameToTradetimeFrameToDetectRegimeregimePrefilter_EnabledregimePrefilter_EMAPeriod- risk settings such as leverage and order sizing
- enter strategy flags and parameters
- exit strategy flags and parameters
- genetic optimizer population, generations, and scoring weights
bun run dev
bun run dev:indicators
bun run indicator-dashboard
bun run nexus-info
bun run nexus-dashboardbun run dev: watch mode, generates journal templates, then runssrc/main.ts runbun run dev:indicators: watch mode with indicator dashboardbun run indicator-dashboard: run the bot with the realtime indicator TUIbun run nexus-info: inspect Nexus query-socket coverage and rangesbun run nexus-dashboard: realtime terminal dashboard for a symbol/timeframe
bun run backtest
bun run backtest -- 2025-12-01 2025-12-31
bun run config-optimizer-brute-force
bun run config-optimizer-genetic
bun run config-optimizer-genetic -- --fastbacktest: runs the bot against historical data usingFakeExchangeconfig-optimizer-brute-force: exhaustively evaluates optimizable config rangesconfig-optimizer-genetic: evolutionary search over the config space with walk-forward out-of-sample scoring--fast: reduced genetic search for quicker iteration
Optimizer outputs are written under outputs/configs/.
bun run generate-journal
bun run open-journal
bun run build
bun run deploy
bun run apply-best-config -- 1generate-journal: rebuilds the static journal fromdata/position_history.sqliteopen-journal: pulls the remote position DB, regenerates the journal, then serves it locallybuild: compiles a Linux x64 Bun binary tobuild/x64/sio-botdeploy: builds, syncs the binary over SSH, and restarts the remote systemd serviceapply-best-config: copies an optimizer snapshot intobot-config.json
bun run lint
bun run typecheck
bun run testRuntime data and generated artifacts are stored in these locations:
data/fake_exchange.sqlite: persisted paper-trade balance and open positionsdata/position_history.sqlite: closed-position history used by the journaloutputs/journal/: static HTML trading journaloutputs/backtest/report.html: generated backtest reportoutputs/configs/: optimizer snapshots, reports, and stability heatmapsbuild/x64/sio-bot: compiled production binary
bot-config.json is not a flat settings file in the usual sense. Many entries encode both
the current value and optimization metadata. Keys prefixed with numeric groups such as
0|... and 1|... are used to organize parameters and strategy blocks for optimization and
serialization. The BotConfig class maps those serialized values back into strongly typed
config objects at runtime.
In practice:
- boolean toggles decide whether a strategy/risk rule is active
- numeric values can define
from,to, andstepranges for optimization - string values can define selectable options
- binary values are used for bitmask-style settings such as trading days
For paper trading:
- Start
sio-nexus - Set
SIOBOT_PAPER_TRADE_ENABLED=true - Tune
bot-config.json - Run
bun run dev - Review positions and journal output in
outputs/journal/
For research and optimization:
- Set backtest dates in
.env - Tune the base search space in
bot-config.json - Run
bun run backtest - Run
bun run config-optimizer-genetic - Review
outputs/configs/ - Apply a chosen snapshot with
bun run apply-best-config -- <snapshot>
src/
siobot/ Bot runtime orchestration
backtester/ Backtesting, optimization, reports
comms/ Telegram integration
domain/ Core trading types
exchanges/ Exchange adapters and Nexus clients
journal/ Static journal generator
orders/ Order orchestration
positions/ Position tracking and persistence
risk/ Risk strategies and sizing
strategies/ Enter and exit strategy implementations
ta/ Technical indicators and dashboards
utils/ Shared helpers, DB access, klines utilities
scripts/
deploy.sh
apply-best-config.sh
open-journal.sh
- Live mode uses Phemex through
ccxt. - Paper mode still consumes realtime data from sio-Nexus.
- Position history is persisted automatically when trades close.
- The journal can regenerate automatically after closed trades and can also be forced manually.
- The optimizer saves ranked config snapshots automatically to
outputs/configs/.
- Nexus socket settings use
SIOBOT_NEXUS_*variables. The default socket paths retain the externalsio-nexusservice names for compatibility. - The historical download pipeline appears partially wired and should be treated as
experimental until its command path is reconciled with
src/main.ts.
- Runtime entrypoint:
src/main.ts - Main runtime class:
src/siobot/SioBot.ts - Config schema and serialization:
src/siobot/BotConfig.ts - The repository uses strict TypeScript and Bun runtime APIs.
- Tests are colocated as
*.test.tsfiles next to source modules.
GPL-3.0-only. See LICENSE for the full text.



