Db
Database access utilities for the dashboard.
Provides functions for accessing the runs database and security master database, including path resolution from environment variables and common query operations.
CHILD_TABLES = ['bars', 'bars_processed', 'order_submissions', 'order_cancellations', 'order_modifications', 'orders_accepted', 'orders_rejected', 'cancellations_accepted', 'cancellations_rejected', 'modifications_accepted', 'modifications_rejected', 'fills', 'expirations']
module-attribute
get_runs_db_path()
Return the path to the runs database from environment or default.
Returns:
| Type | Description |
|---|---|
str
|
Path to the runs SQLite database file. |
get_secmaster_path()
Return the path to the security master database from environment or default.
Returns:
| Type | Description |
|---|---|
str
|
Path to the security master SQLite database file. |
Source code in src/onesecondtrader/dashboard/db.py
connect_runs(*, timeout=5.0)
Context manager for connecting to the runs database.
Yields a connection that is automatically closed on exit (even on exceptions).
Raises FileNotFoundError when the database file does not exist.
Source code in src/onesecondtrader/dashboard/db.py
connect_secmaster(*, timeout=5.0)
Context manager for connecting to the security master database.
Yields a connection that is automatically closed on exit (even on exceptions).
Raises FileNotFoundError when the database file does not exist.
Source code in src/onesecondtrader/dashboard/db.py
get_presets_db_path()
Return the path to the presets database from environment or default.
Returns:
| Type | Description |
|---|---|
str
|
Path to the presets SQLite database file. |
connect_presets(*, timeout=5.0)
Context manager for connecting to the presets database.
Yields a connection that is automatically closed on exit (even on exceptions). The database file is created automatically if it does not exist.
Source code in src/onesecondtrader/dashboard/db.py
ensure_explorer_sessions_table()
Create the explorer_sessions and session_indicators tables if they do not exist.
Source code in src/onesecondtrader/dashboard/db.py
get_runs(limit=50)
Fetch recent runs from the runs database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of runs to return. |
50
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of run dictionaries with run_id, name, timestamps, status, config, and metadata. |
Source code in src/onesecondtrader/dashboard/db.py
get_strategy_key(run_id)
Derive a strategy class key from a run's config for settings persistence.
Queries the runs table, extracts config["strategies"], and returns
a deterministic comma-joined sorted string. Falls back to run_id
when no strategies list is found.
Source code in src/onesecondtrader/dashboard/db.py
ensure_data_splits_table()
Create the data_splits table if it does not exist.