-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f203339
commit 43a9a1c
Showing
7 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import asyncio | ||
import yfinance as yf | ||
|
||
# define your message callback | ||
def message_handler(message): | ||
print("Received message:", message) | ||
|
||
async def main(): | ||
client = yf.AsyncWebSocket() | ||
await client.subscribe(["AAPL", "BTC-USD", "ETH-USD"]) # Subscribe to symbols | ||
await client.unsubscribe("ETH-USD") # Unsubscribe from symbols | ||
await client.listen() | ||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import yfinance as yf | ||
|
||
# define your message callback | ||
def message_handler(message): | ||
print("Received message:", message) | ||
|
||
client = yf.WebSocket() | ||
client.subscribe(["AAPL", "BTC-USD"]) # Subscribe to symbols | ||
client.listen(message_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ | |
|
||
# analysis | ||
dat.analyst_price_targets | ||
|
||
# websocket | ||
dat.live() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
===================== | ||
WebSocket | ||
===================== | ||
|
||
.. currentmodule:: yfinance | ||
|
||
The `WebSocket` module allows you to stream live price data from Yahoo Finance using both synchronous and asynchronous clients. | ||
|
||
Classes | ||
------------ | ||
|
||
.. autosummary:: | ||
:toctree: api/ | ||
|
||
WebSocket | ||
AsyncWebSocket | ||
|
||
Synchronous WebSocket | ||
---------------------- | ||
|
||
The `WebSocket` class provides a synchronous interface for subscribing to price updates. | ||
|
||
Sample Code: | ||
|
||
.. literalinclude:: examples/live_sync.py | ||
:language: python | ||
|
||
Asynchronous WebSocket | ||
----------------------- | ||
|
||
The `AsyncWebSocket` class provides an asynchronous interface for subscribing to price updates. | ||
|
||
Sample Code: | ||
|
||
.. literalinclude:: examples/live_async.py | ||
:language: python |