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.
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_TESTNETis forwarded bydocker-compose.ymlto the API and worker containers, but it is not a field onSettings. Code that needs testnet mode reads it directly (e.g.os.getenv('BYBIT_TESTNET')) or instantiatesBybitDataFetcher(testnet=...)explicitly.- The database URL is not environment-configurable.
dgbit_api.db.connectionhardcodessqlite://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¶
- Log in to Bybit
- Go to Account > API Management
- Click Create New Key
- Enable permissions:
- Read - Required for data fetching
- Trade - Required for order execution (optional)
- Copy the API key and secret
- Add to your
.envfile
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:
Get testnet API keys from testnet.bybit.com.
For production with real funds:
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:
Or use docker-compose with an env file:
Logging Configuration¶
dgbit uses loguru for structured logging. Configure via environment:
Database Configuration¶
dgbit uses SQLite via Tortoise ORM for job tracking. The connection string is hardcoded in dgbit_api/db/connection.py:
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¶
- Trading Strategies - Configure and use strategies
- Docker Deployment - Production configuration
- Configuration Reference - Complete reference