trading_agent.runtime.event_bus
¶
Delivers every published event to every subscriber.
Each subscriber gets its own bounded queue. A subscriber that falls behind loses its oldest events rather than slowing the desks down, and the number lost is counted.
Typical usage example:
event_bus = EventBus() with event_bus.subscribe() as subscription: event_bus.publish(Event.now(EventKind.TEXT, desk='main')) event = await subscription.next_event()
EventSubscription
¶
One subscriber's queue of events.
Attributes:
| Name | Type | Description |
|---|---|---|
dropped_count |
How many events were thrown away because the queue was full. |
Creates an empty subscription.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_bus
|
EventBus
|
The bus this subscription belongs to. |
required |
maximum_queued
|
int
|
How many unread events to keep before dropping the oldest. |
required |
Source code in src/trading_agent/runtime/event_bus.py
deliver
¶
Adds an event to the queue, dropping the oldest one if it is full.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
published_event
|
Event
|
The event to deliver. |
required |
Source code in src/trading_agent/runtime/event_bus.py
next_event
async
¶
close
¶
__enter__
¶
Returns the subscription for use in a with statement.
Returns:
| Type | Description |
|---|---|
EventSubscription
|
This subscription. |
__exit__
¶
Closes the subscription when the with statement ends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exception_type
|
type[BaseException] | None
|
The type of exception raised in the block, if any. |
required |
exception
|
BaseException | None
|
The exception raised in the block, if any. |
required |
traceback
|
TracebackType | None
|
The traceback of that exception, if any. |
required |
Source code in src/trading_agent/runtime/event_bus.py
EventBus
¶
The publish and subscribe hub that every component shares.
Creates a bus with no subscribers.
Source code in src/trading_agent/runtime/event_bus.py
publish
¶
Delivers an event to every current subscriber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
published_event
|
Event
|
The event to deliver. |
required |
Source code in src/trading_agent/runtime/event_bus.py
subscribe
¶
Starts a new subscription that receives every later event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maximum_queued
|
int
|
How many unread events to keep before dropping the oldest. |
_DEFAULT_MAXIMUM_QUEUED
|
Returns:
| Type | Description |
|---|---|
EventSubscription
|
The new subscription. |
Source code in src/trading_agent/runtime/event_bus.py
unsubscribe
¶
Stops delivering events to a subscription.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscription
|
EventSubscription
|
The subscription to stop. |
required |