Cookie settings
We use essential cookies to keep you signed in and secure, and analytics cookies to improve the product. We never use them for ad tracking.Learn more
Building an AI agent? Start with /llms.txt for the full site index.
文件
使用 Python client 快速呼叫 TW Market Data public API,並取得 requestId 與 credits metadata。
目前 Python SDK 為 local/dev preview,可用 editable 安裝方式在本機測試。
cd /Volumes/DEV_USB/Projects/tw-market-data-websitepip install -e packages/python-sdkfrom twmarketdata import TWMarketDataClient client = TWMarketDataClient( api_key="sk_live_xxx", base_url="https://twmarketdata.com", timeout=10,)先從 twse_daily_price 與 issuer_profile 兩個常用工具開始。
price = client.twse_daily_price(symbol="2330", limit=1)profile = client.issuer_profile(symbol="2330") print(price.data)print(profile.data)result = client.monthly_revenue(symbol="2330", limit=12) print(result.meta.request_id)print(result.meta.dry_run)print(result.meta.credits_cost)print(result.meta.credits_charged)print(result.meta.plan)from twmarketdata import ( AuthenticationError, EntitlementError, InsufficientCreditsError, DatasetNotFoundError, UpstreamError,) try: result = client.technical_indicators(symbol="2330", limit=20)except AuthenticationError: print("API key 無效")except EntitlementError: print("目前方案未開通此 dataset")except InsufficientCreditsError: print("credits 不足")except DatasetNotFoundError: print("dataset 不存在")except UpstreamError: print("上游服務異常")建議在本機與 CI 使用環境變數管理金鑰與 base URL。
export TWMD_API_KEY=sk_live_xxxexport TWMD_BASE_URL=https://twmarketdata.com