Skip to content

Configuration

This guide covers configuration options for dgbit.

Environment Variables

dgbit's API uses pydantic-settings to load values from a .env file or the process environment. The schema is dgbit_api.core.config.Settings.

cp dgbit-api/.env.example dgbit-api/.env

Settings consumed by the API

Variable Setting Default
APP_NAME app_name dgbit-api
API_PREFIX api_prefix /api
ENVIRONMENT environment development
LOG_LEVEL log_level INFO
NNG_COMMAND_ADDRESS nng_command_address ipc:///tmp/dgbit_commands.ipc
NNG_EVENT_ADDRESS nng_event_address ipc:///tmp/dgbit_events.ipc
DEFAULT_SYMBOL default_symbol BTCUSDT
DEFAULT_INTERVAL default_interval 1
BYBIT_API_KEY bybit_api_key ""
BYBIT_API_SECRET bybit_api_secret ""

Defaults differ between Settings and docker-compose

The default NNG addresses in Settings use dgbit_commands.ipc / dgbit_events.ipc, while docker-compose.yml exports dgbit_cmd.ipc / dgbit_evt.ipc. Set both ends to the same address when wiring custom deployments.

Variables read elsewhere

  • BYBIT_TESTNET is forwarded by docker-compose.yml to the API and worker containers, but it is not a field on Settings. Code that needs testnet mode reads it directly (e.g. os.getenv('BYBIT_TESTNET')) or instantiates BybitDataFetcher(testnet=...) explicitly.
  • The database URL is not environment-configurable. dgbit_api.db.connection hardcodes sqlite://db/dgbit.db.

Example .env File

# Environment
ENVIRONMENT=development
LOG_LEVEL=INFO

# Bybit API (get from https://www.bybit.com/app/user/api-management)
BYBIT_API_KEY=your_api_key_here
BYBIT_API_SECRET=your_api_secret_here
BYBIT_TESTNET=true

# Trading defaults
DEFAULT_SYMBOL=BTCUSDT
DEFAULT_INTERVAL=15

# Service bus
NNG_COMMAND_ADDRESS=ipc:///tmp/dgbit_cmd.ipc
NNG_EVENT_ADDRESS=ipc:///tmp/dgbit_evt.ipc

Getting Bybit API Keys

  1. Log in to Bybit
  2. Go to Account > API Management
  3. Click Create New Key
  4. Enable permissions:
    • Read - Required for data fetching
    • Trade - Required for order execution (optional)
  5. Copy the API key and secret
  6. Add to your .env file

API Key Security

  • Never commit API keys to version control
  • Use testnet keys for development
  • Restrict API key permissions to what's needed
  • Set IP restrictions when possible

Testnet vs Mainnet

For development and testing, use Bybit's testnet:

BYBIT_TESTNET=true

Get testnet API keys from testnet.bybit.com.

For production with real funds:

BYBIT_TESTNET=false

Backtest Configuration

Configure backtests programmatically:

from dgbit_core.backtesting import BacktestConfig

config = BacktestConfig(
    initial_capital=10000.0,    # Starting capital
    transaction_fee=0.001,      # 0.1% per trade
    train_split=0.7,            # 70% train, 30% test
    report_dir="reports",       # Where to save reports
)

Strategy Configuration

Each strategy has its own parameters. The WaveletReversalStrategy constructor accepts the common base options only:

from dgbit_core.trading.strategy import WaveletReversalStrategy

strategy = WaveletReversalStrategy(
    min_signal_threshold=0.75,  # Minimum signal to enter
    take_profit_pct=0.002,      # Take profit, default 0.002
    stop_loss_pct=0.005,        # Stop loss, default 0.005
)

See Built-in Strategies for parameters per strategy.

Docker Configuration

When running with Docker, pass environment variables:

docker run -e BYBIT_API_KEY=xxx -e BYBIT_API_SECRET=xxx cryptuon/dgbit

Or use docker-compose with an env file:

# docker-compose.yml
services:
  api:
    env_file:
      - .env

Logging Configuration

dgbit uses loguru for structured logging. Configure via environment:

LOG_LEVEL=DEBUG  # See all logs
LOG_LEVEL=INFO   # Standard logging
LOG_LEVEL=ERROR  # Errors only

Database Configuration

dgbit uses SQLite via Tortoise ORM for job tracking. The connection string is hardcoded in dgbit_api/db/connection.py:

DATABASE_URL = "sqlite://db/dgbit.db"

The database file is created automatically on first run; the schema is generated by Tortoise.generate_schemas(). There is no environment variable to override this in the current release.

Next Steps