Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: WebSocket Client for Live Data Streaming #2201

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

dhruvan2006
Copy link
Contributor

@dhruvan2006 dhruvan2006 commented Jan 2, 2025

Changes

  • Introduced a new WebSocket class to stream live market data.
  • Added ProtoBuf files (pricing.proto and pricing_pb2.py) for data de serialization.
  • Updated requirements.txt and setup.py to include new dependencies.
  • Added documentation for usage

Usage

import asyncio
import yfinance as yf

def message_handler(message):
    print("Received message:", message)

async def main():
    client = yf.AsyncWebSocket(verbose=False)
    await client.subscribe(["AAPL", "BTC-USD", "ETH-USD"])
    await client.unsubscribe("ETH-USD")
    await client.listen()

def sync_example():
    client = yf.WebSocket()
    client.subscribe(["AAPL", "BTC-USD"])
    client.listen(message_handler)

Pick one from below to test feature:

asyncio.run(main()) # Async
sync_example()      # Sync
yf.Ticker("SOL-USD").live(message_handler)                              # Ticker
yf.Tickers(["ETH-USD", "SOL-USD"]).live(message_handler, False) # Tickers

@dhruvan2006
Copy link
Contributor Author

@ValueRaider any opinions on this websocket? Is it suitable for this package?

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 6, 2025

I'm focusing on the Screener stuff right now. Can someone else try and feedback?

Previous discussions: #319 #290

Copy link
Contributor

@R5dan R5dan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a new function in WebSocket for initialization.
Also I think its worth considering adding an async option

yfinance/live.py Outdated Show resolved Hide resolved
yfinance/live.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@dhruvan2006
Copy link
Contributor Author

@ValueRaider Should the websocket be an extra feature like nospam & require or part of base yfinance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants