Run Recorder
BATCH_SIZE = 1000
module-attribute
RunRecorder
Bases: Subscriber
Subscriber that records all trading system events to a SQLite runs database.
The recorder subscribes to market data events, order requests, broker responses, fills, and expirations, inserting them into the appropriate tables as defined in the runs schema.
Events are buffered and inserted in batches for performance. The buffer is
flushed on shutdown via _cleanup.
__init__(event_bus, db_path, run_id, name, config=None, metadata=None)
Initialize the recorder and register a new run in the database.
The database is created if it does not exist. A new row is inserted into the runs
table with status running and the current timestamp as ts_start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_bus
|
EventBus
|
Event bus used for subscribing to system events. |
required |
db_path
|
Path
|
Filesystem path to the SQLite runs database. |
required |
run_id
|
str
|
Unique identifier for this run. |
required |
name
|
str
|
Human-readable name for this run. |
required |
config
|
dict | None
|
Optional configuration dictionary to store as JSON. |
None
|
metadata
|
dict | None
|
Optional metadata dictionary to store as JSON. |
None
|
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_init_db()
Initialize the SQLite database connection.
Creates the database file and parent directories if they do not exist. Applies the runs schema if the database is newly created.
Returns:
| Type | Description |
|---|---|
Connection
|
Open database connection configured with WAL journal mode. |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_register_run()
Insert a new run record into the database.
The run is created with status 'running' and the current timestamp as start time.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
update_run_status(status, ts_end=None)
Update the status and end timestamp of the current run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
New status value (e.g., 'completed', 'failed', 'cancelled'). |
required |
ts_end
|
int | None
|
End timestamp in nanoseconds since Unix epoch. Defaults to current time. |
None
|
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_on_event(event)
Dispatch an incoming event to the appropriate buffer method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
EventBase
|
Event received from the event bus. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_on_exception(exc)
Handle an exception raised during event processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
Exception
|
Exception that was raised. |
required |
_cleanup()
Flush all buffered records and close the database connection.
Called automatically during subscriber shutdown.
_flush_all()
Flush all event buffers to the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_bar_received(event)
Buffer a bar received event for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
BarReceived
|
Bar received event to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_bar_processed(event)
Buffer a bar processed event for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
BarProcessed
|
Bar processed event to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_order_submission(event)
Buffer an order submission request for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
OrderSubmissionRequest
|
Order submission request to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_order_cancellation(event)
Buffer an order cancellation request for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
OrderCancellationRequest
|
Order cancellation request to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_order_modification(event)
Buffer an order modification request for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
OrderModificationRequest
|
Order modification request to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_order_accepted(event)
Buffer an order accepted response for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
OrderAccepted
|
Order accepted response to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_order_rejected(event)
Buffer an order rejected response for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
OrderRejected
|
Order rejected response to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_cancellation_accepted(event)
Buffer a cancellation accepted response for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
CancellationAccepted
|
Cancellation accepted response to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_cancellation_rejected(event)
Buffer a cancellation rejected response for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
CancellationRejected
|
Cancellation rejected response to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_modification_accepted(event)
Buffer a modification accepted response for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
ModificationAccepted
|
Modification accepted response to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_modification_rejected(event)
Buffer a modification rejected response for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
ModificationRejected
|
Modification rejected response to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_fill(event)
Buffer a fill event for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
FillEvent
|
Fill event to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_buffer_expiration(event)
Buffer an order expiration event for batch insertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
OrderExpired
|
Order expiration event to buffer. |
required |
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_bars()
Insert buffered bar received records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_bars_processed()
Insert buffered bar processed records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_order_submissions()
Insert buffered order submission records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_order_cancellations()
Insert buffered order cancellation records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_order_modifications()
Insert buffered order modification records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_orders_accepted()
Insert buffered order accepted records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_orders_rejected()
Insert buffered order rejected records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_cancellations_accepted()
Insert buffered cancellation accepted records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_cancellations_rejected()
Insert buffered cancellation rejected records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_modifications_accepted()
Insert buffered modification accepted records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_modifications_rejected()
Insert buffered modification rejected records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_fills()
Insert buffered fill records into the database.
Source code in src/onesecondtrader/orchestrator/run_recorder.py
_flush_expirations()
Insert buffered expiration records into the database.