trading_agent.gateway.routes.event_routes
¶
The WebSocket that streams every event to a client as it happens.
A client can ask for one desk's events only with ?desk=<name>; events that belong to no desk, such as account-wide ones, are always sent.
The handler waits for two things at once: the next event, and the client hanging up. Without the second, a closed connection would only be noticed at the next send, and on a quiet bus its subscription would linger.
Typical usage example:
application.include_router(EventRoutes(event_bus, guard).router())
EventRoutes
¶
Builds the /ws/events WebSocket route.
Creates the route for one event bus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_bus
|
EventBus
|
The bus whose events are streamed. |
required |
guard
|
AccessGuard
|
The guard that checks the access token. |
required |
redactor
|
SecretRedactor | None
|
Masks secrets before an event is sent, or None to send it unchanged. |
None
|
Source code in src/trading_agent/gateway/routes/event_routes.py
router
¶
Builds the router holding the WebSocket route.
Returns:
| Type | Description |
|---|---|
APIRouter
|
The router. |
Source code in src/trading_agent/gateway/routes/event_routes.py
stream_events
async
¶
Sends each event to the client as JSON until it disconnects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
websocket
|
WebSocket
|
The client's connection, with the token in its |
required |