twmarket
參考API

資料模型

BatchResult

保存原始批次輸入、資料或例外;批次保留順序與重複輸入.

欄位

instrument: str | Contract
data: T | None
error: Exception | None

ok

def ok() -> bool: ...

回傳批次是否沒有例外.

SourceInfo

記錄來源、端點及 UTC 取得時間;取得時間與交易日分開.

欄位

provider: str
url: str
received_at: datetime

EquityDaily

保存證券日行情與來源單位;TWSE 為股/元,TPEx 為張/千元.

欄位

symbol: str
date: date
open: Decimal | None
high: Decimal | None
low: Decimal | None
close: Decimal | None
volume: int | None
amount: Decimal | None
volume_unit: Literal['shares', 'lots']
amount_unit: Literal['TWD', 'thousand_TWD']
source: SourceInfo
change: Decimal | None = None
transactions: int | None = None
raw_change: str | None = None
change_basis_reset: bool = False

DerivativeDaily

保存契約交易日、時段及價格;最新成交、結算與合計量分開.

欄位

contract: Contract
date: date
session: Session
open: Decimal | None
high: Decimal | None
low: Decimal | None
last: Decimal | None
settlement: Decimal | None
volume: int | None
open_interest: int | None
source: SourceInfo
combined_volume: int | None = None

MarginRequirement

保存保證金金額或百分數;unit 與選擇權風險組件分開.

欄位

product: str
name: str
category: MarginCategory
date: date
clearing: Decimal | None
maintenance: Decimal | None
initial: Decimal | None
unit: str
source: SourceInfo
underlying: str | None = None
group: int | None = None
component: str | None = None

DerivativeProduct

保存商品目錄、規格 URL 及乘數來源.

欄位

product: str
name: str
kind: InstrumentKind
specification_url: str
source: SourceInfo
underlying: str | None = None
multiplier: Decimal | None = None
multiplier_unit: str | None = None
mis_commodity: str | None = None
multiplier_source: SourceInfo | None = None

TickSize

保存 tick 價格級距;lower 含下界、upper 不含上界,None 表示無界.

欄位

lower: Decimal | None
upper: Decimal | None
tick: Decimal

ContractSpecification

保存乘數、幣別、交割方式及 tick 級距;來源缺值為 None.

欄位

product: str
name: str
kind: InstrumentKind
underlying: str
multiplier: Decimal | None
multiplier_unit: str | None
currency: str | None
settlement: Literal['cash', 'physical'] | None
source: SourceInfo
ticks: tuple[TickSize, ...] = ()
multiplier_source: SourceInfo | None = None

FinancialValue

保存一個科目、期間與金額或百分數;來源未標示單位時為 None.

欄位

symbol: str
kind: str
report_year: int
report_quarter: int
report_type: str | None
account: str
depth: int
is_empty: bool
period_start: date | None
period_end: date
period_label: str
measure: Literal['amount', 'percentage']
value: Decimal | None
unit: str | None
source: SourceInfo

FinancialStatement

保存報表年度、季度及各科目自身的報導期間.

欄位

symbol: str
kind: str
year: int
quarter: int
report_type: str | None
rows: tuple[FinancialValue, ...]
source: SourceInfo

Revenue

保存當月與累計營收及增減;金額與百分數維持來源單位.

欄位

symbol: str
year: int
month: int
current: Decimal | None
previous_year: Decimal | None
change: Decimal | None
change_percent: Decimal | None
cumulative: Decimal | None
previous_year_cumulative: Decimal | None
cumulative_change: Decimal | None
cumulative_change_percent: Decimal | None
unit: str
source: SourceInfo

Dividend

保存普通/特別股決議;盈餘期間、決議日期及各類股利分開.

欄位

symbol: str
share_class: Literal['common', 'preferred']
share_name: str | None
status: str
year: int
quarter: int | None
period_start: date | None
period_end: date | None
installment: int | None
board_date: date | None
meeting_date: date | None
opening_retained_earnings: Decimal | None
net_income: Decimal | None
distributable_earnings: Decimal | None
closing_retained_earnings: Decimal | None
cash_from_earnings: Decimal | None
cash_from_legal_reserve: Decimal | None
cash_from_capital_reserve: Decimal | None
cash_total: Decimal | None
stock_from_earnings: Decimal | None
stock_from_legal_reserve: Decimal | None
stock_from_capital_reserve: Decimal | None
stock_total_shares: int | None
par_value: Decimal | None
par_currency: str | None
source: SourceInfo
amount_unit: str = '元'
per_share_unit: str = '元/股'

EmergingDaily

保存興櫃高低價、加權均價與成交資料;量/額為股/元.

欄位

symbol: str
date: date
high: Decimal | None
low: Decimal | None
weighted_average: Decimal | None
volume: int | None
amount: Decimal | None
transactions: int | None
source: SourceInfo
block_volume: int | None = None
block_amount: Decimal | None = None
block_high: Decimal | None = None
block_low: Decimal | None = None
block_weighted_average: Decimal | None = None
block_transactions: int | None = None

BrokerQuote

保存個別推薦券商的買賣價量及來源時間.

欄位

broker: str
bid: Decimal | None
bid_size: int | None
ask: Decimal | None
ask_size: int | None
quoted_at: datetime | None

EmergingQuote

保存興櫃成交統計與券商個別報價;量/額為股/元.

欄位

symbol: str
last: Decimal | None
high: Decimal | None
low: Decimal | None
weighted_average: Decimal | None
volume: int | None
amount: Decimal | None
quoted_at: datetime | None
broker_quotes: tuple[BrokerQuote, ...]
source: SourceInfo
status: str | None = None

ShareholdingBracket

保存官方持股級距、人數、股數及百分數;16、17 為調整與總計.

欄位

symbol: str
date: date
level: int
people: int | None
shares: int | None
percentage: Decimal | None
source: SourceInfo

Contract

標識期貨或選擇權的商品、到期月份/週別、價差、履約價與買賣權.

欄位

product: str
expiry: str
kind: InstrumentKind = 'future'
strike: Decimal | None = None
right: Literal['call', 'put'] | None = None
mis_symbol: str | None = None
expires_on: date | None = None

expiry_month

def expiry_month() -> str: ...

回傳第一個交割月份;expiry 保留週別與價差期間.

legs

def legs() -> tuple['Contract', ...]: ...

回傳來源價差兩腿期間;單一契約回傳空 tuple.

EconomicObservation

保存按月系列數值或景氣燈號;period 為觀測月份首日.

欄位

period: Date
series: str
value: Decimal | None
text: str | None
source: SourceInfo

ExchangeRate

保存來源日期與 numerator/denominator 匯率方向.

欄位

date: Date
numerator: str
denominator: str
rate: Decimal | None
published_date: Date | None
source: SourceInfo

Instrument

保存證券代號、ISIN、分類及來源日期;代號保留前導零.

欄位

symbol: str
name: str
market: Market
category: str
isin: str | None
listed_on: date | None
industry: str | None
cfi: str | None
source: SourceInfo
as_of: date | None = None

IndexDaily

保存每日指數 OHLC 與來源單位.

欄位

index: str
date: date
open: Decimal | None
high: Decimal | None
low: Decimal | None
close: Decimal | None
source: SourceInfo
change: Decimal | None = None
unit: str = 'points'

IndexClose

保存價格/報酬指數收盤、發布單位及來源日期.

欄位

index: str
date: date
kind: Literal['price', 'total_return']
publisher: str
close: Decimal | None
change: Decimal | None
change_percent: Decimal | None
source: SourceInfo
has_special_note: bool = False
unit: str = 'points'

ExRight

保存歷史除權息事件及參考價格;每千股配股數獨立保存.

欄位

symbol: str
date: date
name: str
kind: EventKind
previous_close: Decimal | None
reference_price: Decimal | None
adjustment: Decimal | None
limit_up: Decimal | None
limit_down: Decimal | None
opening_reference: Decimal | None
dividend_reference: Decimal | None
source: SourceInfo
rights_value: Decimal | None = None
dividend_value: Decimal | None = None
cash_dividend: Decimal | None = None
bonus_shares_per_thousand: Decimal | None = None
subscription_shares: int | None = None
subscription_price: Decimal | None = None
public_shares: int | None = None
employee_shares: int | None = None
shareholder_shares: int | None = None
subscription_shares_per_thousand: Decimal | None = None
price_unit: str = 'TWD'

ExRightSchedule

保存最新除權息預告;配股率與每千股配股數分開.

欄位

symbol: str
date: date
name: str
kind: EventKind
cash_dividend: Decimal | None
bonus_share_ratio: Decimal | None
subscription_share_ratio: Decimal | None
subscription_price: Decimal | None
public_shares: int | None
employee_shares: int | None
shareholder_shares: int | None
shareholder_subscription_shares_per_thousand: Decimal | None
source: SourceInfo
price_unit: str = 'TWD'

TradingRestriction

保存注意、處置或暫停交易的公告日期、有效期間與時間.

欄位

symbol: str
name: str
market: Market
kind: RestrictionKind
announced_on: date | None
starts_on: date | None
ends_on: date | None
source: SourceInfo
halted_at: datetime | None = None
resumed_at: datetime | None = None
close: Decimal | None = None
price_earnings_ratio: Decimal | None = None

TradingStatus

保存最新交易方式及暫停狀態;來源無日期時 date 為 None.

欄位

symbol: str
name: str
market: Literal['twse', 'tpex']
date: date | None
altered: bool
segmented: bool | None
managed: bool | None
suspended: bool | None
matching_interval_minutes: int | None
source: SourceInfo

BookLevel

保存一個買檔或賣檔的檔位、價格及數量.

欄位

level: int
price: Decimal
size: int | None

Quote

保存成交與買賣檔快照;報價時間為台北時區,stale 表示待重新同步.

欄位

symbol: str
last: Decimal | None
open: Decimal | None
high: Decimal | None
low: Decimal | None
volume: int | None
volume_unit: Literal['lots', 'contracts']
bids: tuple[BookLevel, ...]
asks: tuple[BookLevel, ...]
quoted_at: datetime | None
source: SourceInfo
session: Session | None = None
source_date: date | None = None
status: str | None = None
contract: Contract | None = None
stale: bool = False

本頁目錄