trading_agent.terminal.event_stream
¶
Keeps the gateway's event stream open, reconnecting after a drop, as the web page's eventSocket.ts does.
Each event is a JSON object with kind, desk, payload and created_at. The stream never replays old events, so a client reads today's history from the journal routes.
Typical usage example:
stream = EventStream(gateway.events_address()) await stream.follow(on_event, on_state)
AccessRefusedError
¶
Bases: Exception
The gateway closed the event stream because the access token is wrong.
EventStream
¶
One client's view of the gateway's events.
Creates the stream without connecting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The WebSocket address, with the token, from GatewayClient.events_address. |
required |
connect
|
Callable[[str], Any]
|
Opens a connection; replaced by a stand-in in tests. |
connect
|
Source code in src/trading_agent/terminal/event_stream.py
follow
async
¶
Passes every event to on_event until cancelled, reconnecting after a drop.
The wait before reconnecting doubles from 1 second up to 15 seconds, and starts again at 1 second after a connection that worked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_event
|
Callable[[dict[str, Any]], None]
|
Called with each event. |
required |
on_state
|
Callable[[str], None]
|
Called with "connecting", "live", "reconnecting" or "refused". |
required |
Raises:
| Type | Description |
|---|---|
AccessRefusedError
|
The gateway refused the access token. |