How to Integrate Yahoo Finance API with PyQt6

In this PyQt6 article we want to learn How to Integrate Yahoo Finance API with PyQt6, for this we are using yfinance API, now first of all let’s talk about PyQt6.

 

What is PyQt6 ?

PyQt6 is a Python binding for cross platform GUI toolkit Qt. Qt is popular C++ framework for building graphical applications which provides different widgets, layouts and other tools for creating desktop and mobile applications. PyQt6 allows developers to create GUI applications in Python that can run on multiple platforms including Windows, Linux and macOS. it provides different Python modules that wrap the Qt classes and allow developers to use them in more Pythonic way.

 

What is Yahoo Finance API (yfinance) ?

yfinance is popular Python library that provides easy API for accessing historical market data and live financial data from Yahoo Finance. it allows users to fetch data for stock quotes, options, mutual funds, exchange traded funds (ETFs) and cryptocurrencies. yfinance is built on top of the Pandas library and is widely used for financial analysis and data science. 

 

 

How to Integrate Yahoo Finance API with PyQt6

First if all we need to install required libraries

 

 

 

So this is the complete code for this article

This code defines PyQt6 application for fetching and displaying stock data from the Yahoo Finance API using yfinance library. StockTrackerApp class extends from QMainWindow class and defines the GUI components of the application, including a label and text box for entering a stock symbol, a button for fetching the stock data, and a table widget for displaying the data.

fetch_stock_data method is called when the user clicks Fetch Stock Data button. this method gets the stock symbol from the text box, fetches the stock data using yf.Ticker method, and then populates the table widget with the fetched data.

setRowCount and setColumnCount methods are used to set the number of rows and columns in the table widget. setHorizontalHeaderLabels method is used to set the column headers to the names of the columns in fetched data. setColumnWidth method is used to set the width of each column in the table widget.

setItem method is used to add each item in the fetched data to the appropriate cell in the table widget. str function is used to convert each item to string before adding it to table widget.

and lastly if __name__ == ‘__main__’ block creates QApplication object, creates an instance of StockTrackerApp class, shows the GUI window and starts the application event loop using app.exec().

 

 

So now run the code and in here we want to use Microsoft symbol and that is MSFT

How to Integrate Yahoo Finance API with PyQt6
How to Integrate Yahoo Finance API with PyQt6

 

 

Learn More on Python GUI

Leave a Comment