No matter which brokerage app you use, you can view the historical trading information and real-time market data of various securities on the app. This allows investors to make informed investment decisions based on accurate information. This is possible because the Stock API facilitates smooth data transmission between the market trading system and the brokerage app. In this article, we will introduce what a Stock API is and highlight the three most commonly used Taiwan Stock Market APIs, providing valuable references for investors.
Table of Contents
The full name of the API is Application Programming Interface, which facilitates the retrieval of data from another software program. This allows developers to integrate existing features from other software into their applications without rebuilding the database from scratch.
A Securities API enables traditional financial transactions to be completed more efficiently by directly connecting to market trading systems or stock exchanges in other countries. This allows for retrieving real-time dynamic data and the automation of trade execution. Below, the operation process of a Securities API is broken down into five steps to help investors better understand how it works.
Data is just being transmitted between two parties, but in a highly volatile financial market, the accuracy and timeliness of this data are crucial. Securities APIs achieve the goals of information sharing and integration, making them an indispensable tool for investors when analyzing the market.
Suppose you’re interested in trying your hand at analyzing the financial market. In that case, we’ll introduce three of the most commonly used Taiwan Stock Market APIs: finance API, FinMind API, and TEJ API. We’ll also provide a detailed explanation of each API’s unique features.
TEJ (Taiwan Economic Journal), Taiwan’s leading financial information company, developed the TEJ API. It specializes in providing essential data for fundamental analysis of financial markets, covering not only Taiwan but also Japan, Korea, China, and Hong Kong. The TEJ API supports database integration using Python, R, or .NET languages, allowing investors to access a wealth of data through multiple programming languages. The data provided by TEJ API is extensive and versatile, with the added assurance of being officially maintained by a Taiwanese team, offering more excellent reliability for users.
In the past, Yahoo Finance provided an official API that allowed investors to access financial data for free, but it was shut down in 2017. However, finance API is a free Python package that simulates web visits, enabling investors to continue retrieving real-time financial information from Yahoo Finance. However, there are limitations on the number of requests that can be made, and there is always the possibility of being blocked.
FinMind API is an open-source API primarily focused on providing financial information about the Taiwan stock market. The data transmitted via FinMind API includes technical, fundamental, sentiment, and news-related information. It also allows users to perform backtesting, create candlestick charts, and build dashboards, supporting investors in machine learning and data analysis. In addition to monitoring the stock market, it covers futures, options, and other derivatives. While it may not offer as comprehensive international financial data as it does for Taiwan stocks, it still provides information on U.S., U.K., European, and Japanese stock prices, money supply, and gold and oil prices, which is more than sufficient for beginner investors. However, a notable drawback is that it does not offer real-time data updates, with the most recent update and maintenance in 2021.
Below is a simple comparison of the three Taiwan stock market APIs provided as a reference for investors.
TEJ API | yfinance API | FinMind API | |
Data Richness | Includes information from major Asia-Pacific financial markets in addition to Taiwan stocks | Primarily sourced from Yahoo Finance | Focuses on Taiwan stocks, with some data on U.S., European, and Japanese stock prices, as well as gold and oil prices |
Ease of Use | No restrictions on access methods | More complex compared to direct API queries | No restrictions on access methods |
Request Limitations | Free database: 500 requests per day; Paid database: up to 2,000 requests per day | Subject to potential blocking at any time | Free registration allows 600 requests per hour |
Maintenance and Updates | Operated and regularly updated by an official team | Financial data for individual stocks is less frequently updated, with unstable maintenance | Unstable maintenance, unable to provide real-time updates |
After understanding the features of different stock APIs, we’ll now use the TEJ API as an example to explain the setup steps and query methods in detail. This guide will show investors how to use the TEJ API to query stock trading volumes, explore dividend policies, and retrieve financial information, helping you build a customized investment portfolio.
TEJ provides multiple ways to access its database using various programming languages, covering data from Taiwan, China, Hong Kong, Korea, and Japan. The database includes operations, finance, trading, macroeconomics, and credit risk information. Users can connect to the database using the following methods:
Python: Access through the REST API over HTTPS or the TEJ API module.
R Language: Use the R API.
.NET Language: Use the .NET API.
Although these methods operate similarly… (the continuation would typically explain the nuances or differences in implementation across these methods).
Database List:
You can find the necessary databases by visiting the TEJ API official website, navigating to the top-right corner under “Database List,” and searching by region under “Taiwan Database.”
The database list used in this tutorial includes:
TWN/APRCD: Stock Price and Volume Data
TWN/AIM1A: Financial Statement Data
TWN/AMT1: Listed Companies’ Dividend Policy Data
First, import Tejapi and set up your API key. If you don’t have one, you can request a trial through the official TEJ API website.
Steps to Request a Trial: link
At the bottom, you can decide whether to display timezone information based on the time field. In Python, timestamps typically show the full details, including year, month, day, hour, minute, and second, by default. However, when you only need date information, displaying these time details can clutter the layout. To maintain a clean and concise display, you can configure the settings to show only the necessary parts, such as the year, month, and day, while hiding the hours, minutes, and seconds.
The TEJ API primarily retrieves data through a single command, allowing you to filter results based on user needs using different parameters. In the following example, we will use TSMC (2330) as the subject, apply a time filter, and convert the column names to Chinese.
The output is as follows:
You can also choose to display only the open, high, low, close, and volume data, as shown below:
The output is as follows:
Here’s the modified code where the identifier has been changed to the listed companies’ dividend policy identifier TWN/AMT1, while the rest remains unchanged:
The output is as follows:
Here’s how to modify the code with the identifier changed to TWN/AIM1A for listed companies’ financial data. However, the first step involves identifying the necessary accounting items from the income statement. Since TWN/AIM1A includes cumulative financial data for each company across various industries per quarter, we will first use TWN/AIACC to find the IFRS financial accounting item classifications, codes, full names in Chinese and English, and units.
Next, you can use data filtering to find the specific accounting codes you need. By using the Chinese name column and the str.contains() method, you can efficiently search for the relevant codes.
Next, you can sort the data by the desired column, such as the order column, and then convert the accounting items into a list for storage.
The output is as follows:
Finally, you can use Tejapi to retrieve the data by changing the identifier to TWN/AIM1A. Then, append the revenue_list to the opts list, which selects the columns to be included in the query. This will ensure that the fields corresponding to the accounting items appear after the company code and financial report date columns.
Table Information:
If you’re unsure about what columns are included in a specific table before using it, you can easily find out by the following code
However, it’s important to note that the TEJ API distinguishes between free and paid databases. The free database has limitations on the number of calls and the amount of data that can be retrieved.
Trial Database:
Paid Database:
For detailed usage instructions, you can refer to the following three links:
TEJ REST API User Manual
TEJ API Documentation
Differences Between REST API and TEJ API Usage
I want to learn about TEJ API: TEJ API
I want to purchase data only: TEJ E Shop
I want to purchase data and a backtesting engine: TQuant Lab
There are many stock APIs, each with unique features, but few can meet a wide range of needs while allowing access across multiple programming languages. Developed by TEJ (Taiwan Economic Journal), Taiwan’s most prominent financial information company, the TEJ API offers unrestricted access to its databases, supporting Python, R, and .Net, making it particularly friendly for programming language learners. The TEJ financial database covers major financial markets, including Taiwan, China, Hong Kong, Korea, and Japan, and includes data on operations, finance, trading, macroeconomics, and credit risk. This lets investors access comprehensive financial updates in real-time, adjust their portfolios instantly, and make the most informed decisions. Apply for a trial now to discover the TEJ API’s convenience!
Essential Knowledge for Beginners: Introduction to Stock APIs
Subscribe to newsletter