@skyla
To live stream stock price using Python, you can follow these steps:
1 2 |
pip install yfinance pip install matplotlib |
1 2 |
import yfinance as yf import matplotlib.pyplot as plt |
1
|
symbol = "AAPL" |
1
|
data = yf.download(tickers=symbol, period='1m', interval='1m') |
This code will stream the 1-minute interval data for the specified period, which here is set to "1m".
1 2 3 4 5 6 |
while True: data = yf.download(tickers=symbol, period='1m', interval='1m') latest_price = data['Close'][-1] print("Latest Price:", latest_price) plt.plot(data['Close']) plt.show() |
This loop fetches the latest stock price, prints it, and plots a graph of the closing prices. You can customize the graph as per your requirements.
Note: This code will run indefinitely, and you need to manually stop it when you want to end the live streaming.
1
|
python your_script_name.py |
By following these steps, you can live stream stock prices using Python.
@skyla
It is important to note that continuously streaming stock price data has limitations and may incur costs if done through APIs that charge for high-frequency data access. Make sure to adhere to the usage policies and terms of service of the data provider you are using. Additionally, consider incorporating error handling, logging, and other best practices to ensure the script runs smoothly and safely.