Please note, API data availability depends on your subscription plan. Some data isn’t included in the free plan. Visit our pricing page to find the plan that fits your needs.

This article builds upon the previous three in the series, “Build a Financial Trading Dashboard with Python Django”, “Enhancing the Financial Trading Dashboard with Python Django, and “AnyChart integration for the Financial Trading Dashboard with Python Django“.

The EODHD APIs include an endpoint that provides Fundamental Data, which is documented here. While it offers a substantial amount of data, I am primarily interested in extracting five specific sections for the Django application.

This is just a small subset of the data available. In addition to this, I also want to retrieve the Open, High, Close, Previous Close, and Volume. I obtained this data from the EOD endpoint, as documented here.

And finally, I want to retrieve the market capitalisation for the market as well. This needs to be retrieved by another API endpoint which is documented here.

The data when graphed, will look like this…

I currently have a view that provides data for the AnyChart stock chart and the Bootstrap data table. My intention was to include this fundamental and market cap data on the same page by incorporating it into the existing view. However, I wanted to avoid chaining four API calls sequentially, as that would result in slower performance. Instead, I utilised the asyncio library and converted the view into an asynchronous function. This allowed me to dispatch the API requests asynchronously (all at the same time). Once all the data was retrieved, I processed it as required and returned it to the template as usual.

Register & Get Data

Updating the View – fetch_historical_data

The first step is we need to import “asyncio” and “httpx” in our “views.py”.

The updated “fetch_historical_data” in “views.py” now looks like this…

A few points to pay attention to here:

  • The function “def” is now “async def”.
  • The endpoint to retrieve the historical data is, “historical_url”, the endpoint to retrieve the fundamental data is, “fundamental_url”, the endpoint to retrieve the OHLC data is, “ohlc_url” and the endpoint to retrieve the market cap data is “market_cap_url”.
  • You may wonder what I’m doing with “today_minus_7_days”. The EOD API by default returns almost all the data which is a lot more than we need. The API only supports a date range for filtering and I only need the last two days. To be on the safe side, I retrieved the last 7 days and will only use the last 2.
  • The return has now been updated to include all the information we’ll need to be passed to our template, “historical_data.html”.

What I like about Django is how structured it is. Once you have your application structure setup, it is quick to modify and expand on.

Updating the Template – historical_data.html

This template will now have three sections. The fundamental data, the AnyChart stock chart, and the Bootstrap data table. The updated like now looks like this…

Summary

This is the conclusion of the Python Django tutorial series. I hope you found it informative and useful.

Do you enjoy our articles?

We can send new ones right to your email box