跳轉到主要內容
Financial Context 為外部市場資料呼叫支援兩類憑證:
  • 在 Financial Context 帳戶設定中建立的 API key
  • 面向已核准 CLI、MCP 或 agent 用戶端的 OAuth bearer token
請使用這些 Financial Context 憑證發起 API 請求。

API Key Header

curl "https://openapi.fcontext.com/api/market-data/quote?symbols=AAPL.US" \
  -H "x-api-key: YOUR_FCONTEXT_API_KEY"
x-api-key 是伺服器到伺服器整合的建議 header。

OAuth Bearer Token

curl "https://openapi.fcontext.com/api/market-data/quote?symbols=AAPL.US" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Bearer token 必須包含 market_data scope 的市場資料存取權限。

JavaScript 範例

const response = await fetch("https://openapi.fcontext.com/api/market-data/quote?symbols=AAPL.US", {
  headers: {
    "x-api-key": process.env.FCONTEXT_API_KEY,
  },
});

if (!response.ok) {
  throw new Error(`Request failed with ${response.status}`);
}

const data = await response.json();

Python 範例

import os
import requests

response = requests.get(
    "https://openapi.fcontext.com/api/market-data/quote",
    params={"symbols": "AAPL.US"},
    headers={"x-api-key": os.environ["FCONTEXT_API_KEY"]},
    timeout=30,
)
response.raise_for_status()
data = response.json()

錯誤回應

狀態碼含義
401憑證缺失、過期或無效
402需要付費方案或剩餘資料請求額度
403憑證有效,但沒有市場資料存取權限
請定期輪換金鑰,並撤銷不再使用的金鑰。