Skip to content
dgbit GitHub

v0.x · pip install dgbit · MIT

Backtest-to-live trading infrastructure for Bybit — human-run or agent-operated.

dgbit gives you a backtester, a strategy base class, a service-bus execution layer, and a REST + WebSocket surface — tuned for Bybit spot. What you test is what you run, and everything the dashboard does is also an API call, so a person, a cron job, or an autonomous agent can drive the same loop.

shell / install ready
pip install dgbit
# or
docker pull cryptuon/dgbit

// capabilities

What ships in the box

Backtesting

In-memory backtester with Plotly reports

BacktestConfig sets initial capital and transaction fees. The Backtester runs against historical OHLCV from Bybit and returns total return, win rate, and max drawdown alongside interactive reports.

Strategies

Four built-in strategies, one base class

Wavelet Reversal (Daubechies decomposition), MA Crossover, RSI, and Bollinger Bands ship in the box. Custom strategies subclass BaseStrategy and register via strategy_registry.

Execution

Live trading on Bybit spot

Position tracking and risk management plug into the same strategy interface used for backtests. Live keys are configured via BYBIT_API_KEY / BYBIT_API_SECRET, with a BYBIT_TESTNET flag for staging.

Architecture

NNG service bus, FastAPI REST, Vue 3 dashboard

Data, backtest, and strategy services talk to the API over an NNG message bus. A FastAPI backend exposes /backtests, /jobs, /strategies, /execution. A Vue 3 frontend handles monitoring.

API

A loop a person, a cron job, or an agent can drive

Schedule a backtest, request a signal, place an order, and subscribe to job.created, job.completed, job.failed, trade.entered, trade.exited, and signal.generated events at ws://localhost:8000/api/ws/events. The same surface the dashboard uses, open to a scheduler or an autonomous agent.

Deployment

One small VPS, docker-compose on day one

Clone, copy .env.example to .env, fill in API credentials, run docker-compose up -d. In-process NNG bus and SQLite persistence mean no broker to rent — a single small VPS is the cheapest path to a running instance.

// architecture

A pipeline tuned for strategy iteration

The README diagrams the platform as a four-layer stack. Each layer has one responsibility, and the message bus between them is NNG IPC, not HTTP — so a backtest worker can lift a strategy module straight into the live engine without a serialization rewrite. The REST API and WebSocket stream on top mean the whole loop is drivable by an operator that isn't a human.

Full architecture walkthrough →

01 / dashboard

Vue 3

Charts, portfolio view, strategy state, and monitoring. Talks to the API over HTTP and WebSocket.

02 / api

FastAPI REST

/backtests, /jobs, /data, /strategies, /execution. Async, with a WebSocket event stream at /api/ws/events.

03 / workers

NNG IPC bus

Data service, backtest worker, and strategy service exchange messages over an NNG transport (ipc:///tmp/dgbit_cmd.ipc by default).

04 / core

Shared trading library

Strategies, backtesting, position tracking, and the Bybit data fetcher. Imported equally by workers, API, and your own scripts.

// first backtest

From pip install to a result object in eight lines

Fetch klines from Bybit, wire up the wavelet reversal strategy, and run the backtester. The result carries the metrics you actually need for an honest go/no-go decision: total return, win rate, and max drawdown.

  • No multi-exchange wrapperBybitDataFetcher talks directly to the source.
  • Configurable feestransaction_fee=0.001 is the default; tune per pair.
  • Threshold tuningmin_signal_threshold=0.75 filters the wavelet signal.
Full quickstart guide →
python / first_backtest.py 15-min BTCUSDT
from dgbit_core.backtesting import Backtester, BacktestConfig
from dgbit_core.trading.strategy import WaveletReversalStrategy
from dgbit_core.data.data_fetcher import BybitDataFetcher

fetcher = BybitDataFetcher()
data = fetcher.get_kline_data("BTCUSDT", interval="15", limit=1000)

config = BacktestConfig(initial_capital=10000.0, transaction_fee=0.001)
backtester = Backtester(config=config)
backtester.strategy = WaveletReversalStrategy(min_signal_threshold=0.75)
result = backtester.run(data)

print(f"Total Return: {result.metrics['total_return']:.2%}")
print(f"Win Rate:     {result.metrics['win_rate']:.2%}")
print(f"Max Drawdown: {result.metrics['max_drawdown']:.2%}")

// who it's for

Infrastructure, not a trading bot

dgbit is for quantitative traders developing new strategies, developers building trading automation, and teams putting an agent in the loop. It is the operable substrate underneath a strategy — not the strategy, and not a "buy this dip" button. No return claims live here.

Quant developers

You already write strategies in Python and want a backtester that does not hide the assumptions behind it — and a live path that behaves the same.

Automation & agent builders

You are wiring a scheduler or an autonomous agent to a live venue and need a REST + WebSocket surface, position tracking, and risk controls already in place.

Researchers building on Bybit

You want the data fetcher, position tracking, and risk handling already wired to one exchange instead of abstracted across ten.

See detailed use cases →

// faq

Questions to answer before you commit

+ Which exchange does dgbit support?

Bybit spot. The data fetcher, execution layer, and built-in strategies are all built around the Bybit API. dgbit is intentionally exchange-specific so the abstractions can be precise rather than lowest-common-denominator.

+ Is dgbit a Python library or a service?

Both. The Python package is importable for backtests and strategy authoring. The framework also ships a FastAPI server (dgbit-api), an NNG service bus across data/backtest/strategy workers, and a Vue 3 dashboard. You can run as much or as little of that stack as you need.

+ What strategies are included?

Four built-in strategies: Wavelet Reversal (Daubechies wavelet decomposition for mean reversion), MA Crossover (trend following), RSI (momentum), and Bollinger Bands (volatility breakout). Custom strategies subclass BaseStrategy and register with strategy_registry.

+ How do I run a backtest?

Install with pip install dgbit, fetch klines with BybitDataFetcher.get_kline_data, configure with BacktestConfig (initial capital, transaction fee), and call Backtester(config).run(data). The result object exposes total_return, win_rate, and max_drawdown.

+ Can I run live trading?

Yes. Set BYBIT_API_KEY and BYBIT_API_SECRET in .env. Use BYBIT_TESTNET=true to stage against Bybit testnet before flipping to production. The execution endpoint /api/execution/orders places orders; /api/execution/positions returns open positions.

+ How do I deploy it?

Docker-compose up -d after copying dgbit-api/.env.example to .env. All services come up together. Logs stream from the api container with docker-compose logs -f api.

Full FAQ page →

// explore

Go deeper into dgbit

Every part of the project, one link away — the feature set, the quickstart, the architecture, comparisons, and the engineering blog.

Ready to wire a strategy?

Read the docs, clone the repo, run the first backtest, and decide whether the abstractions fit how you think about markets.