trading_agent.runtime.event
¶
One thing that happened inside the agent, as published on the event bus.
Typical usage example:
event = Event.now(EventKind.TURN_STARTED, desk='main', payload={'trigger_id': trigger_id})
EventKind
¶
Bases: StrEnum
The kinds of event the agent publishes.
Event
dataclass
¶
One published event.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
EventKind
|
What happened. |
desk |
str | None
|
The desk it happened on, or None for the whole gateway. |
payload |
dict[str, Any]
|
Details that depend on the kind, kept JSON-serialisable. |
created_at |
datetime
|
When it happened, in UTC. |
now
classmethod
¶
Creates an event stamped with the current time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
EventKind
|
What happened. |
required |
desk
|
str | None
|
The desk it happened on, or None for the whole gateway. |
required |
payload
|
dict[str, Any] | None
|
Details of the event, or None for no details. |
None
|
Returns:
| Type | Description |
|---|---|
Event
|
The new event. |
Source code in src/trading_agent/runtime/event.py
to_json_dictionary
¶
Converts the event to a dictionary that json.dumps can write.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The event's fields, with the time as an ISO 8601 string. |