REST API參考
API基底網址為https://api.clarifindata.com。資料查詢使用Bearer金鑰,每帳戶每小時可請求3000次。
取得資料集目錄
GET/v1/data
列出資料集名稱、分類、欄位、資料口徑、涵蓋範圍及attribution來源陣列。資料來自交易所公開頁面與開放資料,各資料集分別標示來源。
| 參數名稱 | 型別 | 必填 | 說明 |
|---|---|---|---|
category | string | 否 | 篩選分類:technical / chips / fundamentals / derivatives / convertibles / other |
範例請求
bash
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.clarifindata.com/v1/data"200 OK回應節錄
json
{
"datasets": [
{
"name": "TaiwanStockPrice",
"table": "taiwan_stock_price",
"category": "technical",
"status": "live",
"description": "上市櫃股票日 K(TWSE/TPEx STOCK_DAY)",
"columns": ["stock_id","trade_date","open","high","low","close","volume","turnover","trade_count","spread"],
"key_date_column": "trade_date",
"update_freq": "daily",
"supports_stock_id": true,
"unit": null,
"notes": null,
"adjustment_method": null,
"odd_lot_included": null,
"accumulation": null,
"example_query": "/v1/data/TaiwanStockPrice?stock_id=2330&limit=5",
"coverage": {
"first_date": "2004-01-02",
"last_date": "2026-06-11",
"row_count": 9800000
},
"attribution": [
{
"source_id": "twse_web",
"provider": "臺灣證券交易所",
"provider_en": "Taiwan Stock Exchange",
"url": "https://www.twse.com.tw/rwd/zh/",
"license_name": null,
"license_url": null,
"statement": "資料來源:臺灣證券交易所(https://www.twse.com.tw/rwd/zh/)公開資訊。本服務未與資料來源機構簽訂授權契約,非官方資料,僅為分享。"
},
{
"source_id": "tpex_web",
"provider": "證券櫃檯買賣中心",
"provider_en": "Taipei Exchange",
"url": "https://www.tpex.org.tw/www/zh-tw/",
"license_name": null,
"license_url": null,
"statement": "資料來源:證券櫃檯買賣中心(https://www.tpex.org.tw/www/zh-tw/)公開資訊。本服務未與資料來源機構簽訂授權契約,非官方資料,僅為分享。"
}
]
}
]
}attribution各筆包含source_id、provider、provider_en、url、license_name、license_url及statement。授權名稱或網址為null時,表示該來源的開放授權尚待確認。請將原始來源及適用的授權聲明與資料一併保存。
資料集目錄列出各來源資訊;資料利用規範與權利反映方式,請見金晰數據網站的服務條款。
查詢資料集
GET/v1/data/{dataset}
以資料集名稱指定{dataset},例如TaiwanStockPrice。
next_cursor為null代表最後一頁,否則將其帶入下一次請求的cursor。limit最大10,000。回應頂層attribution列出資料集的原始來源,即使查詢沒有資料也會提供。
| 參數名稱 | 型別 | 必填 | 說明 |
|---|---|---|---|
stock_id | string | 否 | 股票代號,例如2330。多檔股票以逗號分隔:2330,2317,0050。僅適用於含stock_id欄位的資料集。 |
start | string | 否 | 起始日,YYYY-MM-DD或年份YYYY,含當天 |
end | string | 否 | 結束日,YYYY-MM-DD或年份YYYY,含當天 |
limit | integer | 否 | 回傳筆數上限,最大10,000筆預設值:1000 |
cursor | string | 否 | 將上一個回應的next_cursor帶入此參數。next_cursor為null時即為最後一頁。 |
period | string | 否 | 財報可指定cumulative累計值或quarterly單季值,預設cumulative |
include_expired | boolean | 否 | 可轉債資料集:是否包含已到期或已終止的債券預設值:false |
include_inactive | boolean | 否 | 金控資料集:是否包含已下市或併購的金控預設值:false |
aggregate | string | 否 | 鉅額交易:daily按日合併並計算成交量加權均價;預設逐筆回傳 |
範例:查詢單一股票
bash
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.clarifindata.com/v1/data/TaiwanStockPrice?stock_id=2330&start=2026-01-01&end=2026-06-11&limit=10"範例:批次查詢多支股票
bash
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.clarifindata.com/v1/data/TaiwanStockPrice?stock_id=2330,2317,0050&limit=100"回應結構範例
json
{
"dataset": "TaiwanStockPrice",
"count": 1,
"data": [
{
"stock_id": "2330",
"trade_date": "2026-06-11",
"open": "1020.0000",
"high": "1025.0000",
"low": "1015.0000",
"close": "1020.0000",
"volume": 15384000,
"turnover": "15691680000",
"trade_count": 28441,
"spread": "10.0000"
}
],
"next_cursor": null,
"attribution": [
{
"source_id": "twse_web",
"provider": "臺灣證券交易所",
"provider_en": "Taiwan Stock Exchange",
"url": "https://www.twse.com.tw/rwd/zh/",
"license_name": null,
"license_url": null,
"statement": "資料來源:臺灣證券交易所(https://www.twse.com.tw/rwd/zh/)公開資訊。本服務未與資料來源機構簽訂授權契約,非官方資料,僅為分享。"
},
{
"source_id": "tpex_web",
"provider": "證券櫃檯買賣中心",
"provider_en": "Taipei Exchange",
"url": "https://www.tpex.org.tw/www/zh-tw/",
"license_name": null,
"license_url": null,
"statement": "資料來源:證券櫃檯買賣中心(https://www.tpex.org.tw/www/zh-tw/)公開資訊。本服務未與資料來源機構簽訂授權契約,非官方資料,僅為分享。"
}
]
}分頁範例
python
import requests
def fetch_all(dataset, api_key, **params):
headers = {"Authorization": f"Bearer {api_key}"}
url = f"https://api.clarifindata.com/v1/data/{dataset}"
rows = []
sources = {}
cursor = None
while True:
p = {**params, "limit": 10000}
if cursor:
p["cursor"] = cursor
response = requests.get(url, headers=headers, params=p, timeout=30)
response.raise_for_status()
body = response.json()
rows.extend(body["data"])
for source in body["attribution"]:
sources[source["source_id"]] = source
cursor = body.get("next_cursor")
if not cursor:
break
return {"data": rows, "attribution": list(sources.values())}查詢用量
GET/v1/key/info
回傳金鑰前綴、帳戶每小時額度及目前用量。此查詢不增加資料請求計數。window_seconds表示計算視窗的秒數。
bash
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.clarifindata.com/v1/key/info"json
{
"prefix": "cfd_",
"rate_limit_per_hour": 3000,
"used_this_hour": 53,
"remaining_this_hour": 2947,
"window_seconds": 3600
}查詢帳戶
GET/v1/me
回傳帳戶識別碼、電子郵件、驗證狀態、建立日期、共用額度及金鑰清單。此帳戶管理端點使用登入後的工作階段Cookie認證。
bash
curl --cookie cookies.txt \
"https://api.clarifindata.com/v1/me"json
{
"id": 42,
"email": "[email protected]",
"email_verified": true,
"created_at": "2026-03-15T08:12:00Z",
"quota": {
"rate_limit_per_hour": 3000,
"used_this_hour": 53,
"remaining_this_hour": 2947,
"window_seconds": 3600
},
"keys": []
}