Skip to main content

使用 Tool API 獲取數據(股價、財務、月營收、集保和股票屬性)

安裝套件

pip install tej-tool-api

匯入套件

import os
os.environ['TEJAPI_KEY'] = "YOURAPIKEY"

import TejToolAPI

get_history_data - 獲取歷史資料

list_of_Stocks = ['2330','2303','2454', '2882', '2881']
# 撈取歷史資料
data = TejToolAPI.get_history_data(
ticker=list_of_Stocks,
columns= ['稅前淨利成長率', '單月營收成長率%'], 
transfer_to_chinese=False
)

目前資料庫僅支援台灣市場。
Tool API 可獲取 PIT 資料庫的所有欄位,共計超過 600 個指標,具體指標內容參考TEJAPI_量化投資資料庫
財務數據是根據發布日(announcement date)來mapping,非發布日的財務數據會使用當下可獲得最新的資料為準進行填值。ex: 2330 在 2010-02-01 時所能獲得最新的財務資料為 2009Q3 的財務資料,則 2010-01-01 會以 2009Q3 的資料進行填補。惟公司2009Q4自結財報早於 2010-02-01 發布時,且 include_self_acc = 'Y',這時 2010-02-01 的財務數據使用自結財務數據。

參數:

Parameters Is Required Data Type Descriptions
ticker Required list 股票代碼,ex: ['2330', '2881', '2882']
columns Required list 欄位代碼,可參考TEJAPI_量化投資資料庫
start Optional date/str 起始日,ex: '2008-01-01' (預設值為 '2013-01-01'),目前版本尚未支援timezone的設定
end Optional date/str 結束日,ex: '2008-01-01' (預設值為今日 datetime.now()),目前版本尚未支援timezone的設定
transfer_to_chinese Optional boolean 欄位轉換成中文,若 transfer_to_chinese=True,則欄位顯示為中文名稱,transfer_to_chinese=False,則欄位顯示為英文名稱。(預設為 False)
fin_type Optional list 會計科目類型 -> 單季:Q、累計:A、移動四季:TTM,ex: 撈取單季和累積,fin_type=['Q','A']。(預設為 ['Q','A','TTM'])
include_self_acc Optional string 財務是否包含公司自結損益,include_self_acc='Y',表示財務資料包含自結損益,否則僅有財簽資料 (預設為 'N')
npartitions Optional int 代表取得資料時已n家公司為一組單位,ex: 取得100家資料時設定 npartitions = 50 ,則會分成 ceil(100/50) = 2 次 分別抓取後再合併

get_internal_code

內部欄位編碼與中英文簡稱轉換功能

TejToolAPI.get_internal_code(['稅前淨利成長率', 'Gross_Profit_Loss_from_Operations'])
output: ['r404', 'gm']

參數:

Parameters Is Required Data Type Descriptions
columns Required list 欄位代碼,可參考TEJAPI_量化投資資料庫

search_columns

若想從內部編碼反向取得 columns 所對應之中英文欄位則可利用 search_columns 這個function

TejToolAPI.search_columns(['r404'])
columns chn_column_names eng_column_names table_names TABLE_NAMES API_TABLE CHN_NAMES
r404 稅前淨利成長率 Pre_Tax_Income_Growth_Rate fin_self_acc fin_self_acc TWN/AFESTM1 財務-自結數
r404 稅前淨利成長率 Pre_Tax_Income_Growth_Rate fin_board_select fin_board_select TWN/AFESTMD 財務-董事決議數

參數:

Parameters Is Required Data Type Descriptions
columns Required list 欄位代碼,可參考TEJAPI_量化投資資料庫

search_table

TejToolAPI.search_table(['r404'])
COLUMNS TABLE_NAMES
r404 fin_self_acc
r404 fin_auditor

參數:

Parameters Is Required Data Type Descriptions
columns Required list 欄位代碼,可參考TEJAPI_量化投資資料庫

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tej_tool_api-1.3.0.tar.gz (89.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tej_tool_api-1.3.0-py3-none-any.whl (90.5 kB view details)

Uploaded Python 3

File details

Details for the file tej_tool_api-1.3.0.tar.gz.

File metadata

  • Download URL: tej_tool_api-1.3.0.tar.gz
  • Upload date:
  • Size: 89.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for tej_tool_api-1.3.0.tar.gz
Algorithm Hash digest
SHA256 2f4038820f30caca7ff05f155bd10077abf7991077f7405a353422dce65d2067
MD5 086ccf4d84d33f5f66fc77a133c00860
BLAKE2b-256 7e0b534cabcbd45bc8d203ba369a6d6e8ae43ea1e50f2453461abfbea41f030c

See more details on using hashes here.

File details

Details for the file tej_tool_api-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: tej_tool_api-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 90.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for tej_tool_api-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75d8e2d85494d4f176175a23de9fb3de60447ca1a7c9f4cdc381c71316ee2784
MD5 01d29137763a5eb47e6caa46e0987f94
BLAKE2b-256 11d89fda42f0b81367199e4fd0a5206b65dc11fbeb2c0707c4fa7dfce0f002be

See more details on using hashes here.

Release history Release notifications | RSS feed

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page