events
Core domain events and EventBus for publish-subscribe communication.
Classes:
-
DateAdvanced–Event emitted when the simulation date is advanced forward.
-
DateReverted–Event emitted when the simulation date is rolled back.
-
EventBus–Publish-subscribe event bus. Core infrastructure, no framework dependencies.
-
FinancialsUpdated–Event emitted after financial statements have been computed for a date.
-
InstrumentAdded–Event emitted when an instrument is added to a book.
-
InstrumentMatured–Event emitted when a financial instrument reaches maturity.
-
InstrumentRemoved–Event emitted when an instrument is removed from a book.
-
MetricsComputed–Event emitted after bank-level metrics are computed for a date.
-
ShowTransactionsRequested–Event emitted when the user requests to view transactions for an instrument.
-
StatementsChanged–Event emitted after accounting entries change (statements need re-render).
-
TransactionPosted–Event emitted when a transaction is posted to the ledger.
-
TransactionsRecorded–Event emitted after transactions are posted and logged for a date.
-
ValuationsUpdated–Event emitted after all positions have been valued for a date.
DateAdvanced
dataclass
DateAdvanced(date: date)
Event emitted when the simulation date is advanced forward.
DateReverted
dataclass
DateReverted(date: date)
Event emitted when the simulation date is rolled back.
EventBus
EventBus()
Publish-subscribe event bus. Core infrastructure, no framework dependencies.
Methods:
-
batch–Queue events instead of dispatching. Flush on outermost exit.
-
emit–Dispatch an event, or queue it if inside a batch context.
-
subscribe–Register a handler for the given event type.
-
unsubscribe–Remove a previously registered handler for the given event type.
batch
batch() -> Generator[None, None, None]
Queue events instead of dispatching. Flush on outermost exit.
emit
emit(event: Any) -> None
Dispatch an event, or queue it if inside a batch context.
subscribe
subscribe(event_type: type, handler: Callable) -> None
Register a handler for the given event type.
unsubscribe
unsubscribe(event_type: type, handler: Callable) -> None
Remove a previously registered handler for the given event type.
FinancialsUpdated
dataclass
FinancialsUpdated(
date: date,
total_assets: float,
total_liabilities: float,
total_equity: float,
)
Event emitted after financial statements have been computed for a date.
InstrumentAdded
dataclass
InstrumentAdded(
instrument_id: str, book_type: str, instrument: Any
)
Event emitted when an instrument is added to a book.
InstrumentMatured
dataclass
InstrumentMatured(instrument_id: str, date: date)
Event emitted when a financial instrument reaches maturity.
InstrumentRemoved
dataclass
InstrumentRemoved(
instrument_id: str, book_type: str, instrument: Any
)
Event emitted when an instrument is removed from a book.
MetricsComputed
dataclass
MetricsComputed(
date: date, metrics: dict[MetricName, float]
)
Event emitted after bank-level metrics are computed for a date.
ShowTransactionsRequested
dataclass
ShowTransactionsRequested(instrument_id: str)
Event emitted when the user requests to view transactions for an instrument.
StatementsChanged
dataclass
StatementsChanged(date: date)
Event emitted after accounting entries change (statements need re-render).
TransactionPosted
dataclass
TransactionPosted(transaction_id: str, date: date)
Event emitted when a transaction is posted to the ledger.
TransactionsRecorded
dataclass
TransactionsRecorded(
date: date, transactions: tuple[Transaction, ...]
)
Event emitted after transactions are posted and logged for a date.
ValuationsUpdated
dataclass
ValuationsUpdated(
date: date, valuations: dict[str, Decimal]
)
Event emitted after all positions have been valued for a date.