App
FastAPI application providing the dashboard REST API and page routes.
The application exposes endpoints for:
- Serving the backtest configuration page
- Querying and deleting run history from the runs database
- Listing registered strategies and their parameter schemas
- Querying publishers, datasets, and symbol coverage from the security master
- Managing symbol presets for quick backtest configuration
- Executing backtests as background tasks
Environment Variables
RUNS_DB_PATH: Path to the runs SQLite database. Defaults to runs.db.
SECMASTER_DB_PATH: Path to the security master SQLite database. Defaults to secmaster.db.
app = FastAPI(title='OneSecondTrader Dashboard')
module-attribute
_running_jobs = {}
module-attribute
_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
_RTYPE_TO_BAR_PERIOD = {32: 'SECOND', 33: 'MINUTE', 34: 'HOUR', 35: 'DAY'}
module-attribute
DeleteRunsRequest
PresetRequest
BacktestRequest
Bases: BaseModel
Request model for running a backtest.
Source code in src/onesecondtrader/dashboard/app.py
_get_runs_db_path()
_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/app.py
index()
async
backtest()
async
api_runs()
async
api_delete_runs(request)
async
Delete runs and their associated data from the runs database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
DeleteRunsRequest
|
Request containing list of run IDs to delete. |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with count of deleted runs. |
Source code in src/onesecondtrader/dashboard/app.py
api_strategies()
async
Return the list of registered strategy classes.
Source code in src/onesecondtrader/dashboard/app.py
api_strategy_schema(name)
async
Return the parameter schema for a strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Class name of the strategy. |
required |
Returns:
| Type | Description |
|---|---|
|
Strategy schema with parameters, or error if not found. |
Source code in src/onesecondtrader/dashboard/app.py
_get_secmaster_path()
Return the path to the security master database from environment or default.
api_secmaster_publishers(rtype=None)
async
Return list of unique publisher names from the security master.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rtype
|
int | None
|
Optional bar period rtype to filter publishers that have data for that period. |
None
|
Returns:
| Type | Description |
|---|---|
|
Dictionary with list of publisher name strings. |
Source code in src/onesecondtrader/dashboard/app.py
api_secmaster_datasets(name, rtype=None)
async
Return datasets for a publisher from the security master.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Publisher name to get datasets for. |
required |
rtype
|
int | None
|
Optional bar period rtype to filter datasets that have data for that period. |
None
|
Returns:
| Type | Description |
|---|---|
|
Dictionary with list of dataset objects containing publisher_id and dataset name. |
Source code in src/onesecondtrader/dashboard/app.py
api_secmaster_symbols_coverage(publisher_id=None, rtype=None)
async
Return symbol coverage data from the security master.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
publisher_id
|
int | None
|
Optional publisher ID to filter symbols. |
None
|
rtype
|
int | None
|
Optional bar period rtype to filter symbols. |
None
|
Returns:
| Type | Description |
|---|---|
|
Dictionary with list of symbol coverage objects containing publisher_id, |
|
|
symbol, rtype, min_ts, and max_ts. |
Source code in src/onesecondtrader/dashboard/app.py
list_presets()
async
Return list of all symbol preset names.
Source code in src/onesecondtrader/dashboard/app.py
get_preset(name)
async
Return a symbol preset by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the preset to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with preset name and list of symbols, or error if not found. |
Source code in src/onesecondtrader/dashboard/app.py
create_preset(request)
async
Create a new symbol preset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
PresetRequest
|
Request containing preset name and list of symbols. |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with status and preset name. |
Source code in src/onesecondtrader/dashboard/app.py
update_preset(name, request)
async
Update an existing symbol preset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the preset to update. |
required |
request
|
PresetRequest
|
Request containing new symbols list. |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with status and preset name. |
Source code in src/onesecondtrader/dashboard/app.py
delete_preset(name)
async
Delete a symbol preset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the preset to delete. |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with status and preset name. |
Source code in src/onesecondtrader/dashboard/app.py
_deserialize_params(params, param_specs)
Deserialize strategy parameters from JSON values to Python types.
Converts enum string names back to enum instances based on parameter specifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dictionary of parameter names to JSON-serialized values. |
required |
param_specs
|
dict
|
Dictionary of parameter names to ParamSpec objects. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of parameter names to deserialized Python values. |
Source code in src/onesecondtrader/dashboard/app.py
_run_backtest(request, run_id)
Execute a backtest as a background task.
Creates configured strategy, datafeed, and orchestrator instances based on the request parameters and runs the backtest. Updates job status in _running_jobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
BacktestRequest
|
Backtest configuration including strategy, symbols, and date range. |
required |
run_id
|
str
|
Unique identifier for tracking job status. |
required |
Source code in src/onesecondtrader/dashboard/app.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
api_backtest_run(request, background_tasks)
async
Start a backtest as a background task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
BacktestRequest
|
Backtest configuration. |
required |
background_tasks
|
BackgroundTasks
|
FastAPI background tasks manager. |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with run_id and initial status. |
Source code in src/onesecondtrader/dashboard/app.py
api_backtest_status(run_id)
async
Get the status of a running or completed backtest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
Unique identifier of the backtest job. |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with run_id and current status. |