How to Integrate Yahoo Finance API with wxPython

In this wxPython article we want to learn about How to Integrate Yahoo Finance API with wxPython, for this purpose we want to use Yahoo Finance API or yfinance library, so Yahoo Finance API is popular choice for developers to obtain financial data. in this article we want to talk how to integrate Yahoo Finance API with wxPython using the yfinance library.

 

What is wxPython ?

wxPython is popular Python library for creating cross platform desktop applications. it is based on the popular C++ GUI toolkit wxWidgets. wxPython provides native look and feel on different platforms and has different widgets that can be used to create complex user interfaces.

 

What is yfinance ?

yfinance is Python library that allows you to download historical market data from Yahoo Finance API. it is popular library among finance enthusiasts and can be used to extract stock data for any stock listed on Yahoo Finance.

 

 

How to Integrate Yahoo Finance API with wxPython ?

First of all we need to install our required libraries for this article.

 

 

So first of all let’s create our basic GUI window using wxPython.

 

 

Run the code and this will be the result

Integrate Yahoo Finance API with wxPython
Integrate Yahoo Finance API with wxPython

 

 

After that we need to create a GUI for our application. we want to create a simple GUI that consists of a text box and button. when the user enters the stock symbol in the text box and clicks the button, we will download the historical data for that stock from Yahoo Finance API.

 

 

Run the code and this will be the result

Yahoo Finance API with wxPython
Yahoo Finance API with wxPython

 

 

Now that we have created the GUI, we can download historical data from Yahoo Finance API. we will use the yfinance library to download the data.

In the download_data method, we first get the stock symbol entered by the user from the text box. after that we use yf.download function to download the historical data for that stock from Yahoo Finance API. data is returned as pandas DataFrame. after that we creates a grid using wx.grid.Grid class and set its size based on the size of the downloaded data. we then loop through each cell in the grid and set its value to the corresponding value in the DataFrame. if the value in the DataFrame is a number, we convert it to a string before setting the cell value. this is necessary because SetCellValue method expects string as its argument. and lastly we show the grid in the GUI.

 

 

 

Run the code and this will be the result

How to Integrate Yahoo Finance API with wxPython
How to Integrate Yahoo Finance API with wxPython

 

 

Learn More on wxPython

Leave a Comment