How to get TWSE data programmatically (Python / API)

You can get TWSE data programmatically in three ways: call the official TWSE OpenAPI and parse the JSON yourself, use a data provider's REST API, or let an AI agent fetch it over an MCP server. With TW Market Data you sign up for a free API key and make a single HTTP request with an X-API-Key header, and the response is clean JSON.

Python quick start

Request the TWSE daily price dataset and read the JSON rows:

import requests

headers = {"X-API-Key": "your_api_key_here"}
url = "https://api.twmarketdata.com/v2/datasets/twse-daily-price?symbol=2330&limit=10"
print(requests.get(url, headers=headers).json())

Read coverage and data gaps before you rely on a series

Check the freshness and data_gaps signals in the response and on the dataset page rather than assuming full history. TW Market Data is TWSE-first; TPEx historical depth is disclosed per dataset.

Free tier for testing

The free plan includes the basic datasets with a monthly request quota so you can validate your integration end-to-end before upgrading. A Python SDK (pip install) is planned but not yet published.

Common questions

1How do I authenticate?
Send your key in the X-API-Key request header. Get a free key by signing up at twmarketdata.com.
2What does a request look like?
GET https://api.twmarketdata.com/v2/datasets/twse-daily-price?symbol=2330&limit=10 with an X-API-Key header returns JSON daily price rows.
3Can I try it without an API key?
Yes. Five symbols — 2330, 2317, 2454, 0050 and 2603 — respond without any key, so you can confirm the request shape before signing up.
4How do I get TWSE data from the official API in Python instead?
Call the official open-data endpoints directly with requests — they need no key. Plan for ROC-calendar date strings, Chinese field names and string-typed numbers, and note that most endpoints return the latest period as a snapshot rather than a date range, so history has to be accumulated.
5How do I avoid look-ahead bias?
Filter on the knowledge date rather than the reporting period. Each row records when its value became knowable, so an as-of query returns only what was actually public at that point in your backtest.

Want to query this data yourself? Create a free account.

Related articles