Skip to content
Velo

.stream_news

Opens a WebSocket connection to the live priority-news feed and returns an asynchronous generator.

Example

import asyncio
import json
 
async def stream():
    async for message in client.news.stream_news():
        if message in ('connected', 'heartbeat', 'closed'):
            print(message)
        else:
            story = json.loads(message)
            print(story)
 
asyncio.run(stream())

Parameters

None.

Yields

str

The generator yields:

ValueDescription
"connected"The feed is connected and subscribed.
"heartbeat"A server heartbeat was received.
"closed"The connection closed or receiving failed. The generator then ends.
JSON stringA news story, edit, or delete message. Decode it with json.loads().

The method does not reconnect automatically or replay messages missed while disconnected.