Reconnects and Health
Clients expose health():
connectedlast_message_timestamp_msreconnect_countmessages_receivedmessages_sentlast_errorlast_error_timestamp_msuptime_seconds
Connection retry behavior uses exponential backoff with jitter. Live systems
should monitor last_message_timestamp_ms, reconnect counts, and process-level
logs.
Connection manager shutdown
Polymarket, Kalshi, and Opinion connection managers own their background message reader. Always shut a manager down through its public lifecycle:
await manager.start()
try:
...
finally:
await manager.stop()
stop() cancels and awaits the message reader before closing the websocket
client, so it completes even when the stream is idle. Calling stop() before
start() or more than once is safe. Consumers should not inspect or cancel
private task attributes.