AsyncWebSocket#

class yfinance.AsyncWebSocket(url: str = 'wss://streamer.finance.yahoo.com/?version=2', verbose=True)#

Asynchronous WebSocket client for streaming real time pricing data.

Initialize the AsyncWebSocket client.

Parameters:
  • url (str) – The WebSocket server URL. Defaults to Yahoo Finance’s WebSocket URL.

  • verbose (bool) – Flag to enable or disable print statements. Defaults to True.

Methods

__init__(url: str = 'wss://streamer.finance.yahoo.com/?version=2', verbose=True)

Initialize the AsyncWebSocket client.

Parameters:
  • url (str) – The WebSocket server URL. Defaults to Yahoo Finance’s WebSocket URL.

  • verbose (bool) – Flag to enable or disable print statements. Defaults to True.

async close()

Close the WebSocket connection.

async listen(message_handler=None)

Start listening to messages from the WebSocket server.

Parameters:

message_handler (Optional[Callable[[dict], None]]) – Optional function to handle received messages.

async subscribe(symbols: str | List[str])

Subscribe to a stock symbol or a list of stock symbols.

Parameters:

symbols (str | List[str]) – Stock symbol(s) to subscribe to.

async unsubscribe(symbols: str | List[str])

Unsubscribe from a stock symbol or a list of stock symbols.

Parameters:

symbols (str | List[str]) – Stock symbol(s) to unsubscribe from.

async close()#

Close the WebSocket connection.

async listen(message_handler=None)#

Start listening to messages from the WebSocket server.

Parameters:

message_handler (Optional[Callable[[dict], None]]) – Optional function to handle received messages.

async subscribe(symbols: str | List[str])#

Subscribe to a stock symbol or a list of stock symbols.

Parameters:

symbols (str | List[str]) – Stock symbol(s) to subscribe to.

async unsubscribe(symbols: str | List[str])#

Unsubscribe from a stock symbol or a list of stock symbols.

Parameters:

symbols (str | List[str]) – Stock symbol(s) to unsubscribe from.