TWSE OpenAPI (Taiwan Stock Exchange 臺灣證券交易所)
Official open-data API of the Taiwan Stock Exchange. Free, no API key, no registration.
- Base URL:
https://openapi.twse.com.tw/v1 - Method: all endpoints are plain
GET, no parameters at all (no query string, no path params) - Response: always a JSON array of flat objects; every value is a string (numbers included)
- Full endpoint catalog: 143 endpoints across 7 categories (see Endpoint catalog below)
- Swagger spec:
https://openapi.twse.com.tw/v1/swagger.json(docs UI: https://openapi.twse.com.tw/)
Critical conventions (read before calling)
-
No server-side filtering. Each endpoint returns the entire dataset (typically the latest trading day's snapshot, or a historical series). To get data for one stock, fetch the whole array and filter client-side by stock code (
Codeor公司代號). Responses range from a few rows to ~30,000 rows (insider-transfer tables), so filter with a script rather than dumping raw output into context. -
Two field-naming styles. Endpoints under
/exchangeReport,/indicesReport,/announcement,/block,/fund,/holidayScheduleetc. mostly use English JSON keys (Code,Name,ClosingPrice…). Endpoints under/opendata(thet187ap*datasets) use Traditional Chinese JSON keys (公司代號,公司名稱,營業收入-當月營收…). The reference files list the exact keys per endpoint — use them verbatim; do not guess or translate key names. -
ROC (Minguo 民國) dates. Most
Date/出表日期values look like1150706= ROC year 115, July 6 = 2026-07-06 (Gregorian year = ROC year + 1911). Some fields (e.g. company founding date成立日期) use GregorianYYYYMMDDinstead — check the magnitude: 7 digits starting with1is ROC, 8 digits starting with19/20is Gregorian. -
Snapshot data, not historical query. Most endpoints only expose the latest period:
STOCK_DAY_ALL= latest trading day,FMSRFK_ALL= current month's aggregate (one row per stock),FMNPTK_ALL= current year's aggregate. There is no way to request an arbitrary past date through this API. True historical series exist only where noted (e.g./indicesReport/MI_5MINS_HISTfor TAIEX daily history). -
Number parsing. Numeric strings may contain commas (
"1,030,726,137"), be empty, or be"-"/"-"for N/A. Strip commas and handle blanks before converting. -
Data scope is TWSE listed (上市) securities. OTC/TPEx (上櫃) securities are served by a different API (
https://www.tpex.org.tw/openapi/), not this one. Endpoints suffixed_L= listed companies (上市),_P/_X= public non-listed companies (公開發行).
Quick start
# Daily OHLC for all listed stocks, filter for TSMC (2330)
curl -s https://openapi.twse.com.tw/v1/exchangeReport/STOCK_DAY_ALL |
python3 -c "import json,sys; print([r for r in json.load(sys.stdin) if r['Code']=='2330'])"
import json, urllib.request
BASE = "https://openapi.twse.com.tw/v1"
def twse(path):
with urllib.request.urlopen(BASE + path) as r:
return json.load(r)
# P/E, dividend yield, P/B for one stock
row = next(r for r in twse("/exchangeReport/BWIBBU_ALL") if r["Code"] == "2330")
# {'Code': '2330', 'Name': '台積電', 'PEratio': '...', 'DividendYield': '...', 'PBratio': '...'}
# Company profile (Chinese keys!)
tsmc = next(r for r in twse("/opendata/t187ap03_L") if r["公司代號"] == "2330")
Task → endpoint cheat sheet
| Task | Endpoint |
|---|---|
| Today's OHLC/volume, all stocks | /exchangeReport/STOCK_DAY_ALL |
| P/E, dividend yield, P/B | /exchangeReport/BWIBBU_ALL |
| Closing price + monthly average | /exchangeReport/STOCK_DAY_AVG_ALL |
| Per-stock current-month / current-year aggregate | /exchangeReport/FMSRFK_ALL / FMNPTK_ALL |
| TAIEX index history (daily OHLC) | /indicesReport/MI_5MINS_HIST |
| Whole-market daily volume/value | /exchangeReport/FMTQIK |
| Company basic profile | /opendata/t187ap03_L |
| Monthly revenue, all companies | /opendata/t187ap05_L |
| Income statement (general industry) | /opendata/t187ap06_L_ci |
| Balance sheet (general industry) | /opendata/t187ap07_L_ci |
| Dividend distributions | /opendata/t187ap45_L |
| Material news / announcements | /opendata/t187ap04_L |
| Ex-dividend calendar | /exchangeReport/TWT48U_ALL |
| Margin trading balances | /exchangeReport/MI_MARGN |
| Trading holidays / market calendar | /holidaySchedule/holidaySchedule |
| TWSE news | /news/newsList |
Endpoint catalog
Read the reference file for the category you need — each lists every endpoint with its exact response keys (Chinese originals kept as comments):
| Reference file | Category (原分類) | Endpoints | Contents |
|---|---|---|---|
| references/securities-trading.md | 證券交易 | 36 | Daily quotes, valuation ratios, market stats, margin/block/day trading, attention & disposition stocks, market calendar |
| references/corporate-governance.md | 公司治理 | 56 | Company profiles, insider/director holdings, board data, material news, dividends, shareholder meetings, 21 ESG datasets |
| references/financial-statements.md | 財務報表 | 30 | Monthly revenue, income statements & balance sheets by industry format, profitability summaries |
| references/indices.md | 指數 | 5 | TAIEX, Taiwan 50, Formosa Index histories |
| references/warrants.md | 權證 | 3 | Warrant issuance and trading stats |
| references/brokers.md | 券商資料 | 9 | Securities firm directories, personnel, monthly financials |
| references/misc.md | 其他 | 4 | TWSE news/events, government bonds, funds |