Historical Candles
取得 1 年內的上市櫃歷史股價(依代碼查詢),個股資料區間最遠可回溯至 2010 年,指數部分最遠可回溯至 2015 年!
GET /historical/candles/{symbol}
Parameters
| Name | Type | Description | 
|---|---|---|
symbol* | string | 股票代碼 | 
from | string | 開始日期(格式:yyyy-MM-dd) | 
to | string | 結束日期(格式:yyyy-MM-dd) | 
timeframe | string | K線週期,可選 1 1分K;3 3分K;5 5分K;10 10分K;15 15分K;30 30分K;60 60分K;D 日K;W 週K;M 月K | 
fields | string | 欄位,可選:open,high,low,close,volume,turnover,change | 
sort | string | 時間排序,預設為  desc 降冪 ;可選 asc 升冪 | 
caution
目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近 30 日資料,並且無法選擇 turnover 與 change 的欄位。
Response
| Name | Type | Description | 
|---|---|---|
date* | string | 日期 | 
type* | string | 證券類型 | 
exchange* | string | 交易所 | 
market* | string | 市場別 | 
symbol* | string | 股票代號 | 
timeframe* | string | K線週期 | 
data* | object[] | K線資料 | 
data.date* | string | 日期(分 K 含時間) | 
data.open | number | K線開盤價 | 
data.high | number | K線最高價 | 
data.low | number | K線最低價 | 
data.close | number | K線收盤價 | 
data.volume | number | K線成交量(股) | 
data.turnover | number | K線成交金額(元) | 
data.change | number | K線漲跌 | 
Example
- cURL
 - Python
 - Node.js
 
curl -X 'GET' \
  'https://api.fugle.tw/marketdata/v1.0/stock/historical/candles/0050?fields=open,high,low,close,volume' \
  -H 'X-API-KEY: <YOUR_API_KEY>'
from fugle_marketdata import RestClient
client = RestClient(api_key = 'YOUR_API_KEY')  # 輸入您的 API key
stock = client.stock  # Stock REST API client
stock.historical.candles(**{"symbol": "0050", "from": "2023-02-06", "to": "2023-02-08", "fields": "open,high,low,close,volume,change"})
const { RestClient } = require('@fugle/marketdata');
const client = new RestClient({ apiKey: 'YOUR_API_KEY' });
client.stock.historical.candles({ symbol: '0050', from: '2023-02-06', to: '2023-02-08', fields: 'open,high,low,close,volume,change' })
  .then(data => console.log(data));
Response Body:
{
  "symbol": "0050",
  "type": "EQUITY",
  "exchange": "TWSE",
  "market": "TSE",
  "timeframe": "D",
  "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
    }
  ]
}