Skip to main content

Historical Candles

取得 1 年內的上市櫃歷史股價(依代碼查詢),個股資料區間最遠可回溯至 2010 年,指數部分最遠可回溯至 2015 年!

historical/candles/{symbol}

Parameters

NameTypeDescription
symbol*string股票代碼
fromstring開始日期(格式:yyyy-MM-dd
tostring結束日期(格式:yyyy-MM-dd
timeframestringK線週期,可選 1 1分K;5 5分K;10 10分K;15 15分K;30 30分K;60 60分K;D 日K;W 週K;M 月K
fieldsstring欄位,可選:open,high,low,close,volume,turnover,change
sortstring時間排序,預設為 desc 降冪;可選 asc 升冪
caution

目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近五日資料,並且無法選擇 turnover 與 change 的欄位。

Example

from fubon_neo.sdk import FubonSDK, Order

sdk = FubonSDK()

accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限

sdk.init_realtime() # 建立行情連線

reststock = sdk.marketdata.rest_client.stock
print(reststock.historical.candles(**{"symbol": "0050", "from": "2023-02-06", "to": "2023-02-08"}))

Response Body:

{
"symbol": "0050",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"data": [
{
"date": "2023-02-08",
"open": 120.1,
"high": 120.95,
"low": 120,
"close": 120.85,
"volume": 9239321,
"change": 1.85
},
{
"date": "2023-02-07",
"open": 119.1,
"high": 119.25,
"low": 118.55,
"close": 119,
"volume": 8787291,
"change": -0.25
},
{
"date": "2023-02-06",
"open": 120.1,
"high": 120.1,
"low": 119.25,
"close": 119.25,
"volume": 14297030,
"change": -1.75
}
]
}

Response

NameTypeDescription
date*string日期
type*string證券類型
exchange*string交易所
marketstring市場別
symbol*string股票代號
timeframe*stringK線週期
dataCandleK線資料
info

'*' 表示必揭示欄位。