Historical Candles
取得 1 年內的上市櫃歷史股價(依代碼查詢),個股資料區間最遠可回溯至 2010 年,指數部分最遠可回溯至 2015 年!
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;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),一律回傳近五日資料,並且無法選擇 turnover 與 change 的欄位。
Example
- Python
- Node.js
- C#
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"}))
const { FubonSDK } = require('fubon-neo');
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID", "Your Password", "Your Cert Path", "Your Cert Password");
sdk.initRealtime(); // 建立行情連線
const client = sdk.marketdata.restClient
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));
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.Stock.History; //引入 HistoryTimeFrame
using FugleMarketData.QueryModels; //引入 FieldsType
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your Password", "Your Cert Path", "Your Cert Password");
sdk.InitRealtime(); // 建立行情連線
var rest = sdk.MarketData.RestClient.Stock;
var candle = await rest.History.Candles("2330", new(DateTime.Today.AddDays(-100),DateTime.Today,HistoryTimeFrame.Week,FieldsType.High|FieldsType.Low));
var candle_con = candle.Content.ReadAsStringAsync().Result;
Console.WriteLine(candle_con);
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
Name | Type | Description |
---|---|---|
date * | string | 日期 |
type * | string | 證券類型 |
exchange * | string | 交易所 |
market | string | 市場別 |
symbol * | string | 股票代號 |
timeframe* | string | K線週期 |
data | Candle | K線資料 |
info
'*' 表示必揭示欄位。