Workflows / Use Cases
從月營收、損益表、資產負債表與估值資料建立可驗證的台股基本面研究流程。
這篇適合要建立台股基本面 API workflow 的開發者、研究員與 AI agent 整合者。
若你希望從台股資料 API 快速建立可重跑、可驗證的研究流程,可先從本頁開始。
常見的基本面資料包含月營收、損益表、資產負債表、現金流量表與估值資料。建議用統一的 ticker、日期與資料來源規則,避免 cross-dataset 對齊錯誤。
開始前請先準備:
所有 request 都要帶 X-API-Key。下面示例會用同一個 helper 函式讀取不同 dataset。
import requests BASE_URL = "https://api.twmarketdata.com"HEADERS = { "X-API-Key": "your_api_key_here",} def get_dataset(path, params): response = requests.get( f"{BASE_URL}{path}", headers=HEADERS, params=params, ) response.raise_for_status() return response.json()import requests BASE_URL = "https://api.twmarketdata.com"HEADERS = {"X-API-Key": "your_api_key_here"} def get_dataset(path, params): response = requests.get( f"{BASE_URL}{path}", headers=HEADERS, params=params, ) response.raise_for_status() return response.json() profile = get_dataset( "/v2/datasets/issuer-profile", {"symbol": "2330"},) print(profile)import requests BASE_URL = "https://api.twmarketdata.com"HEADERS = {"X-API-Key": "your_api_key_here"} def get_dataset(path, params): response = requests.get( f"{BASE_URL}{path}", headers=HEADERS, params=params, ) response.raise_for_status() return response.json() monthly_revenue = get_dataset( "/v2/datasets/monthly-revenue", { "symbol": "2330", "limit": 12, },) print(monthly_revenue)import requests BASE_URL = "https://api.twmarketdata.com"HEADERS = {"X-API-Key": "your_api_key_here"} def get_dataset(path, params): response = requests.get( f"{BASE_URL}{path}", headers=HEADERS, params=params, ) response.raise_for_status() return response.json() income_statement = get_dataset( "/v2/datasets/income-statement", {"symbol": "2330", "limit": 4},) print(income_statement)import requests BASE_URL = "https://api.twmarketdata.com"HEADERS = {"X-API-Key": "your_api_key_here"} def get_dataset(path, params): response = requests.get( f"{BASE_URL}{path}", headers=HEADERS, params=params, ) response.raise_for_status() return response.json() balance_sheet = get_dataset( "/v2/datasets/balance-sheet", {"symbol": "2330", "limit": 4},) print(balance_sheet)import requests BASE_URL = "https://api.twmarketdata.com"HEADERS = {"X-API-Key": "your_api_key_here"} def get_dataset(path, params): response = requests.get( f"{BASE_URL}{path}", headers=HEADERS, params=params, ) response.raise_for_status() return response.json() cash_flow = get_dataset( "/v2/datasets/cash-flow-statement", {"symbol": "2330", "limit": 4},) print(cash_flow)import requests BASE_URL = "https://api.twmarketdata.com"HEADERS = {"X-API-Key": "your_api_key_here"} def get_dataset(path, params): response = requests.get( f"{BASE_URL}{path}", headers=HEADERS, params=params, ) response.raise_for_status() return response.json() valuation_data = get_dataset( "/v2/datasets/valuation-data", {"symbol": "2330", "limit": 4},) print(valuation_data)實務上建議先看月營收變化,再看損益表與資產負債表,最後用估值資料補上價格與基本面的相對關係。
company_name = (profile.get("rows") or [{}])[0].get("company_name")latest_revenue_yoy = (monthly_revenue.get("rows") or [{}])[0].get("yoy_growth_pct")latest_eps = (income_statement.get("rows") or [{}])[0].get("eps")latest_per = (valuation_data.get("rows") or [{}])[0].get("per")latest_pbr = (valuation_data.get("rows") or [{}])[0].get("pbr") summary = { "company_name": company_name, "latest_revenue_yoy": latest_revenue_yoy, "latest_eps": latest_eps, "latest_per": latest_per, "latest_pbr": latest_pbr,} print(summary)不同資料集的更新節奏與揭露時點不同。使用前請先確認各 API 回傳的時間欄位、資料範圍與 data_gaps 欄位。
TW Market Data 會保留來源角色與資料缺口資訊,請不要假設任一資料集在所有日期與所有標的都完整覆蓋。
完成基本面摘要後,可延伸到: