# 富邦新一代 API|程式交易的新武器
## TradeAPI
### SDK 下載
***
本頁重點
* 提供富邦新一代 API(Fubon Neo API)各語言 SDK 下載。
* 最新版本為 **v2.4.0**,並提供 [版本遷移資訊](#%E7%89%88%E6%9C%AC%E9%81%B7%E7%A7%BB%E8%B3%87%E8%A8%8A)。
* API Key 登入支援 >= v2.2.7,網頁憑證匯出登入支援 >= v2.2.8。
* 安裝步驟與相容性總覽請見 [安裝與版本相容性](https://www.fbs.com.tw/TradeAPI/docs/install-compatibility.txt)。
| 項目 | 說明 |
| ------------ | -------------------------------------------------------------------------- |
| 最新版本 | v2.4.0 |
| 支援語言 | Python / C# / JavaScript (Node.js) / C++、Go(僅支援證券交易帳務及條件單) |
| 支援平台 | 依語言提供 Windows / macOS / Linux 版本 |
| API Key 登入 | >= v2.2.7 |
| 憑證匯出登入 | >= v2.2.8 |
相關資訊
1. 新一代 API 提供測試環境,詳情請見 [快速上手](https://www.fbs.com.tw/TradeAPI/docs/welcome.txt#%E6%B8%AC%E8%A9%A6%E7%92%B0%E5%A2%83) 頁面
2. [網頁憑證匯出](https://www.fbs.com.tw/TradeAPI/docs/key.txt) 可用於 API 登入 (版本要求 >= v2.2.8)
API Key 登入 >= v2.2.7
* [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.txt)
* [API Key 申請](https://www.fbs.com.tw/TradeAPI/docs/key.txt)
版本注意事項 **>=2.2.4**
1. 新增證券委託單 user\_def 欄位輸入規則檢核提醒
a. 僅可使用 ***大小寫英文字母及 0~9 數字***,最多 10 個字元 (***規則更新 >=2.2.8***)
b. 若字元合規但長度超過 10 字元,將自動縮減至 10 字元並帶入下單;交易 event callback 發送提醒訊息
c. 若字元不合規,則自動將 user\_def 帶入空值;交易 event callback 發送提醒訊息
(***註:*** user\_def 欄位輸入不符合規則**仍會送單**,但欄位值將被自動調整,調整方式請參考上述點 b 及 c )
2. Python 行情 Web API 例外情況改用 ***Exception*** 方式回報。詳情請見行情 Web API 中之 Python 程式範例。
版本注意事項 **>=2.2.0**
1. 以下條件單功能目前不支援**期貨夜盤**: a. 分時分量 b. 移動鎖利 c. 時間觸發條件
2. 證券條件單停損停利子單設定物件(TPSLOrder)新增參數 `trigger`,可設定觸發價格參照為 成交價、最佳買價、最價賣價, 若無特別設定則預設值為 成交價,詳請參閱條件單 \[參數對照表]
(***註:*** C# 使用預設值須將此參數填入 ***null***,Python 及 JS 可忽略此參數)
(***註 2:*** **期貨條件單** 物件(FutOptTpslOrder)亦新增此欄位,尚無具體功能,C# 請填入 ***null***,Python 及 JS 可忽略此欄位 )
#### 檔案載點[](#檔案載點 "Direct link to 檔案載點")
##### Python[](#python "Direct link to Python")
支援 3.8、3.9、3.10、3.11、3.12 與 3.13 版本,v2.0.1 後不支援 Python 3.7(目前不支援 3.14)
**SDK:**
* Windows
* x86-64 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.4.0-cp37-abi3-win_amd64.zip)
* macOS
* Arm64 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.4.0-cp37-abi3-macosx_11_0_arm64.zip)
* x86-64 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.4.0-cp37-abi3-macosx_10_12_x86_64.zip)
* Linux
* Arm64 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.4.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.zip)
* x86-64 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.4.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.zip)
info
**範例程式碼:** [Python 範例程式碼](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/python_sample_code.zip) (.ipynb, Jupyter 互動開發格式, 需搭配 SDK 使用)
##### JavaScript[](#javascript "Direct link to JavaScript")
支援 Node.js 16 以上版本
**SDK:**
* Fubon-Neo.tgz [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon-neo-2.4.0.nodejs.zip)
info
**範例程式碼:** [JS 範例程式碼](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/js_sample_code.zip) (.ipynb, Jupyter 互動開發格式, 需搭配 SDK 使用)
##### C#[](#c "Direct link to C#")
使用 .NET Standard 2.0 開發,建議使用 .netcoreapp 3.1 以上,或 .NET Framework 4.7.2 以上版本
**SDK:**
* nupkg(64 位元) [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/FubonNeo.2.4.0.nupkg.zip)
info
**範例程式碼:** [C# 下單範例程式碼](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/fubondotnetsdkgui.zip) (Visual Studio 專案範例 (WPF), 需搭配 SDK 使用)
**範例程式碼:** [C# 行情及帳務範例程式碼](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/marketdata_n_accounting.zip) (Visual Studio 專案範例 (Windows Forms), 需搭配 SDK 使用)
##### C++[](#c-1 "Direct link to C++")
支援 C++ 20 及以上版本
* [SDK 及範例程式碼下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/FubonNeo.2.4.0_CppSDKPackage.zip)
##### Go[](#go "Direct link to Go")
* [SDK 及範例程式碼下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon-neo-2.4.0.golang.zip)
#### 連線測試[](#連線測試 "Direct link to 連線測試")
**連線測試小幫手:** [程式下載](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/API_Sign_Test.zip) (Windows 平台使用)
#### 版本遷移資訊[](#版本遷移資訊 "Direct link to 版本遷移資訊")
##### 2.4.0[](#240 "Direct link to 2.4.0")
* 證券行情新增 [三大法人買賣超](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/ownership/institutional-trades.txt)、[集保戶股權分散](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/ownership/tdcc-distribution.txt)、[董監持股](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/ownership/director-holdings.txt) 查詢
* 期貨行情新增 [期貨歷史K線](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/historical/candles.txt) 查詢(日/週/月K與分K、日盤與夜盤、連續合約 `1!`/`2!`/`3!`)、個股期貨 `ticker`/`tickers` 新增漲跌停價欄位
##### 2.3.0[](#230 "Direct link to 2.3.0")
* 行情元件優化
##### 2.2.9[](#229 "Direct link to 2.2.9")
* 證券行情新增 [ETF 持股資料](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/ownership/etf-holdings.txt) 查詢
* 證券交易新增 [匯撥及圈存](https://www.fbs.com.tw/TradeAPI/docs/trading/guide/reserve-transfer.txt) 功能,支援款項圈存、股票匯撥與申請結果查詢
* 期貨/選擇權行情(WebSocket)新增連續月行情、價差合約行情、延伸一檔報價與試撮資訊
##### 2.2.8[](#228 "Direct link to 2.2.8")
* 證券
1. 行情新增**股務事件**資料 API
2. [歷史行情 Candles](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/historical/candles.txt) 新增**還原股價**選項
* 新增 [AI 輔助開發](https://www.fbs.com.tw/TradeAPI/docs/welcome/build-with-llm.txt) 頁面
版本注意事項 **>=2.2.8**
1. 新增證券委託單 user\_def 欄位輸入規則檢核提醒
a. 僅可使用 ***大小寫英文字母及 0~9 數字***,最多 10 個字元 (***規則更新 >=2.2.8***)
2. API Key 權限變更強制斷線機制,調整為僅限於受變更影響之 key
(例:使用 key1、key2 同時登入上線,刪除 key1 => key1 session 強制斷線; key2 session 不受影響)
3. [網頁憑證匯出](https://www.fbs.com.tw/TradeAPI/docs/key.txt) 可用於 API 登入
##### 2.2.7[](#227 "Direct link to 2.2.7")
* 新增 使用 APY-KEY 登入及憑證匯出功能
info
* [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.txt)
* [API Key 申請](https://www.fbs.com.tw/TradeAPI/docs/key.txt)
##### 2.2.6[](#226 "Direct link to 2.2.6")
* SDK 新增 Golang 版本 (證券交易及帳務)
* 證券 行情 Web API 新增技術指標
##### 2.2.5[](#225 "Direct link to 2.2.5")
* 證券 商品漲跌幅報表查詢功能(上市、櫃)
* 證券 現冲券配額查詢新增警示股註記欄位
* 連線管理元件升級
##### 2.2.4[](#224 "Direct link to 2.2.4")
* 證券 當沖條件單上線
* 證券 支援先進先出帳務查詢
* 證券 委託單 user\_def 欄位新增輸入規範檢核提醒
* SDK 新增 C++ 版本 (證券交易、帳務及條件單功能)
版本注意事項 **>=2.2.4**
1. 新增證券委託單 user\_def 欄位輸入規則檢核提醒
a. 僅可使用 ***ASCII 33-126*** 範圍中字元,最多 10 個字元
b. 若字元合規但長度超過 10 字元,將自動縮減至 10 字元並帶入下單;交易 event callback 發送提醒訊息
c. 若字元不合規,則自動將 user\_def 帶入空值;交易 event callback 發送提醒訊息
(***註:*** user\_def 欄位輸入不符合規則**仍會送單**,但欄位值將被自動調整,調整方式請參考上述點 b 及 c )
2. Python 行情 Web API 例外情況改用 ***Exception*** 方式回報。詳情請見行情 Web API 中之 Python 範例程式。
##### 2.2.3[](#223 "Direct link to 2.2.3")
* 例外處理 ( exception handling ) 元件優化
##### 2.2.2[](#222 "Direct link to 2.2.2")
* 下單模組速度***再*** 優化升級
##### 2.2.1[](#221 "Direct link to 2.2.1")
* 新增連線參數設定 ( [說明](https://www.fbs.com.tw/TradeAPI/docs/trading/guide/advance/ping_pong.txt) )
##### 2.2.0[](#220 "Direct link to 2.2.0")
* 證券 **條件單**停損停利觸發價格條件設定
* 期貨/選擇權 新增**條件單**夜盤功能選項(FutureNight/OptionNight)
版本注意事項 >=2.2.0
1. 以下條件單功能目前不支援**期貨夜盤**: a. 分時分量 b. 移動鎖利 c. 時間觸發條件
2. 證券條件單停損停利子單設定物件(TPSLOrder)新增參數 `trigger`,可設定觸發價格參照為 成交價、最佳買價、最價賣價, 若無特別設定則預設值為 成交價,詳請參閱條件單 \[參數對照表]
(***註:*** C# 使用預設值須將此參數填入 ***null***,Python 及 JS 可忽略此參數)
(***註 2:*** **期貨條件單** 物件(FutOptTpslOrder)亦新增此欄位,尚無具體功能,C# 請填入 ***null***,Python 及 JS 可忽略此欄位 )
##### 2.1.1[](#211 "Direct link to 2.1.1")
* 證券 長日期歷史委託單及成交紀錄查詢(單次查詢最大 30 日區間)
* 期貨/選擇權 新增移動鎖利及分時分量條件單功能
##### 2.1.0[](#210 "Direct link to 2.1.0")
* 期貨/選擇權 條件單功能上線
* (證券) 委託單歷程查詢新增 狀態 (status) 及 錯誤訊息 (err\_msg) 欄位
##### 2.0.1[](#201 "Direct link to 2.0.1")
* 期貨/選擇權 交易及帳務功能
* Python SDK 支援 Python 3.12 (**停止支援 Python 3.7**)
##### 1.3.2[](#132 "Direct link to 1.3.2")
* 下單模組速度優化升級
##### 1.3.1[](#131 "Direct link to 1.3.1")
* 證券條件單
* 期貨/選擇權 行情
* (C#) 交易 callback function 使用方式變更 (詳請見 交易文件 -> SDK Reference -> [版本升級指南](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/upgrade-guide.txt))
##### 1.0.4[](#104 "Direct link to 1.0.4")
* OrderResult 物件新增 details 欄位
* 即時行情新增 Normal Mode(詳請見 行情文件 -> WebSocket -> [模式切換](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/upgrade-guide.txt))
---
### 安裝與版本相容性
本頁重點
* 支援語言:Python / C# / JavaScript (Node.js) / C++、Go(僅支援證券交易帳務及條件單)。
* 最低版本:Python 3.8–3.13(不含 3.14)、Node.js 16+、.NET Standard 2.0、C++20+、Go 1.19+。
* SDK 下載位置:請見 [SDK 下載](https://www.fbs.com.tw/TradeAPI/docs/download/download-sdk.txt)。
* 本頁提供最小安裝步驟與版本相容性總覽。
#### 支援環境與版本相容性[](#支援環境與版本相容性 "Direct link to 支援環境與版本相容性")
| 語言 | 最低版本 | 支援 OS | 安裝方式 | 備註 |
| -------------------- | --------------------- | ----------------------------------------------------------------- | --------------- | -------------------------------------------- |
| Python | 3.8–3.13(v2.0.1 起) | Windows(x86-64)/ macOS(Arm64、x86-64)/ Linux(Arm64、x86-64) | `.whl` | v2.0.1 起停止支援 Python 3.7;不支援 3.14 |
| JavaScript (Node.js) | 16+ | Windows / macOS / Linux | `.tgz` 本地依賴 | 以 Node.js 套件方式安裝 |
| C# | .NET Standard 2.0 | Windows(x86-64)/ macOS(Arm64、x86-64)/ Linux(Arm64、x86-64) | `.nupkg` | 建議 .NET Core 3.1+ 或 .NET Framework 4.7.2+ |
| C++ | C++20+ | Windows / macOS / Linux | SDK 檔案 | 僅支援證券交易帳務及條件單 |
| Go | 1.19+ | Windows / macOS / Linux | SDK 檔案 | 僅支援證券交易帳務及條件單 |
#### 安裝流程(精簡版)[](#安裝流程精簡版 "Direct link to 安裝流程(精簡版)")
##### Python[](#python "Direct link to Python")
1. 下載對應平台的 `.whl`。
2. 安裝:
```bash
pip install fubon_neo--cp37-abi3-win_amd64.whl
```
##### JavaScript (Node.js)[](#javascript-nodejs "Direct link to JavaScript (Node.js)")
1. 下載 `.tgz` 並放入專案資料夾。
2. `package.json` 加入:
```json
"dependencies": {
"fubon-neo": "file:///fubon-neo-.tgz"
}
```
3. 安裝:
```bash
npm install
```
##### C#[](#c "Direct link to C#")
1. 下載 `.nupkg`。
2. Visual Studio 以 NuGet Package Manager 安裝,或使用本機 NuGet 來源。
info
詳細安裝指引請見 [快速開始](https://www.fbs.com.tw/TradeAPI/docs/trading/quickstart.txt)
##### C++[](#c-1 "Direct link to C++")
1. 下載 C++ SDK 與範例程式碼。
2. 依範例專案設定 include/lib 路徑。
##### Go[](#go "Direct link to Go")
1. 下載 Go SDK 與範例程式碼(Go 1.19+)。
2. 依範例專案設定 `go.mod` 及本地模組路徑。
#### 檔名與安裝包說明[](#檔名與安裝包說明 "Direct link to 檔名與安裝包說明")
* `fubon_neo--cp37-abi3-win_amd64.whl`
* `fubon-neo-.tgz`
* `FubonNeo..nupkg`
#### 版本功能對照 / 重大變更[](#版本功能對照--重大變更 "Direct link to 版本功能對照 / 重大變更")
* API Key 登入:>= v2.2.7
* 網頁憑證匯出登入:>= v2.2.8
* Python 3.7:v2.0.1 起停止支援
* Python 3.14:目前不支援
更多版本資訊請見 [版本遷移資訊](https://www.fbs.com.tw/TradeAPI/docs/download/download-sdk.txt#%E7%89%88%E6%9C%AC%E9%81%B7%E7%A7%BB%E8%B3%87%E8%A8%8A)。
#### 常見問題(FAQ)[](#常見問題faq "Direct link to 常見問題(FAQ)")
**Q1:安裝後如何確認 SDK 可用?**
A:請先完成登入與連線測試,再嘗試呼叫任一 API。
**Q2:Python 3.7 為什麼無法安裝?**
A:自 v2.0.1 起停止支援 Python 3.7。
**Q3:Python 3.14 可以使用嗎?**
A:目前不支援,請使用 Python 3.8–3.13。
**Q4:C++ / Go 為何不支援所有功能?**
A:目前僅提供證券交易帳務及條件單相關功能。
#### 下一步[](#下一步 "Direct link to 下一步")
* [事前準備](https://www.fbs.com.tw/TradeAPI/docs/trading/prepare.txt)
* [快速開始](https://www.fbs.com.tw/TradeAPI/docs/trading/quickstart.txt)
* [API Key 申請](https://www.fbs.com.tw/TradeAPI/docs/key.txt)
---
### 金鑰管理與憑證匯出
版本限制
2.2.7 版本新增功能
憑證匯出開放
2.2.8 版起,可於本頁登入後匯出憑證,以支援跨平台使用。您也可持續使用富邦證券官網 [憑證e總管](https://www.fbs.com.tw/Certificate/Management/) 申請的憑證登入並使用 API。
登入方式與 API Key
您仍可使用現有的**交易帳號密碼及憑證**登入並使用 API。
**API Key 是一個選擇性功能**,提供更高的安全性與靈活性,適合有進階需求的使用者。 [了解為什麼選擇 API Key →](#%E7%82%BA%E4%BB%80%E9%BA%BC%E9%81%B8%E6%93%87-api-key)
金鑰管理與憑證匯出
##### 為什麼選擇 API Key?[](#為什麼選擇-api-key "Direct link to 為什麼選擇 API Key?")
* **細緻權限控管**:可限制金鑰僅能使用特定功能(例如僅查詢行情、不允許下單)。
* **IP 白名單**:僅允許指定 IP 存取,降低外部風險。
* **快速撤銷**:隨時停用金鑰,不影響主要帳號。
此功能 **非強制**,但若您希望提升安全性或需要更彈性的整合方式,**建議啟用 API Key**。
注意事項
**請注意!** 當 API Key 列表有變動時(新增或移除),所有以 API Key 方式登入的 session 都會被強制登出
機制調整 >= v2.2.8 (需使用新版 SDK)
API Key 權限變更強制斷線機制,調整為僅限於受變更影響之 key
(例:使用 key1、key2 同時登入上線,刪除 key1 => key1 session 強制斷線; key2 session 不受影響)
#### 申請憑證[](#申請憑證 "Direct link to 申請憑證")
申請 API Key 前,需先申請您的網頁憑證,即可進行 API Key 申請
1. 輸入您的身分證字號、電子平台密碼 
2. 申請網頁版憑證,收取 OTP 
3. 申請完憑證後,即可進行憑證匯出與新增金鑰 
使用預設密碼憑證
在系統提示輸入憑證密碼時,請使用您的登入 ID
4. 進行金鑰申請
* 點擊新增金鑰

* 設置控制權限 ( IP 或有效期限若不輸入,則為無限制 ) 
* 設置成功,顯示 Secret Key ( Secret Key 關閉後即不再顯示 ) 
5. 可檢視先前申請的 Key 內容或停用 ( Key 最多申請 30 把 ) 
本頁重點
* 本頁提供富邦新一代 API(Fubon Neo API)API Key 管理與憑證匯出入口。
* 匯出憑證可支援跨平台使用;也可使用憑證 e 總管申請的憑證登入 API。
* API Key 可用於登入與權限控管(依版本支援情況)。
* 完成申請後,可依需求調整權限或管理已建立的 Key。
| 項目 | 說明 |
| -------- | ------------------------------- |
| 功能 | API Key 管理與憑證匯出 |
| 適用產品 | 富邦新一代 API(Fubon Neo API) |
| 主要用途 | 憑證匯出、登入驗證、權限控管 |
| 相關頁面 | API Key 說明 / 申請流程 |
---
### 資本變動資料
取得上市櫃股票及 ETF 之資本變動資料(面額變更、減資、分割)
```text
GET /corporate-actions/capital-changes/
```
版本資訊
v2.2.8 起新增功能
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ------------ | ------ | ------------------------------------------------------------ |
| `start_date` | string | 開始日期(格式:`yyyy-MM-dd`) |
| `end_date` | string | 結束日期(格式:`yyyy-MM-dd`)可輸入未來日期取得未來預告資訊 |
| `sort` | string | 排序方式(`asc`、`desc`) |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------------------------------ | --------- | ----------------------------------------------------------------------------------------------------------- |
| `start_date`\* | string | 開始日期 |
| `end_date`\* | string | 結束日期 |
| `sort`\* | string | 排序方向 |
| `data`\* | object\[] | 資本變動資料 |
| `data.symbol` | string | 股票代號 |
| `data.name` | string | 股票名稱 |
| `data.actionType` | string | 事件類型:`etf_split_or_merge` ETF 分割或反分割、`par_value_change` 股票面額變更 、`capital_reduction` 減資 |
| `data.exchange` | string | 交易所 |
| `data.haltDate` | string | 停止買賣日期 (YYYY-MM-DD) |
| `data.resumeDate` | string | 恢復買賣日期 (YYYY-MM-DD) |
| `data.raw` | object | 原始資料,欄位依 `actionType` 而異 |
| `data.raw.splitRatio` | number | 換股比例 (ETF 分割或反分割、面額變更時才有值) |
| `data.raw.splitType` | string | 分割類型:`分割`、`反分割` (ETF 分割或反分割時才有值) |
| `data.raw.parValueBefore` | number | 變更前面額 (面額變更時才有值) |
| `data.raw.parValueAfter` | number | 變更後面額 (面額變更時才有值) |
| `data.raw.reason` | string | 減資原因 (減資時才有值) |
| `data.raw.refundPerShare` | number | 每股退還股款 (元) (減資時才有值) |
| `data.raw.sharesPerThousand` | number | 減資後每千股換發股數 (減資時才有值) |
| `data.raw.cashIncreaseRatioAfterReduction` | number | 減資後現金增資配股率 (減資且有現金增資時才有值) |
| `data.raw.subscriptionPrice` | number | 現金增資認購價 (元) (減資且有現金增資時才有值) |
| `data.raw.exrightReferencePrice` | number | 除權參考價 (減資且有現金增資時才有值) |
| `data.raw.previousClose` | number | 停止買賣前收盤價 |
| `data.raw.referencePrice` | number | 恢復買賣參考價 |
| `data.raw.openingReferencePrice` | number | 開盤競價基準 |
| `data.raw.limitUpPrice` | number | 漲停價格 |
| `data.raw.limitDownPrice` | number | 跌停價格 |
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
response = reststock.corporate_actions.capital_changes(**{"start_date": "2025-12-06", "end_date": "2026-01-08"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
print(response)
```
```js
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.corporateActions.capitalChanges({ start_date: '2025-12-06', end_date: '2026-01-08' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.Stock.CorporateActions;
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 dividend = await rest.CorporateActions.CapitalChanges(new()
{
StartDate = fromDate,
EndDate = toDate,
Sort = SortType.Desc // Optional
});
var dividend_cont = dividend.Content.ReadAsStringAsync().Result;
Console.WriteLine(dividend_cont);
```
Response Body:
```json
{
"start_date": "2025-01-01",
"end_date": "2026-01-09",
"sort": "desc",
"data": [
{
"symbol": "4530",
"name": "宏易",
"actionType": "capital_reduction",
"resumeDate": "2025-12-29",
"haltDate": "2025-12-18",
"exchange": "TPEx",
"raw": {
"exrightReferencePrice": 0,
"limitDownPrice": 28.2,
"limitUpPrice": 34.45,
"openingReferencePrice": 31.3,
"previousClose": 12.3,
"reason": "彌補虧損",
"referencePrice": 31.32,
"refundPerShare": 0,
"sharesPerThousand": 392.72795
}
},
{
"symbol": "3593",
"name": "力銘",
"actionType": "capital_reduction",
"resumeDate": "2025-12-22",
"haltDate": "2025-12-11",
"exchange": "TWSE",
"raw": {
"limitDownPrice": 12.15,
"limitUpPrice": 14.85,
"openingReferencePrice": 13.5,
"previousClose": 8.1,
"reason": "彌補虧損",
"referencePrice": 13.5,
"refundPerShare": 0,
"sharesPerThousand": 599.9999936
}
},
{
"symbol": "00715L",
"name": "期街口布蘭特正2",
"actionType": "etf_split_or_merge",
"resumeDate": "2025-12-10",
"haltDate": "2025-12-03",
"exchange": "TWSE",
"raw": {
"limitDownPrice": 0.01,
"limitUpPrice": 9999.95,
"openingReferencePrice": 20.86,
"previousClose": 10.43,
"referencePrice": 20.86,
"splitRatio": 0.5,
"splitType": "反分割"
}
},
{
"symbol": "8103",
"name": "瀚荃",
"actionType": "capital_reduction",
"resumeDate": "2025-12-08",
"haltDate": "2025-11-27",
"exchange": "TWSE",
"raw": {
"limitDownPrice": 77.5,
"limitUpPrice": 94.7,
"openingReferencePrice": 86.1,
"previousClose": 74.7,
"reason": "退還股款",
"referencePrice": 86.11,
"refundPerShare": 1.5,
"sharesPerThousand": 850
}
},
{
"symbol": "0052",
"name": "富邦科技",
"actionType": "etf_split_or_merge",
"resumeDate": "2025-11-26",
"exchange": "TWSE",
"raw": {
"limitDownPrice": 31.54,
"limitUpPrice": 38.54,
"openingReferencePrice": 35.04,
"previousClose": 245.3,
"referencePrice": 35.04,
"splitType": "分割"
}
},
{
"symbol": "1808",
"name": "潤隆",
"actionType": "capital_reduction",
"resumeDate": "2025-11-24",
"haltDate": "2025-11-13",
"exchange": "TWSE",
"raw": {
"limitDownPrice": 33.45,
"limitUpPrice": 40.85,
"openingReferencePrice": 37.15,
"previousClose": 34.45,
"reason": "退還股款",
"referencePrice": 37.16,
"refundPerShare": 1,
"sharesPerThousand": 900
}
},
{
"symbol": "6465",
"name": "威潤",
"actionType": "capital_reduction",
"resumeDate": "2025-11-24",
"haltDate": "2025-11-13",
"exchange": "TPEx",
"raw": {
"exrightReferencePrice": 0,
"limitDownPrice": 15.55,
"limitUpPrice": 18.95,
"openingReferencePrice": 17.25,
"previousClose": 15.65,
"reason": "彌補虧損",
"referencePrice": 17.25,
"refundPerShare": 0,
"sharesPerThousand": 907.01186
}
},
{
"symbol": "9927",
"name": "泰銘",
"actionType": "capital_reduction",
"resumeDate": "2025-11-24",
"haltDate": "2025-11-13",
"exchange": "TWSE",
"raw": {
"limitDownPrice": 62.2,
"limitUpPrice": 76,
"openingReferencePrice": 69.1,
"previousClose": 52.4,
"reason": "退還股款",
"referencePrice": 69.11,
"refundPerShare": 2.82805,
"sharesPerThousand": 717.194904
}
},
{
"symbol": "8422",
"name": "可寧衛",
"actionType": "par_value_change",
"resumeDate": "2025-11-17",
"haltDate": "2025-11-06",
"exchange": "TWSE",
"raw": {
"limitDownPrice": 22.5,
"limitUpPrice": 27.5,
"openingReferencePrice": 25,
"previousClose": 250,
"referencePrice": 25
}
},
{
"symbol": "5301",
"name": "寶得利",
"actionType": "capital_reduction",
"resumeDate": "2025-11-12",
"haltDate": "2025-11-05",
"exchange": "TPEx",
"raw": {
"exrightReferencePrice": 0,
"limitDownPrice": 12.55,
"limitUpPrice": 15.25,
"openingReferencePrice": 13.9,
"previousClose": 6.41,
"reason": "彌補虧損",
"referencePrice": 13.89,
"refundPerShare": 0,
"sharesPerThousand": 461.57
}
},
...
]
}
```
---
### 除權息資料
取得 上市櫃除權息資料(依日期查詢)
```text
GET /corporate-actions/dividends/
```
版本資訊
v2.2.8 起新增功能
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ------------ | ------ | ------------------------------------------------------------ |
| `start_date` | string | 開始日期(格式:`yyyy-MM-dd`) |
| `end_date` | string | 結束日期(格式:`yyyy-MM-dd`)可輸入未來日期取得未來預告資訊 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------------------- | --------- | -------------------------- |
| `data`\* | object\[] | 除權息資料 |
| `data.date`\* | string | 除權息日期 |
| `data.exchange` | string | 交易所 |
| `data.symbol` | string | 股票代號 |
| `data.name` | string | 股票名稱 |
| `data.previousClose` | number | 除權息前收盤價 |
| `data.referencePrice` | number | 除權息參考價 |
| `data.dividend` | number | 除權息總金額 (權值 + 息值) |
| `data.dividendType` | string | 除權息類別 |
| `data.limitUpPrice` | number | 除權後漲停價 |
| `data.limitDownPrice` | number | 除權後跌停價 |
| `data.openingReferencePrice` | number | 開盤競價參考價 |
| `data.exdividendReferencePrice` | number | 減除股利參考價 |
| `data.cashDividend` | number | 現金除息 |
| `data.stockDividendShares` | number | 每千股無償配股 |
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
response = reststock.corporate_actions.dividends(**{"start_date": "2025-08-26", "end_date": "2026-01-08"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
print(response)
```
```js
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.corporateActions.dividends({ start_date: '2025-08-26', end_date: '2026-01-08' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.Stock.CorporateActions;
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 dividend = await rest.CorporateActions.Dividends(new()
{
StartDate = fromDate,
EndDate = toDate,
Sort = SortType.Desc // Optional
});
var dividend_cont = dividend.Content.ReadAsStringAsync().Result;
Console.WriteLine(dividend_cont);
```
Response Body:
```json
{
"data": [
{ // 宣告未來的除權息資料不會帶入價格
"date": "2026-01-08",
"exchange": "TWSE",
"symbol": "2247",
"name": "汎德永業",
"previousClose": null,
"referencePrice": null,
"dividend": 6.5,
"dividendType": "息",
"limitUpPrice": null,
"limitDownPrice": null,
"openingReferencePrice": null,
"exdividendReferencePrice": null,
"cashDividend": 6.5,
"stockDividendShares": null
},
{ // 已發生的除權息資料會帶入價格 (僅有息)
"date": "2026-01-06",
"exchange": "TWSE",
"symbol": "00946",
"name": "群益科技高息成長",
"previousClose": 9.6,
"referencePrice": 9.54,
"dividend": 0.058,
"dividendType": "息",
"limitUpPrice": 10.49,
"limitDownPrice": 8.59,
"openingReferencePrice": 9.54,
"exdividendReferencePrice": 9.54,
"cashDividend": 0.058,
"stockDividendShares": 0
},
{ // 增資 ( 前日開盤會等於減除股利參考價或 stockDividendShares = 0 )
"date": "2026-01-06",
"exchange": "TWSE",
"symbol": "2442",
"name": "新美齊",
"previousClose": 24.8,
"referencePrice": 24.12,
"dividend": 0.671598,
"dividendType": "權",
"limitUpPrice": 27.25,
"limitDownPrice": 21.75,
"openingReferencePrice": 24.8,
"exdividendReferencePrice": 24.8,
"cashDividend": 0,
"stockDividendShares": 0
},
{ // 已發生的除權息資料會帶入價格 (僅有權)
"date": "2025-08-26",
"exchange": "TPEx",
"symbol": "6752",
"name": "叡揚",
"previousClose": 158.5,
"referencePrice": 150.95,
"dividend": 7.548635,
"dividendType": "權",
"limitUpPrice": 166,
"limitDownPrice": 136,
"openingReferencePrice": 151,
"exdividendReferencePrice": 150.95,
"cashDividend": 0,
"stockDividendShares": 50.00706711
},
{ // 已發生的除權息資料會帶入價格 (同時包含權息)
"date": "2025-08-26",
"exchange": "TPEx",
"symbol": "4554",
"name": "橙的",
"previousClose": 36.95,
"referencePrice": 32.39,
"dividend": 4.560619,
"dividendType": "權息",
"limitUpPrice": 35.6,
"limitDownPrice": 29.2,
"openingReferencePrice": 32.4,
"exdividendReferencePrice": 32.39,
"cashDividend": 0.35,
"stockDividendShares": 129.99998584
}
]
}
```
---
### 申請上市櫃公司
取得 申請上市櫃公司資料
```text
GET /corporate-actions/listing-applicants/
```
版本資訊
v2.2.8 起新增功能
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ------------ | ------ | ------------------------------------------------------------ |
| `start_date` | string | 開始日期(格式:`yyyy-MM-dd`) |
| `end_date` | string | 結束日期(格式:`yyyy-MM-dd`)可輸入未來日期取得未來預告資訊 |
| `sort` | string | 排序方式(`asc`、`desc`) |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ---------------------- | ------ | ---------------------------------------- |
| `symbol` | string | 公司代號 |
| `name` | string | 公司簡稱 |
| `exchange` | string | 申請類別:`TWSE`(上市)、`TPEx`(上櫃) |
| `applicationDate` | string | 申請日期 |
| `chairman` | string | 董事長 |
| `capitalAtApplication` | number | 申請時股本(仟元) |
| `reviewCommitteeDate` | string | 上市審議委員審議日 |
| `boardApprovalDate` | string | 交易所董事會通過日 |
| `contractFilingDate` | string | 主管機關核准日期 |
| `listedDate` | string | 股票上市、櫃買賣日期 |
| `underwriter` | string | 承銷商 |
| `underwritingPrice` | number | 承銷價 |
| `remarks` | string | 備註 |
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
response = reststock.corporate_actions.listing_applicants(**{"start_date": "2025-01-07", "end_date": "2026-01-07"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
print(response)
```
```js
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.corporateActions.listingApplicants({ start_date: '2025-01-07', end_date: '2026-01-07' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.Stock.CorporateActions;
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 listing = await rest.CorporateActions.ListingApplicants(new()
{
StartDate = fromDate,
EndDate = toDate,
Sort = SortType.Desc // Optional
});
var listing_cont = listing.Content.ReadAsStringAsync().Result;
Console.WriteLine(listing_cont);
```
Response Body:
```json
{
"start_date": "2025-01-07",
"end_date": "2026-01-07",
"sort": "desc",
"data": [
...
{
"symbol": "7762",
"name": "吉晟生",
"exchange": "TWSE",
"applicationDate": "2025-09-24",
"chairman": "楊朝堂",
"capitalAtApplication": 572328,
"reviewCommitteeDate": null,
"boardApprovalDate": null,
"contractFilingDate": null,
"listedDate": null,
"underwriter": "宏遠",
"underwritingPrice": null,
"remarks": "創新板,114-10-31撤件"
},
{
"symbol": "6961",
"name": "旅天下",
"exchange": "TPEx",
"applicationDate": "2025-09-17",
"chairman": "李嘉寅",
"capitalAtApplication": 236340000,
"reviewCommitteeDate": "2025-11-06",
"boardApprovalDate": "2025-11-21",
"contractApprovalDate": "2025-11-25",
"listedDate": null,
"underwriter": "福邦",
"underwritingPrice": null,
"remarks": ""
},
{
"symbol": "4590",
"name": "富田",
"exchange": "TWSE",
"applicationDate": "2025-09-15",
"chairman": "張金鋒",
"capitalAtApplication": 511941,
"reviewCommitteeDate": "2025-10-23",
"boardApprovalDate": "2025-11-18",
"contractFilingDate": "2025-11-26",
"listedDate": null,
"underwriter": "中信",
"underwritingPrice": null,
"remarks": "創新板"
},
{
"symbol": "6725",
"name": "矽科宏晟",
"exchange": "TPEx",
"applicationDate": "2025-09-11",
"chairman": "郭錦松",
"capitalAtApplication": 330000000,
"reviewCommitteeDate": "2025-10-20",
"boardApprovalDate": "2025-10-30",
"contractApprovalDate": "2025-11-04",
"listedDate": "2025-12-30",
"underwriter": "台新",
"underwritingPrice": 188,
"remarks": ""
}
]
}
```
---
### 開始使用
本頁重點
* 富邦行情 Web API(富邦新一代 API 行情服務)提供台股盤中、快照與歷史資料查詢。
* 超過速率限制會回應 `429`,詳見速率限制說明。
* 提供 Python / Node.js / C# SDK 範例。
* 下一步可從功能列表選擇對應 API 端點。
| 項目 | 說明 |
| -------- | --------------------- |
| 介面 | Web API |
| 市場 | 台股 |
| 資料類型 | 盤中 / 快照 / 歷史 |
| 速率限制 | 超過回應 `429` |
| SDK | Python / Node.js / C# |
富邦行情 Web API 提供開發者友善的 API 服務。您可以查詢台股的日內行情、行情快照與歷史行情等數據。
#### 速率限制[](#速率限制 "Direct link to 速率限制")
如果您 API 請求超過了限制,將收到帶有狀態碼 `429` 的回應。 ( 限制細節請參考 [速率限制](https://www.fbs.com.tw/TradeAPI/docs/market-data/rate-limit.txt) )
#### 功能列表[](#功能列表 "Direct link to 功能列表")
功能列表依資料類型可分為 **盤中行情(intraday)**、**行情快照(snapshot)**、**歷史行情(historical)**、**技術指標(technical)**、**公司行動(corporate-actions)**、**盤後籌碼(ownership)**。富邦行情 Web API 提供的功能如下:
* `/intraday/tickers` - [股票或指數列表(依條件查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/tickers.txt)
* `/intraday/ticker/{symbol}` - [股票基本資料(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/ticker.txt)
* `/intraday/quote/{symbol}` - [股票即時報價(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/quote.txt)
* `/intraday/candles/{symbol}` - [股票價格K線(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/candles.txt)
* `/intraday/trades/{symbol}` - [股票成交明細(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/trades.txt)
* `/intraday/volumes/{symbol}` - [股票分價量表(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/volumes.txt)
* `/snapshot/quotes/{market}` - [股票行情快照(依市場別)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/snapshot/quotes.txt)
* `/snapshot/movers/{market}` - [股票漲跌幅排行(依市場別)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/snapshot/movers.txt)
* `/snapshot/actives/{market}` - [股票成交量值排行(依市場別)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/snapshot/actives.txt)
* `/historical/candles/{symbol}` - [取得 1 年內歷史股價(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/historical/candles.txt)
* `/historical/stats/{symbol}` - [取得近 52 週股價數據(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/historical/stats.txt)
* `/technical/sma/{symbol}` - [簡單移動平均(SMA)(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/technical/sma.txt)
* `/technical/rsi/{symbol}` - [相對強弱指標(RSI)(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/technical/rsi.txt)
* `/technical/kdj/{symbol}` - [隨機指標(KDJ)(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/technical/kdj.txt)
* `/technical/macd/{symbol}` - [指數平滑異同移動平均線(MACD)(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/technical/macd.txt)
* `/technical/bb/{symbol}` - [布林通道(BBands)(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/technical/bbands.txt)
* `/corporate-actions/dividends` - [除權息資料(依日期區間查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/corporate-actions/dividends.txt)
* `/corporate-actions/capital-changes` - [資本變動資料(依日期區間查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/corporate-actions/captital-changes.txt)
* `/corporate-actions/listing-applicants` - [申請上市櫃公司(依日期區間查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/corporate-actions/listing-applicants.txt)
* `/ownership/etf-holdings/{symbol}` - [ETF 持股資料(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/ownership/etf-holdings.txt)
* `/ownership/institutional-trades/{symbol}` - [三大法人買賣超(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/ownership/institutional-trades.txt)
* `/ownership/tdcc-distribution/{symbol}` - [集保戶股權分散(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/ownership/tdcc-distribution.txt)
* `/ownership/director-holdings/{symbol}` - [董監持股(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/ownership/director-holdings.txt)
#### 使用 SDK[](#使用-sdk "Direct link to 使用 SDK")
富邦行情 Web API 提供 Python 、 Node.js SDK 與 C# SDK。您可以透過以下方式存取 API:
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order
# 2.2.4 以後版本, 增加下列匯入:
# from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
reststock = sdk.marketdata.rest_client.stock
```
```js
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
const stock = client.stock;
```
```cs
using FubonNeo.Sdk;
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;
```
---
### Historical Candles
查詢上市櫃及興櫃歷史股價(依代碼查詢)。單次查詢區間須小於 1 年;上市櫃個股日資料最遠可回溯至 2010 年,指數部分最遠可回溯至 2015 年,興櫃則可回溯至 2024 年。
```text
historical/candles/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ----------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `symbol`\* | string | 股票代碼 |
| `from` | string | 開始日期(格式:`yyyy-MM-dd`),未帶時預設為 1 個月前 |
| `to` | string | 結束日期(格式:`yyyy-MM-dd`),未帶時預設為今日 |
| `timeframe` | string | K 線週期,未帶時預設為 `D` 日 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 |
| `adjusted` | string | 還原股價啟用,可選 `true`、`false`(僅日/週/月 K 有效) ***(v2.2.8 新增)*** |
| `fields` | string | 欄位選擇,未帶時預設為 `open,high,low,close,volume,average`(不含 `turnover`、`change`,需要時請明確指定);可選 `open`、`high`、`low`、`close`、`volume`、`average`、`turnover`、`change`(各欄位適用 timeframe 請見 Response 表格) |
| `sort` | string | 時間排序,預設為 `desc` 降冪;可選 `asc` 升冪 |
info
* 歷史資料於每交易日盤後 16:30 前完成更新。
* 查詢區間(`from` ~ `to`)單次須小於 1 年,恰好或超過 1 年會回傳 400 Bad Request(錯誤訊息:`Date range must be less than one year`)。例:`from=2025-01-01&to=2025-12-31` 可查詢;`from=2024-12-31&to=2025-12-31` 恰好 1 年會被拒絕。`from` 不可晚於 `to`,否則亦回傳 400。
* 分 K 歷史資料自 **2023-05-23** 起提供。若查詢區間完全落在起始日前、或完全為非交易日,會回傳 404 Resource Not Found(而非空陣列)。
* 興櫃歷史資料可回溯至 **2024 年**(實際起點依標的而異)。
#### Response[](#response "Direct link to Response")
| Name | Type | Description | 適用 timeframe |
| --------------- | --------- | -------------------------------------------------------------------------------------------------- | -------------- |
| `type`\* | string | 證券類型 | — |
| `exchange`\* | string | 交易所 | — |
| `market`\* | string | 市場別 | — |
| `symbol`\* | string | 股票代號 | — |
| `timeframe`\* | string | K 線週期 | — |
| `data`\* | object\[] | K 線資料 | — |
| `data.date`\* | string | 日期(日/週/月 K 為 `yyyy-MM-dd`;分 K 為 ISO 8601 含時區,例:`2026-07-09T13:30:00.000+08:00`) | 全部 |
| `data.open` | number | K 線開盤價 | 全部 |
| `data.high` | number | K 線最高價 | 全部 |
| `data.low` | number | K 線最低價 | 全部 |
| `data.close` | number | K 線收盤價 | 全部 |
| `data.volume` | number | K 線成交量/成交金額,單位請見下方說明 | 全部 |
| `data.average` | number | 成交均價(自開盤累計) | 僅分 K |
| `data.turnover` | number | K 線成交金額(元) | 僅日/週/月 K |
| `data.change` | number | K 線漲跌 | 僅日/週/月 K |
caution
`volume` 單位依標的與 timeframe 不同:
* 整股標的:分 K 為「成交張數」,日/週/月 K 為「成交股數」(1 張 = 1,000 股)。
* 興櫃股票:分 K 與日/週/月 K 皆為「成交股數」。
* 指數:分 K 為「成交金額」,日/週/月 K 為「成交股數」。
info
`change` 的計算基準:
* 日 K 為與前一交易日收盤價之差;除權息日以調整後前收為基準計算(例如除息 5 元、收盤價較前一日收盤低 6 元時,`change` 為 `-1`)。
* 週/月 K 為區間內各日漲跌之加總。
* `adjusted=true` 時以還原股價序列計算。
#### Examples[](#examples "Direct link to Examples")
##### 日 K 範例[](#日-k-範例 "Direct link to 日 K 範例")
查詢日 K 並指定日期區間:
* Python
* Node.js
* C#
```python
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
# reststock.historical.candles(**{"symbol": "0050", "from": "2026-06-01", "to": "2026-06-05"}) # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.historical.candles(**{"symbol": "0050", "from": "2026-06-01", "to": "2026-06-05", "fields": "open,high,low,close,volume,turnover,change"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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: '2026-06-01', to: '2026-06-05', fields: 'open,high,low,close,volume,turnover,change' })
.then(data => console.log(data));
```
```cs
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("0050", new(new DateTime(2026,6,1), new DateTime(2026,6,5), HistoryTimeFrame.Day, FieldsType.Volume|FieldsType.Change));
var candle_con = candle.Content.ReadAsStringAsync().Result;
Console.WriteLine(candle_con);
```
Response Body:
```json
{
"symbol": "0050",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"timeframe": "D",
"data": [
{
"date": "2026-06-05",
"open": 105,
"high": 105.35,
"low": 102.8,
"close": 104.15,
"volume": 337031371,
"turnover": 34914259576,
"change": -1.95
},
{
"date": "2026-06-04",
"open": 106.75,
"high": 107,
"low": 106.05,
"close": 106.1,
"volume": 236782252,
"turnover": 25181889523,
"change": -1.5
},
{
"date": "2026-06-03",
"open": 107.3,
"high": 107.85,
"low": 107.1,
"close": 107.6,
"volume": 79592362,
"turnover": 8559208311,
"change": 1.9
}
]
}
```
##### 分 K 範例[](#分-k-範例 "Direct link to 分 K 範例")
查詢 1 分 K 並指定日期區間(含均價 `average`):
* Python
* Node.js
* C#
```python
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
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.historical.candles(**{"symbol": "2330", "from": "2026-07-09", "to": "2026-07-09", "timeframe": "1", "fields": "open,high,low,close,volume,average"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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: '2330', from: '2026-07-09', to: '2026-07-09', timeframe: '1', fields: 'open,high,low,close,volume,average' })
.then(data => console.log(data));
```
```cs
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(new DateTime(2026,7,9), new DateTime(2026,7,9), HistoryTimeFrame.OneMin));
var candle_con = candle.Content.ReadAsStringAsync().Result;
Console.WriteLine(candle_con);
```
Response Body:
```json
{
"symbol": "2330",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"timeframe": "1",
"data": [
{
"date": "2026-07-09T13:30:00.000+08:00",
"open": 2415,
"high": 2415,
"low": 2415,
"close": 2415,
"volume": 6261,
"average": 2433.85
},
{
"date": "2026-07-09T13:24:00.000+08:00",
"open": 2430,
"high": 2435,
"low": 2430,
"close": 2435,
"volume": 114,
"average": 2439.56
},
{
"date": "2026-07-09T13:23:00.000+08:00",
"open": 2435,
"high": 2440,
"low": 2430,
"close": 2430,
"volume": 262,
"average": 2439.6
}
]
}
```
info
'\*' 表示必揭示欄位。
---
### Historical Stats
取得近 52 週股價數據(依代碼查詢)
```text
historical/stats/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ----------- |
| `symbol`\* | string | 股票代碼 |
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.historical.stats(symbol = "0050") # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.historical.stats(symbol = "0050")
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.stats({ symbol: '0050' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
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 stats = await rest.History.Stats("0050");
var stats_cont = stats.Content.ReadAsStringAsync().Result;
Console.WriteLine(stats_cont);
```
Response Body:
```json
{
"date": "2023-02-09",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "0050",
"name": "元大台灣50",
"openPrice": 120.5,
"highPrice": 121,
"lowPrice": 120.3,
"closePrice": 120.9,
"change": 0.05,
"changePercent": 0.04,
"tradeVolume": 5032245,
"tradeValue": 607543546,
"previousClose": 120.85000000000001,
"week52High": 145.05,
"week52Low": 96.5
}
```
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ----------------- | ------ | ------------------ |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market`\* | string | 市場別 |
| `symbol`\* | string | 股票代碼 |
| `name`\* | string | 股票簡稱 |
| `openPrice`\* | number | 最後交易日開盤價 |
| `highPrice`\* | number | 最後交易日最高價 |
| `lowPrice`\* | number | 最後交易日最低價 |
| `closePrice`\* | number | 最後交易日收盤價 |
| `change`\* | number | 最後交易日漲跌 |
| `changePercent`\* | number | 最後交易日漲跌幅 |
| `tradeVolume`\* | number | 最後交易日成交量 |
| `tradeValue`\* | number | 最後交易日成交金額 |
| `previousClose`\* | number | 前一交易日收盤價 |
| `week52High`\* | number | 近 52 週高點 |
| `week52Low`\* | number | 近 52 週低點 |
info
'\*' 表示必揭示欄位。
---
### Intraday Candles
股票價格K線(依代碼查詢)
```text
intraday/candles/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ----------- | ------ | --------------------------------------------------------------------------------------------------------- |
| `symbol`\* | string | 股票代碼 |
| `type` | string | Ticker 類型,可選 `oddlot` 盤中零股 |
| `timeframe` | string | K線週期,可選 `1` 1 分K;`3` 3 分K;`5` 5 分K;`10` 10 分K;`15` 15 分K;`30` 30 分K;`60` 60 分K |
| `sort` | string | 時間排序,預設為 `asc` 升冪 ;可選 `desc` 降冪 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------- | --------- | -------------------------------------------------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 股票代號 |
| `timeframe`\* | string | K線週期 |
| `data`\* | object\[] | K線資料 |
| >>`open` | number | K線開盤價 |
| >>`high` | number | K線最高價 |
| >>`low` | number | K線最低價 |
| >>`close` | number | K線收盤價 |
| >>`volume` | number | K線成交量(整股:成交張數;興櫃股票及盤中零股:成交股數;指數:成交金額) |
| >>`average` | number | 成交均價 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.intraday.candles(symbol='2330') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.intraday.candles(symbol='2330')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.intraday.candles({ symbol: '2330' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
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 candles = await rest.Intraday.Candles("2330");
// var candles = await rest.Intraday.Candles("2330", new(){TimeFrame=FugleMarketData.QueryModels.Stock.Intraday.IntradayTimeFrame.TenMin}); // 10分K
var candle_cont = candles.Content.ReadAsStringAsync().Result;
Console.WriteLine(candle_cont);
```
Response Body:
```json
{
"date": "2023-05-29",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"data": [
{
"date": "2023-05-29T09:00:00.000+08:00",
"open": 574,
"high": 574,
"low": 572,
"close": 572,
"volume": 8450,
"average": 573.82
},
{
"date": "2023-05-29T09:01:00.000+08:00",
"open": 572,
"high": 573,
"low": 571,
"close": 571,
"volume": 594,
"average": 573.68
},
{
"date": "2023-05-29T09:02:00.000+08:00",
"open": 572,
"high": 572,
"low": 569,
"close": 570,
"volume": 1372,
"average": 573.26
},
......
]
}
```
---
### Intraday Quote
股票即時報價(依代碼查詢)
```text
intraday/quote/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ---------------------------- |
| `symbol`\* | string | 股票代碼 |
| `type` | string | 類型,可選 `oddlot` 盤中零股 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| --------------------- | --------- | ----------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market`\* | string | 市場別 |
| `symbol`\* | string | 股票代碼 |
| `name`\* | string | 股票簡稱 |
| `referencePrice` | number | 今日參考價 |
| `previousClose` | number | 昨日收盤價 |
| `openPrice` | number | 開盤價 |
| `openTime` | number | 開盤價成交時間 |
| `highPrice` | number | 最高價 |
| `highTime` | number | 最高價成交時間 |
| `lowPrice` | number | 最低價 |
| `lowTime` | number | 最低價成交時間 |
| `closePrice` | number | 收盤價(最後成交價) |
| `closeTime` | number | 收盤價(最後成交價)成交時間 |
| `lastPrice` | number | 最後一筆成交價(含試撮) |
| `lastSize` | number | 最後一筆成交數量(含試撮) |
| `avgPrice` | number | 當日成交均價 |
| `change` | number | 最後一筆成交漲跌(含試撮) |
| `changePercent` | number | 最後一筆成交漲跌幅(含試撮) |
| `amplitude` | number | 當日振幅 |
| `bids` | object\[] | 最佳五檔委買 |
| >> `price` | number | 最佳五檔委買價格 |
| >> `size` | number | 最佳五檔委買數量 |
| `asks` | object\[] | 最佳五檔委賣 |
| >> `price` | number | 最佳五檔委賣價格 |
| >> `size` | number | 最佳五檔委賣數量 |
| `total` | object | 統計資訊 |
| >> `tradeValue` | number | 累計成交金額 |
| >> `tradeVolume` | number | 累計成交量 |
| >> `tradeVolumeAtBid` | number | 累計內盤成交量 |
| >> `tradeVolumeAtAsk` | number | 累計外盤成交量 |
| >> `transaction` | number | 累計成交筆數 |
| >> `time` | number | 統計時間 |
| `lastTrade` | object | 最後一筆成交資訊 |
| >> `bid` | number | 最後一筆成交買價 |
| >> `ask` | number | 最後一筆成交賣價 |
| >> `price` | number | 最後一筆成交價格 |
| >> `size` | number | 最後一筆成交數量 |
| >> `time` | number | 最後一筆成交時間 |
| >> `serial` | number | 最後一筆成交流水號 |
| `lastTrial` | object | 最後一筆試撮資訊 |
| >> `bid` | number | 最後一筆試撮買價 |
| >> `ask` | number | 最後一筆試撮賣價 |
| >> `price` | number | 最後一筆試撮價格 |
| >> `size` | number | 最後一筆試撮數量 |
| >> `time` | number | 最後一筆試撮時間 |
| >> `serial` | number | 最後一筆試撮流水號 |
| `tradingHalt` | object | 暫停交易 |
| >> `isHalted` | boolean | 暫停交易:`true`;恢復交易:`false` |
| >> `time` | number | 暫停交易時間/恢復交易時間 |
| `isLimitDownPrice` | boolean | 最後成交價為跌停價:`true` |
| `isLimitUpPrice` | boolean | 最後成交價為漲停價:`true` |
| `isLimitDownBid` | boolean | 最佳一檔委買跌停價:`true` |
| `isLimitUpBid` | boolean | 最佳一檔委買漲停價:`true` |
| `isLimitDownAsk` | boolean | 最佳一檔委賣跌停價:`true` |
| `isLimitUpAsk` | boolean | 最佳一檔委賣漲停價:`true` |
| `isLimitDownHalt` | boolean | 暫緩撮合且瞬間趨跌:`true` |
| `isLimitUpHalt` | boolean | 暫緩撮合且瞬間趨漲:`true` |
| `isTrial` | boolean | 試撮階段:`true` |
| `isDelayedOpen` | boolean | 延後開盤信號:`true` |
| `isDelayedClose` | boolean | 延後收盤信號:`true` |
| `isContinuous` | boolean | 最後成交為逐筆交易:`true` |
| `isOpen` | boolean | 開盤信號:`true` |
| `isClose` | boolean | 收盤信號:`true` |
| `lastUpdated` | number | 最後更新時間 |
| `serial` | number | 流水號 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.intraday.quote(symbol='2330') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.intraday.quote(symbol='2330')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.intraday.quote({ symbol: '2330' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
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 quote = await rest.Intraday.Quote("2330");
// var quote = await rest.Intraday.Quote("2330", new(){Type=FugleMarketData.QueryModels.TickerType.OddLot}); // 零股
var quote_cont = quote.Content.ReadAsStringAsync().Result;
Console.WriteLine(quote_cont);
```
Response Body:
```json
{
"date": "2023-05-29",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"name": "台積電",
"referencePrice": 566,
"previousClose": 566,
"openPrice": 574,
"openTime": 1685322000049353,
"highPrice": 574,
"highTime": 1685322000049353,
"lowPrice": 564,
"lowTime": 1685327142152580,
"closePrice": 568,
"closeTime": 1685338200000000,
"avgPrice": 568.77,
"change": 2,
"changePercent": 0.35,
"amplitude": 1.77,
"lastPrice": 568,
"lastSize": 4778,
"bids": [
{
"price": 567,
"size": 87
},
{
"price": 566,
"size": 2454
},
{
"price": 565,
"size": 611
},
{
"price": 564,
"size": 609
},
{
"price": 563,
"size": 636
}
],
"asks": [
{
"price": 568,
"size": 800
},
{
"price": 569,
"size": 806
},
{
"price": 570,
"size": 3643
},
{
"price": 571,
"size": 1041
},
{
"price": 572,
"size": 2052
}
],
"total": {
"tradeValue": 31019803000,
"tradeVolume": 54538,
"tradeVolumeAtBid": 19853,
"tradeVolumeAtAsk": 27900,
"transaction": 9530,
"time": 1685338200000000
},
"lastTrade": {
"bid": 567,
"ask": 568,
"price": 568,
"size": 4778,
"time": 1685338200000000,
"serial": 6652422
},
"lastTrial": {
"bid": 567,
"ask": 568,
"price": 568,
"size": 4772,
"time": 1685338196400347,
"serial": 6651941
},
"isClose": true,
"serial": 6652422,
"lastUpdated": 1685338200000000
}
```
---
### Intraday Ticker
取得股票資訊 (依股票代碼查詢)
```text
intraday/ticker/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ---------------------------- |
| `symbol`\* | string | 股票代碼 |
| `type` | string | 類型,可選 `oddlot` 盤中零股 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ----------------------------- | ------- | ------------------------------------------------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 股票代碼 |
| `name`\* | string | 股票簡稱 |
| `nameEn` | string | 股票英文簡稱 |
| `industry` | string | 產業別 |
| `securityType` | string | 證券別,參閱 [證券別代碼](#%E8%AD%89%E5%88%B8%E5%88%A5%E4%BB%A3%E7%A2%BC) |
| `referencePrice` | number | 參考價 |
| `limitUpPrice` | number | 漲停價(興櫃股不適用) |
| `limitDownPrice` | number | 跌停價(興櫃股不適用) |
| `canDayTrade` | boolean | 可買賣現沖(興櫃股不適用) |
| `canBuyDayTrade` | boolean | 可先買現沖(興櫃股不適用) |
| `canBelowFlatMarginShortSell` | boolean | 平盤下得融券賣出(興櫃股不適用) |
| `canBelowFlatSBLShortSell` | boolean | 平盤下得借券賣出(興櫃股不適用) |
| `isAttention` | boolean | 注意股 |
| `isDisposition` | boolean | 處置股 |
| `isUnusuallyRecommended` | boolean | 投資理財節目異常推介個股(興櫃股不適用) |
| `isSpecificAbnormally` | boolean | 特殊異常個股(興櫃股不適用) |
| `matchingInterval` | number | 撮合循環秒數(興櫃股不適用) |
| `securityStatus` | string | 證券狀態,分別有 `NORMAL`, `TERMINATED`, `SUSPENDED` 狀態 |
| `boardLot` | number | 交易單位 |
| `tradingCurrency` | string | 交易幣別 |
| `exercisePrice` | number | 履約價格(限權證) |
| `exercisedVolume` | number | 前一交易日履約數量(限權證) |
| `cancelledVolume` | number | 前一交易日註銷數量(限權證) |
| `remainingVolume` | number | 發行餘額量(限權證) |
| `exerciseRatio` | number | 行使比率(限權證) |
| `knockInPrice` | number | 上限價格(限權證) |
| `knockOutPrice` | number | 下限價格(限權證) |
| `maturityDate` | string | 到期日(限權證) |
| `previousClose` | number | 前一交易日收盤價 |
| `openTime` | string | 開盤時間(限指數) |
| `closeTime` | string | 收盤時間(限指數) |
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
reststock.intraday.ticker(symbol='2330')
```
```js
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.intraday.ticker({ symbol: '2330' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
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 ticker = await rest.Intraday.Ticker("2330");
var ticker_cont = ticker.Content.ReadAsStringAsync().Result;
Console.WriteLine(ticker_cont);
```
Response Body:
```json
{
"date": "2023-05-29",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"name": "台積電",
"industry": "24",
"securityType": "01",
"previousClose": 566,
"referencePrice": 566,
"limitUpPrice": 622,
"limitDownPrice": 510,
"canDayTrade": true,
"canBuyDayTrade": true,
"canBelowFlatMarginShortSell": true,
"canBelowFlatSBLShortSell": true,
"isAttention": false,
"isDisposition": false,
"isUnusuallyRecommended": false,
"isSpecificAbnormally": false,
"matchingInterval": 0,
"securityStatus": "NORMAL",
"boardLot": 1000,
"tradingCurrency": "TWD"
}
```
#### 證券別代碼[](#證券別代碼 "Direct link to 證券別代碼")
| 代碼 | 證券別 | 代碼 | 證券別 |
| ---- | ------------------------------------------ | ---- | ---------------------- |
| `01` | 一般股票 | `25` | ETF(外幣計價) |
| `02` | 轉換公司債 | `26` | 槓桿型 ETF |
| `03` | 交換公司債或交換金融債 | `27` | 槓桿型 ETF(外幣計價) |
| `04` | 一般特別股 | `28` | 反向型 ETF |
| `05` | 可交換特別股 | `29` | 反向型 ETF(外幣計價) |
| `06` | 認股權憑證 | `30` | 期信託 ETF |
| `07` | 附認股權特別股 | `31` | 期信託 ETF(外幣計價) |
| `08` | 附認股權公司債 | `32` | 債券 ETF |
| `09` | 附認股權公司債履約或分拆後之公司債 | `33` | 債券 ETF(外幣計價) |
| `10` | 國內標的認購權證 | `34` | 金融資產證券化受益證券 |
| `11` | 國內標的認售權證 | `35` | 不動產資產信託受益證券 |
| `12` | 外國標的認購權證 | `36` | 不動產投資信託受益證券 |
| `13` | 外國標的認售權證 | `37` | ETN |
| `14` | 國內標的下限型認購權證 | `38` | 槓桿型 ETN |
| `15` | 國內標的上限型認售權證 | `39` | 反向型 ETN |
| `16` | 國內標的可展延下限型認購權證 | `40` | 債券型 ETN |
| `17` | 國內標的可展延上限型認售權證 | `41` | 期權策略型 ETN |
| `18` | 受益憑證(封閉式基金) | `42` | 中央登錄公債 |
| `19` | 存託憑證 | `43` | 外國債券 |
| `20` | 存託憑證可轉換公司債 | `44` | 黃金現貨 |
| `21` | 存託憑證附認股權公司債 | `45` | 平衡型 ETF |
| `22` | 存託憑證附認股權公司債履約或分拆後之公司債 | `46` | 主動型 ETF |
| `23` | 存託憑證認股權憑證 | `47` | 債券主動式 ETF |
| `24` | ETF | `00` | 未知或保留代碼 |
---
### Intraday Tickers
股票或指數列表(依條件查詢)
```text
intraday/tickers
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| --------------- | ------- | -------------------------------------------------------------------------------- |
| `type`\* | string | Ticker 類型,可選 `EQUITY` 股票;`INDEX` 指數;`WARRANT` 權證;`ODDLOT` 盤中零股 |
| `exchange` | string | 交易所,可選 `TWSE` 臺灣證券交易所;`TPEx` 證券櫃檯買賣中心 |
| `market` | string | 市場別,可選 `TSE` 上市;`OTC` 上櫃;`ESB` 興櫃一般板;`TIB` 臺灣創新板 |
| `industry` | string | 產業別,參閱 [產業別代碼](#%E7%94%A2%E6%A5%AD%E5%88%A5%E4%BB%A3%E7%A2%BC) |
| `isNormal` | boolean | 查詢正常股票(非注意、處置股票):`true` |
| `isAttention` | boolean | 查詢注意股票:`true` |
| `isDisposition` | boolean | 查詢處置股票:`true` |
| `isHalted` | boolean | 查詢暫停交易股票:`true` |
股票專用條件
`isNormal`、`isAttention`、`isDisposition`、`isHalted` 為股票專用條件,若設定此類條件,將回傳對應股票列表
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| --------------- | --------- | -------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `industry` | string | 產業別 |
| `isNormal` | boolean | 查詢正常股票(非注意、處置股票) |
| `isAttention` | boolean | 查詢注意股票 |
| `isDisposition` | boolean | 查詢處置股票 |
| `isHalted` | boolean | 查詢暫停交易股票 |
| `data` | object\[] | 股票列表 |
| >> `symbol` | string | 股票代碼 |
| >> `name` | string | 股票簡稱 |
info
'\*' 表示必揭示欄位。
info
不具備產業屬性的證券如 ETF、可轉換公司債、附認股權公司債、認購(售)權證等衍生性商品,產業別代碼為 `00`。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.intraday.tickers(type='EQUITY', exchange="TWSE", isNormal=True) # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.intraday.tickers(type='EQUITY', exchange="TWSE", isNormal=True)
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.intraday
.tickers({ type: "EQUITY", exchange: "TWSE", isNormal: true })
.then((data) => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels;
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 ticker = await rest.Intraday.Tickers(FugleMarketData.QueryModels.Stock.Intraday.TickersType.Equity);
var ticker_cont = ticker.Content.ReadAsStringAsync().Result;
Console.WriteLine(ticker_cont);
```
Response Body:
```json
{
"date": "2023-02-09",
"type": "EQUITY",
"exchange": "TWSE",
"isNormal": true,
"data": [
{
"symbol": "0050",
"name": "元大台灣50"
},
{
"symbol": "0051",
"name": "元大中型100"
},
{
"symbol": "0052",
"name": "富邦科技"
},
......
]
}
```
#### 產業別代碼[](#產業別代碼 "Direct link to 產業別代碼")
| 代碼 | 產業別 | 代碼 | 產業別 | 代碼 | 產業別 |
| ---- | -------- | ---- | ---------------- | ---- | ------------ |
| `01` | 水泥工業 | `16` | 觀光餐旅 | `29` | 電子通路業 |
| `02` | 食品工業 | `17` | 金融保險 | `30` | 資訊服務業 |
| `03` | 塑膠工業 | `18` | ~~貿易百貨~~ | `31` | 其他電子業 |
| `04` | 紡織纖維 | `19` | 綜合 | `32` | 文化創意業 |
| `05` | 電機機械 | `20` | 其他 | `33` | 農業科技業 |
| `06` | 電器電纜 | `21` | 化學工業 | `34` | ~~電子商務~~ |
| `08` | 玻璃陶瓷 | `22` | 生技醫療業 | `35` | 綠能環保 |
| `09` | 造紙工業 | `23` | 油電燃氣業 | `36` | 數位雲端 |
| `10` | 鋼鐵工業 | `24` | 半導體業 | `37` | 運動休閒 |
| `11` | 橡膠工業 | `25` | 電腦及週邊設備業 | `38` | 居家生活 |
| `12` | 汽車工業 | `26` | 光電業 | `80` | 管理股票 |
| `14` | 建材營造 | `27` | 通信網路業 | | |
| `15` | 航運業 | `28` | 電子零組件業 | | |
---
### Intraday Trades
股票成交明細(依代碼查詢)
```text
intraday/trades/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------- | --------------------------------------------- |
| `symbol`\* | string | 股票代碼 |
| `type` | string | Ticker 類型,可選 `oddlot` 盤中零股 |
| `offset` | number | 偏移量 |
| `limit` | number | 限制量 |
| `sort` | string | 時間排序,預設為 `desc` 降冪,可選 `asc` 升冪 |
| `isTrial` | boolean | 查詢試撮明細:`true` |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------ | --------- | ----------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 股票代號 |
| `data`\* | object\[] | 成交明細 |
| >> `bid` | number | 成交買價 |
| >> `ask` | number | 成交賣價 |
| >> `price` | number | 成交價格 |
| >> `size` | number | 成交單量 |
| >> `volume` | number | 成交總量 |
| >> `time` | number | 成交時間 |
| >> `serial` | number | 流水號 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.intraday.trades(symbol='2330') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.intraday.trades(symbol='2330')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.intraday.trades({ symbol: '2330' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
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 trade = await rest.Intraday.Trades("2330");
// var trade = await rest.Intraday.Trades("2330", new(){Type=FugleMarketData.QueryModels.TickerType.OddLot}); // 零股
var trade_cont = trade.Content.ReadAsStringAsync().Result;
Console.WriteLine(trade_cont);
```
Response Body:
```json
{
"date": "2023-05-29",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"data": [
{
"price": 568,
"size": 32,
"time": 1685341800000000,
"serial": 99999999
},
{
"bid": 567,
"ask": 568,
"price": 568,
"size": 4778,
"volume": 54538,
"time": 1685338200000000,
"serial": 6652422
},
{
"bid": 565,
"ask": 566,
"price": 566,
"size": 1,
"volume": 49760,
"time": 1685337899721587,
"serial": 6622549
},
......
]
}
```
---
### Intraday Volumes
股票分價量表(依代碼查詢)
```text
intraday/volumes/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ---------------------------- |
| `symbol`\* | string | 股票代碼 |
| `type` | string | 類型,可選 `oddlot` 盤中零股 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ---------------- | --------- | ------------------------ |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 股票代號 |
| `data` | object\[] | 分價量表 |
| >> `price` | number | 成交價 |
| >> `volume` | number | 該成交價之累計成交量 |
| >> `volumeAtBid` | number | 該成交價之內盤累計成交量 |
| >> `volumeAtAsk` | number | 該成交價之外盤累計成交量 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.intraday.volumes(symbol='2330') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.intraday.volumes(symbol='2330')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.intraday.volumes({ symbol: '2330' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
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 volume = await rest.Intraday.Volume("2330");
// var volume = await rest.Intraday.Volume("2330", , new(){Type=FugleMarketData.QueryModels.TickerType.OddLot}); // 零股
var volume_cont = volume.Content.ReadAsStringAsync().Result;
Console.WriteLine(volume_cont);
```
Response Body:
```json
{
"date": "2023-05-29",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"data": [
{
"price": 574,
"volume": 7309,
"volumeAtBid": 0,
"volumeAtAsk": 524
},
{
"price": 573,
"volume": 771,
"volumeAtBid": 657,
"volumeAtAsk": 114
},
{
"price": 572,
"volume": 3364,
"volumeAtBid": 843,
"volumeAtAsk": 2521
},
{
"price": 571,
"volume": 3723,
"volumeAtBid": 1026,
"volumeAtAsk": 2697
},
{
"price": 570,
"volume": 5541,
"volumeAtBid": 3019,
"volumeAtAsk": 2522
},
{
"price": 569,
"volume": 1952,
"volumeAtBid": 1318,
"volumeAtAsk": 634
},
{
"price": 568,
"volume": 7906,
"volumeAtBid": 1422,
"volumeAtAsk": 6484
},
{
"price": 567,
"volume": 10498,
"volumeAtBid": 2816,
"volumeAtAsk": 7682
},
{
"price": 566,
"volume": 8206,
"volumeAtBid": 5988,
"volumeAtAsk": 2218
},
{
"price": 565,
"volume": 4833,
"volumeAtBid": 2329,
"volumeAtAsk": 2504
},
{
"price": 564,
"volume": 435,
"volumeAtBid": 435,
"volumeAtAsk": 0
}
]
}
```
---
### 董監持股
取得指定個股在年月區間內、每月董事、監察人及經理人之持股餘額、設質股數與設質比率明細。
```text
GET /ownership/director-holdings/{symbol}
```
版本資訊
v2.4.0 起新增功能
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | -------------------------------------------------------------------------------------------------------- |
| `symbol`\* | string | 個股代號(如 `2330`),路徑參數 |
| `from` | string | 開始年月(格式:`yyyy-MM`,亦接受 `yyyy-MM-dd`、僅取年月);與 `to` 皆省略時回最新月 |
| `to` | string | 結束年月(格式:`yyyy-MM`,亦接受 `yyyy-MM-dd`、僅取年月);僅提供 `from` 或 `to` 其一時,視同查詢該年月 |
| `sort` | string | 依年月排序,預設 `desc` 降冪;可選 `asc` 升冪 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------------------------- | --------- | ----------------------------------------------------- |
| `type`\* | string | 證券類型 |
| `exchange`\* | string | 交易所 |
| `market`\* | string | 市場別 |
| `symbol`\* | string | 個股代號 |
| `data`\* | object\[] | 每月一筆 |
| `data.date`\* | string | 資料年月(格式:`yyyy-MM`) |
| `data.directors`\* | object\[] | 董事、監察人及經理人持股明細 |
| `data.directors.order`\* | number | 揭露順序(自 `0` 起) |
| `data.directors.title`\* | string | 職稱(如 `董事長本人`、`獨立董事本人`、`總經理本人`) |
| `data.directors.name`\* | string | 姓名或法人名稱 |
| `data.directors.electedShares` | number | 選任時持股數(股) |
| `data.directors.heldShares` | number | 目前持股數(股) |
| `data.directors.pledgedShares` | number | 設質股數(股) |
| `data.directors.pledgeRatio` | number | 設質比率(比例值,`0.2146` 即 21.46%) |
| `data.directors.relatedHeldShares` | number | 配偶、未成年子女及利用他人名義合計持有股數(股) |
| `data.directors.relatedPledgedShares` | number | 前述持股之設質股數(股) |
| `data.directors.relatedPledgeRatio` | number | 前述持股之設質比率(比例值) |
資料說明
* **資料來源**:整理自公開資訊觀測站之董事、監察人及經理人持股餘額明細資料。
* **資料頻率**:每月一筆,`date` 為資料年月。
* **歷史涵蓋**:自 2017-01 起提供。涵蓋上市、上櫃、興櫃個股;ETF 等無董監資料之代號回傳 `data: []`。
* **年月語意**:`from`/`to` 以月為單位;帶日的格式僅取年月(`2026-07-15` 視同 `2026-07`)。
* **查詢區間**:單次查詢 `from` 與 `to` 的間隔須小於 1 年,超過會回傳 `400`;日期不合法或 `from` 晚於 `to` 亦回傳 `400`。
* **查無資料**:代號不存在或該區間無資料時,皆回傳 `200` 與 `data: []`(不回 `404`);此時 `type`/`exchange`/`market` 為預設值,不代表該代號的真實屬性。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
response = reststock.ownership.director_holdings(**{"symbol": "2330", "from": "2026-07", "to": "2026-08"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
print(response)
```
```js
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.ownership.directorHoldings({ symbol: '2330', from: '2026-07', to: '2026-08' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.Stock.Ownership;
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 directorHoldings = await rest.Ownership.DirectorHoldings("2330", new()
{
From = new DateTime(2026, 7, 1),
To = new DateTime(2026, 8, 1)
});
var directorHoldings_cont = directorHoldings.Content.ReadAsStringAsync().Result;
Console.WriteLine(directorHoldings_cont);
```
Response Body(為節省篇幅,`directors` 僅列前 2 筆並以 `...` 註記截斷;實際回應為當月全部明細,此處以 2026-07 期別的資料為例(查詢時 2026-08 尚未公布,故僅回傳 2026-07)):
```json
{
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"data": [
{
"date": "2026-07",
"directors": [
{
"order": 0,
"title": "董事長本人",
"name": "魏哲家",
"electedShares": 6392834,
"heldShares": 7452349,
"pledgedShares": 1600000,
"pledgeRatio": 0.2146,
"relatedHeldShares": 700261,
"relatedPledgedShares": 0,
"relatedPledgeRatio": 0
},
{
"order": 1,
"title": "董事本人",
"name": "行政院國家發展基金管理會",
"electedShares": 1653709980,
"heldShares": 1653709980,
"pledgedShares": 0,
"pledgeRatio": 0,
"relatedHeldShares": 0,
"relatedPledgedShares": 0,
"relatedPledgeRatio": 0
}
// ... 其餘董監明細略
]
}
]
}
```
---
### ETF 持股資料
取得指定 ETF 在日期區間內的每日成分股清單,含成分股代號、名稱、持股數、權重,以及相對前一個有資料日的變動。
```text
GET /ownership/etf-holdings/{symbol}
```
版本資訊
v2.2.9 起新增功能
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ----------------------------------------------------------------------- |
| `symbol`\* | string | ETF 代碼(如 `0050`、`00981A`),路徑參數 |
| `from` | string | 開始日期(格式:`yyyy-MM-dd`),預設 30 天前;與 `to` 的間隔須小於 1 年 |
| `to` | string | 結束日期(格式:`yyyy-MM-dd`),預設今天 |
| `sort` | string | 依日期排序,預設 `desc` 降冪;可選 `asc` 升冪 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| -------------------------------- | --------- | ----------------------------------------------------- |
| `symbol`\* | string | ETF 代號 |
| `type`\* | string | 證券類型 |
| `exchange`\* | string | 交易所 |
| `market`\* | string | 市場別 |
| `data`\* | object\[] | 每日成分資料,一日一筆 |
| `data.date`\* | string | 日期 |
| `data.components`\* | object\[] | 成分股清單 |
| `data.components.symbol`\* | string | 成分股代號(海外型 ETF 可能為外國代號,如 `AAPL UQ`) |
| `data.components.name` | string | 成分股名稱 |
| `data.components.quantity` | number | 持股股數 |
| `data.components.weight` | number | 權重(%) |
| `data.components.quantityChange` | number | 相對上一個有資料日的持股變動(首日省略) |
| `data.components.weightChange` | number | 相對上一個有資料日的權重變動(首日省略) |
資料說明
* **資料來源**:整理自各 ETF 發行投信公司公開揭露之每日成分資訊,僅供參考,實際持股內容以各投信公司/基金公開說明書之公告為準。
* **查詢區間**:單次查詢 `from` 與 `to` 的間隔須小於 1 年,超過會回傳 `400`;日期格式錯誤或 `from` 晚於 `to` 亦回傳 `400`。
* **歷史涵蓋**:成分資料可追溯至 2019 年,個別 ETF 依上市日與發行商揭露情況而定;發行商未提供成分資料之交易日不會出現在回應的 `data` 陣列中,以實際回傳為準。
* **權重範圍**:本資料僅涵蓋 ETF 的**股票部位**成分,權重加總不一定為 100%(差額為現金、期貨、債券或未揭露部位)。台股股票型(被動或主動)通常接近 100%;海外股票型多在 90% 上下;平衡型/多重資產型與槓桿型僅回股票部位,加總可能僅數十個百分點;無股票部位者(純債券型、期貨型、商品型、反向型,以及部分匯率避險/外幣計價級別)回傳 `data: []`。
* **變動欄位**:`quantityChange` / `weightChange` 為相對「該 ETF 上一個有成分資料的日期」之差,**不保證對照前一交易日**;該 ETF 首個有資料日不含此兩欄位。
* **查無資料**:非 ETF 代號、不存在的代號或該區間無揭露時,皆回傳 `200` 與 `data: []`(不回 `404`);此時 `type`/`exchange`/`market` 為預設值,不代表該代號的真實屬性。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
response = reststock.ownership.etf_holdings(**{"symbol": "0050", "from": "2026-07-09", "to": "2026-07-09"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
print(response)
```
```js
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.ownership.etfHoldings({ symbol: '0050', from: '2026-07-09', to: '2026-07-09' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.Stock.Ownership;
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 etfHoldings = await rest.Ownership.EtfHoldings(new()
{
Symbol = "0050",
From = fromDate,
To = toDate
});
var etfHoldings_cont = etfHoldings.Content.ReadAsStringAsync().Result;
Console.WriteLine(etfHoldings_cont);
```
Response Body(為節省篇幅,`components` 僅列前 3 檔成分股並以 `...` 註記截斷;實際回應會包含當日全部成分股,此處以 2026-07-09 收盤後資料為例,預設查詢區間共回傳 21 個交易日):
```json
{
"symbol": "0050",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"data": [
{
"date": "2026-07-09",
"components": [
{
"symbol": "2330",
"name": "台積電",
"quantity": 530358242,
"weight": 58.82,
"quantityChange": 370562,
"weightChange": 0.17
},
{
"symbol": "2454",
"name": "聯發科",
"quantity": 32045645,
"weight": 5.76,
"quantityChange": 22388,
"weightChange": -0.09
},
{
"symbol": "2308",
"name": "台達電",
"quantity": 41931322,
"weight": 3.56,
"quantityChange": 29348,
"weightChange": -0.03
}
// ... 其餘成分股略
]
}
// ... 其餘交易日略
]
}
```
---
### 三大法人買賣超
取得指定個股在日期區間內、每個交易日的三大法人(外資及陸資、投信、自營商)買進、賣出與買賣超股數。
```text
GET /ownership/institutional-trades/{symbol}
```
版本資訊
v2.4.0 起新增功能
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | --------------------------------------------- |
| `symbol`\* | string | 個股代號(如 `2330`),路徑參數 |
| `from` | string | 開始日期(格式:`yyyy-MM-dd`),預設 30 天前 |
| `to` | string | 結束日期(格式:`yyyy-MM-dd`),預設今天 |
| `sort` | string | 依日期排序,預設 `desc` 降冪;可選 `asc` 升冪 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| --------------------- | --------- | ------------------------------------------------------------------------------ |
| `type`\* | string | 證券類型 |
| `exchange`\* | string | 交易所 |
| `market`\* | string | 市場別 |
| `symbol`\* | string | 個股代號 |
| `data`\* | object\[] | 有法人交易的交易日各一筆 |
| `data.date`\* | string | 日期 |
| `data.foreign`\* | object | 外資及陸資合計(不含外資自營商) |
| `data.foreign.buy`\* | number | 買進股數(股) |
| `data.foreign.sell`\* | number | 賣出股數(股) |
| `data.foreign.net`\* | number | 買賣超股數(股,買進 − 賣出) |
| `data.trust`\* | object | 投信,子欄位同 `foreign` |
| `data.dealer`\* | object | 自營商合計(含自行買賣與避險),子欄位同 `foreign` |
| `data.total`\* | number | 三大法人合計買賣超股數(股,為 `foreign.net`、`trust.net`、`dealer.net` 之和) |
資料說明
* **資料來源**:整理自臺灣證券交易所與證券櫃檯買賣中心公開之三大法人買賣超日報資訊。
* **資料頻率**:僅在該股當日有三大法人交易時才有一筆,無法人進出的交易日不會出現在 `data` 陣列中。
* **歷史涵蓋**:上市、上櫃個股自 2013 年起;興櫃個股亦涵蓋,起始日依個股而異,請以實際回傳為準。
* **查詢區間**:單次查詢 `from` 與 `to` 的間隔須小於 1 年,超過會回傳 `400`;日期不合法或 `from` 晚於 `to` 亦回傳 `400`。
* **查無資料**:代號不存在或該區間無資料時,皆回傳 `200` 與 `data: []`(不回 `404`);此時 `type`/`exchange`/`market` 為預設值,不代表該代號的真實屬性。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
response = reststock.ownership.institutional_trades(**{"symbol": "2330", "from": "2026-08-13", "to": "2026-08-13"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
print(response)
```
```js
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.ownership.institutionalTrades({ symbol: '2330', from: '2026-08-13', to: '2026-08-13' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.Stock.Ownership;
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 institutionalTrades = await rest.Ownership.InstitutionalTrades("2330", new()
{
From = new DateTime(2026, 8, 13),
To = new DateTime(2026, 8, 13)
});
var institutionalTrades_cont = institutionalTrades.Content.ReadAsStringAsync().Result;
Console.WriteLine(institutionalTrades_cont);
```
Response Body(以 2026-08-13 收盤後的資料為例):
```json
{
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"data": [
{
"date": "2026-08-13",
"foreign": {
"buy": 18369301,
"sell": 14397070,
"net": 3972231
},
"trust": {
"buy": 2350600,
"sell": 1614607,
"net": 735993
},
"dealer": {
"buy": 482295,
"sell": 389114,
"net": 93181
},
"total": 4801405
}
]
}
```
---
### 集保戶股權分散
取得指定個股在日期區間內、每期集保戶股權分散資料,含各持股級距的股東人數、持股股數與佔集保庫存比例。
```text
GET /ownership/tdcc-distribution/{symbol}
```
版本資訊
v2.4.0 起新增功能
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | -------------------------------------------------------------------------------- |
| `symbol`\* | string | 個股代號(如 `2330`),路徑參數 |
| `from` | string | 開始日期(格式:`yyyy-MM-dd`);與 `to` 皆省略時回最新一期 |
| `to` | string | 結束日期(格式:`yyyy-MM-dd`);僅提供 `from` 或 `to` 其一時,視同以該日查詢單日 |
| `sort` | string | 依日期排序,預設 `desc` 降冪;可選 `asc` 升冪 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| --------------------------------- | --------- | ------------------------------------------------------------------------------------- |
| `type`\* | string | 證券類型 |
| `exchange`\* | string | 交易所 |
| `market`\* | string | 市場別 |
| `symbol`\* | string | 個股代號 |
| `data`\* | object\[] | 每期一筆 |
| `data.date`\* | string | 公布基準日 |
| `data.distributions`\* | object\[] | 各持股級距明細 |
| `data.distributions.range`\* | string | 持股級距(股),15 個固定級距;另含「`合計`」列,部分期別含「`異動`」(差異數調整)列 |
| `data.distributions.holders`\* | number | 股東人數 |
| `data.distributions.shares`\* | number | 持股股數(股) |
| `data.distributions.proportion`\* | number | 佔集保庫存比例(百分比值,`84.67` 即 84.67%) |
資料說明
* **資料來源**:整理自臺灣集中保管結算所公開之集保戶股權分散表。
* **資料頻率**:每週公布一次,`date` 為公布基準日(多為週五,遇假日可能提前);2015-05-08 以前之歷史資料為每月一筆。
* **歷史涵蓋**:自 2013-07-01 起;涵蓋上市、上櫃、興櫃個股。
* **單日查詢**:資料僅落在公布基準日;僅提供 `from` 或 `to` 其一(視同單日查詢)且該日非公布基準日時,回傳 `data: []`。
* **查詢區間**:單次查詢 `from` 與 `to` 的間隔須小於 1 年,超過會回傳 `400`;日期不合法或 `from` 晚於 `to` 亦回傳 `400`。
* **查無資料**:代號不存在或該區間無資料時,皆回傳 `200` 與 `data: []`(不回 `404`);此時 `type`/`exchange`/`market` 為預設值,不代表該代號的真實屬性。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
response = reststock.ownership.tdcc_distribution(**{"symbol": "2330", "from": "2026-08-07", "to": "2026-08-07"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
print(response)
```
```js
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.ownership.tdccDistribution({ symbol: '2330', from: '2026-08-07', to: '2026-08-07' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.Stock.Ownership;
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 tdccDistribution = await rest.Ownership.TdccDistribution("2330", new()
{
From = new DateTime(2026, 8, 7),
To = new DateTime(2026, 8, 7)
});
var tdccDistribution_cont = tdccDistribution.Content.ReadAsStringAsync().Result;
Console.WriteLine(tdccDistribution_cont);
```
Response Body(以 2026-08-07 期別的資料為例,一期共 15 個固定級距,本期另含「異動」與「合計」列):
```json
{
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"data": [
{
"date": "2026-08-07",
"distributions": [
{
"range": "1-999",
"holders": 2523071,
"shares": 293744991,
"proportion": 1.13
},
{
"range": "1000-5000",
"holders": 454920,
"shares": 869533934,
"proportion": 3.35
},
{
"range": "5001-10000",
"holders": 53011,
"shares": 379122752,
"proportion": 1.46
},
{
"range": "10001-15000",
"holders": 17491,
"shares": 214496406,
"proportion": 0.82
},
{
"range": "15001-20000",
"holders": 8096,
"shares": 142302572,
"proportion": 0.54
},
{
"range": "20001-30000",
"holders": 7803,
"shares": 190826713,
"proportion": 0.73
},
{
"range": "30001-40000",
"holders": 3686,
"shares": 127930452,
"proportion": 0.49
},
{
"range": "40001-50000",
"holders": 2048,
"shares": 92338466,
"proportion": 0.35
},
{
"range": "50001-100000",
"holders": 4123,
"shares": 288118496,
"proportion": 1.11
},
{
"range": "100001-200000",
"holders": 2053,
"shares": 288258115,
"proportion": 1.11
},
{
"range": "200001-400000",
"holders": 1314,
"shares": 368794003,
"proportion": 1.42
},
{
"range": "400001-600000",
"holders": 584,
"shares": 285446281,
"proportion": 1.1
},
{
"range": "600001-800000",
"holders": 353,
"shares": 246354564,
"proportion": 0.94
},
{
"range": "800001-1000000",
"holders": 208,
"shares": 186782272,
"proportion": 0.72
},
{
"range": "1000001以上",
"holders": 1475,
"shares": 21958321050,
"proportion": 84.67
},
{
"range": "異動",
"holders": 1,
"shares": 1000,
"proportion": 0
},
{
"range": "合計",
"holders": 3080236,
"shares": 25932370067,
"proportion": 100
}
]
}
]
}
```
---
### Snapshot Actives
股票成交量值排行(依市場別)
```text
snapshot/actives/{market}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ---------------------------------------------------------------------------------- |
| `market`\* | string | 市場別,可選 `TSE` 上市;`OTC` 上櫃;`ESB` 興櫃一般板;`TIB` 臺灣創新板 |
| `trade`\* | string | 成交量/成交值,可選 `volume` 成交量;`value` 成交值 |
| `type` | string | 標的類型,可選 `ALLBUT0999` 包含一般股票、特別股及 ETF ; `COMMONSTOCK` 為一般股票 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------ | --------- | -------------- |
| `date`\* | string | 日期 |
| `time`\* | string | 時間 |
| `market`\* | string | 市場別 |
| `trade`\* | string | 成交量/成交值 |
| `data`\* | object\[] | 快照資料 |
| >> `type` | string | Ticker 類型 |
| >> `symbol` | string | 股票代碼 |
| >> `name` | string | 股票簡稱 |
| >> `openPrice` | number | 開盤價 |
| >> `highPrice` | number | 最高價 |
| >> `lowPrice` | number | 最低價 |
| >> `closePrice` | number | 收盤價 |
| >> `change` | number | 漲跌 |
| >> `changePercent` | number | 漲跌幅 |
| >> `tradeVolume` | number | 成交量 |
| >> `tradeValue` | number | 成交金額 |
| >> `lastUpdated` | number. | 快照時間 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.snapshot.actives(market='TSE', trade='value') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.snapshot.actives(market='TSE', trade='value')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.snapshot.actives({ market: 'TSE', trade: 'value' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels;
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 quote = await rest.Snapshot.Quotes(FugleMarketData.QueryModels.MarketType.TSE)
var quote_cont = quote.Content.ReadAsStringAsync().Result;
Console.WriteLine(quote_cont);
```
Response Body:
```json
{
"date": "2023-05-29",
"time": "140000",
"market": "TSE",
"trade": "value",
"data": [
{
"type": "EQUITY",
"symbol": "2330",
"name": "台積電",
"openPrice": 574,
"highPrice": 574,
"lowPrice": 564,
"closePrice": 568,
"change": 2,
"changePercent": 0.35,
"tradeVolume": 54538,
"tradeValue": 31019803000,
"lastUpdated": 1685338200000000
},
{
"type": "EQUITY",
"symbol": "3231",
"name": "緯創",
"openPrice": 66,
"highPrice": 69.2,
"lowPrice": 65.9,
"closePrice": 68,
"change": 3,
"changePercent": 4.62,
"tradeVolume": 202089,
"tradeValue": 13763365000,
"lastUpdated": 1685338200000000
},
{
"type": "EQUITY",
"symbol": "3661",
"name": "世芯-KY",
"openPrice": 1555,
"highPrice": 1660,
"lowPrice": 1550,
"closePrice": 1660,
"change": 150,
"changePercent": 9.93,
"tradeVolume": 6937,
"tradeValue": 11264055000,
"lastUpdated": 1685338200000000
},
......
]
}
```
---
### Snapshot Movers
股票漲跌幅排行(依市場別)
```text
snapshot/movers/{market}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ------------- | ------ | ---------------------------------------------------------------------------------- |
| `market`\* | string | 市場別 |
| `direction`\* | string | 上漲/下跌,可選 `up` 上漲;`down` 下跌 |
| `change`\* | string | 漲跌/漲跌幅,可選 `percent` 漲跌幅;`value` 漲跌 |
| `gt` | number | 篩選大於漲跌/漲跌幅的股票 |
| `type` | string | 標的類型,可選 `ALLBUT0999` 包含一般股票、特別股及 ETF ; `COMMONSTOCK` 為一般股票 |
| `gte` | number | 篩選大於或等於漲跌/漲跌幅的股票 |
| `lt` | number | 篩選小於漲跌/漲跌幅的股票 |
| `lte` | number | 篩選小於或等於漲跌/漲跌幅的股票 |
| `eq` | number | 篩選等於漲跌/漲跌幅的股票 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------ | --------- | ------------ |
| `date`\* | string | 日期 |
| `time`\* | string | 時間 |
| `market`\* | string | 市場別 |
| `change`\* | string | 漲跌/漲跌幅 |
| `data`\* | object\[] | 快照資料 |
| >> `type` | string | Ticker 類型 |
| >> `symbol` | string | 股票代碼 |
| >> `name` | string | 股票簡稱 |
| >> `openPrice` | number | 開盤價 |
| >> `highPrice` | number | 最高價 |
| >> `lowPrice` | number | 最低價 |
| >> `closePrice` | number | 收盤價 |
| >> `change` | number | 漲跌 |
| >> `changePercent` | number | 漲跌幅 |
| >> `tradeVolume` | number | 成交量 |
| >> `tradeValue` | number | 成交金額 |
| >> `lastUpdated` | number | 快照時間 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.snapshot.movers(market='TSE', direction='up', change='percent') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.snapshot.movers(market='TSE', direction='up', change='percent')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.snapshot.movers({ market: 'TSE', direction: 'up', change: 'percent' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels;
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 movers = await rest.Snapshot.Movers(FugleMarketData.QueryModels.MarketType.TSE, FugleMarketData.QueryModels.DirectionType.Up,
FugleMarketData.QueryModels.ChangeType.Percent);
var movers_cont = movers.Content.ReadAsStringAsync().Result;
Console.WriteLine(movers_cont);
```
Response Body:
```json
{
"date": "2023-05-29",
"time": "133500",
"market": "TSE",
"change": "percent",
"data": [
{
"type": "EQUITY",
"symbol": "2901",
"name": "欣欣",
"openPrice": 27.1,
"highPrice": 29.7,
"lowPrice": 27.1,
"closePrice": 29.7,
"change": 2.7,
"changePercent": 10,
"tradeVolume": 640,
"tradeValue": 18824300,
"lastUpdated": 1685338200000000
},
{
"type": "EQUITY",
"symbol": "2345",
"name": "智邦",
"openPrice": 357.5,
"highPrice": 357.5,
"lowPrice": 346.5,
"closePrice": 357.5,
"change": 32.5,
"changePercent": 10,
"tradeVolume": 9350,
"tradeValue": 3331334500,
"lastUpdated": 1685338200000000
},
{
"type": "EQUITY",
"symbol": "3025",
"name": "星通",
"openPrice": 42.3,
"highPrice": 44.65,
"lowPrice": 41.8,
"closePrice": 44.65,
"change": 4.05,
"changePercent": 9.98,
"tradeVolume": 25625,
"tradeValue": 1114127050,
"lastUpdated": 1685338200000000
},
......
]
}
```
---
### Snapshot Quotes
股票行情快照(依市場別)
```text
snapshot/quotes/{market}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ---------------------------------------------------------------------------------- |
| `market`\* | string | 市場別,可選 `TSE` 上市;`OTC` 上櫃;`ESB` 興櫃一般板;`TIB` 臺灣創新板 |
| `type` | string | 標的類型,可選 `ALLBUT0999` 包含一般股票、特別股及 ETF ; `COMMONSTOCK` 為一般股票 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------ | --------- | ------------------------ |
| `date`\* | string | 日期 |
| `time`\* | string | 時間 |
| `market`\* | string | 市場別 |
| `data`\* | object\[] | 快照資料 |
| >> `type` | string | Ticker 類型 |
| >> `symbol` | string | 股票代碼 |
| >> `name` | string | 股票簡稱 |
| >> `openPrice` | number | 開盤價 |
| >> `highPrice` | number | 最高價 |
| >> `lowPrice` | number | 最低價 |
| >> `closePrice` | number | 收盤價 |
| >> `change` | number | 漲跌 |
| >> `changePercent` | number | 漲跌幅 |
| >> `tradeVolume` | number | 成交量 |
| >> `tradeValue` | number | 成交金額 |
| >> `lastUpdated` | number | 快照時間 |
| >> `lastPrice` | number | 最後一筆成交價(含試撮) |
| >> `isTrial` | bool | 試撮註記 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
# reststock.snapshot.quotes(market='TSE') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.snapshot.quotes(market='TSE')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.snapshot.quotes({ market: 'TSE' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels;
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 quotes = await rest.Snapshot.Quotes(FugleMarketData.QueryModels.MarketType.TSE);
var quotes_cont = quotes.Content.ReadAsStringAsync().Result;
Console.WriteLine(quotes_cont);
```
Response Body:
```json
{
"date": "2023-05-29",
"time": "133500",
"market": "TSE",
"data": [
{
"type": "EQUITY",
"symbol": "0050",
"name": "元大台灣50",
"openPrice": 127.45,
"highPrice": 127.55,
"lowPrice": 126.5,
"closePrice": 126.75,
"change": 0.8,
"changePercent": 0.64,
"tradeVolume": 14444,
"tradeValue": 1832941850,
"lastUpdated": 1685338200000000
},
{
"type": "EQUITY",
"symbol": "0051",
"name": "元大中型100",
"openPrice": 61,
"highPrice": 62.2,
"lowPrice": 61,
"closePrice": 62,
"change": 1.3,
"changePercent": 2.14,
"tradeVolume": 191,
"tradeValue": 11816050,
"lastUpdated": 1685338200000000
},
{
"type": "EQUITY",
"symbol": "0052",
"name": "富邦科技",
"openPrice": 111.8,
"highPrice": 112.1,
"lowPrice": 111.1,
"closePrice": 111.7,
"change": 1.2,
"changePercent": 1.09,
"tradeVolume": 565,
"tradeValue": 63088400,
"lastUpdated": 1685338200000000
},
......
]
}
```
---
### Technical Bbands
取得特定股票在指定時間範圍內的布林通通 (Bollinger Bands)
```text
technical/bb/{symbol}
```
版本資訊
v2.2.6 起新增功能
#### Parameters[](#parameters "Direct link to 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 |
| `period`\* | number | 布林通道週期 |
caution
目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近 30 日資料。
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------- | --------- | ------------ |
| `symbol`\* | string | 股票代號 |
| `from`\* | string | 開始日期 |
| `to`\* | string | 結束日期 |
| `timeframe`\* | string | K線週期 |
| `period`\* | number | 布林通道週期 |
| `data`\* | object\[] | 布林通道資料 |
| >> `data[0].date` | string | 資料日期 |
| >> `data[0].upper` | number | Bolling 上軌 |
| >> `data[0].middle` | number | Bolling 中軌 |
| >> `data[0].lower` | number | Bolling 下軌 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
reststock.technical.bb(**{"symbol": "2330", "from": "2024-08-01", "to": "2024-08-10","timeframe":"D", "period": 10})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.technical.bb({ symbol: '2330', from: '2024-08-01', to: '2024-08-10', timeframe: 'D', period: 10 })
.then(data => console.log(data));
```
```cs
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;
DateTime fromDate = new DateTime(2024, 8, 1);
DateTime toDate = new DateTime(2024, 8, 10);
var bband = await rest.Technical.Bb("2330" ,new(10, fromDate, toDate, HistoryTimeFrame.Day));
//BbRequest 參數 (period, DateTime, DateTime, HistoryTimeFrame)
var bband_con = bband.Content.ReadAsStringAsync().Result;
Console.WriteLine(bband_con);
```
Response Body:
```json
{
"symbol": "2330",
"from": "2024-08-01",
"to": "2024-08-10",
"timeframe": "D",
"period": 20,
"data": [
{
"date": "2024-08-01",
"upper": 1089.4184184924368,
"middle": 997.45,
"lower": 905.4815815075632
},
{
"date": "2024-08-02",
"upper": 1094.230862990929,
"middle": 993.65,
"lower": 893.0691370090711
},
{
"date": "2024-08-05",
"upper": 1111.086637737101,
"middle": 984.15,
"lower": 857.2133622628991
},
{
"date": "2024-08-06",
"upper": 1112.2099400640175,
"middle": 977.9,
"lower": 843.5900599359824
},
{
"date": "2024-08-07",
"upper": 1106.0354361011682,
"middle": 972.15,
"lower": 838.2645638988317
},
{
"date": "2024-08-08",
"upper": 1098.9536939789348,
"middle": 964.95,
"lower": 830.9463060210653
},
{
"date": "2024-08-09",
"upper": 1088.7976815866498,
"middle": 959.4,
"lower": 830.0023184133502
}
]
}
```
---
### Technical KDJ
取得特定股票在指定時間範圍內的隨機指標 (KDJ)
```text
technical/kdj/{symbol}
```
版本資訊
v2.2.6 起新增功能
#### Parameters[](#parameters "Direct link to 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 |
| `rPeriod`\* | number | KDJ 週期 |
| `kPeriod`\* | number | %K 週期 |
| `dPeriod`\* | number | %D 週期 |
caution
目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近 30 日資料。
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ----------------- | --------- | ----------- |
| `symbol`\* | string | 股票代號 |
| `from`\* | string | 開始日期 |
| `to`\* | string | 結束日期 |
| `timeframe`\* | string | K線週期 |
| `rPeriod`\* | number | KDJ 週期 |
| `kPeriod`\* | number | %K 週期 |
| `dPeriod`\* | number | %D 週期 |
| `data`\* | object\[] | KDJ 資料 |
| >> `data[0].date` | string | 資料日期 |
| >> `data[0].k` | number | K |
| >> `data[0].d` | number | D |
| >> `data[0].j` | number | J |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
reststock.technical.kdj(**{"symbol": "2330", "from": "2024-08-01", "to": "2024-08-10","timeframe":"D", "rPeriod": 9, "kPeriod":3, "dPeriod":3})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.technical.kdj({ symbol: '2330', from: '2024-08-01', to: '2024-08-10', timeframe: 'D', rPeriod: 9, kPeriod: 3, dPeriod: 3 })
.then(data => console.log(data));
```
```cs
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;
DateTime fromDate = new DateTime(2024, 8, 1);
DateTime toDate = new DateTime(2024, 8, 10);
var kdj = await rest.Technical.Kdj("2330" ,new(9,3,3, fromDate, toDate, HistoryTimeFrame.Day));
//Kdj 參數 (rPeriod, kPeriod, dPeriod, DateTime, DateTime, HistoryTimeFrame)
var kdj_con = kdj.Content.ReadAsStringAsync().Result;
Console.WriteLine(kdj_con);
```
Response Body:
```json
{
"symbol": "2330",
"from": "2024-08-01",
"to": "2024-08-10",
"timeframe": "D",
"rPeriod": 9,
"kPeriod": 3,
"dPeriod": 3,
"data": [
{
"date": "2024-08-01",
"k": 32.96296296296297,
"d": 27.77777777777779,
"j": 43.333333333333336
},
{
"date": "2024-08-02",
"k": 23.703703703703713,
"d": 27.901234567901245,
"j": 15.308641975308653
},
{
"date": "2024-08-05",
"k": 17.068273092369484,
"d": 24.578313253012055,
"j": 2.048192771084345
},
{
"date": "2024-08-06",
"k": 13.855421686746999,
"d": 18.20913282760673,
"j": 5.147999405027534
},
{
"date": "2024-08-07",
"k": 36.718669549994864,
"d": 22.547454776370447,
"j": 65.0610990972437
},
{
"date": "2024-08-08",
"k": 54.05210585933478,
"d": 34.87539903202555,
"j": 92.40551951395325
},
{
"date": "2024-08-09",
"k": 66.45299145299147,
"d": 52.40792228744038,
"j": 94.54312978409367
}
]
}
```
---
### Technical MACD
取得特定股票在指定時間範圍內的指數平滑異同移動平均線 (MACD)
```text
technical/macd/{symbol}
```
版本資訊
v2.2.6 起新增功能
#### Parameters[](#parameters "Direct link to 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 |
| `fast`\* | number | 快線週期 |
| `slow`\* | number | 慢線週期 |
| `signal`\* | number | 信號線週期 |
caution
目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近 30 日資料。
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ----------------------- | --------- | ----------- |
| `symbol`\* | string | 股票代號 |
| `from`\* | string | 開始日期 |
| `to`\* | string | 結束日期 |
| `timeframe`\* | string | K線週期 |
| `fast`\* | number | 快線週期 |
| `slow`\* | number | 慢線週期 |
| `signal`\* | number | 信號線週期 |
| `data`\* | object\[] | MACD 資料 |
| >> `data[0].date` | string | 資料日期 |
| >> `data[0].macdLine` | number | MACD 線 |
| >> `data[0].signalLine` | number | 信號線 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
reststock.technical.macd(**{"symbol": "2330", "from": "2024-08-01", "to": "2024-08-10","timeframe":"D", "fast": 12, "slow":26, "signal":9})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.technical.macd({ symbol: '2330', from: '2024-08-01', to: '2024-08-10', timeframe: 'D', fast: 12, slow: 26, signal: 9, dPeriod: 3 })
.then(data => console.log(data));
```
```cs
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;
DateTime fromDate = new DateTime(2024, 8, 1);
DateTime toDate = new DateTime(2024, 8, 10);
var macd = await rest.Technical.Macd("2330" ,new( 12, 26, 9, fromDate, oDate, HistoryTimeFrame.Day));
//MacdRequest 參數 (fast, slow, signal DateTime, DateTime, HistoryTimeFrame)
var macd_con = macd.Content.ReadAsStringAsync().Result;
Console.WriteLine(macd_con);
```
Response Body:
```json
{
"symbol": "2330",
"from": "2024-08-01",
"to": "2024-08-10",
"timeframe": "D",
"fast": 12,
"slow": 26,
"signal": 9,
"data": [
{
"date": "2024-08-01",
"macdLine": -8.888098865883194,
"signalLine": 1.1835714956164298
},
{
"date": "2024-08-02",
"macdLine": -13.342205320023709,
"signalLine": -1.721583867511598
},
{
"date": "2024-08-05",
"macdLine": -23.69978495993405,
"signalLine": -6.117224085996089
},
{
"date": "2024-08-06",
"macdLine": -26.359429578554114,
"signalLine": -10.165665184507695
},
{
"date": "2024-08-07",
"macdLine": -24.951921179141777,
"signalLine": -13.12291638343451
},
{
"date": "2024-08-08",
"macdLine": -25.47934996958338,
"signalLine": -15.594203100664284
},
{
"date": "2024-08-09",
"macdLine": -22.570875660446973,
"signalLine": -16.989537612620822
}
]
}
```
---
### Technical RSI
取得特定股票在指定時間範圍內的相對強弱指標 (RSI)
```text
technical/rsi/{symbol}
```
版本資訊
v2.2.6 起新增功能
#### Parameters[](#parameters "Direct link to 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 |
| `period`\* | number | RSI 週期 |
caution
目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近 30 日資料。
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ----------------- | --------- | ----------- |
| `symbol`\* | string | 股票代號 |
| `from`\* | string | 開始日期 |
| `to`\* | string | 結束日期 |
| `timeframe`\* | string | K線週期 |
| `period`\* | number | RSI 週期 |
| `data`\* | object\[] | RSI 資料 |
| >> `data[0].date` | string | 資料日期 |
| >> `data[0].rsi` | number | RSI |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
reststock.technical.rsi(**{"symbol": "2330", "from": "2024-08-01", "to": "2024-08-10","timeframe":"D", "period": 6})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.technical.rsi({ symbol: '2330', from: '2024-08-01', to: '2024-08-10', timeframe: 'D', period: 6 })
.then(data => console.log(data));
```
```cs
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;
DateTime fromDate = new DateTime(2024, 8, 1);
DateTime toDate = new DateTime(2024, 8, 10);
var rsi = await rest.Technical.Rsi("2330" ,new(6, fromDate, toDate, HistoryTimeFrame.Day));
//RsiRequest 參數 (period, DateTime, DateTime, HistoryTimeFrame)
var rsi_con = rsi.Content.ReadAsStringAsync().Result;
Console.WriteLine(rsi_con);
```
Response Body:
```json
{
"symbol": "2330",
"from": "2024-08-01",
"to": "2024-08-10",
"timeframe": "D",
"period": 6,
"data": [
{
"date": "2024-08-01",
"rsi": 41.44144144144145
},
{
"date": "2024-08-02",
"rsi": 25.641025641025635
},
{
"date": "2024-08-05",
"rsi": 15.026786880961723
},
{
"date": "2024-08-06",
"rsi": 37.83577095879935
},
{
"date": "2024-08-07",
"rsi": 48.119604933543954
},
{
"date": "2024-08-08",
"rsi": 42.99811400274545
},
{
"date": "2024-08-09",
"rsi": 52.58621466649552
}
]
}
```
---
### Technical SMA
取得特定股票在指定時間範圍內的簡單移動平均 (SMA)
```text
technical/sma/{symbol}
```
版本資訊
v2.2.6 起新增功能
#### Parameters[](#parameters "Direct link to 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 |
| `period`\* | number | SMA 週期 |
caution
目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近 30 日資料。
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ----------------- | --------- | ----------- |
| `symbol`\* | string | 股票代號 |
| `from`\* | string | 開始日期 |
| `to`\* | string | 結束日期 |
| `timeframe`\* | string | K線週期 |
| `period`\* | number | SMA 週期 |
| `data`\* | object\[] | SMA 資料 |
| >> `data[0].date` | string | 資料日期 |
| >> `data[0].sma` | number | SMA |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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
## 2.2.6 及以後版本使用更簡化 (使用 Exception 進行例外處理)
from fubon_neo.sdk import FugleAPIError
try:
reststock.technical.sma(**{"symbol": "2330", "from": "2024-08-01", "to": "2024-08-10","timeframe":"D", "period": 5})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.technical.sma({ symbol: '2330', from: '2024-08-01', to: '2024-08-10', timeframe: 'D', period: 5 })
.then(data => console.log(data));
```
```cs
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;
DateTime fromDate = new DateTime(2024, 8, 1);
DateTime toDate = new DateTime(2024, 8, 10);
var sma = await rest.Technical.Sma("2330" ,new(5, fromDate, toDate, HistoryTimeFrame.Day));
//SmaRequest 參數 (period, DateTime, DateTime, HistoryTimeFrame)
var sma_con = sma.Content.ReadAsStringAsync().Result;
Console.WriteLine(sma_con);
```
Response Body:
```json
{
"symbol": "2330",
"from": "2024-08-01",
"to": "2024-08-10",
"timeframe": "D",
"period": 5,
"data": [
{
"date": "2024-08-01",
"sma": 940.4
},
{
"date": "2024-08-02",
"sma": 936.2
},
{
"date": "2024-08-05",
"sma": 910.4
},
{
"date": "2024-08-06",
"sma": 898.4
},
{
"date": "2024-08-07",
"sma": 895.6
},
{
"date": "2024-08-08",
"sma": 882.8
},
{
"date": "2024-08-09",
"sma": 889
}
]
}
```
---
### 富邦新一代 API 證券行情服務
本頁重點
* 富邦新一代 API(Fubon Neo API)證券行情服務提供台股即時與歷史資料。
* 介面包含 Web API 與 WebSocket API。
* 資料來源為交易所與資訊供應商,使用前請詳閱規範與聲明。
* 下一步可從 [Web API](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/getting-started.txt) 或 [WebSocket API](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/getting-started.txt) 開始。
| 項目 | 說明 |
| -------- | ------------------------------------------------ |
| 服務 | 新一代 API 證券行情服務 |
| 市場 | 台灣證券市場 |
| 介面 | Web API / WebSocket API |
| 資料來源 | 臺灣證券交易所、證券櫃檯買賣中心、臺灣期貨交易所 |
| 規範 | 使用規範與聲明 |
即時行情資料來源為臺灣證券交易所、證券櫃檯買賣中心、臺灣期貨交易所。請您詳閱相關使用 [規範與聲明](#statement)。
#### Web API[](#web-api "Direct link to Web API")
富邦行情 [Web API](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/getting-started.txt) 提供開發者友善的 API 服務。您可以查詢台股的日內行情、行情快照與歷史行情等數據;數據來源為時報資訊與群馥科技。
#### WebSocket API[](#websocket-api "Direct link to WebSocket API")
富邦行情 [WebSocket API](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/getting-started.txt) 提供台股即時行情服務。透過 WebSocket API 可以滿足您想要接收即時行情的需求。
#### 使用規範與聲明[](#statement "Direct link to 使用規範與聲明")
* 透過本服務取得之行情資料僅供參考,成交值及成交量不含零股及鉅額交易,使用者依本資料交易發生交易損失需自行負責。
* 時報資訊與群馥科技對資料內容錯誤、更新延誤或傳輸中斷不負任何責任。您應對您所為之任何金融或投資決策自行負責。
* 使用者應遵守 [臺灣證券交易所股份有限公司交易資訊使用管理辦法](https://www.selaw.com.tw/Chinese/RegulatoryInformationResult/Article?isIntegratedSearch=True\&sysNumber=LW10809760\&searchString1=%E8%87%BA%E7%81%A3%E8%AD%89%E5%88%B8%E4%BA%A4%E6%98%93%E6%89%80%E8%82%A1%E4%BB%BD%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%E4%BA%A4%E6%98%93%E8%B3%87%E8%A8%8A%E4%BD%BF%E7%94%A8%E7%AE%A1%E7%90%86%E8%BE%A6%E6%B3%95)、[臺灣期貨交易所股份有限公司交易資訊使用管理辦法](https://www.selaw.com.tw/Chinese/RegulatoryInformationResult/Article?isIntegratedSearch=True\&sysNumber=LW10815483\&searchString1=%E8%87%BA%E7%81%A3%E6%9C%9F%E8%B2%A8%E4%BA%A4%E6%98%93%E6%89%80%E8%82%A1%E4%BB%BD%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%E4%BA%A4%E6%98%93%E8%B3%87%E8%A8%8A%E4%BD%BF%E7%94%A8%E7%AE%A1%E7%90%86%E8%BE%A6%E6%B3%95)、[財團法人中華民國證券櫃檯買賣中心有價證券交易資訊使用管理辦法](https://www.selaw.com.tw/Chinese/RegulatoryInformationResult/Article?isIntegratedSearch=True\&sysNumber=LW10813063\&searchString1=%E8%B2%A1%E5%9C%98%E6%B3%95%E4%BA%BA%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E8%AD%89%E5%88%B8%E6%AB%83%E6%AA%AF%E8%B2%B7%E8%B3%A3%E4%B8%AD%E5%BF%83%E6%9C%89%E5%83%B9%E8%AD%89%E5%88%B8%E4%BA%A4%E6%98%93%E8%B3%87%E8%A8%8A%E4%BD%BF%E7%94%A8%E7%AE%A1%E7%90%86%E8%BE%A6%E6%B3%95)、各資訊來源提供者所定之資訊使用相關規範及智慧財產權相關法令,所有資訊以各資訊來源提供者公告資料為準。如有盜接 、轉接交易資訊,或以其他方式出售、出租、轉讓、再授權交易資訊,或將交易資訊另行取樣並編製指數、其他衍生性商品或將之傳送予第三人,應負違約及侵權之相關民、刑事責任。
* 富邦新一代 API 行情服務由 [Fugle](https://www.fugle.tw/) 技術團隊開發提供。
---
### 建立連線
##### 建立行情連線[](#建立行情連線 "Direct link to 建立行情連線")
本頁重點
* 示範如何同時建立多條 WebSocket 行情連線(上限 7 條)。
* Web API 速率限制共用,WebSocket 每條連線可訂閱 300 檔。
以下範例程式碼示範如何同時建立 7 條行情 WebSocket 連線。
info
一般僅 WebSocket 需要同時啟用多條連線,若使用 Web API 則建議使用單一連線方便管理。 Web API 速率限制為所有連線共用;WebSocket 每條連線各可訂閱 300 檔標的。
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password" ,"Your cert path" ,"Your cert password") # 需登入後,才能取得行情權限
websockets = [] # 不同連線 WebSocket 介面列表
for _ in range(7): # 建立 7 條連線
sdk.init_realtime() # 啟動一條行情連線
ws = sdk.marketdata.websocket_client.stock # WebSocket 介面 (證券)
#ws = sdk.marketdata.websocket_client.futopt # WebSocket 介面 (期貨)
# 將介面置入可用列表中
websockets.append(ws)
# 設定 WebSocket Callback 並開啟連結
for ws in websockets:
## Callback functions 需另外定義 ##
ws.on('message', handle_message) # 註冊行情資料 callback
ws.on("connect", handle_connect) # 註冊連線事件 callback
ws.on("disconnect", handle_disconnect) # 註冊斷線事件 callback
ws.on("error", handle_error) # 註冊錯誤事件 callback
ws.connect() # 啟用連結
# 斷開連線
# for ws in websockets:
# we.disconnect()
```
```js
const { FubonSDK } = require('fubon-neo');
// 需先登入才能取得行情權限
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID", "Your Password", "Your Cert Path", "Your Cert Password");
const websockets = []; // 不同連線 WebSocket 介面列表
// 建立 7 條行情連線
for (let i = 0; i < 7; i++) {
// 啟動一條行情連線
sdk.initRealtime();
// 取得 WebSocket 介面
const ws = sdk.marketdata.webSocketClient.stock; // (證券)
//const ws = sdk.marketdata.webSocketClient.futopt; // (期貨)
// 將介面置入可用列表中
websockets.push(ws);
}
// 設定 WebSocket Callback 並開啟連結
for (const ws of websockets) {
/* -- Callback functions 需另外定義 -- */
ws.on('message', handle_message); // 註冊行情資料 callback
ws.on('connect', handle_connect); // 註冊連線事件 callback
ws.on('disconnect', handle_disconnect); // 註冊斷線事件 callback
ws.on('error', handle_error); // 註冊錯誤事件 callback
// 啟用連結
(async () => {
await ws.connect();
})()
}
// 斷開連線
//for (const ws of websockets) {
// (async () => {
// await ws.disconnect();
// })()
//}
```
```cs
using FubonNeo.Sdk;
// 需先登入才能取得行情權限
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your Password", "Your Cert Path", "Your Cert Password");
// 不同連線 WebSocket 介面列表
var websockets = new List(); // (證券)
//var websockets = new List(); // (期貨)
// 建立 7 條行情連線
for (int i = 0; i < 7; i++)
{
sdk.InitRealtime(); // 建立行情連線
// 取得 WebSocket 介面
var ws = sdk.MarketData.WebSocketClient.Stock; // (證券)
//var ws = sdk.MarketData.WebSocketClient.FutureOption; // (期貨)
// 將介面置入可用列表中
websockets.Add(ws);
}
// 設定 WebSocket Callback 並開啟連結
foreach (var ws in websockets)
{
ws.OnMessage = (msg) => Console.WriteLine($"OnMessage receive: {msg}"); // 註冊行情資料 callback
ws.OnError = (msg) => Console.WriteLine($"OnError receive: {msg}"); // 註冊錯誤事件 callback
ws.OnConnected = (msg) => Console.WriteLine($"OnConnected receive: {msg}"); // 註冊連線事件 callback
ws.OnDisconnected = (msg) => Console.WriteLine($"OnDisconnected receive: {msg}"); // 註冊斷線事件 callback
// 啟用連結
await ws.Connect();
}
// 斷開連線
// foreach (var ws in websockets)
// {
// await ws.Disconnect();
// }
```
---
### 速率限制
##### 速率限制[](#速率限制 "Direct link to 速率限制")
本頁重點
* 本頁整理富邦新一代 API 行情服務的 Web API / WebSocket 速率限制。
* 超過限制將回應 `429` 或訂閱錯誤訊息。
* 若短時間內大量建立連線可能被判定為異常。
| 項目 | 上限 |
| --------- | -------------------------------------- |
| 日內行情 | 300 / min |
| 行情快照 | 300 / min |
| 歷史行情 | 60 / min |
| WebSocket | 單一連線 300 訂閱數;可同時開啟 7 連線 |
富邦新一代 API 行情服務提供 Web API 與 WebSocket,並設定了以下存取的限制
* 日內行情 : 300 / min
* WebSocket : 單一連線 300 訂閱數;可同時開啟 7 連線
* 行情快照 : 300 / min
* 歷史行情 : 60 / min
如果您 API 請求超過了限制,將收到帶有狀態碼 `429` 的回應。需再等候 1 分鐘。
```json
{"statusCode":429,"message":"Rate limit exceeded"}
```
或是您的 WebSocket 訂閱數超過上限,將收到以下訊息:
```json
{
"event": "error",
"data": {
"code": 1001,
"message": "Maximum number of connections reached"
}
}
```
caution
若短時間內持續大量建立連線,系統會判斷您為惡意攻擊,將會阻擋您的連線請求(404 連線錯誤), 若遇到此種狀況,請聯絡
---
### 開始使用
本頁重點
* 富邦行情 WebSocket API(富邦新一代 API 行情服務)提供台股即時行情訂閱。
* 支援 `Speed` / `Normal` 兩種行情模式。
* 需登入後建立行情連線並訂閱頻道。
* 下一步可前往各頻道說明頁。
| 項目 | 說明 |
| -------- | --------------------- |
| 介面 | WebSocket API |
| 市場 | 台股 |
| 模式 | Speed / Normal |
| SDK | Python / Node.js / C# |
| 訂閱方式 | 連線後訂閱頻道 |
富邦行情 WebSocket API 提供台股即時行情服務。透過 WebSocket API 可以滿足您想要接收即時行情的需求。
#### 使用 SDK[](#使用-sdk "Direct link to 使用 SDK")
富邦行情 WebSocket API 提供 Python 、 Node.js 與 C# SDK。您可以透過以下方式存取 WebSocket API、並透過行情 Mode 模式切換要訂閱的行情:
訂閱 WebSocket Callback 方法獲得下方 Callback 訊息。
info
行情 Mode 提供 Low Latency `Speed` Mode 以及完整資訊的 `Normal` Mode
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK,Mode
def handle_message(message):
print(message)
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
# 可指定行情連線的Mode , Default 為Speed
# sdk.init_realtime(Mode.Speed) or sdk.init_realtime(Mode.Normal)
stock = sdk.marketdata.websocket_client.stock
stock.on('message', handle_message)
stock.connect()
```
```js
const { FubonSDK, Mode } = require('fubon-neo');
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.initRealtime(); // 建立行情連線
// 可指定行情連線的Mode , Default 為Speed
// sdk.initRealtime(Mode.Speed) or sdk.initRealtime(Mode.Normal)
const stock = sdk.marketdata.webSocketClient.stock;
stock.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
(async () => {
await stock.connect();
stock.subscribe({
'channel': 'trades',
'symbol': '2881'
});
})()
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // 建立行情連線
// 可指定行情連線的Mode , Default 為Speed
// sdk.InitRealtime(Mode.Speed) or sdk.InitRealtime(Mode.Normal)
var stock = sdk.MarketData.WebSocketClient.Stock;
stock.OnMessage += (msg) => Console.WriteLine($"receive: {msg}");
await stock.Connect();
```
#### 身份驗證[](#身份驗證 "Direct link to 身份驗證")
當驗證成功後,會收到以下訊息:
```json
{
"event": "authenticated",
"data": {
"message": "Authenticated successfully"
}
}
```
若驗證失敗,則收到以下訊息:
```json
{
"event": "error",
"data": {
"message": "Invalid authentication credentials"
}
}
```
#### Heartbeat[](#heartbeat "Direct link to Heartbeat")
每隔 30 秒 WebSocket server 會送出一個 heartbeat 訊息:
```json
{
"event": "heartbeat",
"data": {
"time": ""
}
}
```
#### Ping/Pong[](#pingpong "Direct link to Ping/Pong")
SDK 每 30 秒會自動發送一次 ping 到伺服器;您也可以自行發送 ping,並可額外自訂 `state`(選填):
* Python
* Node.js
* C#
```python
stock.ping({
'state' : ''
})
```
```js
stock.ping({state:''});
```
```cs
stock.ping("");
```
WebSocket Server 會回應以下訊息 (若 ping 未送 `state` 則不會有該欄位):
```json
{
"event": "pong",
"data": {
"time": "",
"state": ""
}
}
```
#### Channels[](#channels "Direct link to Channels")
富邦行情 WebSocket API 目前提供以下可訂閱頻道:
* `trades` - [接收訂閱股票最新成交資訊](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/market-data-channels/trades.txt)
* `books` - [接收訂閱股票最新最佳五檔委買委賣資訊](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/market-data-channels/books.txt)
* `indices` - [接收訂閱股票最新指數行情資料](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/market-data-channels/indices.txt)
##### 訂閱頻道[](#訂閱頻道 "Direct link to 訂閱頻道")
要訂閱一個頻道可用下方範例進行訂閱:
* Python
* Node.js
* C#
```python
stock.subscribe({
"channel" : "",
"symbol" : ""
#"intradayOddLot": True 若要訂閱盤中零股,可再額外加入此參數
})
```
```js
stock.subscribe({
channel: '',
symbol: '',
//intradayOddLot: true 若要訂閱盤中零股,可再額外加入此參數
});
```
```cs
stock.Subscribe(StockChannel.,"");
//stock.Subscribe(StockChannel.Trades,new StockSubscribeParams{Symbol="", IntradayOddLot=true}); 訂閱盤中零股
```
訂閱成功後,會收到以下事件回應:
```json
{
"event": "subscribed",
"data": {
"id": "",
"channel": "",
"symbol": ""
}
}
```
支援訂閱同頻道的多檔股票:
* Python
* Node.js
* C#
```python
stock.subscribe({
"channel" : "",
"symbols" : ["",""]
#"intradayOddLot": True 若要訂閱盤中零股,可再額外加入此參數
})
```
```js
stock.subscribe({
channel: '',
symbols: ['','']
//intradayOddLot: true 若要訂閱盤中零股,可再額外加入此參數
});
```
```cs
stock.Subscribe(StockChannel.,"","");
//stock.Subscribe(StockChannel.Trades, new StockSubscribeParams{Symbols = new List{"", ""}, IntradayOddLot=true}); 訂閱多檔盤中零股
```
訂閱成功後,會收到以下事件回應:
```json
{
"event": "subscribed",
"data": [
{
"id": "",
"channel": "",
"symbol": ""
},
{
"id": "",
"channel": "",
"symbol": ""
}
]
}
```
##### 取消訂閱[](#取消訂閱 "Direct link to 取消訂閱")
要取消頻道可用下方範例進行取消:
* Python
* Node.js
* C#
```python
stock.unsubscribe({
'id':''
})
```
```js
stock.unsubscribe({
id : ''
});
```
```cs
stock.Unsubscribe("");
```
取消訂閱成功後,會收到以下事件回應:
```json
{
"event": "unsubscribed",
"data": {
"id": "",
"channel" : "",
"symbol" : ""
}
}
```
支援取消訂閱多個頻道:
* Python
* Node.js
* C#
```python
stock.unsubscribe({
'ids':['','']
})
```
```js
stock.unsubscribe({
ids : ['','']
});
```
```cs
stock.Unsubscribe("","");
```
取消訂閱成功後,會收到以下事件回應:
```json
{
"event": "unsubscribed",
"data": [
{
"id": "",
"channel" : "",
"symbol" : ""
},
{
"id": "",
"channel" : "",
"symbol" : ""
}
]
}
```
##### 訂閱資訊[](#訂閱資訊 "Direct link to 訂閱資訊")
要取得目前連線已訂閱的頻道清單,可用下方範例查詢:
* Python
* Node.js
```python
stock.subscriptions()
```
```js
stock.subscriptions();
```
會收到以下事件回應:
```json
{
"event": "subscriptions",
"data": [
{
"id": "",
"channel": "",
"symbol": ""
}
]
}
```
#### 錯誤處理[](#錯誤處理 "Direct link to 錯誤處理")
當您所訂閱或處理的 WebSocket Callback 有異常時,您可補充處理錯誤訊息如下。
`disconnect` 事件在兩種情況觸發:伺服器關閉連線,以及連線健康檢查逾時(超過約 60 秒未收到伺服器任何訊息時,SDK 會主動關閉連線並發出此事件)。逾時斷線在各語言的通知形態,見各範例下方說明。
* Python
* Node.js
* C#
```python
def handle_connect():
print('market data connected')
def handle_disconnect(code, message, *reason): # 連線健康檢查逾時斷線時會多帶一個參數
print(f'market data disconnect: {code}, {message}')
def handle_error(error):
print(f'market data error: {error}')
stock.on("connect", handle_connect)
stock.on("disconnect", handle_disconnect)
stock.on("error", handle_error)
```
健康檢查逾時斷線時,`disconnect` 會多帶第三個參數 `{'reason': 'health-check-timeout'}`,handler 以 `*reason` 接住即可。
```js
stock.on("connect", () => {
console.log("market data connected");
});
stock.on("disconnect", (event, reason) => {
console.log("market data disconnect:", event.code, reason);
});
stock.on("error", (error) => {
console.log("market data error:", error);
});
```
健康檢查逾時斷線時,`disconnect` 的第二個參數為 `{ reason: 'health-check-timeout' }`。
```cs
stock.OnConnected += (connmsg) => Console.WriteLine($"Connect: {connmsg}");
stock.OnDisconnected += (disconmsg) => Console.WriteLine($"Disconnect: {disconmsg}");
stock.OnError += (errmsg) => Console.WriteLine($"handle error: {errmsg}");
```
健康檢查需在 `Connect` 時以第二個參數開啟(`Connect(5000, true)`,第一個參數為驗證逾時毫秒數);逾時斷線時 `OnDisconnected` 的訊息為 `health-check-timeout`。未開啟時,連線靜默中斷不會觸發 `OnDisconnected`。
##### 斷線重連[](#��斷線重連 "Direct link to 斷線重連")
連線中斷後,SDK 不會自動重新連線,也不會保留原有訂閱;程式需在收到 `disconnect` 事件後重新連線,並重新送出所有訂閱。以下範例接續上方的登入與建立連線程式:收到斷線事件後在背景重新連線與訂閱,重試間隔逐次拉長(2、4、8、16、30 秒)並以 5 次為上限,避免網路尚未恢復時短時間內大量重連。訂閱清單每個頻道一筆、以 `symbols` 一次訂閱多檔,重連後重新訂閱的呼叫次數等於頻道數,不隨檔數增加。
* Python
* Node.js
* C#
```python
# 接續 stock = sdk.marketdata.websocket_client.stock 之後,取代原本的 stock.connect()
import threading
import time
SUBSCRIPTIONS = [ # 初次訂閱與重連後重新訂閱共用同一份清單;每個頻道一筆,多檔用 symbols
{'channel': 'trades', 'symbols': ['2330', '2317']},
]
reconnect_needed = threading.Event()
def handle_disconnect(code, message, *reason): # 連線健康檢查逾時斷線時會多帶一個參數,用 *reason 接住
print(f'market data disconnect: {code}, {message}')
reconnect_needed.set() # 只通知,不在此直接重連
def subscribe_all():
for params in SUBSCRIPTIONS:
stock.subscribe(params)
def connect_with_timeout(seconds=10):
# 網路不通時 connect() 不會返回,另開執行緒加上逾時
result = {}
def run():
try:
stock.connect()
except Exception as error:
result['error'] = error
worker = threading.Thread(target=run, daemon=True)
worker.start()
worker.join(seconds)
if worker.is_alive():
raise TimeoutError('connect timeout')
if 'error' in result:
raise result['error']
def reconnect_loop():
retries = 0
while reconnect_needed.wait():
reconnect_needed.clear()
retries += 1
if retries > 5:
print('Reconnect failed 5 times, please check the network')
return
time.sleep(min(2 ** retries, 30)) # 等 2、4、8、16、30 秒後再試
try:
stock.disconnect() # 先重設連線狀態,否則 connect() 不會重新連線
connect_with_timeout()
subscribe_all()
retries = 0
print('Reconnected and resubscribed')
except Exception as error:
print(f'Reconnect failed: {error}')
reconnect_needed.set()
stock.on('disconnect', handle_disconnect)
threading.Thread(target=reconnect_loop, daemon=True).start()
stock.connect()
subscribe_all()
```
```js
// 接續 sdk.login(...) 之後;initRealtime 與事件綁定改由 connectAndSubscribe() 處理
const SUBSCRIPTIONS = [ // 初次訂閱與重連後重新訂閱共用同一份清單;每個頻道一筆,多檔用 symbols
{ channel: 'trades', symbols: ['2330', '2317'] },
];
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
let stock;
let reconnecting = false;
function handleMessage(message) {
console.log(JSON.parse(message));
}
async function connectAndSubscribe() {
sdk.initRealtime(); // 重連時重建行情連線物件,事件需重新綁定
stock = sdk.marketdata.webSocketClient.stock;
const client = stock;
client.on('message', handleMessage);
client.on('disconnect', (event, reason) => handleDisconnect(client, event, reason));
await Promise.race([ // 網路不通時 connect() 不會完成,加上逾時
client.connect(),
sleep(10000).then(() => { throw new Error('connect timeout'); }),
]);
for (const params of SUBSCRIPTIONS) client.subscribe(params);
}
async function handleDisconnect(client, event, reason) {
console.log('market data disconnect:', event.code, reason);
if (client !== stock || reconnecting) return; // 舊連線物件的事件、或已在重連中,略過
reconnecting = true;
try {
for (let retries = 1; retries <= 5; retries++) {
await sleep(Math.min(2 ** retries, 30) * 1000); // 等 2、4、8、16、30 秒後再試
try {
stock.disconnect(); // 關閉舊連線並停止其計時器
await connectAndSubscribe();
console.log('Reconnected and resubscribed');
return;
} catch (error) {
console.log(`Reconnect failed: ${error.message}`);
}
}
console.log('Reconnect failed 5 times, please check the network');
} finally {
reconnecting = false;
}
}
await connectAndSubscribe();
```
```cs
// 接續 var stock = sdk.MarketData.WebSocketClient.Stock; 之後,取代原本的 await stock.Connect()
var subscriptions = new[] { (StockChannel.Trades, new StockSubscribeParams { Symbols = new List { "2330", "2317" } }) }; // 初次訂閱與重連後重新訂閱共用同一份清單;每個頻道一筆,多檔用 Symbols
var reconnecting = 0;
async Task SubscribeAll()
{
foreach (var (channel, param) in subscriptions)
await stock.Subscribe(channel, param);
}
stock.OnDisconnected += (msg) =>
{
Console.WriteLine($"market data disconnect: {msg}");
if (Interlocked.Exchange(ref reconnecting, 1) == 1) return; // 一次斷線可能收到多次通知,只保留一條重連流程
_ = Task.Run(async () =>
{
try
{
for (var retries = 1; retries <= 5; retries++)
{
await Task.Delay(TimeSpan.FromSeconds(Math.Min(Math.Pow(2, retries), 30))); // 等 2、4、8、16、30 秒後再試
try
{
await stock.Connect(5000, true); // 5 秒驗證逾時;開啟連線健康檢查
if (!stock.IsConnected) continue; // 驗證逾時時 Connect 不會拋出例外,需自行檢查
await SubscribeAll();
Console.WriteLine("Reconnected and resubscribed");
return;
}
catch (Exception ex)
{
Console.WriteLine($"Reconnect failed: {ex.Message}");
}
}
Console.WriteLine("Reconnect failed 5 times, please check the network");
}
finally
{
Interlocked.Exchange(ref reconnecting, 0);
}
});
};
await stock.Connect(5000, true); // 開啟連線健康檢查,連線靜默中斷時才會收到斷線通知
await SubscribeAll();
```
---
### Aggregates
接收訂閱股票聚合數據的行情資訊
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------------- | ------- | --------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `candles`, `books`, `aggregates`, `indices` |
| `symbol`\* | string | 股票代碼 |
| `intradayOddLot` | boolean | `intradayOddLot` true: 盤中零股, false: 股票, default: false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| --------------------- | --------- | ---------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 股票代碼 |
| `name`\* | string | 股票簡稱 |
| `referencePrice` | number | 參考價 |
| `previousClose` | number | 前一交易日收盤價 |
| `openPrice` | number | 開盤價 |
| `openTime` | number | 開盤價成交時間 |
| `highPrice` | number | 最高價 |
| `highTime` | number | 最高價成交時間 |
| `lowPrice` | number | 最低價 |
| `lowTime` | number | 最低價成交時間 |
| `closePrice` | number | 收盤價(最後成交價) |
| `closeTime` | number | 收盤價(最後成交價)成交時間 |
| `avgPrice` | number | 當日成交均價 |
| `change` | number | 最後一筆成交漲跌(含試撮) |
| `changePercent` | number | 最後一筆成交漲跌幅(含試撮) |
| `amplitude` | number | 當日振幅 |
| `lastPrice` | number | 最後一筆成交價(含試撮) |
| `lastSize` | number | 最後一筆成交數量(含試撮) |
| `bids` | object\[] | 最佳五檔委買 |
| >> `price` | number | 最佳五檔委買價格 |
| >> `size` | number | 最佳五檔委買數量 |
| `asks` | object\[] | 最佳五檔委賣 |
| >> `price` | number | 最佳五檔委賣價格 |
| >> `size` | number | 最佳五檔委賣數量 |
| `total` | object | 統計資訊 |
| >> `tradeValue` | number | 累計成交金額 |
| >> `tradeVolume` | number | 累計成交量 |
| >> `tradeVolumeAtBid` | number | 累計內盤成交量 |
| >> `tradeVolumeAtAsk` | number | 累計外盤成交量 |
| >> `transaction` | number | 累計成交筆數 |
| >> `time` | number | 累計資訊時間 |
| `lastTrade` | object | 最後一筆成交資訊 |
| >> `bid` | number | 最後一筆成交買價 |
| >> `ask` | number | 最後一筆成交賣價 |
| >> `price` | number | 最後一筆成交價格 |
| >> `size` | number | 最後一筆成交數量 |
| >> `time` | number | 最後一筆成交時間 |
| `lastTrial` | object | 最後一筆試撮資訊 |
| >> `bid` | number | 最後一筆試撮買價 |
| >> `ask` | number | 最後一筆試撮賣價 |
| >> `price` | number | 最後一筆試撮價格 |
| >> `size` | number | 最後一筆試撮數量 |
| >> `time` | number | 最後一筆試撮時間 |
| `isLimitDownPrice` | boolean | 最後成交價為跌停價:`true` |
| `isLimitUpPrice` | boolean | 最後成交價為漲停價:`true` |
| `isLimitDownBid` | boolean | 最佳一檔委買跌停價:`true` |
| `isLimitUpBid` | boolean | 最佳一檔委買漲停價:`true` |
| `isLimitDownAsk` | boolean | 最佳一檔委賣跌停價:`true` |
| `isLimitUpAsk` | boolean | 最佳一檔委賣漲停價:`true` |
| `isLimitDownHalt` | boolean | 暫緩撮合且瞬間趨跌:`true` |
| `isLimitUpHalt` | boolean | 暫緩撮合且瞬間趨漲:`true` |
| `isTrial` | boolean | 試撮階段:`true` |
| `isDelayedOpen` | boolean | 延後開盤信號:`true` |
| `isDelayedClose` | boolean | 延後收盤信號:`true` |
| `isContinuous` | boolean | 最後成交為逐筆交易:`true` |
| `isOpen` | boolean | 開盤信號:`true` |
| `isClose` | boolean | 收盤信號:`true` |
| `lastUpdated` | number | 最後更新時間 |
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order, Mode
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime(Mode.Normal) # 建立行情連線
stock = sdk.marketdata.websocket_client.stock
stock.on('message', handle_message)
stock.connect()
stock.subscribe({
'channel': 'aggregates',
'symbol': '2330'
})
```
```js
const { FubonSDK, Mode } = require('fubon-neo');
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.initRealtime(Mode.Normal); // 建立行情連線
const stock = sdk.marketdata.webSocketClient.stock;
stock.connect().then(() => {
stock.subscribe({ channel: "aggregates", symbol: "0050" });
});
stock.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(Mode.Normal); // 建立行情連線
var stock = sdk.MarketData.WebSocketClient.Stock;
stock.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await stock.Connect();
await stock.Subscribe(StockChannel.Aggregates, "2330");
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"date": "2023-05-29",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"symbol": "2330",
"name": "台積電",
"referencePrice": 566,
"previousClose": 566,
"openPrice": 574,
"openTime": 1685322000049353,
"highPrice": 574,
"highTime": 1685322000049353,
"lowPrice": 564,
"lowTime": 1685327142152580,
"closePrice": 568,
"closeTime": 1685338200000000,
"avgPrice": 568.77,
"change": 2,
"changePercent": 0.35,
"amplitude": 1.77,
"lastPrice": 568,
"lastSize": 4778,
"bids": [
{
"price": 567,
"size": 87
},
{
"price": 566,
"size": 2454
},
{
"price": 565,
"size": 611
},
{
"price": 564,
"size": 609
},
{
"price": 563,
"size": 636
}
],
"asks": [
{
"price": 568,
"size": 800
},
{
"price": 569,
"size": 806
},
{
"price": 570,
"size": 3643
},
{
"price": 571,
"size": 1041
},
{
"price": 572,
"size": 2052
}
],
"total": {
"tradeValue": 31019803000,
"tradeVolume": 54538,
"tradeVolumeAtBid": 19853,
"tradeVolumeAtAsk": 27900,
"transaction": 9530,
"time": 1685338200000000
},
"lastTrade": {
"bid": 567,
"ask": 568,
"price": 568,
"size": 4778,
"time": 1685338200000000,
"serial": 6652422
},
"lastTrial": {
"bid": 567,
"ask": 568,
"price": 568,
"size": 4772,
"time": 1685338196400347,
"serial": 6651941
},
"isClose": true,
"serial": 6652422,
"lastUpdated": 1685338200000000
},
"id": "",
"channel": "aggregates"
}
```
---
### Books
接收訂閱股票最新最佳五檔委買委賣資訊
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------------- | ------- | --------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `candles`, `books`, `aggregates`, `indices` |
| `symbol`\* | string | 股票代碼 |
| `intradayOddLot` | boolean | `intradayOddLot` true: 盤中零股, false: 股票, default: false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| -------------- | --------- | ------------------------------------------- |
| `symbol`\* | string | 股票代碼 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `time`\* | number | 時間 |
| `bids` | object\[] | 最佳五檔委買 |
| >> `price` | number | 最佳五檔委買價格 |
| >> `size` | number | 最佳五檔委買數量 |
| `asks` | object\[] | 最佳五檔委賣 |
| >> `price` | number | 最佳五檔委賣價格 |
| >> `size` | number | 最佳五檔委賣數量 |
| `isContinuous` | boolean | 逐筆交易階段為 `true`(僅逐筆交易階段出現) |
| `isTrial` | boolean | 試撮階段為 `true`(僅試撮階段出現) |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
stock = sdk.marketdata.websocket_client.stock
stock.on('message', handle_message)
stock.connect()
stock.subscribe({
'channel': 'books',
'symbol': '2330'
})
```
```js
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 stock = sdk.marketdata.webSocketClient.stock;
stock.connect().then(() => {
stock.subscribe({ channel: "books", symbol: "2330" });
});
stock.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // 建立行情連線
var stock = sdk.MarketData.WebSocketClient.Stock;
stock.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await stock.Connect();
await stock.Subscribe(StockChannel.Books, "2330");
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"symbol": "2330",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"bids": [
{
"price": 567,
"size": 87
},
{
"price": 566,
"size": 2454
},
{
"price": 565,
"size": 611
},
{
"price": 564,
"size": 609
},
{
"price": 563,
"size": 636
}
],
"asks": [
{
"price": 568,
"size": 800
},
{
"price": 569,
"size": 806
},
{
"price": 570,
"size": 3643
},
{
"price": 571,
"size": 1041
},
{
"price": 572,
"size": 2052
}
],
"time": 1685338200000000
},
"id": "",
"channel": "books"
}
```
---
### Candles
接收訂閱股票最新分鐘K
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------------- | ------- | --------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `candles`, `books`, `aggregates`, `indices` |
| `symbol`\* | string | 股票代碼 |
| `intradayOddLot` | boolean | `intradayOddLot` true: 盤中零股, false: 股票, default: false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------ | ------ | -------------------------------------------------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 股票代號 |
| `open`\* | number | K線開盤價 |
| `high`\* | number | K線最高價 |
| `low`\* | number | K線最低價 |
| `close`\* | number | K線收盤價 |
| `volume`\* | number | K線成交量(整股:成交張數;興櫃股票及盤中零股:成交股數;指數:成交金額) |
| `average`\* | number | 成交均價 |
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order, Mode
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime(Mode.Normal) # 建立行情連線
stock = sdk.marketdata.websocket_client.stock
stock.on('message', handle_message)
stock.connect()
stock.subscribe({
'channel': 'candles',
'symbol': '2330'
})
```
```js
const { FubonSDK, Mode } = require('fubon-neo');
const sdk = new FubonSDK(Mode.Normal);
const accounts = sdk.login("Your ID", "Your password", "Your cert path","Your cert password");
sdk.initRealtime(Mode.Normal); // 建立行情連線
const stock = sdk.marketdata.webSocketClient.stock;
stock.connect().then(() => {
stock.subscribe({ channel: "candles", symbol: "0050" });
});
stock.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // 建立行情連線
var stock = sdk.MarketData.WebSocketClient.Stock;
stock.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await stock.Connect();
await stock.Subscribe(StockChannel.Candles, "2330");
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"symbol": "2330",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"date": "2023-05-29T13:30:00.000+08:00",
"open": 568,
"high": 568,
"low": 568,
"close": 568,
"volume": 4778,
"average": 568.77
},
"id": "",
"channel": "candles"
}
```
---
### Indices
接收訂閱股票最新指數行情資料
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
stock = sdk.marketdata.websocket_client.stock
stock.on('message', handle_message)
stock.connect()
stock.subscribe({
'channel': 'indices',
'symbol': 'IR0001'
})
```
```js
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 stock = sdk.marketdata.webSocketClient.stock;
stock.connect().then(() => {
stock.subscribe({ channel: 'indices', symbol: 'IR0001' });
});
stock.on('message', (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // 建立行情連線
var stock = sdk.MarketData.WebSocketClient.Stock;
stock.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await stock.Connect();
await stock.Subscribe(StockChannel.Indices, "IR0001");
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"symbol": "IR0001",
"type": "INDEX",
"exchange": "TWSE",
"index": 35276.44,
"time": 1686114510000000
},
"id": "",
"channel": "indices"
}
```
---
### Trades
接收訂閱股票最新成交資訊
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------------- | ------- | --------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `candles`, `books`, `aggregates`, `indices` |
| `symbol`\* | string | 股票代碼 |
| `intradayOddLot` | boolean | `intradayOddLot` true: 盤中零股, false: 股票, default: false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------ | ------- | -------------------------- |
| `symbol`\* | string | 股票代號 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `time`\* | number | 時間 |
| `serial`\* | number | 流水號 |
| `bid` | number | 成交買價 |
| `ask` | number | 成交賣價 |
| `price` | number | 成交價格 |
| `size` | number | 成交單量 |
| `volume` | number | 成交總量 |
| `isLimitDownPrice` | boolean | 最後成交價為跌停價:`true` |
| `isLimitUpPrice` | boolean | 最後成交價為漲停價:`true` |
| `isLimitDownBid` | boolean | 最佳一檔委買跌停價:`true` |
| `isLimitUpBid` | boolean | 最佳一檔委買漲停價:`true` |
| `isLimitDownAsk` | boolean | 最佳一檔委賣跌停價:`true` |
| `isLimitUpAsk` | boolean | 最佳一檔委賣漲停價:`true` |
| `isLimitDownHalt` | boolean | 暫緩撮合且瞬間趨跌:`true` |
| `isLimitUpHalt` | boolean | 暫緩撮合且瞬間趨漲:`true` |
| `isTrial` | boolean | 試撮階段:`true` |
| `isDelayedOpen` | boolean | 延後開盤信號:`true` |
| `isDelayedClose` | boolean | 延後收盤信號:`true` |
| `isContinuous` | boolean | 最後成交為逐筆交易:`true` |
| `isOpen` | boolean | 開盤信號:`true` |
| `isClose` | boolean | 收盤信號:`true` |
info
'\*' 表示必揭示欄位 、 上方 Boolean 型態皆為發生時才會顯示
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK
def handle_message(message):
print(message)
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
stock = sdk.marketdata.websocket_client.stock
stock.on('message', handle_message)
stock.connect()
stock.subscribe({
'channel': 'trades',
'symbol': '2330'
})
```
```js
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 stock = sdk.marketdata.webSocketClient.stock;
stock.connect().then(() => {
stock.subscribe({ channel: "trades", symbol: "0050" });
});
stock.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // 建立行情連線
var stock = sdk.MarketData.WebSocketClient.Stock;
stock.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await stock.Connect();
await stock.Subscribe(StockChannel.Trades, "2330");
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"symbol": "2330",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"bid": 567,
"ask": 568,
"price": 568,
"size": 4778,
"volume": 54538,
"isClose": true,
"time": 1685338200000000,
"serial": 6652422
},
"id": "",
"channel": "trades"
}
```
---
### 模式切換
**適用版本 v1.0.4 及以上**
#### 行情 WebSocket 模式切換[](#行情-websocket-模式切換 "Direct link to 行情 WebSocket 模式切換")
新版功能中,提供 Low Latency 行情與多資訊的 Socket 行情切換
##### 引入套件 (僅 Python 、 NodeJs 需要, C#不需額外操作)[](#引入套件-僅-python--nodejs-需要-c不需額外操作 "Direct link to 引入套件 (僅 Python 、 NodeJs 需要, C#不需額外操作)")
* Python
* Node.js
```py
# 引入Mode 套件模組
from fubon_neo.sdk import FubonSDK, Mode
```
```js
const { FubonSDK, Mode } = require('fubon-neo');
```
* Python
* Node.js
* C#
```python
sdk.init_realtime(Mode.Speed) # 提供Speed / Normal選擇 (default 為Speed)
#sdk.init_realtime(Mode.Speed) or sdk.init_realtime(Mode.Normal)
stock = sdk.marketdata.websocket_client.stock
stock.on('message', handle_message)
stock.connect()
```
```js
sdk.initRealtime(Mode.Speed); // 提供Speed / Normal選擇 (default 為Speed)
// sdk.initRealtime(Mode.Speed) or sdk.initRealtime(Mode.Normal)
const stock = sdk.marketdata.webSocketClient.stock;
stock.connect()
stock.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels; // 新增 "Mode"
sdk.InitRealtime(Mode.Speed); // 提供Speed / Normal選擇 (default 為Speed)
// sdk.initRealtime(Mode.Speed) or sdk.initRealtime(Mode.Normal)
var stock = sdk.MarketData.WebSocketClient.Stock;
stock.OnMessage += (msg) => Console.WriteLine($"receive: {msg}");
await stock.Connect();
```
---
### 開始使用
本頁重點
* 富邦行情期貨 Web API(富邦新一代 API 期貨行情服務)提供期貨與期權日內資料、期貨歷史K線查詢。
* 超過速率限制會回應 `429`。
* 提供 Python / Node.js / C# SDK 範例。
* 下一步可從功能列表選擇對應 API 端點。
| 項目 | 說明 |
| -------- | --------------------- |
| 介面 | Web API |
| 市場 | 期貨 / 期權 |
| 資料類型 | 日內 / 歷史 |
| 速率限制 | 超過回應 `429` |
| SDK | Python / Node.js / C# |
富邦行情 Web API 提供開發者友善的 API 服務。您可以查詢期貨與期權日內行情、期貨歷史K線等數據。
#### 速率限制[](#速率限制 "Direct link to 速率限制")
如果您 API 請求超過了限制,將收到帶有狀態碼 `429` 的回應。
#### 功能列表[](#功能列表 "Direct link to 功能列表")
富邦行情期貨 Web API 提供的功能如下:
* `/intraday/products` - [期權契約列表(依條件查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/products.txt)
* `/intraday/tickers` - [期權商品列表(依條件查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/tickers.txt)
* `/intraday/quote/{symbol}` - [期貨即時報價(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/quote.txt)
* `/intraday/candles/{symbol}` - [期貨價格K線(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/candles.txt)
* `/intraday/trades/{symbol}` - [期貨成交明細(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/trades.txt)
* `/intraday/volumes/{symbol}` - [期貨分價量表(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/volumes.txt)
* `/historical/candles/{product}` - [期貨歷史K線(依商品代號查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/historical/candles.txt)
#### 商品代碼與連續月別名[](#商品代碼與連續月別名 "Direct link to 商品代碼與連續月別名")
期貨選擇權商品可使用具體合約代碼(含月份碼,如 `TXFG6`)查詢;此外也提供**連續月別名**(v2.2.9 起),方便您持續追蹤特定近月合約,不需自行換月。
| 別名 | 說明 |
| ---------- | ----------------------- |
| `{ROOT}1!` | 第 1 近月(最近月)合約 |
| `{ROOT}2!` | 第 2 近月(次近月)合約 |
| `{ROOT}3!` | 第 3 近月合約 |
* `{ROOT}` 為商品根代碼,例如臺股期貨為 `TXF`,故 `TXF1!` 代表最近月臺股期貨。
* 系統會自動將別名解析(resolve)為當前對應的具體合約(例如 `TXF1!` → `TXFG6`),並在每次結算後自動轉倉(rollover)到新的近月;回傳資料中的 `symbol` 為解析後的具體合約代碼。
* 連續月別名可作為 `{symbol}` 用於 `/intraday/ticker`、`/intraday/quote`、`/intraday/candles`、`/intraday/trades`、`/intraday/volumes` 端點,以及 [WebSocket](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt) 各訂閱頻道。
* 連續月別名不會出現在 `/intraday/products`、`/intraday/tickers` 等清單回應中,需直接以別名查詢。
* 目前提供 `1!`/`2!`/`3!`(第 1~3 近月)三種連續月別名。
* 歷史K線端點 [`/historical/candles`](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/historical/candles.txt) 以商品代號查詢,連續合約改由 `contractMonth` 參數指定(`1!`/`2!`/`3!`),回傳的每根K線會標示實際所屬的契約月份。
以連續月別名查詢報價,回傳的 `symbol` 為解析後的具體合約:
* Python
* Node.js
```python
restfutopt.intraday.quote(symbol='TXF1!') # 以連續月別名查詢最近月臺股期貨報價
```
```js
futopt.intraday.quote({ symbol: 'TXF1!' }); // 以連續月別名查詢最近月臺股期貨報價
```
Response Body(節錄,`symbol` 已解析為具體合約):
```json
{
"date": "2026-07-03",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "TXFG6",
"name": "臺股期貨076",
"previousClose": 46599,
"openPrice": 45700,
"lastPrice": 46510
}
```
#### 使用 SDK[](#使用-sdk "Direct link to 使用 SDK")
富邦行情 Web API 提供 Python 、 Node.js SDK 與 C# SDK。您可以透過以下方式存取 API:
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order
# 2.2.4 以後版本, 增加下列匯入:
# from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
restfutopt = sdk.marketdata.rest_client.futopt
```
```js
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
const futopt = client.futopt;
```
```cs
using FubonNeo.Sdk;
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.FutureOption;
```
---
### Historical Candles
查詢期貨歷史 K 線(依商品代號查詢)。支援日/週/月 K 與分 K、日盤與夜盤,契約月份可填具體月份或連續合約 `1!`/`2!`/`3!`。單次查詢區間須小於 1 年;日/週/月 K 可回溯至 2010 年,分 K 自 2017-06 起提供。
```text
historical/candles/{product}
```
版本資訊
v2.4.0 起新增功能
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| --------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `product`\* | string | 期貨商品代號,例如 `TXF`、`MXF`、`CDF`(大寫)。契約月份請用 `contractMonth` 指定;週契約亦以商品代號查詢(例:`MXF` 搭配 `contractMonth=202609W2`),`MX4` 這類週契約前綴不是商品代號。契約代碼(例:`TXFI6`)不可作為 `product`,會回傳 404,換算方式見下方說明。目前僅支援期貨,選擇權與價差契約尚未提供 |
| `contractMonth` | string | 契約月份,未帶時預設為 `1!` 近月。可選:具體月份 `yyyyMM`(例:`202609`);週契約(例:`202609W2`);連續合約 `1!` 近月、`2!` 次近月、`3!` 第三近月(`4!` 以上回傳 400) |
| `from` | string | 開始日期(格式:`yyyy-MM-dd`),未帶時預設為 1 週前 |
| `to` | string | 結束日期(格式:`yyyy-MM-dd`),未帶時預設為今日 |
| `timeframe` | string | K 線週期,未帶時預設為 `D` 日 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 |
| `session` | string | 交易時段,未帶時預設為 `regular` 日盤;可選 `afterhours` 夜盤(盤後交易時段) |
| `fields` | string | 欄位選擇,未帶時預設為 `open,high,low,close,volume`(**不含 `average`、`transaction`、`change`**,需要時請明確指定);可選 `open`、`high`、`low`、`close`、`volume`、`average`、`transaction`、`change`(各欄位適用 timeframe 請見 Response 表格)。不提供成交金額 `turnover`,帶入會回傳 400 |
| `sort` | string | 時間排序,未帶時預設為 `desc` 降冪;可選 `asc` 升冪 |
info
* 日/週/月 K 可回溯至 **2010 年**。
* 分 K(日盤與夜盤)自 **2017-06** 起提供(夜盤自當日 15:00 起,歸屬次一交易日)。
* 分 K 依單式委託的成交計算;透過價差(組合)委託成交的兩腿與鉅額交易不計入分 K,因此同一合約的日 K 成交量可能大於當日分 K 加總,日 K 有量但當日分 K 查無資料屬正常。
* 查詢區間(`from` ~ `to`)單次須小於 1 年,恰好或超過 1 年會回傳 400 Bad Request(錯誤訊息:`Date range must be less than one year`)。`from` 不可晚於 `to`,否則亦回傳 400。
* `from`/`to` 以**交易日**計。夜盤依期交所規則歸屬次一交易日,例如 `session=afterhours&from=2026-09-10&to=2026-09-10` 回傳的是 2026-09-09 15:00 至 2026-09-10 05:00 這一場夜盤。
* 連續合約(`1!`/`2!`/`3!`)依合約到期自動換月:最後交易日當天仍指向到期合約,次一交易日起切換至下一張;每根 K 線的 `data.contractMonth` 標示實際所屬合約。**不做換月價差調整**,換月日的 K 線會有跳空。連續合約只在月契約之間排序,不含週契約。
* 查詢區間內查無資料會回傳 404 Resource Not Found,而非空陣列(例:區間完全為非交易日、早於該 timeframe 的資料起始日、商品代號或契約月份不存在、以選擇權商品代號查詢)。
* 手上若是日內行情使用的契約代碼(例:`TXFI6`),請拆成商品代號與契約月份再查詢:前 3 碼為商品代號(`TXF`),第 4 碼為月份碼 `A`~`L` 對應 1~12 月(`I` = 9 月),第 5 碼為西元年末碼(`6` = 2026),即 `product=TXF`、`contractMonth=202609`;連續月別名 `TXF1!` 則對應 `product=TXF`、`contractMonth=1!`。
#### Response[](#response "Direct link to Response")
| Name | Type | Description | 適用 timeframe |
| ---------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| `product`\* | string | 商品代號 | — |
| `contractMonth`\* | string | 查詢時帶入的契約月份(連續合約查詢時為 `1!`/`2!`/`3!`) | — |
| `exchange`\* | string | 交易所 | — |
| `session`\* | string | 盤別,`REGULAR` 日盤、`AFTERHOURS` 夜盤 | — |
| `timeframe`\* | string | K 線週期 | — |
| `sort`\* | string | 排序方向(`desc` 或 `asc`) | — |
| `data`\* | object\[] | K 線資料 | — |
| `data.date`\* | string | 日 K 為交易日、週 K 為該週週一、月 K 為當月 1 日(`yyyy-MM-dd`);分 K 為 K 線起始時刻,ISO 8601 含時區(例:`2026-09-10T08:45:00.000+08:00`) | 全部 |
| `data.contractMonth`\* | string | 該根 K 線實際所屬的契約月份。連續合約查詢時可藉此判斷換月發生在哪一根;跨換月的週/月 K 標示收盤時所屬的合約 | 全部 |
| `data.open` | number | K 線開盤價 | 全部 |
| `data.high` | number | K 線最高價 | 全部 |
| `data.low` | number | K 線最低價 | 全部 |
| `data.close` | number | K 線收盤價 | 全部 |
| `data.volume` | number | K 線成交量(口數) | 全部 |
| `data.average` | number | 該根 K 線期間的成交量加權平均價(VWAP) | 僅分 K |
| `data.transaction` | number | 該根 K 線的成交筆數 | 僅分 K |
| `data.change` | number | K 線漲跌 | 僅日/週/月 K |
info
`change` 的計算基準:
* 日 K 為該合約與其前一交易日收盤價之差。連續合約查詢時,換月當日的 `change` 以新合約自身的前一日收盤計算,不與前一張合約比較。
* 週/月 K 為區間內各日漲跌之加總。
#### Examples[](#examples "Direct link to Examples")
##### 日 K 範例(連續合約)[](#日-k-範例連續合約 "Direct link to 日 K 範例(連續合約)")
以近月連續合約 `1!` 查詢日 K 並指定日期區間,區間跨越 2026 年 8 月合約到期日(8/19),可由 `contractMonth` 看到換月發生在 8/20:
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfutopt = sdk.marketdata.rest_client.futopt
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfutopt.historical.candles(**{"product": "TXF", "contractMonth": "1!", "from": "2026-08-17", "to": "2026-08-21", "fields": "open,high,low,close,volume,change"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.historical.candles({ product: 'TXF', contractMonth: '1!', from: '2026-08-17', to: '2026-08-21', fields: 'open,high,low,close,volume,change' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.FuOpt.Historical; //引入 HistoricalTimeFrame、HistoricalFieldsType
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.FutureOption;
var candles = await rest.Historical.Candles("TXF", new(new DateTime(2026,8,17), new DateTime(2026,8,21), HistoricalTimeFrame.Day, HistoricalFieldsType.Open|HistoricalFieldsType.High|HistoricalFieldsType.Low|HistoricalFieldsType.Close|HistoricalFieldsType.Volume|HistoricalFieldsType.Change, "1!"));
var candles_cont = candles.Content.ReadAsStringAsync().Result;
Console.WriteLine(candles_cont);
```
Response Body:
```json
{
"product": "TXF",
"contractMonth": "1!",
"exchange": "TAIFEX",
"session": "REGULAR",
"timeframe": "D",
"sort": "desc",
"data": [
{
"date": "2026-08-21",
"contractMonth": "202609",
"open": 44887,
"high": 45294,
"low": 44566,
"close": 45148,
"volume": 51446,
"change": 245
},
{
"date": "2026-08-20",
"contractMonth": "202609",
"open": 44950,
"high": 45122,
"low": 44448,
"close": 44868,
"volume": 53693,
"change": 368
},
{
"date": "2026-08-19",
"contractMonth": "202608",
"open": 44411,
"high": 44869,
"low": 44208,
"close": 44612,
"volume": 27795,
"change": -476
},
{
"date": "2026-08-18",
"contractMonth": "202608",
"open": 45967,
"high": 45977,
"low": 45070,
"close": 45085,
"volume": 83392,
"change": -782
},
{
"date": "2026-08-17",
"contractMonth": "202608",
"open": 45850,
"high": 46140,
"low": 45738,
"close": 45888,
"volume": 79450,
"change": 76
}
]
}
```
##### 分 K 範例[](#分-k-範例 "Direct link to 分 K 範例")
以具體契約月份查詢 60 分 K 並指定日期區間(含均價 `average` 與成交筆數 `transaction`):
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfutopt = sdk.marketdata.rest_client.futopt
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfutopt.historical.candles(**{"product": "TXF", "contractMonth": "202609", "timeframe": "60", "from": "2026-09-10", "to": "2026-09-10", "fields": "open,high,low,close,volume,average,transaction"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.historical.candles({ product: 'TXF', contractMonth: '202609', timeframe: '60', from: '2026-09-10', to: '2026-09-10', fields: 'open,high,low,close,volume,average,transaction' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.FuOpt.Historical; //引入 HistoricalTimeFrame、HistoricalFieldsType
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.FutureOption;
var candles = await rest.Historical.Candles("TXF", new(new DateTime(2026,9,10), new DateTime(2026,9,10), HistoricalTimeFrame.SixtyMin, HistoricalFieldsType.Open|HistoricalFieldsType.High|HistoricalFieldsType.Low|HistoricalFieldsType.Close|HistoricalFieldsType.Volume|HistoricalFieldsType.Average|HistoricalFieldsType.Transaction, "202609"));
var candles_cont = candles.Content.ReadAsStringAsync().Result;
Console.WriteLine(candles_cont);
```
Response Body:
```json
{
"product": "TXF",
"contractMonth": "202609",
"exchange": "TAIFEX",
"session": "REGULAR",
"timeframe": "60",
"sort": "desc",
"data": [
{
"date": "2026-09-10T12:45:00.000+08:00",
"contractMonth": "202609",
"open": 46733,
"high": 46949,
"low": 46733,
"close": 46870,
"volume": 10066,
"average": 46868.04,
"transaction": 7729
},
{
"date": "2026-09-10T11:45:00.000+08:00",
"contractMonth": "202609",
"open": 46673,
"high": 46820,
"low": 46666,
"close": 46730,
"volume": 4133,
"average": 46745.72,
"transaction": 3212
},
{
"date": "2026-09-10T10:45:00.000+08:00",
"contractMonth": "202609",
"open": 46748,
"high": 46803,
"low": 46652,
"close": 46677,
"volume": 3896,
"average": 46719.47,
"transaction": 3192
},
{
"date": "2026-09-10T09:45:00.000+08:00",
"contractMonth": "202609",
"open": 46661,
"high": 46800,
"low": 46589,
"close": 46747,
"volume": 7357,
"average": 46688.19,
"transaction": 5398
},
{
"date": "2026-09-10T08:45:00.000+08:00",
"contractMonth": "202609",
"open": 46940,
"high": 46950,
"low": 46506,
"close": 46663,
"volume": 20094,
"average": 46683.01,
"transaction": 16071
}
]
}
```
##### 夜盤範例[](#夜盤範例 "Direct link to 夜盤範例")
帶 `session=afterhours` 查詢夜盤 60 分 K。`from`/`to` 填夜盤所屬的交易日(2026-09-10),回傳的是 2026-09-09 15:00 起至 2026-09-10 05:00 的夜盤 K 線:
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfutopt = sdk.marketdata.rest_client.futopt
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfutopt.historical.candles(**{"product": "TXF", "contractMonth": "202609", "timeframe": "60", "session": "afterhours", "from": "2026-09-10", "to": "2026-09-10"})
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.historical.candles({ product: 'TXF', contractMonth: '202609', timeframe: '60', session: 'afterhours', from: '2026-09-10', to: '2026-09-10' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.FuOpt; //引入 TradeSession
using FugleMarketData.QueryModels.FuOpt.Historical; //引入 HistoricalTimeFrame
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.FutureOption;
var candles = await rest.Historical.Candles("TXF", new(new DateTime(2026,9,10), new DateTime(2026,9,10), HistoricalTimeFrame.SixtyMin, contractMonth: "202609", session: TradeSession.AfterHours));
var candles_cont = candles.Content.ReadAsStringAsync().Result;
Console.WriteLine(candles_cont);
```
Response Body(節錄):
```json
{
"product": "TXF",
"contractMonth": "202609",
"exchange": "TAIFEX",
"session": "AFTERHOURS",
"timeframe": "60",
"sort": "desc",
"data": [
{
"date": "2026-09-10T04:00:00.000+08:00",
"contractMonth": "202609",
"open": 46987,
"high": 47019,
"low": 46971,
"close": 46984,
"volume": 359
},
{
"date": "2026-09-10T03:00:00.000+08:00",
"contractMonth": "202609",
"open": 47024,
"high": 47086,
"low": 46965,
"close": 46992,
"volume": 671
},
...
{
"date": "2026-09-09T16:00:00.000+08:00",
"contractMonth": "202609",
"open": 47234,
"high": 47295,
"low": 47182,
"close": 47233,
"volume": 1608
},
{
"date": "2026-09-09T15:00:00.000+08:00",
"contractMonth": "202609",
"open": 47214,
"high": 47267,
"low": 47136,
"close": 47232,
"volume": 2098
}
]
}
```
info
'\*' 表示必揭示欄位。
---
### Intraday Candles
期權價格K線(依商品查詢)
```text
intraday/candles/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ----------- | ------ | --------------------------------------------------------------------------------------------- |
| `symbol`\* | string | 期權代碼 |
| `session` | string | session 類型,可選 `afterhours` 夜盤 |
| `timeframe` | string | K線週期,可選 `1` 1 分K;`5` 5 分K;`10` 10 分K;`15` 15 分K;`30` 30 分K;`60` 60 分K |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------- | --------- | ----------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `symbol`\* | string | 期權代碼 |
| `timeframe`\* | string | K線週期 |
| `data`\* | object\[] | K線資料 |
| >> `open`\* | number | K線開盤價 |
| >> `high`\* | number | K線最高價 |
| >> `low`\* | number | K線最低價 |
| >> `close`\* | number | K線收盤價 |
| >> `volume` | number | K線成交量 |
| >> `average` | number | 成交均價 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfutopt = sdk.marketdata.rest_client.futopt
# restfutopt.intraday.candles(symbol='TXFA4') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfutopt.intraday.candles(symbol='TXFA4')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.intraday.candles({ symbol: 'TXFA4' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.FuOpt;
using FugleMarketData.QueryModels.FuOpt.Intraday;
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.FutureOption;
var candles = await rest.Intraday.Candles("TXFA4");
// var candles = await rest.Intraday.Candles("TXFA4", new(){TimeFrame=FugleMarketData.QueryModels.FuOpt.Intraday.CandlesTimeFrame.FifteenMin}); // 15分鐘K
var candle_cont = candles.Content.ReadAsStringAsync().Result;
Console.WriteLine(candle_cont);
```
Response Body:
```json
{
"date": "2023-12-15",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "TXFA4",
"timeframe": "1",
"data": [
{
"date": "2023-12-15T08:45:00.000+08:00",
"open": 17744,
"high": 17756,
"low": 17744,
"close": 17756,
"volume": 98,
"average": 17749.97
},
{
"date": "2023-12-15T08:46:00.000+08:00",
"open": 17755,
"high": 17756,
"low": 17742,
"close": 17747,
"volume": 48,
"average": 17749.1
},
{
"date": "2023-12-15T08:47:00.000+08:00",
"open": 17746,
"high": 17746,
"low": 17731,
"close": 17731,
"volume": 26,
"average": 17747.8
},
...
]
}
```
---
### Products List
期權契約清單(依條件查詢)
```text
intraday/products
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| -------------- | ------ | ------------------------------------------------------------------------------------- |
| `type`\* | string | 類型,可選 `FUTURE` 期貨 ; `OPTION` 選擇權 |
| `exchange` | string | 交易所,可選 `TAIFEX` 臺灣期貨交易所 |
| `session` | string | 交易時段,可選 `REGULAR` 一般交易 或 `AFTERHOURS` 盤後交易 |
| `contractType` | string | 契約類別,可選 `I` 指數類;`R` 利率類;`B` 債券類;`C` 商品類;`S` 股票類;`E` 匯率類 |
| `status` | string | 契約狀態,可選 `N` 正常;`P` 暫停交易;`U` 即將上市 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| --------------------- | --------- | -------------------------------------------- |
| `type`\* | string | 期權類型 |
| `exchange` | string | 交易所 |
| `session` | string | 交易時段 |
| `contractType` | string | 契約類別 |
| `status` | string | 契約狀態 |
| `data` | object\[] | 契約列表 |
| >> `symbol` | string | 契約代號 |
| >> `type` | string | 期權類型 |
| >> `name` | string | 契約名稱 |
| >> `underlyingSymbol` | string | 股票現貨代號 |
| >> `contractType` | string | 契約類別 |
| >> `contractSize` | string | 契約乘數 |
| >> `statusCode` | string | 狀態碼 |
| >> `tradingCurrency` | string | 交易幣別 |
| >> `quoteAcceptable` | boolean | 是否可報價 |
| >> `startDate` | string | 上市日期 |
| >> `canBlockTrade` | boolean | 是否可鉅額交易 |
| >> `expiryType` | string | 到期別,`S` 標準;`W` 週 |
| >> `underlyingType` | string | 股票現貨類別,`E` ETF;`S` 個股 |
| >> `marketCloseGroup` | string | 商品收盤時間群組 |
| >> `endSession` | string | 交易時段,`0` 一般交易時段;`1` 盤後交易時段 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfutopt = sdk.marketdata.rest_client.futopt
# restfutopt.intraday.products(type='FUTURE', exchange='TAIFEX',session='REGULAR', contractType='E') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfutopt.intraday.products(type='FUTURE', exchange='TAIFEX',session='REGULAR', contractType='E')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.intraday.products({ type: 'FUTURE', exchange:'TAIFEX', session:'REGULAR', contractType:'E'})
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.FuOpt;
using FugleMarketData.QueryModels.FuOpt.Intraday;
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.FutureOption;
var contracts = await rest.Intraday.Products(FutOptType.Future, new(){
Exchange=FutOptExchangeType.TaiFex,
Session=SessionType.AfterHours,
ContractType=ContractType.E
});
var contracts_cont = contracts.Content.ReadAsStringAsync().Result;
Console.WriteLine(contracts_cont);
```
Response Body:
```json
{
"type": "FUTURE",
"exchange": "TAIFEX",
"session": "AFTERHOURS",
"contractType": "E",
"data": [
{
"symbol": "RHF",
"type": "FUTURE_AH",
"canBlockTrade": true,
"contractSize": 100000,
"contractType": "E",
"endSession": "0",
"expiryType": "S",
"marketCloseGroup": 10,
"name": "美元兌人民幣期貨",
"quoteAcceptable": true,
"startDate": "",
"statusCode": "N",
"tradingCurrency": "CNY",
"underlyingSymbol": "",
"underlyingType": ""
},
{
"symbol": "RTF",
"type": "FUTURE_AH",
"canBlockTrade": true,
"contractSize": 20000,
"contractType": "E",
"endSession": "0",
"expiryType": "S",
"marketCloseGroup": 10,
"name": "小型美元兌人民幣期貨",
"quoteAcceptable": true,
"startDate": "",
"statusCode": "N",
"tradingCurrency": "CNY",
"underlyingSymbol": "",
"underlyingType": ""
},
{
"symbol": "XAF",
"type": "FUTURE_AH",
"canBlockTrade": true,
"contractSize": 25000,
"contractType": "E",
"endSession": "0",
"expiryType": "S",
"marketCloseGroup": 10,
"name": "澳幣兌美元期貨",
"quoteAcceptable": true,
"startDate": "",
"statusCode": "N",
"tradingCurrency": "USD",
"underlyingSymbol": "",
"underlyingType": ""
}
]
}
```
---
### Intraday Quote
期權即時報價(依商品代碼查詢)
```text
intraday/quote/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `symbol`\* | string | 期權代碼;支援價差契約代碼(含 `/`,未編碼直接放入路徑,其報價可能為負值),詳見 [價差契約](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/tickers.txt#%E5%83%B9%E5%B7%AE%E5%A5%91%E7%B4%84) |
| `session` | string | 交易時段,可選 `afterhours` 盤後交易 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------ | ------- | ------------------------------------------------------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange` | string | 交易所 |
| `symbol` | string | 商品代號 |
| `name` | string | 商品名稱 |
| `previousClose` | number | 昨日收盤價 |
| `openPrice` | number | 開盤價 |
| `openTime` | number | 開盤價成交時間 |
| `highPrice` | number | 最高價 |
| `highTime` | number | 最高價成交時間 |
| `lowPrice` | number | 最低價 |
| `lowTime` | number | 最低價成交時間 |
| `closePrice` | number | 收盤價(最後成交價) |
| `closeTime` | number | 收盤價(最後成交價)成交時間 |
| `avgPrice` | number | 當日成交均價 |
| `change` | number | 最後成交價漲跌(含試撮) |
| `changePercent` | number | 最後成交價漲跌幅(含試撮) |
| `amplitude` | number | 當日振幅 |
| `lastPrice` | number | 最後一筆成交價(含試撮) |
| `lastSize` | number | 最後一筆成交數量(含試撮) |
| `total` | object | 成交統計 |
| >> `tradeVolume` | number | 累計成交量 |
| >> `totalBidMatch` | number | 累計委買成交筆數 |
| >> `totalAskMatch` | number | 累計委賣成交筆數 |
| >> `time` | number | 統計時間 |
| `lastTrade` | object | 最後一筆成交資訊 |
| >> `bid` | number | 最後一筆成交買價 |
| >> `ask` | number | 最後一筆成交賣價 |
| >> `price` | number | 最後一筆成交價格 |
| >> `size` | number | 最後一筆成交數量 |
| >> `time` | number | 最後一筆成交時間 |
| >> `serial` | string | 最後一筆成交流水號 |
| `lastTrial` | object | 最後一筆試撮資訊 |
| >> `bid` | number | 最後一筆試撮買價 |
| >> `ask` | number | 最後一筆試撮賣價 |
| >> `price` | number | 最後一筆試撮價格 |
| >> `size` | number | 最後一筆試撮數量 |
| >> `time` | number | 最後一筆試撮時間 |
| >> `serial` | string | 最後一筆試撮流水號 |
| `isTrial` | boolean | 是否處於試撮狀態:試撮階段為 `true`,非試撮時**省略此欄位**(缺省視為 `false`) |
| `serial` | number | 流水號 |
| `lastUpdated` | number | 最後異動時間 |
info
'\*' 表示必揭示欄位。
試撮欄位
`lastTrial` 為開盤前**試撮階段**的最後一筆試撮揭示(`bid`/`ask`/`price`/`size`/`time`/`serial`)。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfut = sdk.marketdata.rest_client.futopt
# restfut.intraday.quote(symbol='TXFA4') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfut.intraday.quote(symbol='TXFA4')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.intraday.quote({ symbol: 'TXFA4' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.FuOpt;
using FugleMarketData.QueryModels.FuOpt.Intraday;
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.FutureOption;
var quote = await rest.Intraday.Quote("TXFA4");
// var quote = await rest.Intraday.Quote("TXFA4", new(){Session=FugleMarketData.QueryModels.FuOpt.TradeSession.AfterHours}); // 盤後交易
var quote_cont = quote.Content.ReadAsStringAsync().Result;
Console.WriteLine(quote_cont);
```
Response Body:
```json
{
"date": "2023-12-12",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "TXFA4",
"name": "臺股期貨014",
"previousClose": 17416,
"openPrice": 17514,
"openTime": 1702341900070000,
"highPrice": 17540,
"highTime": 1702342491330000,
"lowPrice": 17427,
"lowTime": 1702355400574000,
"closePrice": 17460,
"closeTime": 1702359886936000,
"avgPrice": 17478.89,
"change": 44,
"changePercent": 0.25,
"amplitude": 0.65,
"lastPrice": 17460,
"lastSize": 1,
"total": {
"tradeVolume": 1626,
"totalBidMatch": 0,
"totalAskMatch": 0
},
"lastTrade": {
"bid": 17459,
"ask": 17460,
"price": 17460,
"size": 1,
"time": 1702359886936000,
"serial": "00165753"
},
"lastTrial": {
"price": 45380,
"size": 1,
"time": 1781506205000000,
"serial": "00000003"
},
"serial": 165753,
"lastUpdated": 1702359886936000
}
```
---
### Intraday Ticker
期權基本資料(依條件查詢)
```text
intraday/ticker/
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `symbol`\* | string | 商品代碼;支援價差契約代碼(含 `/`,未編碼直接放入路徑),詳見 [價差契約](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/tickers.txt#%E5%83%B9%E5%B7%AE%E5%A5%91%E7%B4%84) |
| `session` | string | 交易時段,可選 `afterhours` 盤後交易 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------- | --------- | ------------------------------------------ |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange`\* | string | 交易所 |
| `symbol`\* | string | 商品代號 |
| `name`\* | string | 商品名稱 |
| `referencePrice` | number | 參考價 |
| `limitUpPrice` | number | 漲停價 |
| `limitDownPrice` | number | 跌停價 |
| `priceLimitLevels` | object\[] | 各階漲跌停價(限適用分階漲跌幅的商品) |
| >> `level` | number | 階數,`1` 為基準階 |
| >> `limitUpPrice` | number | 該階漲停價 |
| >> `limitDownPrice` | number | 該階跌停價 |
| `limitUpLevel` | number | 漲停目前適用階數(限適用分階漲跌幅的商品) |
| `limitDownLevel` | number | 跌停目前適用階數(限適用分階漲跌幅的商品) |
| `settlementDate` | string | 最後結算日 |
| `startDate` | string | 上市日期 |
| `endDate` | string | 下市日期 |
| `openDatetime` | string | 交易時段開始時間 |
| `closeDatetime` | string | 交易時段結束時間 |
| `settleDate` | string | 交割年月(`yyyy-MM`) |
info
'\*' 表示必揭示欄位。
info
臺股期貨、個股期貨等單一漲跌幅商品僅回傳 `limitUpPrice` 與 `limitDownPrice`。黃金、原油、匯率、國外指數及國外成分證券 ETF 的期貨與選擇權採分階漲跌幅,另回傳 `priceLimitLevels` 完整階梯與 `limitUpLevel`/`limitDownLevel` 目前適用階數,此時 `limitUpPrice`/`limitDownPrice` 為目前適用階數的價格;盤中漲跌幅放寬後,適用階數與漲跌停價會隨之更新,且漲停與跌停可能適用不同階數。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfut = sdk.marketdata.rest_client.futopt
# restfut.intraday.ticker(symbol='TXFI6') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfut.intraday.ticker(symbol='TXFI6')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.intraday.ticker({ symbol: 'TXFI6'})
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.FuOpt;
using FugleMarketData.QueryModels.FuOpt.Intraday;
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.FutureOption;
var contracts = await rest.Intraday.Ticker("TXFI6", new(){
Session=TradeSession.AfterHours
});
var contracts_cont = contracts.Content.ReadAsStringAsync().Result;
Console.WriteLine(contracts_cont);
```
Response Body:
```json
{
"date": "2026-09-09",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "TXFI6",
"name": "臺股期貨096",
"referencePrice": 46955,
"limitUpPrice": 51650,
"limitDownPrice": 42260,
"settlementDate": "2026-09-16",
"startDate": "2025-09-18",
"endDate": "2026-09-16",
"openDatetime": "2026-09-09T08:45:00.000+08:00",
"closeDatetime": "2026-09-09T13:45:00.000+08:00",
"settleDate": "2026-09"
}
```
##### 分階漲跌幅商品[](#分階漲跌幅商品 "Direct link to 分階漲跌幅商品")
* Python
* Node.js
```python
restfut.intraday.ticker(symbol='OAFC7')
```
```js
client.futopt.intraday
.ticker({ symbol: 'OAFC7' })
.then((data) => console.log(data));
```
Response Body:
```json
{
"date": "2026-09-09",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "OAFC7",
"name": "富邦上証ETF期貨037",
"referencePrice": 40.2,
"limitUpPrice": 43.01,
"limitDownPrice": 37.39,
"priceLimitLevels": [
{
"level": 1,
"limitUpPrice": 43.01,
"limitDownPrice": 37.39
},
{
"level": 2,
"limitUpPrice": 44.22,
"limitDownPrice": 36.18
},
{
"level": 3,
"limitUpPrice": 46.23,
"limitDownPrice": 34.17
}
],
"limitUpLevel": 1,
"limitDownLevel": 1,
"settlementDate": "2027-03-17",
"startDate": "2026-04-16",
"endDate": "2027-03-17",
"openDatetime": "2026-09-09T08:45:00.000+08:00",
"closeDatetime": "2026-09-09T16:15:00.000+08:00",
"settleDate": "2027-03"
}
```
---
### Intraday Tickers
期權商品列表(依條件查詢)
```text
intraday/tickers/
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| -------------- | ------- | ------------------------------------------------------------------------------------- |
| `type`\* | string | 類型,可選 `FUTURE` 期貨 ; `OPTION` 選擇權 |
| `exchange` | string | 交易所,可選 `TAIFEX` 臺灣期貨交易所 |
| `session` | string | 交易時段,可選 `REGULAR` 一般交易 或 `AFTERHOURS` 盤後交易 |
| `product` | string | 期權商品代碼 |
| `contractType` | string | 契約類別,可選 `I` 指數類;`R` 利率類;`B` 債券類;`C` 商品類;`S` 股票類;`E` 匯率類 |
| `isSpread` | boolean | 帶 `true` 回傳時間價差(calendar spread)契約清單;預設回傳一般契約 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| -------------------------------------- | --------- | ---------------------------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange` | string | 交易所 |
| `session` | string | 交易時段 |
| `contractType` | string | 契約類別 |
| `isSpread` | boolean | 是否為價差契約查詢(帶 `isSpread=true` 時為 `true`) |
| `data` | object\[] | 契約列表 |
| >> `type` | string | 期權類型 |
| >> `symbol` | string | 商品代號 |
| >> `name` | string | 商品名稱 |
| >> `referencePrice` | number | 參考價 |
| >> `limitUpPrice` | number | 漲停價 |
| >> `limitDownPrice` | number | 跌停價 |
| >> `priceLimitLevels` | object\[] | 各階漲跌停價(限適用分階漲跌幅的商品) |
| >> `priceLimitLevels[].level` | number | 階數,`1` 為基準階 |
| >> `priceLimitLevels[].limitUpPrice` | number | 該階漲停價 |
| >> `priceLimitLevels[].limitDownPrice` | number | 該階跌停價 |
| >> `limitUpLevel` | number | 漲停目前適用階數(限適用分階漲跌幅的商品) |
| >> `limitDownLevel` | number | 跌停目前適用階數(限適用分階漲跌幅的商品) |
| >> `contractType` | string | 契約類別 |
| >> `startDate` | string | 上市日期 |
| >> `endDate` | string | 下市日期 |
| >> `openDatetime` | string | 交易時段開始時間 |
| >> `closeDatetime` | string | 交易時段結束時間 |
| >> `flowGroup` | string | 流程群組 |
| >> `settlementDate` | string | 最後結算日 |
| >> `isDynamicBanding` | boolean | 是否適用動態價格穩定 |
info
'\*' 表示必揭示欄位。
info
臺股期貨、個股期貨等單一漲跌幅商品僅回傳 `limitUpPrice` 與 `limitDownPrice`。黃金、原油、匯率、國外指數及國外成分證券 ETF 的期貨與選擇權採分階漲跌幅,另回傳 `priceLimitLevels` 完整階梯與 `limitUpLevel`/`limitDownLevel` 目前適用階數,此時 `limitUpPrice`/`limitDownPrice` 為目前適用階數的價格;盤中漲跌幅放寬後,適用階數與漲跌停價會隨之更新,且漲停與跌停可能適用不同階數。
價差契約查詢
價差契約查詢 v2.2.9 起提供。帶 `isSpread=true` 查詢價差契約時,`data` 回傳的欄位較精簡(`symbol`、`type`、`name`、`isSpread`)。詳見下方「[價差契約](#%E5%83%B9%E5%B7%AE%E5%A5%91%E7%B4%84)」。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfut = sdk.marketdata.rest_client.futopt
# restfut.intraday.tickers(type='FUTURE', exchange='TAIFEX',session='REGULAR', contractType='E') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfut.intraday.tickers(type='FUTURE', exchange='TAIFEX',session='REGULAR', contractType='E')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.intraday.tickers({ type: 'FUTURE', exchange:'TAIFEX', session:'REGULAR', contractType:'E'})
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.QueryModels.FuOpt;
using FugleMarketData.QueryModels.FuOpt.Intraday;
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.FutureOption;
var contracts = await rest.Intraday.Tickers(FutOptType.Future, new(){
Exchange=FutOptExchangeType.TaiFex,
Session=SessionType.AfterHours,
ContractType=ContractType.E
});
var contracts_cont = contracts.Content.ReadAsStringAsync().Result;
Console.WriteLine(contracts_cont);
```
Response Body:
```json
{
"type": "FUTURE",
"exchange": "TAIFEX",
"session": "REGULAR",
"contractType": "E",
"data": [
{
"symbol": "XAFC7",
"type": "FUTURE",
"closeDatetime": "2026-09-09T16:15:00.000+08:00",
"contractType": "E",
"endDate": "2027-03-15",
"flowGroup": 5,
"isDynamicBanding": true,
"name": "澳幣兌美元期貨037",
"openDatetime": "2026-09-09T08:45:00.000+08:00",
"referencePrice": 0.7189,
"settlementDate": "2027-03-15",
"startDate": "2026-03-19",
"limitDownLevel": 1,
"limitDownPrice": 0.6974,
"limitUpLevel": 1,
"limitUpPrice": 0.7404,
"priceLimitLevels": [
{
"level": 1,
"limitUpPrice": 0.7404,
"limitDownPrice": 0.6974
},
{
"level": 2,
"limitUpPrice": 0.7548,
"limitDownPrice": 0.683
},
{
"level": 3,
"limitUpPrice": 0.7692,
"limitDownPrice": 0.6686
}
]
},
{
"symbol": "XAFF7",
"type": "FUTURE",
"closeDatetime": "2026-09-09T16:15:00.000+08:00",
"contractType": "E",
"endDate": "2027-06-14",
"flowGroup": 5,
"isDynamicBanding": true,
"name": "澳幣兌美元期貨067",
"openDatetime": "2026-09-09T08:45:00.000+08:00",
"referencePrice": 0.7178,
"settlementDate": "2027-06-14",
"startDate": "2026-06-18",
"limitDownLevel": 1,
"limitDownPrice": 0.6963,
"limitUpLevel": 1,
"limitUpPrice": 0.7393,
"priceLimitLevels": [
{
"level": 1,
"limitUpPrice": 0.7393,
"limitDownPrice": 0.6963
},
{
"level": 2,
"limitUpPrice": 0.7536,
"limitDownPrice": 0.682
},
{
"level": 3,
"limitUpPrice": 0.768,
"limitDownPrice": 0.6676
}
]
},
......
]
}
```
#### 價差契約[](#價差契約 "Direct link to 價差契約")
時間價差(calendar spread)契約**預設不會**出現在清單中,帶 `isSpread=true` 才會回傳。價差契約有以下特性:
* **代碼格式為 `{近月}/{遠月}`**:由近、遠兩腳合約組成,例如 `EXFG6/H6`、`TXFG6/F7`;契約名稱標示兩個月份(例如「電子期貨 076-086」)。
* **可依單一代碼查詢**:`/intraday/ticker`、`/intraday/quote`、`/intraday/trades`、`/intraday/candles`、`/intraday/volumes` 都接受價差契約代碼,代碼中的 `/` 直接放入路徑即可(SDK 範例:`restfut.intraday.quote(symbol='TXFJ6/K6')`);也可透過 [WebSocket](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt#%E5%83%B9%E5%B7%AE%E5%A5%91%E7%B4%84%E8%A8%82%E9%96%B1) 訂閱即時行情。
* **報價可為負值**:價差為兩腳合約的價格之差,買賣報價可能為負數,屬正常現象。
- Python
- Node.js
```python
restfut.intraday.tickers(type='FUTURE', exchange='TAIFEX', session='AFTERHOURS', isSpread=True)
```
```js
client.futopt.intraday
.tickers({ type: 'FUTURE', exchange: 'TAIFEX', session: 'AFTERHOURS', isSpread: true })
.then((data) => console.log(data));
```
---
### Intraday Trades
期權成交明細(依代碼查詢)
```text
intraday/trades/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------- | ------------------------------------------ |
| `symbol`\* | string | 期權代碼 |
| `session` | string | 交易時段,可選 `afterhours` 夜盤 |
| `offset` | number | 偏移量 |
| `limit` | number | 限制量 |
| `isTrial` | boolean | 查詢試撮明細,預設 `false`(回傳正式成交) |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------ | --------- | ----------- |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange`\* | string | 交易所 |
| `symbol`\* | string | 商品代號 |
| `data`\* | object\[] | 成交明細 |
| >> `bid` | number | 成交買價 |
| >> `ask` | number | 成交賣價 |
| >> `price` | number | 成交價格 |
| >> `size` | number | 成交單量 |
| >> `time` | number | 成交時間 |
| >> `serial` | number | 流水號 |
info
'\*' 表示必揭示欄位。
試撮查詢
`isTrial=true` 用於查詢**試撮階段**(盤前試撮揭示)之成交明細;預設(`false`)僅回傳正式撮合之成交明細,兩者為獨立查詢模式而非同一結果混合旗標。此參數 v2.2.9 起提供。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfutopt = sdk.marketdata.rest_client.futopt
# restfutopt.intraday.trades(symbol='TXFA4') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfutopt.intraday.trades(symbol='TXFA4')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.intraday.trades({ symbol: 'TXFA4' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
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.FutureOption;
var trade = await rest.Intraday.Trades("TXFA4");
// var trade = await rest.Intraday.Trades("TXFA4", new(){Session=FugleMarketData.QueryModels.FuOpt.TradeSession.AfterHours}); // 盤後交易
var trade_cont = trade.Content.ReadAsStringAsync().Result;
Console.WriteLine(trade_cont);
```
Response Body:
```json
{
"date": "2023-12-20",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "TXFA4",
"data": [
{
"price": 17660,
"size": 3,
"time": 1703051099834000,
"serial": 218307
},
{
"price": 17661,
"size": 2,
"time": 1703051099779000,
"serial": 218304
},
{
"price": 17661,
"size": 1,
"time": 1703051099778000,
"serial": 218303
},
{
"price": 17661,
"size": 1,
"time": 1703051099778000,
"serial": 218301
},
....
]
}
```
---
### Intraday Volumes
期權分價量表(依代碼查詢)
```text
intraday/volumes/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | -------------------------------- |
| `symbol`\* | string | 期權代碼 |
| `session` | string | 交易時段,可選 `afterhours` 夜盤 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------ | --------- | -------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange`\* | string | 交易所 |
| `symbol`\* | string | 商品代號 |
| `data` | object\[] | 分價量表 |
| >> `price` | number | 成交價 |
| >> `volume` | number | 該成交價之累計成交量 |
info
'\*' 表示必揭示欄位。
#### Example[](#example "Direct link to Example")
* Python
* Node.js
* C#
```python
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() # 建立行情連線
restfutopt = sdk.marketdata.rest_client.futopt
# restfutopt.intraday.volumes(symbol='TXFA4') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfutopt.intraday.volumes(symbol='TXFA4')
except FugleAPIError as e:
print(f"Error: {e}")
print("------------")
print(f"Status Code: {e.status_code}") # 例: 429
print(f"Response Text: {e.response_text}") # 例: {"statusCode":429,"message":"Rate limit exceeded"}
```
```js
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.futopt.intraday.volumes({ symbol: 'TXFA4' })
.then(data => console.log(data));
```
```cs
using FubonNeo.Sdk;
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.FutureOption;
var volume = await rest.Intraday.Volumes("TXFA4");
// var volume = await rest.Intraday.Volumes("TXFA4", new(){Session=FugleMarketData.QueryModels.FuOpt.TradeSession.AfterHours}); // 盤後交易
var volume_cont = volume.Content.ReadAsStringAsync().Result;
Console.WriteLine(volume_cont);
```
Response Body:
```json
{
"date": "2023-12-20",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "TXFA4",
"data": [
{
"price": 17676,
"volume": 68
},
{
"price": 17675,
"volume": 392
},
{
"price": 17674,
"volume": 265
},
{
"price": 17673,
"volume": 396
},
{
"price": 17672,
"volume": 430
},
{
"price": 17671,
"volume": 518
},
{
"price": 17670,
"volume": 681
},
{
"price": 17669,
"volume": 338
},
{
"price": 17668,
"volume": 395
},
{
"price": 17667,
"volume": 568
},
{
"price": 17666,
"volume": 670
},
{
"price": 17665,
"volume": 641
},
{
"price": 17664,
"volume": 542
},
{
"price": 17663,
"volume": 898
},
{
"price": 17662,
"volume": 870
},
{
"price": 17661,
"volume": 656
},
{
"price": 17660,
"volume": 876
},
{
"price": 17659,
"volume": 402
},
{
"price": 17658,
"volume": 352
},
{
"price": 17657,
"volume": 190
},
{
"price": 17656,
"volume": 470
},
....
]
}
```
---
### 富邦新一代 API 期貨行情服務
本頁重點
* 富邦新一代 API(Fubon Neo API)期貨行情服務提供期貨即時與日內資料。
* 介面包含 Web API 與 WebSocket API。
* 資料來源為交易所與資訊供應商,使用前請詳閱規範與聲明。
* 下一步可從 [Web API](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/getting-started.txt) 或 [WebSocket API](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt) 開始。
| 項目 | 說明 |
| -------- | ------------------------------------------------ |
| 服務 | 新一代 API 期貨行情服務 |
| 市場 | 台灣期貨市場 |
| 介面 | Web API / WebSocket API |
| 資料來源 | 臺灣證券交易所、證券櫃檯買賣中心、臺灣期貨交易所 |
| 規範 | 使用規範與聲明 |
即時行情資料來源為臺灣證券交易所、證券櫃檯買賣中心、臺灣期貨交易所。請您詳閱相關使用 [規範與聲明](#statement)。
#### Web API[](#web-api "Direct link to Web API")
富邦行情 [Web API](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/getting-started.txt) 提供開發者友善的 Web API 服務。您可以查詢期貨的日內行情數據。
#### WebSocket API[](#websocket-api "Direct link to WebSocket API")
富邦行情 [WebSocket API](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt) 提供期貨即時行情服務。透過 WebSocket API 可以滿足您想要接收即時行情的需求。
#### 使用規範與聲明[](#statement "Direct link to 使用規範與聲明")
* 透過本服務取得之行情資料僅供參考,成交值及成交量不含零股及鉅額交易,使用者依本資料交易發生交易損失需自行負責。
* 時報資訊與群馥科技對資料內容錯誤、更新延誤或傳輸中斷不負任何責任。您應對您所為之任何金融或投資決策自行負責。
* 使用者應遵守 [臺灣證券交易所股份有限公司交易資訊使用管理辦法](https://www.selaw.com.tw/Chinese/RegulatoryInformationResult/Article?isIntegratedSearch=True\&sysNumber=LW10809760\&searchString1=%E8%87%BA%E7%81%A3%E8%AD%89%E5%88%B8%E4%BA%A4%E6%98%93%E6%89%80%E8%82%A1%E4%BB%BD%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%E4%BA%A4%E6%98%93%E8%B3%87%E8%A8%8A%E4%BD%BF%E7%94%A8%E7%AE%A1%E7%90%86%E8%BE%A6%E6%B3%95)、[臺灣期貨交易所股份有限公司交易資訊使用管理辦法](https://www.selaw.com.tw/Chinese/RegulatoryInformationResult/Article?isIntegratedSearch=True\&sysNumber=LW10815483\&searchString1=%E8%87%BA%E7%81%A3%E6%9C%9F%E8%B2%A8%E4%BA%A4%E6%98%93%E6%89%80%E8%82%A1%E4%BB%BD%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%E4%BA%A4%E6%98%93%E8%B3%87%E8%A8%8A%E4%BD%BF%E7%94%A8%E7%AE%A1%E7%90%86%E8%BE%A6%E6%B3%95)、[財團法人中華民國證券櫃檯買賣中心有價證券交易資訊使用管理辦法](https://www.selaw.com.tw/Chinese/RegulatoryInformationResult/Article?isIntegratedSearch=True\&sysNumber=LW10813063\&searchString1=%E8%B2%A1%E5%9C%98%E6%B3%95%E4%BA%BA%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E8%AD%89%E5%88%B8%E6%AB%83%E6%AA%AF%E8%B2%B7%E8%B3%A3%E4%B8%AD%E5%BF%83%E6%9C%89%E5%83%B9%E8%AD%89%E5%88%B8%E4%BA%A4%E6%98%93%E8%B3%87%E8%A8%8A%E4%BD%BF%E7%94%A8%E7%AE%A1%E7%90%86%E8%BE%A6%E6%B3%95)、各資訊來源提供者所定之資訊使用相關規範及智慧財產權相關法令,如有盜接、轉接交易資訊,或以其他方式出售、出租、轉讓、再授權交易資訊,或將交易資訊另行取樣並編製指數、其他衍生性商品或將之傳送予第三人,應負違約及侵權之相關民、刑事責任。
* 使用者須遵守臺灣證券交易所「[交易資訊使用管理辦法](https://www.twse.com.tw/downloads/zh/products/regulation_use.pdf)」等交易資訊管理相關規定,所有資訊以臺灣證券交易所公告資料為準。
* 富邦新一代 API 期貨行情服務由 [Fugle](https://www.fugle.tw/) 技術團隊開發提供。
---
### 建立連線
##### 建立行情連線[](#建立行情連線 "Direct link to 建立行情連線")
以下範例程式碼示範如何同時建立 7 條行情 WebSocket 連線。
info
一般僅 WebSocket 需要同時啟用多條連線,若使用 Web API 則建議使用單一連線方便管理。 Web API 速率限制為所有連線共用;WebSocket 每條連線各可訂閱 300 檔標的。
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password" ,"Your cert path" ,"Your cert password") # 需登入後,才能取得行情權限
websockets = [] # 不同連線 WebSocket 介面列表
for _ in range(7): # 建立 7 條連線
sdk.init_realtime() # 啟動一條行情連線
#ws = sdk.marketdata.websocket_client.stock # WebSocket 介面 (證券)
ws = sdk.marketdata.websocket_client.futopt # WebSocket 介面 (期貨)
# 將介面置入可用列表中
websockets.append(ws)
# 設定 WebSocket Callback 並開啟連結
for ws in websockets:
## Callback functions 需另外定義 ##
ws.on('message', handle_message) # 註冊行情資料 callback
ws.on("connect", handle_connect) # 註冊連線事件 callback
ws.on("disconnect", handle_disconnect) # 註冊斷線事件 callback
ws.on("error", handle_error) # 註冊錯誤事件 callback
ws.connect() # 啟用連結
# 斷開連線
# for ws in websockets:
# we.disconnect()
```
```js
const { FubonSDK } = require('fubon-neo');
// 需先登入才能取得行情權限
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID", "Your Password", "Your Cert Path", "Your Cert Password");
const websockets = []; // 不同連線 WebSocket 介面列表
// 建立 7 條行情連線
for (let i = 0; i < 7; i++) {
// 啟動一條行情連線
sdk.initRealtime();
// 取得 WebSocket 介面
//const ws = sdk.marketdata.webSocketClient.stock; // (證券)
const ws = sdk.marketdata.webSocketClient.futopt; // (期貨)
// 將介面置入可用列表中
websockets.push(ws);
}
// 設定 WebSocket Callback 並開啟連結
for (const ws of websockets) {
/* -- Callback functions 需另外定義 -- */
ws.on('message', handle_message); // 註冊行情資料 callback
ws.on('connect', handle_connect); // 註冊連線事件 callback
ws.on('disconnect', handle_disconnect); // 註冊斷線事件 callback
ws.on('error', handle_error); // 註冊錯誤事件 callback
// 啟用連結
(async () => {
await ws.connect();
})()
}
// 斷開連線
//for (const ws of websockets) {
// (async () => {
// await ws.disconnect();
// })()
//}
```
```cs
using FubonNeo.Sdk;
// 需先登入才能取得行情權限
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your Password", "Your Cert Path", "Your Cert Password");
// 不同連線 WebSocket 介面列表
//var websockets = new List(); // (證券)
var websockets = new List(); // (期貨)
// 建立 7 條行情連線
for (int i = 0; i < 7; i++)
{
sdk.InitRealtime(); // 建立行情連線
// 取得 WebSocket 介面
//var ws = sdk.MarketData.WebSocketClient.Stock; // (證券)
var ws = sdk.MarketData.WebSocketClient.FutureOption; // (期貨)
// 將介面置入可用列表中
websockets.Add(ws);
}
// 設定 WebSocket Callback 並開啟連結
foreach (var ws in websockets)
{
ws.OnMessage = (msg) => Console.WriteLine($"OnMessage receive: {msg}"); // 註冊行情資料 callback
ws.OnError = (msg) => Console.WriteLine($"OnError receive: {msg}"); // 註冊錯誤事件 callback
ws.OnConnected = (msg) => Console.WriteLine($"OnConnected receive: {msg}"); // 註冊連線事件 callback
ws.OnDisconnected = (msg) => Console.WriteLine($"OnDisconnected receive: {msg}"); // 註冊斷線事件 callback
// 啟用連結
await ws.Connect();
}
// 斷開連線
// foreach (var ws in websockets)
// {
// await ws.Disconnect();
// }
```
---
### 速率限制
##### 速率限制[](#速率限制 "Direct link to 速率限制")
本頁重點
* 本頁整理富邦新一代 API 期貨行情服務的 Web API / WebSocket 速率限制。
* 超過限制將回應 `429` 或訂閱錯誤訊息。
* 若短時間內大量建立連線可能被判定為異常。
| 項目 | 上限 |
| --------- | -------------------- |
| 日內行情 | 300 / min |
| 行情快照 | 300 / min |
| 歷史行情 | 60 / min |
| WebSocket | 300 訂閱數;7 連線數 |
富邦新一代 API 期貨行情服務提供 Web API 與 WebSocket,並設定了以下存取的限制
* 日內行情 : 300 / min
* WebSocket : 300 訂閱數;7 連線數
* 行情快照 : 300 / min
* 歷史行情 : 60 / min
如果您 API 請求超過了限制,將收到帶有狀態碼 `429` 的回應。需再等候 1 分鐘。
```json
{"statusCode":429,"message":"Rate limit exceeded"}
```
或是您的 WebSocket 訂閱數超過上限,將收到以下訊息:
```json
{
"event": "error",
"data": {
"code": 1001,
"message": "Maximum number of connections reached"
}
}
```
caution
若短時間內,Socket 持續大量建立連線,系統會判斷您為惡意攻擊,將會阻擋您的連線請求(404 連線錯誤), 若遇到此種狀況,請聯絡
---
### 開始使用
本頁重點
* 富邦行情期貨 WebSocket API(富邦新一代 API 期貨行情服務)提供期貨即時行情訂閱。
* 支援 `Speed` / `Normal` 兩種行情模式。
* 需登入後建立行情連線並訂閱頻道。
* 下一步可前往各頻道說明頁。
| 項目 | 說明 |
| -------- | --------------------- |
| 介面 | WebSocket API |
| 市場 | 期貨 / 期權 |
| 模式 | Speed / Normal |
| SDK | Python / Node.js / C# |
| 訂閱方式 | 連線後訂閱頻道 |
富邦行情 WebSocket API 提供期貨即時行情服務。透過 WebSocket API 可以滿足您想要接收即時行情的需求。
#### 使用 SDK[](#使用-sdk "Direct link to 使用 SDK")
富邦行情 WebSocket API 提供 Python 、 Node.js 與 C# SDK。您可以透過以下方式存取 WebSocket API、並透過行情 Mode 模式切換要訂閱的行情:
訂閱 WebSocket Callback 方法獲得下方 Callback 訊息。
info
行情 Mode 提供 Low Latency `Speed` Mode 以及完整資訊的 `Normal` Mode
期權行情連線版本
期權行情 WebSocket 提供 `v1.0` 與 `v1.1` 兩個連線版本,建立連線時未指定版本即連到 `v1.1`。**`trades` 與 `books` 頻道的試撮訊息(`isTrial`)僅 `v1.1` 連線推送**,指定連到 `v1.0` 則不會收到;`aggregates` 頻道在兩個版本都會推送試撮期間的更新。股票行情僅提供 `v1.0`。此參數 v2.2.9 起提供。
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Mode
def handle_message(message):
print(message)
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
# 可指定行情連線的Mode , Default 為Speed
# sdk.init_realtime(Mode.Speed) or sdk.init_realtime(Mode.Normal)
# 可指定期權行情連線版本,未指定為 v1.1;連到 v1.0 則不接收 trades/books 試撮訊息
# sdk.init_realtime(Mode.Speed, version={"futopt": "v1.0"})
# 連線後可由 sdk.marketdata.websocket_client.futopt.url 確認實際連上的版本
futopt = sdk.marketdata.websocket_client.futopt
futopt.on('message', handle_message)
futopt.connect()
```
```js
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(); // 建立行情連線
// 可指定行情連線的Mode , Default 為Speed
// sdk.initRealtime(Mode.Speed) or sdk.initRealtime(Mode.Normal)
// 可指定期權行情連線版本,未指定為 v1.1;連到 v1.0 則不接收 trades/books 試撮訊息
// sdk.initRealtime(Mode.Speed, { futopt: 'v1.0' });
// 連線後可由 sdk.marketdata.webSocketClient.futopt.url 確認實際連上的版本
const futopt = sdk.marketdata.webSocketClient.futopt;
futopt.connect()
futopt.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // 建立行情連線
// 可指定行情連線的Mode , Default 為Speed
// sdk.InitRealtime(Mode.Speed) or sdk.InitRealtime(Mode.Normal)
// 可指定期權行情連線版本,未指定為 v1.1;連到 v1.0 則不接收 trades/books 試撮訊息
// sdk.InitRealtime(Mode.Speed, new FugleMarketData.WebsocketClient.WebsocketVersionOptions { FutOpt = "v1.0" });
var futopt = sdk.MarketData.WebSocketClient.FutureOption;
futopt.OnMessage += (msg) => Console.WriteLine($"receive: {msg}");
await futopt.Connect();
```
#### 身份驗證[](#��身份驗證 "Direct link to 身份驗證")
當驗證成功後,會收到以下訊息:
```json
{
"event": "authenticated",
"data": {
"message": "Authenticated successfully"
}
}
```
若驗證失敗,則收到以下訊息:
```json
{
"event": "error",
"data": {
"message": "Invalid authentication credentials"
}
}
```
#### Heartbeat[](#heartbeat "Direct link to Heartbeat")
每隔 30 秒 WebSocket server 會送出一個 heartbeat 訊息:
```json
{
"event": "heartbeat",
"data": {
"time": ""
}
}
```
#### Ping/Pong[](#pingpong "Direct link to Ping/Pong")
SDK 每 30 秒會自動發送一次 ping 到伺服器;您也可以自行發送 ping,並可額外自訂 `state`(選填):
* Python
* Node.js
* C#
```python
futopt.ping({
'state' : ''
})
```
```js
futopt.ping({state:''});
```
```cs
futopt.ping("");
```
WebSocket Server 會回應以下訊息 (若 ping 未送 `state` 則不會有該欄位):
```json
{
"event": "pong",
"data": {
"time": "",
"state": ""
}
}
```
#### Channels[](#channels "Direct link to Channels")
富邦行情 WebSocket API 目前提供以下可訂閱頻道:
* `trades` - [接收訂閱期權商品最新成交資訊](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/market-data-channels/trades.txt)
* `books` - [接收訂閱期權商品最新最佳五檔委買委賣資訊](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/market-data-channels/books.txt)
* `aggregates` - [接收訂閱期權聚合數據的行情資訊](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/market-data-channels/aggregates.txt)
##### 期貨/選擇權行情功能一覽[](#期貨選擇權行情功能一覽 "Direct link to 期貨/選擇權行情功能一覽")
自 v2.2.9 起提供下列行情功能:
* **連續月行情**:可用 `{ROOT}1!`/`2!`/`3!` 訂閱近月別名;請見下方 [連續月別名](#%E9%80%A3%E7%BA%8C%E6%9C%88%E5%88%A5%E5%90%8D)。
* **價差合約行情**:先以 [Intraday Tickers](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/tickers.txt) 的 `isSpread=true` 取得價差合約代碼,再將回傳的 `symbol` 用於 WebSocket 訂閱;請見下方 [價差契約訂閱](#%E5%83%B9%E5%B7%AE%E5%A5%91%E7%B4%84%E8%A8%82%E9%96%B1)。
* **延伸一檔報價**:`books` 頻道的 [`derivedBid`/`derivedAsk`](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/market-data-channels/books.txt) 提供衍生最佳一檔報價,主要適用於價差合約。
* **試撮資訊**:`books` 的 [`isTrial`](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/market-data-channels/books.txt) 與 `aggregates` 的 [`lastTrial`](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/market-data-channels/aggregates.txt) 用於揭示試撮階段資訊。
##### 訂閱頻道[](#訂閱頻道 "Direct link to 訂閱頻道")
要訂閱一個頻道可用下方範例進行訂閱:
* Python
* Node.js
* C#
```python
futopt.subscribe({
"channel" : "",
"symbol" : ""
#"afterHours" : True 若要訂閱夜盤行情,可再額外加入此參數
})
```
```js
futopt.subscribe({
channel: '',
symbol: '',
//afterHours : true 若要訂閱夜盤行情,可再額外加入此參數
});
```
```cs
futopt.Subscribe(FutureOptionChannel.,"");
//futopt.Subscribe(FutureOptionChannel.Trades,new FutureOptionParams{Symbol="", AfterHours = true}); 訂閱夜盤行情
```
訂閱成功後,會收到以下事件回應:
```json
{
"event": "subscribed",
"data": {
"id": "",
"channel": "",
"symbol": ""
}
}
```
支援訂閱同頻道的多檔商品:
* Python
* Node.js
* C#
```python
futopt.subscribe({
"channel" : "",
"symbols" : ["",""]
#"afterHours" : True 若要訂閱夜盤行情,可再額外加入此參數
})
```
```js
futopt.subscribe({
channel: '',
symbols: ['','']
//afterHours : true 若要訂閱夜盤行情,可再額外加入此參數
});
```
```cs
futopt.Subscribe(FutureOptionChannel.,"","");
//futopt.Subscribe(FutureOptionChannel.Trades, new FutureOptionParams{Symbols = new List{"", ""}, AfterHours = true}); 訂閱多檔夜盤行情
```
訂閱成功後,會收到以下事件回應:
```json
{
"event": "subscribed",
"data": [
{
"id": "",
"channel": "",
"symbol": ""
},
{
"id": "",
"channel": "",
"symbol": ""
}
]
}
```
##### 連續月別名[](#連續月別名 "Direct link to 連續月別名")
訂閱時的 `symbol` 除了具體合約代碼(如 `TXFG6`),也可使用**連續月別名** `{ROOT}1!`/`2!`/`3!` 訂閱第 1/2/3 近月合約(如 `TXF1!` 為最近月臺股期貨)。系統會於**送出訂閱的當下**解析為對應的具體合約,`data` 事件回傳的 `symbol` 為解析後的具體合約代碼。詳見 [Web API — 商品代碼與連續月別名](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/getting-started.txt#%E5%95%86%E5%93%81%E4%BB%A3%E7%A2%BC%E8%88%87%E9%80%A3%E7%BA%8C%E6%9C%88%E5%88%A5%E5%90%8D)。
別名只在訂閱當下解析一次
別名只在送出訂閱的當下解析一次,之後訂閱固定綁在該合約,跨結算日**不會**自動轉倉(舊合約結算後將收不到資料)。長效連線請於換月後重新訂閱(先 `unsubscribe` 再 `subscribe`)或改用具體合約代碼;Web API 每次呼叫都重新解析,不受影響。
* Python
* Node.js
* C#
```python
futopt.subscribe({
"channel": "trades",
"symbol": "TXF1!" # 連續月別名,訂閱最近月臺股期貨
#"afterHours" : True 若要訂閱夜盤行情,可再額外加入此參數
})
```
```js
futopt.subscribe({
channel: "trades",
symbol: "TXF1!" // 連續月別名,訂閱最近月臺股期貨
//afterHours : true 若要訂閱夜盤行情,可再額外加入此參數
});
```
```cs
futopt.Subscribe(FutureOptionChannel.Trades, "TXF1!"); // 連續月別名,訂閱最近月臺股期貨
```
##### 價差契約訂閱[](#價差契約訂閱 "Direct link to 價差契約訂閱")
價差契約(如 `TXFJ6/K6`)同樣以 `symbol` 欄位訂閱,代碼原樣放入即可,訂閱成功後會收到該價差契約的行情資料。價差契約代碼格式詳見 [價差契約](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/tickers.txt#%E5%83%B9%E5%B7%AE%E5%A5%91%E7%B4%84)。
* Python
* Node.js
* C#
```python
futopt.subscribe({
"channel": "books",
"symbol": "TXFJ6/K6"
})
```
```js
futopt.subscribe({
channel: "books",
symbol: "TXFJ6/K6"
});
```
```cs
futopt.Subscribe(FutureOptionChannel.Books, "TXFJ6/K6");
```
##### 取消訂閱[](#取消訂閱 "Direct link to 取消訂閱")
要取消頻道可用下方範例進行取消:
* Python
* Node.js
* C#
```python
futopt.unsubscribe({
'id':''
})
```
```js
futopt.unsubscribe({
id : ''
});
```
```cs
futopt.Unsubscribe("");
```
取消訂閱成功後,會收到以下事件回應:
```json
{
"event": "unsubscribed",
"data": {
"id": "",
"channel" : "",
"symbol" : ""
}
}
```
支援取消訂閱多個頻道:
* Python
* Node.js
* C#
```python
futopt.unsubscribe({
'ids':['','']
})
```
```js
futopt.unsubscribe({
ids : ['','']
});
```
```cs
futopt.Unsubscribe("","");
```
取消訂閱成功後,會收到以下事件回應:
```json
{
"event": "unsubscribed",
"data": [
{
"id": "",
"channel" : "",
"symbol" : ""
},
{
"id": "",
"channel" : "",
"symbol" : ""
}
]
}
```
##### 訂閱資訊[](#訂閱資訊 "Direct link to 訂閱資訊")
要取得目前連線已訂閱的頻道清單,可用下方範例查詢:
* Python
* Node.js
```python
futopt.subscriptions()
```
```js
futopt.subscriptions();
```
會收到以下事件回應:
```json
{
"event": "subscriptions",
"data": [
{
"id": "",
"channel": "",
"symbol": ""
}
]
}
```
#### 錯誤處理[](#錯誤處理 "Direct link to 錯誤處理")
當您所訂閱或處理的 WebSocket Callback 有異常時,您可補充處理錯誤訊息如下。
`disconnect` 事件在兩種情況觸發:伺服器關閉連線,以及連線健康檢查逾時(超過約 60 秒未收到伺服器任何訊息時,SDK 會主動關閉連線並發出此事件)。逾時斷線在各語言的通知形態,見各範例下方說明。
* Python
* Node.js
* C#
```python
def handle_connect():
print('market data connected')
def handle_disconnect(code, message, *reason): # 連線健康檢查逾時斷線時會多帶一個參數
print(f'market data disconnect: {code}, {message}')
def handle_error(error):
print(f'market data error: {error}')
futopt.on("connect", handle_connect)
futopt.on("disconnect", handle_disconnect)
futopt.on("error", handle_error)
```
健康檢查逾時斷線時,`disconnect` 會多帶第三個參數 `{'reason': 'health-check-timeout'}`,handler 以 `*reason` 接住即可。
```js
futopt.on("connect", () => {
console.log("market data connected");
});
futopt.on("disconnect", (event, reason) => {
console.log("market data disconnect:", event.code, reason);
});
futopt.on("error", (error) => {
console.log("market data error:", error);
});
```
健康檢查逾時斷線時,`disconnect` 的第二個參數為 `{ reason: 'health-check-timeout' }`。
```cs
futopt.OnConnected += (connmsg) => Console.WriteLine($"Connect: {connmsg}");
futopt.OnDisconnected += (disconmsg) => Console.WriteLine($"Disconnect: {disconmsg}");
futopt.OnError += (errmsg) => Console.WriteLine($"handle error: {errmsg}");
```
健康檢查需在 `Connect` 時以第二個參數開啟(`Connect(5000, true)`,第一個參數為驗證逾時毫秒數);逾時斷線時 `OnDisconnected` 的訊息為 `health-check-timeout`。未開啟時,連線靜默中斷不會觸發 `OnDisconnected`。
##### 斷線重連[](#斷線重連 "Direct link to 斷線重連")
連線中斷後,SDK 不會自動重新連線,也不會保留原有訂閱;程式需在收到 `disconnect` 事件後重新連線,並重新送出所有訂閱。以下範例接續上方的登入與建立連線程式:收到斷線事件後在背景重新連線與訂閱,重試間隔逐次拉長(2、4、8、16、30 秒)並以 5 次為上限,避免網路尚未恢復時短時間內大量重連。訂閱清單每個頻道一筆、以 `symbols` 一次訂閱多檔,重連後重新訂閱的呼叫次數等於頻道數,不隨檔數增加。
* Python
* Node.js
* C#
```python
# 接續 futopt = sdk.marketdata.websocket_client.futopt 之後,取代原本的 futopt.connect()
import threading
import time
SUBSCRIPTIONS = [ # 初次訂閱與重連後重新訂閱共用同一份清單;每個頻道一筆,多檔用 symbols
{'channel': 'trades', 'symbols': ['TXF1!', 'MXF1!'], 'afterHours': True},
]
reconnect_needed = threading.Event()
def handle_disconnect(code, message, *reason): # 連線健康檢查逾時斷線時會多帶一個參數,用 *reason 接住
print(f'market data disconnect: {code}, {message}')
reconnect_needed.set() # 只通知,不在此直接重連
def subscribe_all():
for params in SUBSCRIPTIONS:
futopt.subscribe(params)
def connect_with_timeout(seconds=10):
# 網路不通時 connect() 不會返回,另開執行緒加上逾時
result = {}
def run():
try:
futopt.connect()
except Exception as error:
result['error'] = error
worker = threading.Thread(target=run, daemon=True)
worker.start()
worker.join(seconds)
if worker.is_alive():
raise TimeoutError('connect timeout')
if 'error' in result:
raise result['error']
def reconnect_loop():
retries = 0
while reconnect_needed.wait():
reconnect_needed.clear()
retries += 1
if retries > 5:
print('Reconnect failed 5 times, please check the network')
return
time.sleep(min(2 ** retries, 30)) # 等 2、4、8、16、30 秒後再試
try:
futopt.disconnect() # 先重設連線狀態,否則 connect() 不會重新連線
connect_with_timeout()
subscribe_all()
retries = 0
print('Reconnected and resubscribed')
except Exception as error:
print(f'Reconnect failed: {error}')
reconnect_needed.set()
futopt.on('disconnect', handle_disconnect)
threading.Thread(target=reconnect_loop, daemon=True).start()
futopt.connect()
subscribe_all()
```
```js
// 接續 sdk.login(...) 之後;initRealtime 與事件綁定改由 connectAndSubscribe() 處理
const SUBSCRIPTIONS = [ // 初次訂閱與重連後重新訂閱共用同一份清單;每個頻道一筆,多檔用 symbols
{ channel: 'trades', symbols: ['TXF1!', 'MXF1!'], afterHours: true },
];
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
let futopt;
let reconnecting = false;
function handleMessage(message) {
console.log(JSON.parse(message));
}
async function connectAndSubscribe() {
sdk.initRealtime(); // 重連時重建行情連線物件,事件需重新綁定
futopt = sdk.marketdata.webSocketClient.futopt;
const client = futopt;
client.on('message', handleMessage);
client.on('disconnect', (event, reason) => handleDisconnect(client, event, reason));
await Promise.race([ // 網路不通時 connect() 不會完成,加上逾時
client.connect(),
sleep(10000).then(() => { throw new Error('connect timeout'); }),
]);
for (const params of SUBSCRIPTIONS) client.subscribe(params);
}
async function handleDisconnect(client, event, reason) {
console.log('market data disconnect:', event.code, reason);
if (client !== futopt || reconnecting) return; // 舊連線物件的事件、或已在重連中,略過
reconnecting = true;
try {
for (let retries = 1; retries <= 5; retries++) {
await sleep(Math.min(2 ** retries, 30) * 1000); // 等 2、4、8、16、30 秒後再試
try {
futopt.disconnect(); // 關閉舊連線並停止其計時器
await connectAndSubscribe();
console.log('Reconnected and resubscribed');
return;
} catch (error) {
console.log(`Reconnect failed: ${error.message}`);
}
}
console.log('Reconnect failed 5 times, please check the network');
} finally {
reconnecting = false;
}
}
await connectAndSubscribe();
```
```cs
// 接續 var futopt = sdk.MarketData.WebSocketClient.FutureOption; 之後,取代原本的 await futopt.Connect()
var subscriptions = new[] { (FutureOptionChannel.Trades, new FutureOptionParams { Symbols = new List { "TXF1!", "MXF1!" }, AfterHours = true }) }; // 初次訂閱與重連後重新訂閱共用同一份清單;每個頻道一筆,多檔用 Symbols
var reconnecting = 0;
async Task SubscribeAll()
{
foreach (var (channel, param) in subscriptions)
await futopt.Subscribe(channel, param);
}
futopt.OnDisconnected += (msg) =>
{
Console.WriteLine($"market data disconnect: {msg}");
if (Interlocked.Exchange(ref reconnecting, 1) == 1) return; // 一次斷線可能收到多次通知,只保留一條重連流程
_ = Task.Run(async () =>
{
try
{
for (var retries = 1; retries <= 5; retries++)
{
await Task.Delay(TimeSpan.FromSeconds(Math.Min(Math.Pow(2, retries), 30))); // 等 2、4、8、16、30 秒後再試
try
{
await futopt.Connect(5000, true); // 5 秒驗證逾時;開啟連線健康檢查
if (!futopt.IsConnected) continue; // 驗證逾時時 Connect 不會拋出例外,需自行檢查
await SubscribeAll();
Console.WriteLine("Reconnected and resubscribed");
return;
}
catch (Exception ex)
{
Console.WriteLine($"Reconnect failed: {ex.Message}");
}
}
Console.WriteLine("Reconnect failed 5 times, please check the network");
}
finally
{
Interlocked.Exchange(ref reconnecting, 0);
}
});
};
await futopt.Connect(5000, true); // 開啟連線健康檢查,連線靜默中斷時才會收到斷線通知
await SubscribeAll();
```
---
### Aggregates
接收訂閱期權聚合數據的行情資訊
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ------------ | ------- | ------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `books`, `aggregates`, `candles` |
| `symbol`\* | string | 期權代碼 |
| `afterHours` | boolean | 訂閱夜盤行情 true : 夜盤行情 false : 日盤行情 default : false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------ | ------- | ------------------------------------------------------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange` | string | 交易所 |
| `symbol` | string | 商品代號 |
| `name` | string | 商品名稱 |
| `previousClose` | number | 昨日收盤價 |
| `openPrice` | number | 開盤價 |
| `openTime` | number | 開盤價成交時間 |
| `highPrice` | number | 最高價 |
| `highTime` | number | 最高價成交時間 |
| `lowPrice` | number | 最低價 |
| `lowTime` | number | 最低價成交時間 |
| `closePrice` | number | 收盤價(最後成交價) |
| `closeTime` | number | 收盤價(最後成交價)成交時間 |
| `avgPrice` | number | 當日成交均價 |
| `change` | number | 最後成交價漲跌 |
| `changePercent` | number | 最後成交價漲跌幅 |
| `amplitude` | number | 當日振幅 |
| `lastPrice` | number | 最後一筆成交價(含試撮) |
| `lastSize` | number | 最後一筆成交數量(含試撮) |
| `total` | object | 成交統計 |
| >> `tradeVolume` | number | 累計成交量 |
| >> `totalBidMatch` | number | 累計委買成交筆數 |
| >> `totalAskMatch` | number | 累計委賣成交筆數 |
| >> `time` | number | 統計時間 |
| `lastTrade` | object | 最後一筆成交資訊 |
| >> `bid` | number | 最後一筆成交買價 |
| >> `ask` | number | 最後一筆成交賣價 |
| >> `price` | number | 最後一筆成交價格 |
| >> `size` | number | 最後一筆成交數量 |
| >> `time` | number | 最後一筆成交時間 |
| >> `serial` | string | 最後一筆成交流水號 |
| `lastTrial` | object | 最後一筆試撮資訊(僅試撮階段有值) |
| >> `bid` | number | 最後一筆試撮買價 |
| >> `ask` | number | 最後一筆試撮賣價 |
| >> `price` | number | 最後一筆試撮價格 |
| >> `size` | number | 最後一筆試撮數量 |
| >> `time` | number | 最後一筆試撮時間 |
| >> `serial` | string | 最後一筆試撮流水號 |
| `isTrial` | boolean | 是否處於試撮狀態:試撮階段為 `true`,非試撮時**省略此欄位**(缺省視為 `false`) |
| `serial` | number | 流水號 |
| `lastUpdated` | number | 最後異動時間 |
試撮欄位
`lastTrial` 為開盤前**試撮階段**的最後一筆試撮揭示(`bid`/`ask`/`price`/`size`/`time`/`serial`)。`isTrial` 反映最近一筆行情訊息是否為試撮——收到任何正式行情後即回到非試撮狀態並省略此欄位。
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order, Mode
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime(Mode.Normal) # 建立行情連線
futopt = sdk.marketdata.websocket_client.futopt
futopt.on('message', handle_message)
futopt.connect()
futopt.subscribe({
'channel': 'aggregates',
'symbol': 'TXFA4'
})
```
```js
const { FubonSDK, Mode } = require('fubon-neo');
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.initRealtime(Mode.Normal); // 建立行情連線
const futopt = sdk.marketdata.webSocketClient.futopt;
futopt.connect().then(() => {
futopt.subscribe({ channel: "aggregates", symbol: "TXFA4" });
});
futopt.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(Mode.Normal); // 建立行情連線
var futopt = sdk.MarketData.WebSocketClient.FutureOption;
futopt.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await futopt.Connect();
await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Aggregates, "TXFA4");
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"date": "2023-12-26",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "TXFA4",
"name": "臺股期貨014",
"previousClose": 17622,
"openPrice": 17651,
"openTime": 1703551500020000,
"highPrice": 17740,
"highTime": 1703560921393000,
"lowPrice": 17634,
"lowTime": 1703552892448000,
"closePrice": 17735,
"closeTime": 1703569500075000,
"avgPrice": 17700.51,
"change": 113,
"changePercent": 0.64,
"amplitude": 0.6,
"lastPrice": 17735,
"lastSize": 7,
"total": {
"tradeVolume": 52553,
"totalBidMatch": 26280,
"totalAskMatch": 26273
},
"lastTrade": {
"price": 17735,
"size": 7,
"time": 1703569500075000,
"serial": "00136127"
},
"lastTrial": {
"bid": 17734,
"ask": 17736,
"price": 17735,
"size": 1,
"time": 1703551499000000,
"serial": "00000003"
},
"serial": 136127,
"lastUpdated": 1703569500075000
},
"id": "",
"channel": "aggregates"
}
```
---
### Books
接收訂閱期權商品最新最佳五檔委買委賣資訊
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ------------ | ------- | ------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `books`, `aggregates`, `candles` |
| `symbol`\* | string | 契約代碼 |
| `afterHours` | boolean | 訂閱夜盤行情 true : 夜盤行情 false : 日盤行情 default : false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------ | --------- | --------------------------------------------------------------- |
| `symbol`\* | string | 期權代碼 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `time`\* | number | 時間 |
| `bids` | object\[] | 最佳五檔委買 |
| >> `price` | number | 最佳五檔委買價格 |
| >> `size` | number | 最佳五檔委買數量 |
| `asks` | object\[] | 最佳五檔委賣 |
| >> `price` | number | 最佳五檔委賣價格 |
| >> `size` | number | 最佳五檔委賣數量 |
| `derivedBid` | object | 衍生最佳一檔委買(延伸一檔;無衍生檔位時 `price`/`size` 為 0) |
| >> `price` | number | 衍生委買價格 |
| >> `size` | number | 衍生委買數量 |
| `derivedAsk` | object | 衍生最佳一檔委賣(延伸一檔;無衍生檔位時 `price`/`size` 為 0) |
| >> `price` | number | 衍生委賣價格 |
| >> `size` | number | 衍生委賣數量 |
| `isTrial` | boolean | 試撮階段為 `true`(僅試撮階段出現) |
info
'\*' 表示必揭示欄位。
衍生一檔與試撮欄位
* `derivedBid`/`derivedAsk`(延伸一檔)主要出現於**價差合約**之衍生報價,一般期貨通常為 `price=0`/`size=0`。
* `isTrial` 於商品處於**試撮階段**時可能為 `true`,包含開盤前試撮與盤中緩撮/試撮;正常連續撮合時,欄位可能為 `false` 或不出現。`isTrial: true` 時 `bids`/`asks` 為試撮後的剩餘委託簿,不是正式盤中委託簿。
* 此頻道的試撮訊息僅 `v1.1` 連線推送,`aggregates` 頻道在 `v1.0` 也會推送試撮期間的更新;連線版本設定見 [開始使用](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt)。
* 上述期權進階行情欄位 v2.2.9 起提供。
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
futopt = sdk.marketdata.websocket_client.futopt
futopt.on('message', handle_message)
futopt.connect()
futopt.subscribe({
'channel': 'books',
'symbol': 'TXFA4'
#'afterHours' : True # 夜盤行情
})
```
```js
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 futopt = sdk.marketdata.webSocketClient.futopt;
futopt.connect().then(() => {
futopt.subscribe({
channel: "books",
symbol: "TXFA4"
// afterHours: true //夜盤行情
});
});
futopt.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // 建立行情連線
var futopt = sdk.MarketData.WebSocketClient.FutureOption;
futopt.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await futopt.Connect();
await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Books, "TXFA4");
// await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Books, new FutureOptionParams { Symbol = "TXFC4", AfterHours = true }); // 夜盤行情
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"symbol": "TXFA4",
"type": "FUTURE",
"exchange": "TAIFEX",
"bids": [
{
"price": 17539,
"size": 2
},
{
"price": 17538,
"size": 4
},
{
"price": 17537,
"size": 3
},
{
"price": 17536,
"size": 10
},
{
"price": 17535,
"size": 10
}
],
"asks": [
{
"price": 17541,
"size": 2
},
{
"price": 17542,
"size": 15
},
{
"price": 17543,
"size": 3
},
{
"price": 17544,
"size": 5
},
{
"price": 17545,
"size": 4
}
],
"derivedBid": {
"price": 17540,
"size": 1
},
"derivedAsk": {
"price": 0,
"size": 0
},
"time": 1702956500113000
},
"id": "",
"channel": "books"
}
```
---
### Candles
接收訂閱期權商品最新分鐘K
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ------------ | ------- | ------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `books`, `aggregates`, `candles` |
| `symbol`\* | string | 契約代碼 |
| `afterHours` | boolean | 訂閱夜盤行情 true : 夜盤行情 false : 日盤行情 default : false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------- | ------ | -------------------------------------------------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `symbol`\* | string | 股票代號 |
| `timeframe`\* | number | K線週期 |
| `open`\* | number | K線開盤價 |
| `high`\* | number | K線最高價 |
| `low`\* | number | K線最低價 |
| `close`\* | number | K線收盤價 |
| `volume`\* | number | K線成交量(整股:成交張數;興櫃股票及盤中零股:成交股數;指數:成交金額) |
| `average`\* | number | 成交均價 |
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order, Mode
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime(Mode.Normal) # 建立行情連線
futopt = sdk.marketdata.websocket_client.futopt
futopt.on('message', handle_message)
futopt.connect()
futopt.subscribe({
'channel': 'candles',
'symbol': 'TXFA4'
})
```
```js
const { FubonSDK, Mode } = require('fubon-neo');
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID", "Your password", "Your cert path","Your cert password");
sdk.initRealtime(Mode.Normal); // 建立行情連線
const futopt = sdk.marketdata.webSocketClient.futopt;
futopt.connect().then(() => {
futopt.subscribe({ channel: "candles", symbol: "TXFA4" });
});
futopt.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(Mode.Normal); // 建立行情連線
var futopt = sdk.MarketData.WebSocketClient.FutureOption;
futopt.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await futopt.Connect();
await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Candles, "TXFA4");
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"symbol": "TXFA4",
"type": "FUTURE",
"exchange": "TAIFEX",
"date": "2023-12-28T12:01:00.000+08:00",
"open": 17861,
"high": 17862,
"low": 17859,
"close": 17862,
"volume": 22,
"average": 17820.19
},
"id": "",
"channel": "candles"
}
```
---
### Trades
接收訂閱期權商品最新成交資訊
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ------------ | ------- | ------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `books`, `aggregates`, `candles` |
| `symbol`\* | string | 期貨商品代碼 |
| `afterHours` | boolean | 訂閱夜盤行情 true : 夜盤行情 false : 日盤行情 default : false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------ | --------- | ----------------------------------------------------------- |
| `symbol`\* | string | 商品代號 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `trades` | object\[] | 成交報價 |
| >> `price` | number | 成交價格 |
| >> `size` | number | 成交單量 |
| >> `bid` | number | 成交買價 |
| >> `ask` | number | 成交賣價 |
| `total` | object | 成交量 |
| >> `tradeVolume` | number | 成交總量 |
| >> `totalBidMatch` | number | 委買成筆 |
| >> `totalAskMatch` | number | 委賣成筆 |
| `time`\* | number | 時間 |
| `serial`\* | number | 流水號 |
| `isTrial` | boolean | 試撮階段為 `true`(僅試撮階段出現,開盤後不再出現於回應中) |
info
'\*' 表示必揭示欄位。
試撮欄位
`isTrial` 僅於開盤前**試撮階段**揭示(`true`),開盤後即恢復正式撮合資料、不再出現此欄位。試撮階段的 `trades` 為試撮撮合結果、不是實際成交,請勿計入成交統計:
* 試撮訊息不累計統計量,`total.tradeVolume`/`total.totalBidMatch`/`total.totalAskMatch` 均為 0。
* 試撮未撮合出價格時,`trades[0].price`/`trades[0].size` 為 0,代表該次試撮無成交,並非成交價為 0。
此頻道的試撮訊息僅 `v1.1` 連線推送,`aggregates` 頻道在 `v1.0` 也會推送試撮期間的更新;連線版本設定見 [開始使用](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt)。此欄位 v2.2.9 起提供。
#### Example[](#example "Direct link to Example")
##### Subscribe channel[](#subscribe-channel "Direct link to Subscribe channel")
* Python
* Node.js
* C#
```python
from fubon_neo.sdk import FubonSDK, Order
def handle_message(message):
print(f'market data message: {message}')
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your cert path", "Your cert password") # 需登入後,才能取得行情權限
sdk.init_realtime() # 建立行情連線
futopt = sdk.marketdata.websocket_client.futopt
futopt.on('message', handle_message)
futopt.connect()
futopt.subscribe({
'channel': 'trades',
'symbol': 'TXFA4'
#'afterHours' : True # 夜盤行情
})
```
```js
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 futopt = sdk.marketdata.webSocketClient.futopt;
futopt.connect().then(() => {
futopt.subscribe({
channel: "trades",
symbol: "TXFA4"
// afterHours: true //夜盤行情
});
});
futopt.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
var sdk = new FubonSDK();
var result = sdk.Login("Your ID", "Your password", "Your cert path", "Your cert password");
sdk.InitRealtime(); // 建立行情連線
var futopt = sdk.MarketData.WebSocketClient.FutureOption;
futopt.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await futopt.Connect();
await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Trades, "TXFA4");
// await futopt.Subscribe(FugleMarketData.WebsocketModels.FutureOptionChannel.Trades, new FutureOptionParams { Symbol = "TXFC4", AfterHours = true }); // 夜盤行情
```
訂閱多檔商品
同時訂閱多檔商品方式,請參考 [訂閱頻道](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.txt#%E8%A8%82%E9%96%B1%E9%A0%BB%E9%81%93)
##### Receive data[](#receive-data "Direct link to Receive data")
```json
{
"event": "data",
"data": {
"symbol": "TXFA4",
"type": "FUTURE",
"exchange": "TAIFEX",
"trades": [
{
"price": 17540,
"size": 1,
"bid": 17539,
"ask": 17540
}
],
"total": {
"tradeVolume": 12174,
"totalBidMatch": 8760,
"totalAskMatch": 7907
},
"time": 1702956487023000,
"serial": 159250
},
"id": "",
"channel": "trades"
}
```
###### 試撮階段(`isTrial`)[](#試撮階段istrial "Direct link to 試撮階段istrial")
開盤前試撮階段,`data` 會多帶 `isTrial: true`:
```json
{
"event": "data",
"data": {
"symbol": "TXFF6",
"type": "FUTURE_AH",
"exchange": "TAIFEX",
"trades": [
{
"price": 45380,
"size": 1
}
],
"total": {
"tradeVolume": 0,
"totalBidMatch": 0,
"totalAskMatch": 0
},
"isTrial": true,
"time": 1781506205000000,
"serial": 3
},
"channel": "trades"
}
```
---
### 模式切換
**適用版本 v1.3.1 及以上**
#### 行情 WebSocket 模式切換[](#行情-websocket-模式切換 "Direct link to 行情 WebSocket 模式切換")
新版本功能中,提供 Low Latency 行情與多資訊的 Socket 行情切換
##### 引入套件 (僅 Python 、 NodeJs 需要, C#不需額外操作)[](#引入套件-僅-python--nodejs-需要-c不需額外操作 "Direct link to 引入套件 (僅 Python 、 NodeJs 需要, C#不需額外操作)")
* Python
* Node.js
```py
# 引入Mode 套件模組
from fubon_neo.sdk import FubonSDK, Mode
```
```js
const { FubonSDK, Mode } = require('fubon-neo');
```
* Python
* Node.js
* C#
```python
sdk.init_realtime(Mode.Speed) # 提供Speed / Normal選擇 (default 為Speed)
#sdk.init_realtime(Mode.Speed) or sdk.init_realtime(Mode.Normal)
futopt = sdk.marketdata.websocket_client.futopt
futopt.on('message', handle_message)
futopt.connect()
```
```js
sdk.initRealtime(Mode.Speed); // 提供Speed / Normal選擇 (default 為Speed)
// sdk.initRealtime(Mode.Speed) or sdk.initRealtime(Mode.Normal)
const futopt = sdk.marketdata.webSocketClient.futopt;
futopt.connect().then(() => {
futopt.subscribe({
channel: "trades",
symbol: "TXFA4"
// afterHours: true //夜盤行情
});
});
futopt.on("message", (message) => {
const data = JSON.parse(message);
console.log(data);
});
```
```cs
using FubonNeo.Sdk;
using FugleMarketData.WebsocketModels; // 新增 "Mode"
sdk.InitRealtime(Mode.Speed); // 提供Speed / Normal選擇 (default 為Speed)
// sdk.initRealtime(Mode.Speed) or sdk.initRealtime(Mode.Normal)
var futopt = sdk.MarketData.WebSocketClient.FutureOption;
futopt.OnMessage += (msg) => Console.WriteLine($"receive: { msg }");
await futopt.Connect();
```
---
### 停損停利單
富邦新一代 API 支援條件下單後的停損停利單,
停損停利運作機制 : 當觸發的條件單,觸發後,並委託成交,就會啟動停損停利的監控機制,而當停利條件達成時,停損就會失效;反之亦然 (同一般市面上常見 OCO)

#### 程式範例[](#程式範例 "Direct link to 程式範例")
* Python
* Node.js
* C#
```py
# 設計條件內容
condition = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.MatchedPrice,
trigger_value = "66",
comparison = Operator.LessThan
)
order = ConditionOrder(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 1000,
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
# 停損停利若為Market , price 則填空值""
tp = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="85",
price="85",
# trigger=TriggerContent.MatchedPrice # v2.2.0 新增
)
sl = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="60",
price="60",
# trigger=TriggerContent.MatchedPrice # v2.2.0 新增
)
tpsl = TPSLWrapper(
stop_sign= StopSign.Full,
tp=tp, # optional field
sl=sl, # optional field
end_date="20240517",
intraday =False # optional field
)
sdk.stock.single_condition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)
```
```js
// 設計條件內容
const condition = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.MatchedPrice,
triggerValue: "80",
comparison: Operator.LessThan
}
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: ConditionMarketType.Common,
priceType: ConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
};
// 停損停利若為Market , price 則填空值""
const tp = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "85",
price: "85",
// trigger: TriggerContent.MatchPrice // v2.2.0 新增
}
const sl = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "60",
price: "60",
// trigger: TriggerContent.MatchPrice // v2.2.0 新增
}
const tpsl = {
stopSign: StopSign.Full,
tp: tp, // optional field
sl: sl, // optional field
endDate: "20240517",
intraday: false // optional field
}
sdk.stock.singleCondition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)
```
```cs
// 設計條件內容
var condition = new Condition(
TradingType.Reference,
"2881",
TriggerContent.MatchedPrice,
"66",
Operator.LessThan
);
var order = new ConditionOrder(
BsAction.Buy,
"2881",
"66",
2000,
ConditionMarketType.Common,
ConditionPriceType.Limit,
TimeInForce.Rod,
ConditionOrderType.Stock
);
// 停損停利若為Market , price 則填空值""
var tp = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"85",
"85",
null // 2.2.0 以後版本使用,詳請見 [參數對照表] -> [TpslOrder Object]
);
var sl = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"60",
"60",
null // 2.2.0 以後版本使用,詳請見 [參數對照表] -> [TpslOrder Object]
);
var tpsl = new TpslWrapper(
StopSign.Full,
tp,
sl,
"20240517",
false
);
sdk.Stock.SingleCondition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)
```
---
### 移動鎖利條件單
富邦新一代 API 支援移動鎖利單,
移動鎖利運作機制 : 當基準條件觸發後,若設定的回檔幅度未達到,則不會觸發,當後續股價持續往上,則會使用新的價格作為基準,若此時回檔幅度到達設定值,則送出委託

##### 程式範例[](#程式範例 "Direct link to 程式範例")
* Python
* Node.js
* C#
```py
# 設計條件內容
trail = TrailOrder(
symbol = "2330",
price = "1000",
direction = Direction.Down ,
percentage = 5, # 漲跌 % 數
buy_sell = BSAction.Sell,
quantity = 2000,
price_type = ConditionPriceType.MatchedPrice,
diff = 1, # 向上 or 向下追買 tick數 (向下為負值)
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
sdk.stock.trail_profit(target_account, "20240427","20240516", StopSign.Full, trail)
```
```js
// 設計條件內容
const trail = {
symbol: "2330",
price: "1000",
direction: Direction.Down,
percentage: 5,
buySell: BSAction.Sell,
quantity: 2000,
priceType: ConditionPriceType.MatchedPrice,
diff: 1,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
};
sdk.stock.trailProfit(target_account, "20240427","20240516", StopSign.Full, trail)
```
```cs
// 設計條件內容
var trail = new TrailOrder(
"2330",
"1000",
Direction.Down ,
5, // 漲跌 % 數
BsAction.Sell,
2000,
ConditionPriceType.MatchedPrice,
1, // 向上 or 向下追買 tick數 (向下為負值)
TimeInForce.Rod,
ConditionOrderType.Stock
);
sdk.Stock.TrailProfit(target_account, "20240427","20240516", StopSign.Full, trail);
```
---
### 條件單使用說明
本公司為服務投資人,提供網路下單客戶得預先設定下單條件之條件下單功能服務(以下簡稱本功能或本服務)。本服務不收取任何費用,但本公司保留得隨時調整、修正、暫停或終止此項服務之權利;為確保使用者權益及網路交易安全秩序,請投資人於啟用本功能前,詳細閱讀以下條款,以保障投資人的權利,在投資人點選本使用同意書下方之同意鈕,即視為已經詳閱並接受本同意書之內容。
一、條件下單功能服務具有以下(但不限於此)之風險,投資人應自承以下風險所衍生之損害或損失:
1 網際網路之傳輸通訊,可能因不可抗力或不可歸責於本公司之事由,包括(但不在此限)斷電、斷線、網路壅塞等因素,導致資料傳輸延遲、停滯、無法發出或無法接收。
2 本功能或服務有可能因病毒、系統或機件發生故障、錯誤、執行障礙,駭客入侵等因素,導致資料或資訊傳送發生遺漏、錯誤、或遭竄改。
3 其他網路交易之風險。
二、條件下單功能服務,係依據投資人設定之個股或期貨商品種類及下單條件,提供即時有效之資訊,並結合既有之網路下單功能,允許投資人在同一網頁操作證券或期貨下單之委託指示。本公司目前所提供之條件下單功能服務包括觸價下單、觸量下單、定時下單、長效停損/停利下單及多條件下單共五種(簡稱為條件下單),不同種類的條件下單,其設定方式、效力有可能不同,或受有特別限制,投資人於設定每一筆條件下單前應詳細閱讀注意事項,審慎為之。
三、經觸發條件下單功能服務「直接下單」功能鍵後,具有與口頭、電話、傳真、網路下單相同之效力,如經成交即不得取消,投資人負有交割義務,以及證券、期貨相關法令所規定之各項責任。
四、投資人得於成交前以網路或電話方式變更或取消委託,投資人於下單前應充分瞭解有關變更或取消委託之操作。因不可抗力或不可歸責於本公司之事由,包括(但不在此限)斷電、斷線、網路壅塞、傳輸干擾等因素,致變更或取消意思表示無法即時送達之風險,由投資人自行負擔。
五、基於網路維運、符合資訊法規及網路規範、確保網路交易安全,或服從主管機關之命令等因素,對於有礙系統正常運作、或可能造成系統資訊不穩定、或其他異常狀況之條件下單,本公司保留刪除之權利。如經決定刪除,本公司將另以電子平台公告、行動簡訊或電子郵件通知投資人,並請投資人至富邦證券網站、HTS 快易點、HTS2 多易點及 Online 查詢條件下單訊息公告。
六、經公告於本公司網站上之其他有關電子下單、客戶資料使用、網站管理、保密措施等規範,於條件下單功能服務均有其適用。如有未盡事宜,悉照中華民國相關法令以及經公告之網際網路交易規範為準據。
七、請投資人依本公司條件下單之下單規則,於完成有效期間條件下單之設定後, 請於該條件下單之有效期間內之每一營業日當日查詢該條件下單狀態;條件下單之詳細狀態僅保留至當日,若投資人對條件下單狀態有疑慮,請於該筆交易當日洽詢所屬分公司營業同仁。如交易當日條件下單有故障或因不可抗力因素導致系統無法送單情形,則該交易視為未下單處理。
注意事項:
1. 如使用條件單訂閱功能,請務必確認各項訂閱條件內容,避免產生錯誤。另提醒投資人,此為訂閱功能,待條件符合,才會觸發下單,如欲查詢訂閱狀況可至富邦 Online/HTS2 多易點/HTS 快易點。
2. 就前述訂閱功能,投資人可設定條件單觸發後,系統以 e-mail 發送觸發通知給投資人,或直接下單。如不熟悉條件單操作流程,建議設定觸發通知,待熟悉後再選擇直接下單。
3. 如使用定時單下最後一盤,建議設定停盤丟單,因條件單主機與交易所主機不同,雖然固定每 3 分鐘進行 1 次網路校時,但難免出現秒差(如設定 13:25 下單,可能會下在 13:24:59),請留意。
4. 條件單接受比對 A 商品下 B 商品,設定 A 商品時會自動帶委託 A 商品,要委託 B 商品請手動調整。
5. 當投資人設定之行情條件觸發且本系統送出投資人設定之委託單後,本公司會將該委託單送至交易所,該委託單將會轉為一般委託,此時無法取消訂閱該筆條件單,請直接使用下單查詢功能,查找觸發後的一般委託進行改單調整。
6. 條件單訂閱冷門商品,有可能會碰到開盤沒報價或價格穩定措施 3 分鐘無行情,這時條件單會進入等價狀況,待有行情才會開始繼續洗價比對。
7. 請留意,使用條件單訂閱功能時,待觸發送單後才會與本公司後台風控進行比對。
8. 請留意,證期權多條件長效單、移動鎖利條件單、庫存停損利條件單之效期最長為 3 個月,定時定額條件單效期最長為 6 個月。
9. 其餘未盡事宜請參閱各條件單介面下方注意事項,確認閱讀內容完畢後始得訂閱條件單。
---
### 錯誤碼與狀態碼對照表
本頁面彙整了富邦新一代 API(條件單)中常見的狀態碼,方便開發者在遇到問題或進行狀態判斷時快速檢索。
#### 條件單狀態 (ConditionStatus)[](#條件單狀態-conditionstatus "Direct link to 條件單狀態 (ConditionStatus)")
條件單的當前狀態。
| 狀態名稱 | 說明 |
| -------- | ------------ |
| `Type1` | 今日相關查詢 |
| `Type2` | 尚有效單 |
| `Type3` | 條件比對中 |
| `Type4` | 委託處理中 |
| `Type5` | 委託成功 |
| `Type6` | 已通知 |
| `Type7` | 委託失敗 |
| `Type8` | 已有成交 |
| `Type9` | 刪除成功 |
| `Type10` | 異常 |
| `Type11` | 失效 |
#### 歷史條件單狀態 (HistoryStatus)[](#歷史條件單狀態-historystatus "Direct link to 歷史條件單狀態 (HistoryStatus)")
歷史條件單的狀態。
| 狀態名稱 | 說明 |
| -------- | ------------------------------- |
| `Type1` | 所有條件單 (不包含已刪除、失效) |
| `Type2` | 選擇期間內全部成交單 |
| `Type3` | 選擇期間內部分成交單 |
| `Type4` | 選擇期間刪除單 |
| `Type5` | 選擇期間失效單 |
| `Type6` | 選擇期間內已觸發記錄 |
---
### 富邦新一代 API 條件單
本頁重點
* 本頁介紹富邦新一代 API 條件單功能與支援範圍。
* 提供多種條件單類型,適用自動化策略與風險管理。
* 下一步建議先完成 [事前準備](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/prepare.txt)。
| 項目 | 說明 |
| -------- | -------------------------------------------------------------------------- |
| 產品 | 富邦新一代 API 條件單 |
| 主要功能 | 觸價/觸量、停損停利、分時分量 |
| 平台 | Windows / macOS / Linux |
| 語言 | Python / C# / JavaScript (Node.js) / C++、Go(僅支援證券交易帳務及條件單) |
| 前置 | 需簽署條件單使用同意書 |
#### 概述[](#概述 "Direct link to 概述")
富邦新一代 API 條件單為您的程式交易,提供了更完善的功能,滿足每一位開發者達成條件下單。
提供用戶自由選擇主流開發語言( Python、C#、JavaScript),在創建程式交易的過程中,輕易地取用 API,使用 API 各種功能。
#### 特色[](#特色 "Direct link to 特色")
支援跨平台:
新一代 API 支援 Windows、macOS、Linux。
新一代 API 支援 Python、C#、JavaScript(Node.js)、C++、Go 主流語言(C++、Go 僅支援證券交易帳務及條件單)。
#### 主要功能[](#主要功能 "Direct link to 主要功能")
直接管理交易:建立單一條件觸價觸量單、多條件觸價觸量單、停損停利單、分時分量單···等。
#### 版本支援[](#版本支援 "Direct link to 版本支援")
Python 版本支援:3.7(~v1.3.2)、3.8–3.13(v2.0.1~,不含 3.14)。 Node.js 版本支援 : 目前支援 Node.js 16 以上的版本。 C# 使用 .NET Standard 2.0 開發,建議您使用 .netcoreapp 3.1 以上;如使用 .NET Framework 建議您使用 .NET Framework 4.7.2 以上版本。
---
### 取消條件單
cancel\_condition\_orders
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | ----------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 CancelResult 欄位[](#委託資訊-cancelresult--欄位 "Direct link to 委託資訊 CancelResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| -------- | ------ | ------------ |
| advisory | string | 回覆狀態內容 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
auto cancel_condition = sdk->stock->cancel_condition_orders(target_account, "564b7ad6-a332-470c-93ea-cf3fea00d7fa");
if (!cancel_condition.is_success) {
std::cout << "cancel condition result failed reason: "
<< (cancel_condition.message.has_value() ? cancel_condition.message.value() : "No message")
<< std::endl;
}
else {
if (cancel_condition.data.has_value()) {
for (const auto& result : cancel_condition.data.value()) {
std::cout << result << std::endl;
}
}
else {
std::cout << "cancel condition success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
Result {
isSuccess = true,
message = None,
data = CancelResult {
advisory = 成功筆數:1,失敗筆數:0!
}
}
```
---
### 當沖條件單查詢
get\_condition\_daytrade\_by\_id
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | ----------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| create\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpsl\_count | string | 停損停利筆數 |
| tpsl\_record | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
auto get_daytrade_conditionid = sdk->stock->get_condition_daytrade_by_id(target_account, "564b7ad6-a332-470c-93ea-cf3fea00d7fa");
if (!get_daytrade_conditionid.is_success) {
std::cout << "get condition result failed reason: "
<< (get_daytrade_conditionid.message.has_value() ? get_daytrade_conditionid.message.value() : "No message")
<< std::endl;
}
else {
if (get_daytrade_conditionid.data.has_value()) {
for (const auto& result : get_daytrade_conditionid.data.value()) {
std::cout << result << std::endl;
}
}
else {
std::cout << "Condition result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data =
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords = ,
tPSLCount = 0,
tPSLRecord =
}
}
```
---
### 當沖多條件單
multi\_conditions\_day\_trade
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定回補成功,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合當日沖銷交易規則(例如信用交易使用資券互抵)
當沖條件單查詢
* 使用 guid 查詢當沖條件單請使用***當沖條件單查詢***功能
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL` 部分成交為止、`UNTIL_END` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditiondaytrade-object) | 當沖委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
| FixSession | bool | 當沖回補 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
// 設計條件內容
Condition condition = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::MATCHED_PRICE,
"66",
Operator::LESS_THAN,
};
Condition condition2 = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::TOTAL_QUANTITY,
"1000",
Operator::GREATER_THAN,
};
std::vector conditions;
conditions.push_back(condition);
conditions.push_back(condition2);
ConditionOrder order = ConditionOrder{
BsAction::BUY,
"2330",
"1000",
1000,
ConditionMarketType::COMMON,
ConditionPriceType::LIMIT,
TimeInForce::ROD,
ConditionOrderType::STOCK,
};
ConditionDayTrade day_order = ConditionDayTrade{
"131500", // 收盤前沖銷時間,可設定區間為 130100 ~ 132000
true,
"",
ConditionPriceType::MARKET
};
TpslOrder tp = TpslOrder{
TimeInForce::ROD,
ConditionPriceType::LIMIT,
ConditionOrderType::STOCK,
"85",
"85",
};
TpslOrder sl = TpslOrder{
TimeInForce::ROD,
ConditionPriceType::LIMIT,
ConditionOrderType::STOCK,
"60",
"60",
};
TPSLWrapper tpsl = TPSLWrapper{
StopSign::FULL,
tp,
sl,
"20250816",
true // ** 設定 true 以啟用當日沖銷洗價
};
auto daytrade_condition_order = sdk->stock->multi_condition_day_trade(target_account, StopSign::FULL, "130000", conditions , order, day_order, tpsl, true);
if (!daytrade_condition_order.is_success) {
std::cout << "get order result failed reason: "
<< (daytrade_condition_order.message.has_value() ? daytrade_condition_order.message.value() : "No message")
<< std::endl;
}
else {
if (daytrade_condition_order.data.has_value()) {
const auto& send = daytrade_condition_order.data.value();
std::cout << send << std::endl;
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX
}
}
```
---
### 當沖單一條件單
single\_condition\_day\_trade
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定回補成功,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合當日沖銷交易規則(例如信用交易使用資券互抵)
當沖條件單查詢
* 使用 guid 查詢當沖條件單請使用***當沖條件單查詢***功能
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL` 部分成交為止、`UNTIL_END` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditiondaytrade-object) | 當沖委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
| FixSession | bool | 當沖回補 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
// 設計條件內容
Condition condition = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::MATCHED_PRICE,
"66",
Operator::LESS_THAN,
};
ConditionOrder order = ConditionOrder{
BsAction::BUY,
"2330",
"1000",
1000,
ConditionMarketType::COMMON,
ConditionPriceType::LIMIT,
TimeInForce::ROD,
ConditionOrderType::STOCK,
};
ConditionDayTrade day_order = ConditionDayTrade{
"131500", // 收盤前沖銷時間,可設定區間為 130100 ~ 132000
true,
"",
ConditionPriceType::MARKET
};
TpslOrder tp = TpslOrder{
TimeInForce::ROD,
ConditionPriceType::LIMIT,
ConditionOrderType::STOCK,
"85",
"85",
};
TpslOrder sl = TpslOrder{
TimeInForce::ROD,
ConditionPriceType::LIMIT,
ConditionOrderType::STOCK,
"60",
"60",
};
TPSLWrapper tpsl = TPSLWrapper{
StopSign::FULL,
tp,
sl,
"20250816",
true // ** 設定 true 以啟用當日沖銷洗價
};
auto daytrade_condition_order = sdk->stock->single_condition_day_trade(target_account, StopSign::FULL, "130000", condition , order, day_order, tpsl, true);
if (!daytrade_condition_order.is_success) {
std::cout << "get order result failed reason: "
<< (daytrade_condition_order.message.has_value() ? daytrade_condition_order.message.value() : "No message")
<< std::endl;
}
else {
if (daytrade_condition_order.data.has_value()) {
const auto& send = daytrade_condition_order.data.value();
std::cout << send << std::endl;
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX
}
}
```
---
### 參數對照表
#### 類別[](#類別 "Direct link to 類別")
Class
##### Condition Object[](#condition-object "Direct link to Condition Object")
| Parameter | Type | Meaning |
| ------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| marketType | TradingType | [監控類型](#tradingtype) 可選用參數 : `REFERENCE` 自動參考委託物件、`SCHEDULED` 時間 |
| symbol | string | 股票代號 |
| trigger | TriggerContent | [觸發條件](#triggercontent) 可選用參數 : `BID_PRICE` 買進價、`ASK_PRICE` 賣出價、`MATCHED_PRICE` 成交價、`TOTAL_QUANTITY` 總量、`TIME` 時間 |
| triggerValue | string | 監控條件數值 (若為時間則填入 HHMMSS) |
| comparison | Operator | [比對值](#operator) 可選用參數 `GREATER_THAN_OR_EQUAL` 大於等於、`LESS_THAN_OR_EQUAL` 小於等於 、 `GREATER_THAN` 大於 、 `LESS_THAN` 小於 |
info
1. 選擇 `REFERENCE` 時, trigger 可搭配 `BID_PRICE` 、`ASK_PRICE` 、`MATCHED_PRICE` 、`TOTAL_QUANTITY` 、 `TIME`,若 trigger 使用 `TIME`,則時間條件達成,且時間範圍內商品有交易產生才觸發
2. 選擇 `SCHEDULED` 時,symbol 需填入空值"",trigger 需帶入 `TIME`,則會使用系統時間判斷,當時間條件達成即觸發
##### ConditionOrder Object[](#conditionorder-object "Direct link to ConditionOrder Object")
| Parameter | Type | Meaning |
| ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| buySell | BsAction | [買賣別](#bsaction) |
| symbol | string | 股票代號 |
| price | string | 委託價格 |
| quantity | int | 委託數量 |
| marketType | ConditionMarketType | [盤別](#conditionmarkettype) 可選用參數 `COMMON` 整股、`FIXING` 定盤、`INTRADAY_ODD` 盤中零股、`ODD` 盤後零股 |
| priceType | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BID_PRICE` 買進價、 `ASK_PRICE` 賣出價、`MATCHED_PRICE` 成交價、`LIMIT` 限價、`LIMIT_UP` 漲停、`LIMIT_DOWN` 跌停、`MARKET` 市價、`REFERENCE` 參考價(平盤價) |
| timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) : 可選參數 :`STOCK` 現貨、`MARGIN` 融資、`SHORT` 融券 |
##### ConditionDayTrade Object[](#conditiondaytrade-object "Direct link to ConditionDayTrade Object")
| Parameter | Type | Meaning |
| --------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| dayTradeEndTime | string | 收盤前沖銷時間,格式 "HHMMSS" (例 "130000");可設定區間為 130100 ~ 132000 |
| autoCancel | bool | 洗價結束後是否刪除已觸發委託 |
| price | string | 委託價格 (若無指定價格,例如市價單,請填空字串 "") |
| priceType | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BID_PRICE` 買進價、 `ASK_PRICE` 賣出價、`MATCHED_PRICE` 成交價、`LIMIT` 限價、`LIMIT_UP` 漲停、`LIMIT_DOWN` 跌停、`MARKET` 市價、`REFERENCE` 參考價(平盤價) |
關於收盤前沖銷時間
可設定區間為 130100 ~ 132000
##### TpslOrder Object[](#tpslorder-object "Direct link to TpslOrder Object")
| Parameter | Type | Meaning |
| ----------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| timeInForce | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`ROD`、`IOC`、`FOK` |
| priceType | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BID_PRICE` 買進價、 `ASK_PRICE` 賣出價、`MATCHED_PRICE` 成交價、`LIMIT` 限價、`LIMIT_UP` 漲停、`LIMIT_DOWN` 跌停、`MARKET` 市價、`REFERENCE` 參考價(平盤價) |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) : 可選參數 :`STOCK` 現貨、`MARGIN` 融資、`SHORT` 融券 |
| targetPrice | string | 停損/停利觸發價 |
| price | string | 停損/停利委託價 |
| trigger | TriggerContent | 停損/停利 [觸發條件](#triggercontent) (詳見表末說明) |
info
`priceType` 若為 `LIMIT` 時,`price` 需填入價格;其餘 price 填入 std::nullopt
停損/停利觸發條件
2.2.0 以後版本新增(***2.1.1 及以前版本無此欄位***),可設定停損/停利觸發價格別為 1. MATCHED\_PRICE 2. 最佳買價(BID\_PRICE);3. 最佳賣價(ASK\_PRICE)
若未設定則此欄位填入 ***null***, 預設使用 成交價(MATCHED\_PRICE)
##### TpslWrapper Object[](#tpslwrapper-object "Direct link to TpslWrapper Object")
| Parameter | Type | Meaning |
| --------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| stopSign | StopSign | [停止條件](#stopsign) : 可選用 `FULL` 全部成交為止、`PARTIAL` 部分成交為止、`UNTIL_END` 效期結束為止 |
| tp | TpslOrder Object (Optional) | 停利條件內容 |
| sl | TpslOrder Object (Optional) | 停損條件內容 |
| endDate | string (Optional : 空值同母單 StartDate) | 條件停止日期 |
| intraday | bool (Optional) | 全部成交後日內當沖 ( \* 配合當沖條件單使用時需設為 `true`) |
日內當沖
使用當沖條件單時,`intraday` 需設定為 `true`
##### TrailOrder[](#trailorder "Direct link to TrailOrder")
| Parameter | Type | Meaning |
| ----------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| symbol | string | 股票代號 |
| price | string | 基準價 (Note. 只可輸入至多小數點後兩位,若超出將造成系統洗價失敗) |
| direction | Direction | [方向](#direction) : 可選用 `UP` 上漲、`DOWN` 下跌 |
| percentage | int | 上漲 / 下跌 % 數 |
| buysell | BsAction | 買賣別 : 可選用 `BUY` 買進 、`SELL` 賣出 |
| quantity | int | 委託股數 |
| PriceType | ConditionPriceType | [價格類別](#conditionpricetype) : 可選用 `BID_PRICE` 買進價、`ASK_PRICE` 賣出價、`MATCHED_PRICE` 成交價、`MARKET` 市價、`LIMIT_UP` 漲停價、`LIMIT_DOWN` 跌停價、`REFERENCE` 參考價(平盤價) |
| diff | int | 委託買賣價格檔數 (根據 priceType 加減檔數) ,正值為向上加檔數、負值為向下加檔數 |
| timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) 可選用參數為 `STOCK` 現股、`MARGIN` 融資、`SHORT` 融券 |
##### SplitDescription[](#splitdescription "Direct link to SplitDescription")
| Parameter | Type | Meaning |
| -------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| method | SliceType | [Slice Condition](#slicetype) : 可選用 :
`TYPE1` 從 `startTime` 開始,每隔幾秒送一筆,總共 `totalQuantity`,每筆送 `singleQuantity`
`TYPE2` 從 `startTime` 開始到 `endTime` 結束,每隔 `interval` 秒送一筆,總共 `totalQuantity`,剩餘張數加總至最後一筆
`TYPE3` 從 `startTime` 開始到 `endTime` 結束,每隔 `interval` 秒送一筆,總共 `totalQuantity`,剩餘張數從最後一筆往前分配.
|
| interval | int | 下單間隔時間 (秒) |
| singleQuantity | int | 單筆下單量 (股數) |
| totalQuantity | int (Optional) | 總共下單量 (股數) |
| startTime | string | 開始時間 |
| endTime | string (Optional) | 結束時間 |
caution
請注意,總共下單量需大於單筆下單量。
##### ConditionOrderResult[](#conditionorderresult "Direct link to ConditionOrderResult")
| Parameter | Type | Meaning |
| --------- | ------ | -------- |
| guid | string | 條件單號 |
#### Constants ( 欄位對應數值 )[](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )")
##### BsAction[](#bsaction "Direct link to BsAction")
買賣別
| Name | Value | Meaning |
| ------------- | ----- | ------------ |
| BUY | 1 | 買 |
| SELL | 2 | 賣 |
| UN\_SUPPORTED | 3 | 不支援此型別 |
| UN\_DEFINED | 4 | 未定義此型別 |
##### ConditionMarketType[](#conditionmarkettype "Direct link to ConditionMarketType")
盤別
| Name | Value | Meaning |
| ------------- | ----- | -------- |
| COMMON | 1 | 一般盤 |
| FIXING | 2 | 定盤 |
| INTRADAY\_ODD | 3 | 盤中零股 |
| ODD | 4 | 盤後零股 |
##### TradingType[](#tradingtype "Direct link to TradingType")
監控類型
| Name | Value | Meaning |
| --------- | ----- | ---------------- |
| REFERENCE | 1 | 自動參考委託物件 |
| SCHEDULED | 3 | 時間 |
##### TriggerContent[](#triggercontent "Direct link to TriggerContent")
觸發條件
| Name | Value | Meaning |
| --------------- | ----- | ------- |
| BID\_PRICE | 1 | 買進價 |
| ASK\_PRICE | 2 | 賣出價 |
| MATCHED\_PRICE | 3 | 成交價 |
| TOTAL\_QUANTITY | 4 | 總量 |
| TIME | 5 | 時間 |
##### Operator[](#operator "Direct link to Operator")
| Name | Value | Meaning |
| ------------------------ | ----- | -------- |
| GREATER\_THAN\_OR\_EQUAL | 1 | 大於等於 |
| LESS\_THAN\_OR\_EQUAL | 2 | 小於等於 |
| GREATER\_THAN | 3 | 大於 |
| LESS\_THAN | 4 | 小於 |
##### StopSign[](#stopsign "Direct link to StopSign")
| Name | Value | Meaning |
| ---------- | ----- | ------------ |
| FULL | 1 | 全部成交為止 |
| PARTIAL | 2 | 部分成交為止 |
| UNTIL\_END | 3 | 效期結束為止 |
##### TimeInForce[](#timeinforce "Direct link to TimeInForce")
委託條件 (TimeInForce)
| Name | Value | Meaning |
| ------------- | ----- | ------------------------------------- |
| ROD | 1 | 當日有效(Rest of Day) |
| FOK | 2 | 全部成交否則取消(Fill-or-Kill) |
| IOC | 3 | 立即成交否則取消(Immediate-or-Cancel) |
| UN\_SUPPORTED | 4 | 不支援此型別 |
| UN\_DEFINED | 5 | 未定義此型別 |
##### ConditionPriceType[](#conditionpricetype "Direct link to ConditionPriceType")
價格類型 (ConditionPriceType)
| Name | Value | Meaning |
| -------------- | ----- | -------------- |
| LINIT | 1 | 限價 |
| BID\_PRICE | 2 | 買進價 |
| ASK\_PRICE | 3 | 賣出價 |
| MARKET | 4 | 市價 |
| MATCHED\_PRICE | 5 | 成交價 |
| LIMIT\_UP | 6 | 漲停價 |
| LIMIT\_DOWN | 7 | 跌停價 |
| REFERENCE | 8 | 參考價(平盤價) |
##### ConditionOrderType[](#conditionordertype "Direct link to ConditionOrderType")
委託類型 (orderType)
| Name | Value | Meaning |
| ---------- | ----- | -------- |
| STOCK | 1 | 現貨 |
| MARGIN | 2 | 融資 |
| SHORT | 3 | 融券 |
| DAY\_TRADE | 4 | 現股當沖 |
##### Direction[](#direction "Direct link to Direction")
移動鎖利上漲/下跌追蹤 (direction)
| Name | Value | Meaning |
| ---- | ----- | ------- |
| Up | 1 | 上漲 |
| Down | 2 | 下跌 |
##### SliceType[](#slicetype "Direct link to SliceType")
分單型態 (SliceType)
| Name | Meaning |
| ----- | -------------------------------------------------------------------- |
| Type1 | 從開始時間,每隔幾秒送一筆,總共送 N 筆,每筆送 M 張 |
| Type2 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數加總至最後一筆 |
| Type3 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數從最後一筆往前分配 |
##### ConditionStatus[](#conditionstatus "Direct link to ConditionStatus")
條件單狀態 (ConditionStatus)
| Name | Meaning |
| ------ | ------------ |
| Type1 | 今日相關查詢 |
| Type2 | 尚有效單 |
| Type3 | 條件比對中 |
| Type4 | 委託處理中 |
| Type5 | 委託成功 |
| Type6 | 已通知 |
| Type7 | 委託失敗 |
| Type8 | 已有成交 |
| Type9 | 刪除成功 |
| Type10 | 異常 |
| Type11 | 失效 |
##### HistoryStatus[](#historystatus "Direct link to HistoryStatus")
歷史條件單狀態 (HistoryStatus)
| Name | Meaning |
| ----- | -------------------------------- |
| Type1 | 所有條件單 ( 不包含已刪除、失效) |
| Type2 | 選擇期間內全部成交單 |
| Type3 | 選擇期間內部分成交單 |
| Type4 | 選擇期間刪除單 |
| Type5 | 選擇期間失效單 |
| Type6 | 選擇期間內已觸發記錄 |
---
### 條件單查詢 By 條件單號
get\_condition\_order\_by\_id
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | ----------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| create\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpsl\_count | string | 停損停利筆數 |
| tpsl\_record | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
auto get_conditionid = sdk->stock->get_condition_order_by_id(target_account, "564b7ad6-a332-470c-93ea-cf3fea00d7fa");
if (!get_conditionid.is_success) {
std::cout << "get condition result failed reason: "
<< (get_conditionid.message.has_value() ? get_conditionid.message.value() : "No message")
<< std::endl;
}
else {
if (get_conditionid.data.has_value()) {
for (const auto& result : get_conditionid.data.value()) {
std::cout << result << std::endl;
}
}
else {
std::cout << "Condition result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data =
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords = ,
tPSLCount = 0,
tPSLRecord =
}
}
```
---
### 歷史條件單查詢
GetConditionHistory
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| startDate | string | 查詢條件單創建日 |
| endDate | string | 查詢截止日 |
| conditionHistoryStatus | [History Status](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#historystatus) (Optional) | 歷史條件單狀態 `Type1` 所有條件單 ( 不包含已刪除、失效) 、 `Type2` 選擇期間內全部成交單 、 `Type3` 選擇期間內部分成交單 、 `Type4` 選擇期間刪除單 、 `Type5` 選擇期間失效單 、 `Type6` 選擇期間內已觸發記錄 |
info
歷史資料日期以條件單創建日期為準
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| create\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpsl\_count | string | 停損停利筆數 |
| tpsl\_record | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
auto get_conditionid = sdk->stock->get_condition_history(target_account, "20250604","20250605", std::nullopt);
if (!get_conditionid.is_success) {
std::cout << "get order result failed reason: "
<< (get_conditionid.message.has_value() ? get_conditionid.message.value() : "No message")
<< std::endl;
}
else {
if (get_conditionid.data.has_value()) {
for (const auto& result : get_conditionid.data.value()) {
std::cout << result << std::endl;
}
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = True,
message = ,
data = [
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords = ,
tPSLCount = 0,
tPSLRecord =
},
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 市價(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords =,
tPSLCount = 0,
tPSLRecord =
},
ConditionDetail {
guid = ec757279-bcb3-46f4-80ac-fccfc786bc8d,
batchNo = ,
orderLevel = 0,
lastTime = 2024-05-21 10:30:00,
conditionType = 多條件,
parentGuid = ec757279-bcb3-46f4-80ac-fccfc786bc8d,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於575元,且 台積電成交總量大於等於1001張,且 台積電時間大於等於10:30:00 部份成交為止,
action = 下單(當沖),
conditionBuySell = 現股買,
conditionSymbol = 台積電 現股買,
conditionPrice = 576元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:30:02,
startDate = 2024/03/14,
status = 觸發-委託失敗(X),
errorMessage = 單價輸入錯誤[4385715],
detailRecordsCount = 0,
detailRecords = [],
tPSLCount = 2,
tPSLRecord = [
ParentChildRecord
{
guid = c94b552a-22da-43e4-be44-f27a9c2026e1,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage =
},
ParentChildRecord
{
guid = c94b552a-22da-43e4-be44-f27a9c2026e1,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 市價(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage =
}
]
}
]
}
```
---
### 條件單查詢
get\_condition\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| conditionStatus | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditionstatus) (Optional) | 條件單狀態 : `Type1` 今日相關查詢 、 `Type2` 尚有效單 、 `Type3` 條件比對中 、 `Type4` 委託處理中 、`Type5` 委託成功 、 `Type6` 已通知 、 `Type7` 委託失敗 、 `Type8` 已有成交 、`Type9` 刪除成功 、`Type10` 異常 、 `Type11` 失效 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| create\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpsl\_count | string | 停損停利筆數 |
| tpsl\_record | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求��範例")
```cpp
auto get_conditionid = sdk->stock->get_condition_order(target_account, std::nullopt);
if (!get_conditionid.is_success) {
std::cout << "get order result failed reason: "
<< (get_conditionid.message.has_value() ? get_conditionid.message.value() : "No message")
<< std::endl;
}
else {
if (get_conditionid.data.has_value()) {
for (const auto& result : get_conditionid.data.value()) {
std::cout << result << std::endl;
}
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data = [
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords = ,
tPSLCount = 0,
tPSLRecord =
},
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 市價(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords =,
tPSLCount = 0,
tPSLRecord =
},
ConditionDetail {
guid = ec757279-bcb3-46f4-80ac-fccfc786bc8d,
batchNo = ,
orderLevel = 0,
lastTime = 2024-05-21 10:30:00,
conditionType = 多條件,
parentGuid = ec757279-bcb3-46f4-80ac-fccfc786bc8d,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於575元,且 台積電成交總量大於等於1001張,且 台積電時間大於等於10:30:00 部份成交為止,
action = 下單(當沖),
conditionBuySell = 現股買,
conditionSymbol = 台積電 現股買,
conditionPrice = 576元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:30:02,
startDate = 2024/03/14,
status = 觸發-委託失敗(X),
errorMessage = 單價輸入錯誤[4385715],
detailRecordsCount = 0,
detailRecords = [],
tPSLCount = 2,
tPSLRecord = [
ParentChildRecord
{
guid = c94b552a-22da-43e4-be44-f27a9c2026e1,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage =
},
ParentChildRecord
{
guid = c94b552a-22da-43e4-be44-f27a9c2026e1,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 市價(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage =
}
]
}
]
}
```
---
### 多條件單
multi\_condition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL` 部分成交為止、`UNTIL_END` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
// 設計條件內容
Condition condition = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::MATCHED_PRICE,
"66",
Operator::LESS_THAN,
};
Condition condition2 = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::TOTAL_QUANTITY,
"1000",
Operator::GREATER_THAN,
};
std::vector conditions;
conditions.push_back(condition);
conditions.push_back(condition2);
ConditionOrder order = ConditionOrder{
BsAction::BUY,
"2330",
"1000",
1000,
ConditionMarketType::COMMON,
ConditionPriceType::LIMIT,
TimeInForce::ROD,
ConditionOrderType::STOCK,
};
auto send_condition_order = sdk->stock->multi_condition(target_account, "20250605", "20250605", StopSign::FULL, conditions, order);
if (!send_condition_order.is_success) {
std::cout << "get order result failed reason: "
<< (send_condition_order.message.has_value() ? send_condition_order.message.value() : "No message")
<< std::endl;
}
else {
if (send_condition_order.data.has_value()) {
const auto& send = send_condition_order.data.value();
std::cout << send << std::endl;
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 多條件單包含停損停利
multi\_condition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則(例如信用交易資買資賣等)
info
待主單完全成交後,停損停利部分才會啟動
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL` 部分成交為止、`UNTIL_END` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託�資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
Condition condition = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::MATCHED_PRICE,
"66",
Operator::LESS_THAN,
};
Condition condition2 = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::TOTAL_QUANTITY,
"1000",
Operator::GREATER_THAN,
};
std::vector conditions;
conditions.push_back(condition);
conditions.push_back(condition2);
ConditionOrder order = ConditionOrder{
BsAction::BUY,
"2330",
"1000",
1000,
ConditionMarketType::COMMON,
ConditionPriceType::LIMIT,
TimeInForce::ROD,
ConditionOrderType::STOCK,
};
TpslOrder tp = TpslOrder{
TimeInForce::ROD,
ConditionPriceType::LIMIT,
ConditionOrderType::STOCK,
"85",
"85",
};
TpslOrder sl = TpslOrder{
TimeInForce::ROD,
ConditionPriceType::LIMIT,
ConditionOrderType::STOCK,
"60",
"60",
};
TPSLWrapper tpsl = TPSLWrapper{
StopSign::FULL,
tp,
sl,
"20250605",
false
};
auto send_condition_order = sdk->stock->multi_condition(target_account, "20250605", "20250605", StopSign::FULL, conditions, order, tpsl);
if (!send_condition_order.is_success) {
std::cout << "get order result failed reason: "
<< (send_condition_order.message.has_value() ? send_condition_order.message.value() : "No message")
<< std::endl;
}
else {
if (send_condition_order.data.has_value()) {
const auto& send = send_condition_order.data.value();
std::cout << send << std::endl;
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX
}
}
```
---
### 單一條件單
single\_condition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL` 部分成交為止、`UNTIL_END` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
// 設計條件內容
Condition condition = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::MATCHED_PRICE,
"66",
Operator::LESS_THAN,
};
ConditionOrder order = ConditionOrder{
BsAction::BUY,
"2881",
"1000",
1000,
ConditionMarketType::COMMON,
ConditionPriceType::LIMIT,
TimeInForce::ROD,
ConditionOrderType::STOCK,
};
auto send_condition_order = sdk->stock->single_condition(target_account,"20250605","20250605", StopSign::FULL, condition, order, std::nullopt);
if (!send_condition_order.is_success) {
std::cout << "get order result failed reason: "
<< (send_condition_order.message.has_value() ? send_condition_order.message.value() : "No message")
<< std::endl;
}
else {
if (send_condition_order.data.has_value()) {
const auto& send = send_condition_order.data.value();
std::cout << send << std::endl;
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX
}
}
```
---
### 單一條件單包含停損停利
single\_condition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則(例如信用交易資買資賣等)
info
待主單完全成交後,停損停利部分才會啟動
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL` 部分成交為止、`UNTIL_END` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資��訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
// 設計條件內容
Condition condition = Condition{
TradingType::REFERENCE,
"2881",
TriggerContent::MATCHED_PRICE,
"66",
Operator::LESS_THAN,
};
ConditionOrder order = ConditionOrder{
BsAction::BUY,
"2330",
"1000",
1000,
ConditionMarketType::COMMON,
ConditionPriceType::LIMIT,
TimeInForce::ROD,
ConditionOrderType::STOCK,
};
TpslOrder tp = TpslOrder{
TimeInForce::ROD,
ConditionPriceType::LIMIT,
ConditionOrderType::STOCK,
"85",
"85",
};
TpslOrder sl = TpslOrder{
TimeInForce::ROD,
ConditionPriceType::LIMIT,
ConditionOrderType::STOCK,
"60",
"60",
};
TPSLWrapper tpsl = TPSLWrapper{
StopSign::FULL,
tp,
sl,
"20250605",
false
};
auto send_condition_order = sdk->stock->single_condition(target_account, "20250605", "20250605", StopSign::FULL, condition, order, tpsl);
if (!send_condition_order.is_success) {
std::cout << "get order result failed reason: "
<< (send_condition_order.message.has_value() ? send_condition_order.message.value() : "No message")
<< std::endl;
}
else {
if (send_condition_order.data.has_value()) {
const auto& send = send_condition_order.data.value();
std::cout << send << std::endl;
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 分時分量查詢
get\_time\_slice\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | ----------------------------------------------------------------------------------------- | ---------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| batchNo | string | 分時分量條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| create\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpsl\_count | string | 停損停利筆數 |
| tpsl\_record | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
auto get_timeslice = sdk->stock->get_time_slice_order(target_account, "25060500000002");
if (!get_timeslice.is_success) {
std::cout << "get order result failed reason: "
<< (get_timeslice.message.has_value() ? get_timeslice.message.value() : "No message")
<< std::endl;
}
else {
if (get_timeslice.data.has_value()) {
for (const auto& result : get_timeslice.data.value()) {
std::cout << result << std::endl;
}
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data = [
ConditionDetail{
Guid = c4dc90c1-4277-42ea-b585-085dc347eac0,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-07-23 17:30:01,
ConditionType = 分時分量,
ParentGuid = ,
Symbol = 2881,
OrderAmount = 0,
ChildBatchNo = ,
Account = 1307515,
ConditionContent = 當於2024/07/23 定時單時間大於等於08:40:00 全部成交為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 富邦金 現股買,
ConditionPrice = 66元(ROD),
ConditionVolume = 1張,
ConditionFilledVolume = 0張,
CreateTime = 2024-07-22 17:30:03,
StartDate = 2024/07/23,
Status = 條件單中止(I),
ErrorMessage = ,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
},
ConditionDetail
{
Guid = 2975702e-f36f-4da4-bab6-1310344ec05d,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-07-23 17:30:01,
ConditionType = 分時分量,
ParentGuid = ,
Symbol = 2881,
OrderAmount = 0,
ChildBatchNo = ,
Account = 1307515,
ConditionContent = 當於2024/07/23 定時單時間大於等於09:10:00 全部成交為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 富邦金 現股買,
ConditionPrice = 66元(ROD),
ConditionVolume = 1張,
ConditionFilledVolume = 0張,
CreateTime = 2024-07-22 17:30:03,
StartDate = 2024/07/23,
Status = 條件單中止(I),
ErrorMessage = ,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
}
]
}
```
---
### 分時分量條件單
time\_slice\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| splitDescription | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#splitdescription) | 分單條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------- | ------ | ---------------- |
| batchId | string | 分時分量條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
// 設計條件內容
SplitDescription split = SplitDescription{
TimeSliceOrderType::TYPE1,
30,
1000,
10000,
"083000",
std::nullopt
};
ConditionOrder sliceorder = ConditionOrder{
BsAction::BUY,
"2330",
"1000",
1000,
ConditionMarketType::COMMON,
ConditionPriceType::LIMIT,
TimeInForce::ROD,
ConditionOrderType::STOCK,
};
auto timeslice = sdk->stock->time_slice_order(target_account, "20250605","20250605", StopSign::FULL, split, sliceorder);
if (!timeslice.is_success) {
std::cout << "send timeslice result failed reason: "
<< (timeslice.message.has_value() ? timeslice.message.value() : "No message")
<< std::endl;
}
else {
if (timeslice.data.has_value()) {
const auto& send = timeslice.data.value();
std::cout << send << std::endl;
}
else {
std::cout << "send timeslice success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data = ConditionOrderResult {
guid = 24080500000002,
}
}
```
---
### 歷史移動鎖利查詢
get\_trail\_history
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | ----------------------------------------------------------------------------------------- | ---------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 查詢開始日 |
| end\_date | string | 查詢截止日 |
#### Result 回傳[](#result-回�傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| create\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpsl\_count | string | 停損停利筆數 |
| tpsl\_record | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
auto get_trail_his = sdk->stock->get_trail_history(target_account, "20250601", "20250606");
if (!get_trail_his.is_success) {
std::cout << "get order result failed reason: "
<< (get_trail_his.message.has_value() ? get_trail_his.message.value() : "No message")
<< std::endl;
}
else {
if (get_trail_his.data.has_value()) {
for (const auto& result : get_trail_his.data.value()) {
std::cout << result << std::endl;
}
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = True,
message = ,
data = [
ConditionDetail {
Guid = 5c154a76-e7ef-4b8f-94b5-80bf08fa4b8e,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-08-02 16:45:01,
ConditionType = ,
ParentGuid = ,
Symbol = 2889,
OrderAmount = 0,
ChildBatchNo = ,
Account = 1307515,
ConditionContent = 從2024/08/02到2024/08/02內當國票金從1000(原始基準價),下跌達10%,持續至預定張數全部成交或期限到達為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 國票金 (2889),
ConditionPrice = 成交價(1) 檔(ROD),
ConditionVolume = 1張,
ConditionFilledVolume = 0張,
CreateTime = 2024-08-02 10:07:31,
StartDate = 2024/08/02,
Status = 條件單中止(I),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
},
ConditionDetail
{
Guid = c71117c8-aa70-4477-9f04-ff4c73a4fad0,
BatchNo = "",
OrderLevel = 0,
LastTime = 2024-07-29 17:30:00,
ConditionType = ,
ParentGuid = ,
Symbol = 2330,
OrderAmount = 0,
ChildBatchNo = "",
Account = 1307515,
ConditionContent = 從2024/07/29到2024/07/29內當台積電從860(原始基準價),上漲達5%,持續至預定張數全部成交或期限到達為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 台積電 (2330),
ConditionPrice = 成交價(5) 檔(ROD),
ConditionVolume = 2張,
ConditionFilledVolume = 0張,
CreateTime = 2024-07-29 11:01:49,
StartDate = 2024/07/29,
Status = 條件單中止(I),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
}
]
}
```
---
### 移動鎖利查詢
get\_trail\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | ----------------------------------------------------------------------------------------- | ---- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| create\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpsl\_count | string | 停損停利筆數 |
| tpsl\_record | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
auto get_trail = sdk->stock->get_trail_order(target_account);
if (!get_trail.is_success) {
std::cout << "get order result failed reason: "
<< (get_trail.message.has_value() ? get_trail.message.value() : "No message")
<< std::endl;
}
else {
if (get_trail.data.has_value()) {
for (const auto& result : get_trail.data.value()) {
std::cout << result << std::endl;
}
}
else {
std::cout << "Order result success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data = [
ConditionDetail {
Guid = 5c154a76-e7ef-4b8f-94b5-80bf08fa4b8e,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-08-02 16:45:01,
ConditionType = ,
ParentGuid = ,
Symbol = 2889,
OrderAmount = 0,
ChildBatchNo = ,
Account = 1307515,
ConditionContent = 從2024/08/02到2024/08/02內當國票金從1000(原始基準價),下跌達10%,持續至預定張數全部成交或期限到達為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 國票金 (2889),
ConditionPrice = 成交價(1) 檔(ROD),
ConditionVolume = 1張,
ConditionFilledVolume = 0張,
CreateTime = 2024-08-02 10:07:31,
StartDate = 2024/08/02,
Status = 條件單中止(I),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
},
ConditionDetail
{
Guid = c71117c8-aa70-4477-9f04-ff4c73a4fad0,
BatchNo = "",
OrderLevel = 0,
LastTime = 2024-07-29 17:30:00,
ConditionType = ,
ParentGuid = ,
Symbol = 2330,
OrderAmount = 0,
ChildBatchNo = "",
Account = 1307515,
ConditionContent = 從2024/07/29到2024/07/29內當台積電從860(原始基準價),上漲達5%,持續至預定張數全部成交或期限到達為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 台積電 (2330),
ConditionPrice = 成交價(5) 檔(ROD),
ConditionVolume = 2張,
ConditionFilledVolume = 0張,
CreateTime = 2024-07-29 11:01:49,
StartDate = 2024/07/29,
Status = 條件單中止(I),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
}
]
}
```
---
### 移動鎖利條件單
trail\_profit
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| TrailOrder | [TrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.txt#trailorder) | 分單條件 |
caution
TrailOrder 內之 基準價 (price) 只可輸入至多小數點後兩位,若超出將造成系統洗價失敗
info
當前股票價格價觸及觸發價時(以基準價計算之漲跌 % 數) 即下單
**例:** 若初始基準價設 100, 向下 5% 下單停損/利,初始觸發價為 95,若價格無上漲超過 100(即基準價無調整), 則市場價為 95 時將觸發條件下單
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| ----------- | ------------------- | --------------------------------- |
| is\_success | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cpp
// 設計條件內容
TrailOrder trail = TrailOrder{
"2330",
"1000",
Direction::UP,
5,
BsAction::BUY,
2000,
ConditionPriceType::MATCHED_PRICE,
5,
TimeInForce::ROD,
ConditionOrderType::STOCK
};
auto trail_order = sdk->stock->trail_profit(target_account, "20250606","20250606", StopSign::FULL, trail);
if (!trail_order.is_success) {
std::cout << "send trail_order result failed reason: "
<< (trail_order.message.has_value() ? trail_order.message.value() : "No message")
<< std::endl;
}
else {
if (trail_order.data.has_value()) {
const auto& send = trail_order.data.value();
std::cout << send << std::endl;
}
else {
std::cout << "send trail_order success but no data returned." << std::endl;
}
}
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cpp
{
isSuccess = true,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 取消條件單
CancelConditionOrders
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 CancelResult 欄位[](#委託資訊-cancelresult--欄位 "Direct link to 委託資訊 CancelResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| -------- | ------ | ------------ |
| advisory | string | 回覆狀態內容 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.Stock.CancelConditionOrders(account, "c9df498a-3b28-4b50-a6f2-f7bd524e96df");
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
Result {
isSuccess = true,
message = None,
data = CancelResult {
advisory = 成功筆數:1,失敗筆數:0!
}
}
```
---
### 當沖條件單查詢
GetConditionDaytradeById
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | ------------ |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 當沖條件單號 |
#### Result 回傳[](#result-回�傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.Stock.GetConditionDaytradeById(account,"8ff3472b-185a-488c-be5a-b478deda080c");
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data =
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords = ,
tPSLCount = 0,
tPSLRecord =
}
}
```
---
### 當沖多條件單
MultiConditionDayTrade
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定回補成功,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合當日沖銷交易規則(例如信用交易使用資券互抵)
當沖條件單查詢
* 使用 guid 查詢當沖條件單請使用***當沖條件單查詢***功能
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| endTime | string | 父單洗價結束時間 |
| multicondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
| fixSession | bool | 執行定盤回補 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition1 = new Condition(
TradingType.Reference,
"2881",
TriggerContent.MatchedPrice,
"66",
Operator.LessThan
);
var condition2 = new Condition(
TradingType.Reference,
"2881",
TriggerContent.TotalQuantity,
"8000",
Operator.LessThan
);
List conditions = new List();
conditions.Add(condition1);
conditions.Add(condition2);
var order = new ConditionOrder(
BsAction.Buy,
"2881",
"66",
2000,
ConditionMarketType.Common,
ConditionPriceType.Limit,
TimeInForce.Rod,
ConditionOrderType.Stock
);
var daytrade_obj = new ConditionDayTrade(
"131000", // 收盤前沖銷時間,可設定區間為 130100 ~ 132000
true,
"",
ConditionPriceType.Market
);
var tp = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"85",
"85",
null
);
var sl = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"60",
"60",
null
);
var tpsl = new TpslWrapper(
StopSign.Full,
tp,
sl,
"20240517",
true // ** 設定 true 以啟用當日沖銷洗價
);
sdk.Stock.MultiConditionDayTrade(account, StopSign.Full, "130000", conditions, order, daytrade_obj, tpsl, true);
// 不設定停損停利
//sdk.Stock.MultiConditionDayTrade(account, StopSign.Full, "130000", conditions, order, daytrade_obj, null, true);
// 不設定定盤回補
//sdk.Stock.MultiConditionDayTrade(account, StopSign.Full, "130000", conditions, order, daytrade_obj, tpsl, false);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 當沖單一條件單
SingleConditionDayTrade
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定回補成功,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合當日沖銷交易規則(例如信用交易使用資券互抵)
當沖條件單查詢
* 使用 guid 查詢當沖條件單請使用***當沖條件單查詢***功能
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| endTime | string | 父單洗價結束時間 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
| fixSession | bool | 執行定盤回補 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition = new Condition(
TradingType.Reference,
"2881",
TriggerContent.MatchedPrice,
"66",
Operator.LessThan
);
var order = new ConditionOrder(
BsAction.Buy,
"2881",
"66",
2000,
ConditionMarketType.Common,
ConditionPriceType.Limit,
TimeInForce.Rod,
ConditionOrderType.Stock
);
var daytrade_obj = new ConditionDayTrade(
"131000", // 收盤前沖銷時間,可設定區間為 130100 ~ 132000
true,
"",
ConditionPriceType.Market
);
var tp = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"85",
"85",
null
);
var sl = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"60",
"60",
null
);
var tpsl = new TpslWrapper(
StopSign.Full,
tp,
sl,
"20240517",
true // ** 設定 true 以啟用當日沖銷洗價
);
sdk.Stock.SingleConditionDayTrade(account, StopSign.Full, "130000", condition, order, daytrade_obj, tpsl, true);
// 不設定停損停利
//sdk.Stock.SingleConditionDayTrade(account, StopSign.Full, "130000", condition, order, daytrade_obj, null, true);
// 不設定定盤回補
//sdk.Stock.SingleConditionDayTrade(account, StopSign.Full, "130000", condition, order, daytrade_obj, tpsl, false);
```
#### 回傳範例[](#回傳範例 "Direct link to 回�傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 參數對照表
#### 類別[](#類別 "Direct link to 類別")
Class
##### Condition Object[](#condition-object "Direct link to Condition Object")
| Parameter | Type | Meaning |
| ------------ | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| marketType | TradingType | [監控類型](#tradingtype) 可選用參數 : `Reference` 自動參考委託物件、`Scheduled` 時間 |
| symbol | string | 股票代號 |
| trigger | TriggerContent | [觸發條件](#triggercontent) 可選用參數 : `BidPrice` 買進價、`AskPrice` 賣出價、`MatchedPrice` 成交價、`TotalQuantity` 總量、`Time` 時間 |
| triggerValue | string | 監控條件數值 (若為時間則填入 HHMMSS) |
| comparison | Operator | [比對值](#operator) 可選用參數 `GreaterThanOrEqual` 大於等於、`LessThanOrEqual` 小於等於 、 `GreaterThan` 大於 、 `LessThan` 小於 |
info
1. 選擇 `Reference` 時, trigger 可搭配 `BidPrice` 、`AskPrice` 、`MatchedPrice` 、`TotalQuantity` 、 `Time`,若 trigger 使用 Time,則時間條件達成,且時間範圍內商品有交易產生才觸發
2. 選擇 `Scheduled` 時,symbol 需填入空值"",trigger 需帶入 `Time`,則會使用系統時間判斷,當時間條件達成即觸發
##### ConditionOrder Object[](#conditionorder-object "Direct link to ConditionOrder Object")
| Parameter | Type | Meaning |
| ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| buySell | BsAction | [買賣別](#bsaction) |
| symbol | string | 股票代號 |
| price | string | 委託價格 |
| quantity | int | 委託數量 |
| marketType | ConditionMarketType | [盤別](#conditionmarkettype) 可選用參數 `Common` 整股、`Fixing` 定盤、`IntradayOdd` 盤中零股、`Odd` 盤後零股 |
| priceType | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice` 成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) |
| timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `Rod`、`Fok`、`Ioc` |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) : 可選參數 :`Stock` 現貨、`Margin` 融資、`Short` 融券 |
##### TpslOrder Object[](#tpslorder-object "Direct link to TpslOrder Object")
| Parameter | Type | Meaning |
| ----------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| timeInForce | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`ROD`、`IOC`、`FOK` |
| priceType | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice` 成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) : 可選參數 :`Stock` 現貨、`Margin` 融資、`Short` 融券 |
| targetPrice | string | 停損/停利觸發價 |
| price | string | 停損/停利委託價 |
| trigger | TriggerContent | 停損/停利 [觸發條件](#triggercontent) (詳見表末說明) |
info
`priceType` 若為 `limit` 時,`price` 需填入價格;其餘 price 填入空字串 **或** `null` (>= ver. 2.2.4)
停損/停利觸發條件
2.2.0 以後版本新增(***2.1.1 及以前版本無此欄位***),可設定停損/停利觸發價格別為 1. 成交價(MatchedPrice);2. 最佳買價(BidPrice);3. 最佳賣價(AskPrice)
若未設定則此欄位填入 ***null***, 預設使用 成交價(MatchedPrice)
##### TpslWrapper Object[](#tpslwrapper-object "Direct link to TpslWrapper Object")
| Parameter | Type | Meaning |
| --------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------- |
| stopSign | StopSign | [停止條件](#stopsign) : 可選用 `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| tp | TpslOrder Object (Optional) | 停利條件內容 |
| sl | TpslOrder Object (Optional) | 停損條件內容 |
| endDate | string (Optional : 空值同母單 StartDate) | 條件停止日期 |
| intraday | bool (Optional) | 全部成交後日內當沖 |
日內當沖
使用當沖條件單時,`intraday` 需設定為 `true`
##### TrailOrder[](#trailorder "Direct link to TrailOrder")
| Parameter | Type | Meaning |
| ----------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| symbol | string | 股票代號 |
| price | string | 基準價 (Note. 只可輸入至多小數點後兩位,若超出將造成系統洗價失敗) |
| direction | Direction | [方向](#direction) : 可選用 `Up` 上漲、`Down` 下跌 |
| percentage | int | 上漲 / 下跌 % 數 |
| buysell | BsAction | 買賣別 : 可選用 `Buy` 買進 、`Sell` 賣出 |
| quantity | int | 委託股數 |
| PriceType | ConditionPriceType | [價格類別](#conditionpricetype) : 可選用 `BidPrice` 買進價、`AskPrice` 賣出價、`MatchedPrice` 成交價、`Market` 市價、`LimitUp` 漲停價、`LimitDown` 跌停價、`Reference` 參考價(平盤價) |
| diff | int | 買賣價格檔數 (根據 priceType 加減檔數) ,正值為向上加檔數、負值為向下加檔數 |
| timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) 可選用參數為 `Stock` 現股、`Margin` 融資、`Short` 融券 |
##### SplitDescription[](#splitdescription "Direct link to SplitDescription")
| Parameter | Type | Meaning |
| -------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| method | SliceType | [Slice Condition](#slicetype) : 可選用 :
`Type1` 從 `startTime` 開始,每隔幾秒送一筆,總共 `totalQuantity`,每筆送 `singleQuantity`
`Type2` 從 `startTime` 開始到 `endTime` 結束,每隔 `interval` 秒送一筆,總共 `totalQuantity`,剩餘張數加總至最後一筆
`Type3` 從 `startTime` 開始到 `endTime` 結束,每隔 `interval` 秒送一筆,總共 `totalQuantity`,剩餘張數從最後一筆往前分配.
|
| interval | int | 下單間隔時間 (秒) |
| singleQuantity | int | 單筆下單量 (股數) |
| totalQuantity | int (Optional) | 總共下單量 (股數) |
| startTime | string | 開始時間 |
| endTime | string (Optional) | 結束時間 |
caution
請注意,總共下單量需大於單筆下單量。
##### ConditionOrderResult[](#conditionorderresult "Direct link to ConditionOrderResult")
| Parameter | Type | Meaning |
| --------- | ------ | -------- |
| guid | string | 條件單號 |
##### ConditionDayTrade Object[](#conditiondaytrade-object "Direct link to ConditionDayTrade Object")
| Parameter | Type | Meaning |
| --------------- | ----------------------------------------- | -------------------------------------------------- |
| dayTradeEndTime | string | 收盤前沖銷時間,格式 "HHMMSS" (例 "131500") |
| autoCancel | bool | 洗價結束後是否刪除已觸發委託 |
| price | string | 委託價格 (若無指定價格,例如市價單,請填空字串 "") |
| priceType | [ConditionPriceType](#conditionpricetype) | 委託單價格類型 |
關於收盤前沖銷時間
可設定區間為 130100 ~ 132000
#### Constants ( 欄位對應數值 )[](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )")
##### BsAction[](#bsaction "Direct link to BsAction")
買賣別
| Name | Meaning |
| ---- | ------- |
| Buy | 買 |
| Sell | 賣 |
##### ConditionMarketType[](#conditionmarkettype "Direct link to ConditionMarketType")
盤別
| Name | Meaning |
| ----------- | -------- |
| Common | 一般盤 |
| Fixing | 定盤 |
| IntradayOdd | 盤中零股 |
| Odd | 盤後零股 |
##### TradingType[](#tradingtype "Direct link to TradingType")
監控類型
| Name | Meaning |
| --------- | ---------------- |
| Reference | 自動參考委託物件 |
| Scheduled | 時間 |
##### TriggerContent[](#triggercontent "Direct link to TriggerContent")
觸發條件
| Name | Meaning |
| ------------- | ------- |
| BidPrice | 買進價 |
| AskPrice | 賣出價 |
| MatchedPrice | 成交價 |
| TotalQuantity | 總量 |
| Time | 時間 |
##### Operator[](#operator "Direct link to Operator")
| Name | Meaning |
| ------------------ | -------- |
| GreaterThanOrEqual | 大於等於 |
| LessThanOrEqual | 小於等於 |
| GreaterThan | 大於 |
| LessThan | 小於 |
##### StopSign[](#stopsign "Direct link to StopSign")
| Name | Meaning |
| -------- | ------------ |
| Full | 全部成交為止 |
| Partial | 部分成交為止 |
| UntilEnd | 效期結束為止 |
##### TimeInForce[](#timeinforce "Direct link to TimeInForce")
委託條件 (TimeInForce)
| Name | Meaning |
| ---- | ------------------------------------- |
| ROD | 當日有效(Rest of Day) |
| FOK | 全部成交否則取消(Fill-or-Kill) |
| IOC | 立即成交否則取消(Immediate-or-Cancel) |
##### ConditionPriceType[](#conditionpricetype "Direct link to ConditionPriceType")
價格類型 (ConditionPriceType)
| Name | Meaning |
| ------------ | -------------- |
| Limit | 限價 |
| BidPrice | 買進價 |
| AskPrice | 賣出價 |
| Market | 市價 |
| MatchedPrice | 成交價 |
| LimitUp | 漲停價 |
| LimitDown | 跌停價 |
| Reference | 參考價(平盤價) |
##### ConditionOrderType[](#conditionordertype "Direct link to ConditionOrderType")
委託類型 (orderType)
| Name | Meaning |
| ------ | ------- |
| Stock | 現貨 |
| Margin | 融資 |
| Short | 融券 |
##### Direction[](#direction "Direct link to Direction")
移動鎖利上漲/下跌追蹤 (direction)
| Name | Meaning |
| ---- | ------- |
| Up | 上漲 |
| Down | 下跌 |
##### SliceType[](#slicetype "Direct link to SliceType")
分單型態 (SliceType)
| Name | Meaning |
| ----- | -------------------------------------------------------------------- |
| Type1 | 從開始時間,每隔幾秒送一筆,總共送 N 筆,每筆送 M 張 |
| Type2 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數加總至最後一筆 |
| Type3 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數從最後一筆往前分配 |
##### ConditionStatus[](#conditionstatus "Direct link to ConditionStatus")
條件單狀態 (ConditionStatus)
| Name | Meaning |
| ------ | ------------ |
| Type1 | 今日相關查詢 |
| Type2 | 尚有效單 |
| Type3 | 條件比對中 |
| Type4 | 委託處理中 |
| Type5 | 委託成功 |
| Type6 | 已通知 |
| Type7 | 委託失敗 |
| Type8 | 已有成交 |
| Type9 | 刪除成功 |
| Type10 | 異常 |
| Type11 | 失效 |
##### HistoryStatus[](#historystatus "Direct link to HistoryStatus")
歷史條件單狀態 (HistoryStatus)
| Name | Meaning |
| ----- | -------------------------------- |
| Type1 | 所有條件單 ( 不包含已刪除、失效) |
| Type2 | 選擇期間內全部成交單 |
| Type3 | 選擇期間內部分成交單 |
| Type4 | 選擇期間刪除單 |
| Type5 | 選擇期間失效單 |
| Type6 | 選擇期間內已觸發記錄 |
---
### 條件單查詢 By 條件單號
GetConditionOrderById
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.Stock.GetConditionOrderById(account,"8ff3472b-185a-488c-be5a-b478deda080c");
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data =
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords = ,
tPSLCount = 0,
tPSLRecord =
}
}
```
---
### 歷史條件單查詢
GetConditionHistory
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| startDate | string | 查詢條件單創建日 |
| endDate | string | 查詢截止日 |
| conditionHistoryStatus | [History Status](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#historystatus) (Optional) | 歷史條件單狀態 |
info
歷史資料日期以條件單創建日期為準
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.Stock.GetConditionHistory(account,"20240301","20240601");
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = [
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords = ,
tPSLCount = 0,
tPSLRecord =
},
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 市價(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords =,
tPSLCount = 0,
tPSLRecord =
},
ConditionDetail {
guid = ec757279-bcb3-46f4-80ac-fccfc786bc8d,
batchNo = ,
orderLevel = 0,
lastTime = 2024-05-21 10:30:00,
conditionType = 多條件,
parentGuid = ec757279-bcb3-46f4-80ac-fccfc786bc8d,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於575元,且 台積電成交總量大於等於1001張,且 台積電時間大於等於10:30:00 部份成交為止,
action = 下單(當沖),
conditionBuySell = 現股買,
conditionSymbol = 台積電 現股買,
conditionPrice = 576元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:30:02,
startDate = 2024/03/14,
status = 觸發-委託失敗(X),
errorMessage = 單價輸入錯誤[4385715],
detailRecordsCount = 0,
detailRecords = [],
tPSLCount = 2,
tPSLRecord = [
ParentChildRecord
{
guid = c94b552a-22da-43e4-be44-f27a9c2026e1,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage =
},
ParentChildRecord
{
guid = c94b552a-22da-43e4-be44-f27a9c2026e1,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 市價(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage =
}
]
}
]
}
```
---
### 條件單查詢
GetConditionOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| conditionStatus | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditionstatus) (Optional) | 條件單狀態 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.Stock.GetConditionOrder(account);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = [
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords = ,
tPSLCount = 0,
tPSLRecord =
},
ConditionDetail {
guid = 8ff3472b-185a-488c-be5a-b478deda080c,
batchNo = ,
orderLevel = 1,
lastTime = 2024-03-14 12:39:02,
conditionType = 多條件,
parentGuid = 58e7a51e-9701-4d26-bc16-18a392a840bd,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 市價(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:39:22,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage = null,
detailRecordsCount = 0,
detailRecords =,
tPSLCount = 0,
tPSLRecord =
},
ConditionDetail {
guid = ec757279-bcb3-46f4-80ac-fccfc786bc8d,
batchNo = ,
orderLevel = 0,
lastTime = 2024-05-21 10:30:00,
conditionType = 多條件,
parentGuid = ec757279-bcb3-46f4-80ac-fccfc786bc8d,
symbol = 2330,
orderAmount = 0,
childBatchNo = ,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於575元,且 台積電成交總量大於等於1001張,且 台積電時間大於等於10:30:00 部份成交為止,
action = 下單(當沖),
conditionBuySell = 現股買,
conditionSymbol = 台積電 現股買,
conditionPrice = 576元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
createTime = 2024-03-14 12:30:02,
startDate = 2024/03/14,
status = 觸發-委託失敗(X),
errorMessage = 單價輸入錯誤[4385715],
detailRecordsCount = 0,
detailRecords = [],
tPSLCount = 2,
tPSLRecord = [
ParentChildRecord
{
guid = c94b552a-22da-43e4-be44-f27a9c2026e1,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 580元(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage =
},
ParentChildRecord
{
guid = c94b552a-22da-43e4-be44-f27a9c2026e1,
account = 1307515,
conditionContent = 當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止,
action = 下單(次日回補),
conditionBuySell = 現股賣,
conditionSymbol = 台積電 現股賣,
conditionPrice = 市價(ROD),
conditionVolume = 5張,
conditionFilledVolume = 0張,
startDate = 2024/03/14,
status = 未生效(W),
errorMessage =
}
]
}
]
}
```
---
### 多條件單
MultiCondition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition1 = new Condition(
TradingType.Reference,
"2881",
TriggerContent.MatchedPrice,
"66",
Operator.LessThan
);
var condition2 = new Condition(
TradingType.Reference,
"2881",
TriggerContent.TotalQuantity,
"8000",
Operator.LessThan
);
List conditions = new List();
conditions.Add(condition1);
conditions.Add(condition2);
var order = new ConditionOrder(
BsAction.Buy,
"2881",
"66",
2000,
ConditionMarketType.Common,
ConditionPriceType.Limit,
TimeInForce.Rod,
ConditionOrderType.Stock
);
sdk.Stock.MultiCondition(account, "20240426", "20240430", StopSign.Full, conditions , order);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 多條件單包含停損停利
MultiCondition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則(例如信用交易資買資賣等)
info
待主單完全成交後,停損停利部分才會啟動
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition1 = new Condition(
TradingType.Reference,
"2881",
TriggerContent.MatchedPrice,
"66",
Operator.LessThan
);
var condition2 = new Condition(
TradingType.Reference,
"2881",
TriggerContent.TotalQuantity,
"8000",
Operator.LessThan
);
List conditions = new List();
conditions.Add(condition1);
conditions.Add(condition2);
var order = new ConditionOrder(
BsAction.Buy,
"2881",
"66",
2000,
ConditionMarketType.Common,
ConditionPriceType.Limit,
TimeInForce.Rod,
ConditionOrderType.Stock
);
// 停損停利若為Market , price 則填空值""
var tp = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"85",
"85",
null // 2.2.0 以後版本使用,詳請見 [參數對照表] -> [TpslOrder Object]
);
var sl = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"60",
"60",
null // 2.2.0 以後版本使用,詳請見 [參數對照表] -> [TpslOrder Object]
);
var tpsl = new TpslWrapper(
StopSign.Full,
tp,
sl,
"20240517",
false
);
sdk.Stock.MultiCondition(account, "20240426", "20240430", StopSign.Full, conditions, order, tpsl);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX
}
}
```
---
### 單一條件單
SingleCondition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition = new Condition(
TradingType.Reference,
"2881",
TriggerContent.MatchedPrice,
"66",
Operator.LessThan
);
var order = new ConditionOrder(
BsAction.Buy,
"2881",
"66",
2000,
ConditionMarketType.Common,
ConditionPriceType.Limit,
TimeInForce.Rod,
ConditionOrderType.Stock
);
sdk.Stock.SingleCondition(account, "20240426", "20240430", StopSign.Full, condition, order);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX
}
}
```
---
### 單一條件單包含停損停利
SingleCondition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則(例如信用交易資買資賣等)
info
待主單完全成交後,停損停利部分才會啟動
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition = new Condition(
TradingType.Reference,
"2881",
TriggerContent.MatchedPrice,
"66",
Operator.LessThan
);
var order = new ConditionOrder(
BsAction.Buy,
"2881",
"66",
2000,
ConditionMarketType.Common,
ConditionPriceType.Limit,
TimeInForce.Rod,
ConditionOrderType.Stock
);
// 停損停利若為Market , price 則填空值""
var tp = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"85",
"85",
null // 2.2.0 以後版本使用,詳請見 [參數對照表] -> [TpslOrder Object]
);
var sl = new TpslOrder(
TimeInForce.Rod,
ConditionPriceType.Limit,
ConditionOrderType.Stock,
"60",
"60",
null // 2.2.0 以後版本使用,詳請見 [參數對照表] -> [TpslOrder Object]
);
var tpsl = new TpslWrapper(
StopSign.Full,
tp,
sl,
"20240517",
false
);
sdk.Stock.SingleCondition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 分時分量查詢
GetTimeSliceOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | ---------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| batchNo | string | 分時分量條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.Stock.GetTimeSliceOrder(account,"1234567");
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = [
ConditionDetail{
Guid = c4dc90c1-4277-42ea-b585-085dc347eac0,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-07-23 17:30:01,
ConditionType = 分時分量,
ParentGuid = ,
Symbol = 2881,
OrderAmount = 0,
ChildBatchNo = ,
Account = 1307515,
ConditionContent = 當於2024/07/23 定時單時間大於等於08:40:00 全部成交為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 富邦金 現股買,
ConditionPrice = 66元(ROD),
ConditionVolume = "1張,
ConditionFilledVolume = 0張,
CreateTime = 2024-07-22 17:30:03,
StartDate = 2024/07/23,
Status = 條件單中止(I),
ErrorMessage = ,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
},
ConditionDetail
{
Guid = 2975702e-f36f-4da4-bab6-1310344ec05d,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-07-23 17:30:01,
ConditionType = 分時分量,
ParentGuid = ,
Symbol = 2881,
OrderAmount = 0,
ChildBatchNo = ,
Account = 1307515,
ConditionContent = 當於2024/07/23 定時單時間大於等於09:10:00 全部成交為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 富邦金 現股買,
ConditionPrice = 66元(ROD),
ConditionVolume = 1張,
ConditionFilledVolume = 0張,
CreateTime = 2024-07-22 17:30:03,
StartDate = 2024/07/23,
Status = 條件單中止(I),
ErrorMessage = ,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
}
]
}
```
---
### 分時分量條件單
TimeSliceOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| splitDescription | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#splitdescription) | 分單條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------- | ------ | ---------------- |
| batchId | string | 分時分量條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var split = new SplitDescription(
TimeSliceOrderType.Type1,
300,
1000,
10000,
"083000",
null
);
var order = new ConditionOrder(
BsAction.Buy,
"2881",
"66",
2000,
ConditionMarketType.Common,
ConditionPriceType.Limit,
TimeInForce.Rod,
ConditionOrderType.Stock
);
sdk.Stock.TimeSliceOrder(target_account, "20240427","20240516", StopSign.Full, split, order);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 24080500000002,
}
}
```
---
### 歷史移動鎖利查詢
GetTrailHistory
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | -------------------------------------------------------------------------------------------- | ---------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 查詢開始日 |
| end\_date | string | 查詢截止日 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.Stock.GetTrailHistory(account,"20240301","20240601");
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = [
ConditionDetail {
Guid = 5c154a76-e7ef-4b8f-94b5-80bf08fa4b8e,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-08-02 16:45:01,
ConditionType = ,
ParentGuid = ,
Symbol = 2889,
OrderAmount = 0,
ChildBatchNo = ,
Account = 1307515,
ConditionContent = 從2024/08/02到2024/08/02內當國票金從1000(原始基準價),下跌達10%,持續至預定張數全部成交或期限到達為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 國票金 (2889),
ConditionPrice = 成交價(1) 檔(ROD),
ConditionVolume = 1張,
ConditionFilledVolume = 0張,
CreateTime = 2024-08-02 10:07:31,
StartDate = 2024/08/02,
Status = 條件單中止(I),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
},
ConditionDetail
{
Guid = c71117c8-aa70-4477-9f04-ff4c73a4fad0,
BatchNo = "",
OrderLevel = 0,
LastTime = 2024-07-29 17:30:00,
ConditionType = ,
ParentGuid = ,
Symbol = 2330,
OrderAmount = 0,
ChildBatchNo = "",
Account = 1307515,
ConditionContent = 從2024/07/29到2024/07/29內當台積電從860(原始基準價),上漲達5%,持續至預定張數全部成交或期限到達為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 台積電 (2330),
ConditionPrice = 成交價(5) 檔(ROD),
ConditionVolume = 2張,
ConditionFilledVolume = 0張,
CreateTime = 2024-07-29 11:01:49,
StartDate = 2024/07/29,
Status = 條件單中止(I),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
}
]
}
```
---
### 移動鎖利查詢
GetTrailOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | ---- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.Stock.GetTrailOrder(account);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = [
ConditionDetail {
Guid = 5c154a76-e7ef-4b8f-94b5-80bf08fa4b8e,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-08-02 16:45:01,
ConditionType = ,
ParentGuid = ,
Symbol = 2889,
OrderAmount = 0,
ChildBatchNo = ,
Account = 1307515,
ConditionContent = 從2024/08/02到2024/08/02內當國票金從1000(原始基準價),下跌達10%,持續至預定張數全部成交或期限到達為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 國票金 (2889),
ConditionPrice = 成交價(1) 檔(ROD),
ConditionVolume = 1張,
ConditionFilledVolume = 0張,
CreateTime = 2024-08-02 10:07:31,
StartDate = 2024/08/02,
Status = 條件單中止(I),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
},
ConditionDetail
{
Guid = c71117c8-aa70-4477-9f04-ff4c73a4fad0,
BatchNo = "",
OrderLevel = 0,
LastTime = 2024-07-29 17:30:00,
ConditionType = ,
ParentGuid = ,
Symbol = 2330,
OrderAmount = 0,
ChildBatchNo = "",
Account = 1307515,
ConditionContent = 從2024/07/29到2024/07/29內當台積電從860(原始基準價),上漲達5%,持續至預定張數全部成交或期限到達為止,
Action = 下單,
ConditionBuySell = 現股買,
ConditionSymbol = 台積電 (2330),
ConditionPrice = 成交價(5) 檔(ROD),
ConditionVolume = 2張,
ConditionFilledVolume = 0張,
CreateTime = 2024-07-29 11:01:49,
StartDate = 2024/07/29,
Status = 條件單中止(I),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 0,
TpslRecord = []
}
]
}
```
---
### 移動鎖利條件單
TrailProfit
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| TrailOrder | [TrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.txt#trailorder) | 分單條件 |
caution
TrailOrder 內之 基準價 (price) 只可輸入至多小數點後兩位,若超出將造成系統洗價失敗
info
當前股票價格價觸及觸發價時(以基準價計算之漲跌 % 數) 即下單
**例:** 若初始基準價設 100, 向下 5% 下單停損/利,初始觸發價為 95,若價格無上漲超過 100(即基準價無調整), 則市場價為 95 時將觸發條件下單
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var trail = new TrailOrder(
"2330",
"860",
Direction.Up ,
5, // 漲跌 % 數
BsAction.Buy,
2000,
ConditionPriceType.MatchedPrice,
5, // 向上 or 向下追買 tick數 (向下為負值)
TimeInForce.Rod,
ConditionOrderType.Stock
);
sdk.Stock.TrailProfit(target_account, "20240427","20240516", StopSign.Full, trail);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 取消條件單
cancelConditionOrders
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 CancelResult 欄位[](#委託資訊-cancelresult--欄位 "Direct link to 委託資訊 CancelResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| -------- | ------ | ------------ |
| advisory | string | 回覆狀態內容 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
sdk.stock.cancelConditionOrders(account, "c9df498a-3b28-4b50-a6f2-f7bd524e96df")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
advisory: "成功筆數:1,失敗筆數:0!",
}
}
```
---
### 當沖條件單查詢
getConditionDaytradeById
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess : false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
sdk.stock.getConditionDaytradeById(account,"8ff3472b-185a-488c-be5a-b478deda080c")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data :
{
guid : "8ff3472b-185a-488c-be5a-b478deda080c",
batchNo : "",
orderLevel : "1",
lastTime : "2024-03-14 12:39:02",
conditionType : "多條件",
parentGuid : "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol : "2330",
orderAmount : "0",
childBatchNo : "",
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action : "下單(次日回補)",
conditionBuySell : "現股賣",
conditionSymbol : "台積電 現股賣",
conditionPrice : "580元(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
createTime : "2024-03-14 12:39:22",
startDate : "2024/03/14",
status : "未生效(W)",
detailRecordsCount : "0",
tPSLCount : "0"
}
}
```
---
### 當沖多條件單
multiConditionDayTrade
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定回補成功,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合當日沖銷交易規則(例如信用交易使用資券互抵)
當沖條件單查詢
* 使用 guid 查詢當沖條件單請使用***當沖條件單查詢***功能
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| endTime | string | 父單洗價結束時間 |
| multicondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
| fixSession | bool | 執行定盤回補 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
// 設計條件內容
const condition = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.MatchedPrice,
triggerValue: "80",
comparison: Operator.LessThan
}
const condition2 = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.TotalQuantity,
triggerValue: "8000",
comparison: Operator.GreaterThan
}
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: ConditionMarketType.Common,
priceType: ConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
}
const daytrade_obj = {
dayTradeEndTime : "131000", // 收盤前沖銷時間,可設定區間為 130100 ~ 132000
autoCancel : true,
price : "",
priceType : ConditionPriceType.Market
}
const tp = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "85",
price: "85",
}
const sl = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "60",
price: "60",
}
const tpsl = {
stopSign: StopSign.Full,
endDate: "20240517",
tp: tp,
sl: sl,
intraday: true // ** 設定 true 以啟用當日沖銷洗價
}
sdk.stock.multiConditionDayTrade(account, StopSign.Full, "130000", [condition, condition2], order, daytrade_obj, tpsl, true)
// 不設定停損停利
// sdk.stock.multiConditionDayTrade(account, StopSign.Full, "130000", [condition, condition2], order, daytrade_obj, null, true)
// 不設定定盤回補
// sdk.stock.multiConditionDayTrade(account, StopSign.Full, "130000", [condition, condition2], order, daytrade_obj, null, false)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 當沖單一條件單
singleConditionDayTrade
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定回補成功,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合當日沖銷交易規則(例如信用交易使用資券互抵)
當沖條件單查詢
* 使用 guid 查詢當沖條件單請使用***當沖條件單查詢***功能
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| endTime | string | 父單洗價結束時間 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
| fixSession | bool | 執行定盤回補 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
// 設計條件內容
const condition = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.MatchedPrice,
triggerValue: "80",
comparison: Operator.LessThan
}
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: ConditionMarketType.Common,
priceType: ConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock,
};
const daytrade_obj = {
dayTradeEndTime : "131000", // 收盤前沖銷時間,可設定區間為 130100 ~ 132000
autoCancel : true,
price : "",
priceType : ConditionPriceType.Market
}
const tp = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "85",
price: "85",
}
const sl = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "60",
price: "60",
}
const tpsl = {
stopSign: StopSign.Full,
endDate: "20240517",
tp: tp,
sl: sl,
intraday: true // ** 設定 true 以啟用當日沖銷洗價
}
sdk.stock.singleConditionDayTrade(account, StopSign.Full, "130000", condition, order, daytrade_obj, tpsl, true)
// 不設定停損停利
// sdk.stock.singleConditionDayTrade(account, StopSign.Full, "130000", condition, order, daytrade_obj, null, true)
// 不設定定盤回補
// sdk.stock.singleConditionDayTrade(account, StopSign.Full, "130000", condition, order, daytrade_obj, null, false)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 參數對照表
#### 類別[](#類別 "Direct link to 類別")
Class
##### Condition Object[](#condition-object "Direct link to Condition Object")
| Parameter | Type | Meaning |
| ------------ | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| marketType | TradingType | [監控類型](#tradingtype) 可選用參數 : `Reference` 自動參考委託物件、`Scheduled` 時間 |
| symbol | string | 股票代號 |
| trigger | TriggerContent | [觸發條件](#triggercontent) 可選用參數 : `BidPrice` 買進價、`AskPrice` 賣出價、`MatchedPrice` 成交價、`TotalQuantity` 總量、`Time` 時間 |
| triggerValue | string | 監控條件數值 (若為時間則填入 HHMMSS) |
| comparison | Operator | [比對值](#operator) 可選用參數 `GreaterThanOrEqual` 大於等於、`LessThanOrEqual` 小於等於 、 `GreaterThan` 大於 、 `LessThan` 小於 |
info
1. 選擇 `Reference` 時, trigger 可搭配 `BidPrice` 、`AskPrice` 、`MatchedPrice` 、`TotalQuantity` 、 `Time`,若 trigger 使用 Time,則時間條件達成,且時間範圍內商品有交易產生才觸發
2. 選擇 `Scheduled` 時,symbol 需填入空值"",trigger 需帶入 `Time`,則會使用系統時間判斷,當時間條件達成即觸發
##### ConditionOrder Object[](#conditionorder-object "Direct link to ConditionOrder Object")
| Parameter | Type | Meaning |
| ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| buySell | BSAction | [買賣別](#bsaction) |
| symbol | string | 股票代號 |
| price | string | 委託價格 |
| quantity | int | 委託數量 |
| marketType | ConditionMarketType | [盤別](#conditionmarkettype) 可選用參數 `Common` 整股、`Fixing` 定盤、`IntradayOdd` 盤中零股、`Odd` 盤後零股 |
| priceType | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice` 成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) |
| timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) : 可選參數 :`Stock` 現貨、`Margin` 融資、`Short` 融券 |
##### TPSLOrder Object[](#tpslorder-object "Direct link to TPSLOrder Object")
| Parameter | Type | Meaning |
| ------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| timeInForce | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`ROD`、`IOC`、`FOK` |
| priceType | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice` 成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) : 可選參數 :`Stock` 現貨、`Margin` 融資、`Short` 融券 |
| targetPrice | string | 停損/停利觸發價 |
| price | string | 停損/停利委託價 |
| trigger (optional) | TriggerContent | 停損/停利 [觸發條件](#triggercontent) (詳見表末說明) |
info
`priceType` 若為 `limit` 時,`price` 需填入價格;其餘 price 填入空字串 **或** 不使用 price 欄位 (>= ver. 2.2.4)
停損/停利觸發條件
2.2.0 以後版本新增(***2.1.1 及以前版本無此欄位***),可設定停損/停利觸發價格別為 1. 成交價(MatchedPrice);2. 最佳買價(BidPrice);3. 最佳賣價(AskPrice)
若未設定則預設使用 成交價(MatchedPrice)
##### TPSLWrapper Object[](#tpslwrapper-object "Direct link to TPSLWrapper Object")
| Parameter | Type | Meaning |
| --------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------- |
| stopSign | StopSign | [停止條件](#stopsign) : 可選用 `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| tp | TPSLOrder Object (Optional) | 停利條件內容 |
| sl | TPSLOrder Object (Optional) | 停損條件內容 |
| endDate | string (Optional : 空值同母單 StartDate) | 條件停止日期 |
| intraday | bool (Optional) | 全部成交後日內當沖 |
日內當沖
使用當沖條件單時,`intraday` 需設定為 `true`
##### TrailOrder[](#trailorder "Direct link to TrailOrder")
| Parameter | Type | Meaning |
| ----------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| symbol | string | 股票代號 |
| price | string | 基準價 (Note. 只可輸入至多小數點後兩位,若超出將造成系統洗價失敗) |
| direction | Direction | [方向](#direction) : 可選用 `Up` 上漲、`Down` 下跌 |
| percentage | int | 上漲 / 下跌 % 數 |
| buysell | BSAction | 買賣別 : 可選用 `Buy` 買進 、`Sell` 賣出 |
| quantity | int | 委託股數 |
| PriceType | ConditionPriceType | [價格類別](#conditionpricetype) : 可選用 `BidPrice` 買進價、`AskPrice` 賣出價、`MatchedPrice` 成交價、`Market` 市價、`LimitUp` 漲停價、`LimitDown` 跌停價、`Reference` 參考價(平盤價) |
| diff | int | 買賣價格檔數 (根據 priceType 加減檔數) ,正值為向上加檔數、負值為向下加檔數 |
| timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` |
| orderType | ConditionOrderType | [委託類別](#conditionordertype) 可選用參數為 `Stock` 現股、`Margin` 融資、`Short` 融券 |
##### SplitDescription[](#splitdescription "Direct link to SplitDescription")
| Parameter | Type | Meaning |
| -------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| method | SliceType | [Slice Condition](#slicetype) : 可選用 :
`Type1` 從 `startTime` 開始,每隔幾秒送一筆,總共 `totalQuantity`,每筆送 `singleQuantity`
`Type2` 從 `startTime` 開始到 `endTime` 結束,每隔 `interval` 秒送一筆,總共 `totalQuantity`,剩餘張數加總至最後一筆
`Type3` 從 `startTime` 開始到 `endTime` 結束,每隔 `interval` 秒送一筆,總共 `totalQuantity`,剩餘張數從最後一筆往前分配.
|
| interval | int | 下單間隔時間 (秒) |
| singleQuantity | int | 單筆下單量 (股數) |
| totalQuantity | int (Optional) | 總共下單量 (股數) |
| startTime | string | 開始時間 |
| endTime | string (Optional) | 結束時間 |
caution
請注意,總共下單量需大於單筆下單量。
##### ConditionOrderResult[](#conditionorderresult "Direct link to ConditionOrderResult")
| Parameter | Type | Meaning |
| --------- | ------ | -------- |
| guid | string | 條件單號 |
##### ConditionDayTrade Object[](#conditiondaytrade-object "Direct link to ConditionDayTrade Object")
| Parameter | Type | Meaning |
| --------------- | ----------------------------------------- | -------------------------------------------------- |
| dayTradeEndTime | string | 收盤前沖銷時間,格式 "HHMMSS" (例 "131500") |
| autoCancel | bool | 洗價結束後是否刪除已觸發委託 |
| price | string | 委託價格 (若無指定價格,例如市價單,請填空字串 "") |
| priceType | [ConditionPriceType](#conditionpricetype) | 下單價格類型 |
關於收盤前沖銷時間
可設定區間為 130100 ~ 132000
#### Constants ( 欄位對應數值 )[](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )")
##### BsAction[](#bsaction "Direct link to BsAction")
買賣別
| Name | Meaning |
| ---- | ------- |
| Buy | 買 |
| Sell | 賣 |
##### ConditionMarketType[](#conditionmarkettype "Direct link to ConditionMarketType")
盤別
| Name | Meaning |
| ----------- | -------- |
| Common | 一般盤 |
| Fixing | 定盤 |
| IntradayOdd | 盤中零股 |
| Odd | 盤後零股 |
##### TradingType[](#tradingtype "Direct link to TradingType")
監控類型
| Name | Meaning |
| --------- | ---------------- |
| Reference | 自動參考委託物件 |
| Scheduled | 時間 |
##### TriggerContent[](#triggercontent "Direct link to TriggerContent")
觸發條件
| Name | Meaning |
| ------------- | ------- |
| BidPrice | 買進價 |
| AskPrice | 賣出價 |
| MatchedPrice | 成交價 |
| TotalQuantity | 總量 |
| Time | 時間 |
##### Operator[](#operator "Direct link to Operator")
| Name | Meaning |
| ------------------ | -------- |
| GreaterThanOrEqual | 大於等於 |
| LessThanOrEqual | 小於等於 |
| GreaterThan | 大於 |
| LessThan | 小於 |
##### StopSign[](#stopsign "Direct link to StopSign")
| Name | Meaning |
| -------- | ------------ |
| Full | 全部成交為止 |
| Partial | 部分成交為止 |
| UntilEnd | 效期結束為止 |
##### TimeInForce[](#timeinforce "Direct link to TimeInForce")
委託條件 (TimeInForce)
| Name | Meaning |
| ---- | ------------------------------------- |
| ROD | 當日有效(Rest of Day) |
| FOK | 全部成交否則取消(Fill-or-Kill) |
| IOC | 立即成交否則取消(Immediate-or-Cancel) |
##### ConditionPriceType[](#conditionpricetype "Direct link to ConditionPriceType")
價格類型 (ConditionPriceType)
| Name | Meaning |
| ------------ | -------------- |
| Limit | 限價 |
| BidPrice | 買進價 |
| AskPrice | 賣出價 |
| Market | 市價 |
| MatchedPrice | 成交價 |
| LimitUp | 漲停價 |
| LimitDown | 跌停價 |
| Reference | 參考價(平盤價) |
##### ConditionOrderType[](#conditionordertype "Direct link to ConditionOrderType")
委託類型 (orderType)
| Name | Meaning |
| ------ | ------- |
| Stock | 現貨 |
| Margin | 融資 |
| Short | 融券 |
##### Direction[](#direction "Direct link to Direction")
移動鎖利上漲/下跌追蹤 (direction)
| Name | Meaning |
| ---- | ------- |
| Up | 上漲 |
| Down | 下跌 |
##### SliceType[](#slicetype "Direct link to SliceType")
分單型態 (SliceType)
| Name | Meaning |
| ----- | -------------------------------------------------------------------- |
| Type1 | 從開始時間,每隔幾秒送一筆,總共送 N 筆,每筆送 M 張 |
| Type2 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數加總至最後一筆 |
| Type3 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數從最後一筆往前分配 |
##### ConditionStatus[](#conditionstatus "Direct link to ConditionStatus")
條件單狀態 (ConditionStatus)
| Name | Meaning |
| ------ | ------------ |
| Type1 | 今日相關查詢 |
| Type2 | 尚有效單 |
| Type3 | 條件比對中 |
| Type4 | 委託處理中 |
| Type5 | 委託成功 |
| Type6 | 已通知 |
| Type7 | 委託失敗 |
| Type8 | 已有成交 |
| Type9 | 刪除成功 |
| Type10 | 異常 |
| Type11 | 失效 |
##### HistoryStatus[](#historystatus "Direct link to HistoryStatus")
歷史條件單狀態 (HistoryStatus)
| Name | Meaning |
| ----- | -------------------------------- |
| Type1 | 所有條件單 ( 不包含已刪除、失效) |
| Type2 | 選擇期間內全部成交單 |
| Type3 | 選擇期間內部分成交單 |
| Type4 | 選擇期間刪除單 |
| Type5 | 選擇期間失效單 |
| Type6 | 選擇期間內已觸發記錄 |
---
### 條件單查詢 By 條件單號
getConditionOrderById
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess : false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
sdk.stock.getConditionOrderById(account,"8ff3472b-185a-488c-be5a-b478deda080c")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data :
{
guid : "8ff3472b-185a-488c-be5a-b478deda080c",
batchNo : "",
orderLevel : "1",
lastTime : "2024-03-14 12:39:02",
conditionType : "多條件",
parentGuid : "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol : "2330",
orderAmount : "0",
childBatchNo : "",
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action : "下單(次日回補)",
conditionBuySell : "現股賣",
conditionSymbol : "台積電 現股賣",
conditionPrice : "580元(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
createTime : "2024-03-14 12:39:22",
startDate : "2024/03/14",
status : "未生效(W)",
detailRecordsCount : "0",
tPSLCount : "0"
}
}
```
---
### 歷史條件單查詢
getConditionHistory
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | -------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 查詢開始日 |
| end\_date | string | 查詢截止日 |
| condition\_history\_status | [History Status](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#historystatus) (Optional) | 歷史條件單狀態 |
info
歷史資料日期以條件單創建日期為準
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess : false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
sdk.stock.getConditionHistory(account,"20240301","20240601")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data :[
{
guid : "8ff3472b-185a-488c-be5a-b478deda080c",
batchNo : "",
orderLevel : "1",
lastTime : "2024-03-14 12:39:02",
conditionType : "多條件",
parentGuid : "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol : "2330",
orderAmount : "0",
childBatchNo : "",
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action : "下單(次日回補)",
conditionBuySell : "現股賣",
conditionSymbol : "台積電 現股賣",
conditionPrice : "580元(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
createTime : "2024-03-14 12:39:22",
startDate : "2024/03/14",
status : "未生效(W)",
detailRecordsCount : "0",
tPSLCount : "0"
},
{
guid : "ec757279-bcb3-46f4-80ac-fccfc786bc8d",
batchNo : ,
orderLevel : "0",
lastTime : "2024-05-21 10:30:00",
conditionType : "多條件",
parentGuid : "ec757279-bcb3-46f4-80ac-fccfc786bc8d",
symbol : "2330",
orderAmount : "0",
childBatchNo : ,
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價大於等於575元,且 台積電成交總量大於等於1001張,且 台積電時間大於等於10:30:00 部份成交為止",
action : "下單(當沖)",
conditionBuySell : "現股買",
conditionSymbol : "台積電 現股買",
conditionPrice :" 576元(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
createTime : "2024-03-14 12:30:02",
startDate : "2024/03/14",
status : "觸發-委託失敗(X)",
errorMessage : "單價輸入錯誤[4385715]",
detailRecordsCount : "0",
tPSLCount : "2",
tPSLRecord : [
{
guid : "c94b552a-22da-43e4-be44-f27a9c2026e1",
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action : "下單(次日回補)",
conditionBuySell : "現股賣",
conditionSymbol : "台積電 現股賣",
conditionPrice : "580元(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
startDate : "2024/03/14",
status : "未生效(W)",
},
{
guid : "c94b552a-22da-43e4-be44-f27a9c2026e1",
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止",
action : "下單(次日回補)",
conditionBuySell : "現股賣",
conditionSymbol : "台積電 現股賣",
conditionPrice : "市價(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
startDate : "2024/03/14",
status : "未生效(W)",
}
]
}
]
}
```
---
### 條件單查詢
getConditionOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| conditionStatus | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditionstatus) (Optional) | 條件單狀態 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess : false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
sdk.stock.getConditionOrder(account)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data :[
{
guid : "8ff3472b-185a-488c-be5a-b478deda080c",
batchNo : "",
orderLevel : "1",
lastTime : "2024-03-14 12:39:02",
conditionType : "多條件",
parentGuid : "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol : "2330",
orderAmount : "0",
childBatchNo : "",
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action : "下單(次日回補)",
conditionBuySell : "現股賣",
conditionSymbol : "台積電 現股賣",
conditionPrice : "580元(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
createTime : "2024-03-14 12:39:22",
startDate : "2024/03/14",
status : "未生效(W)",
detailRecordsCount : "0",
tPSLCount : "0"
},
{
guid : "ec757279-bcb3-46f4-80ac-fccfc786bc8d",
batchNo : ,
orderLevel : "0",
lastTime : "2024-05-21 10:30:00",
conditionType : "多條件",
parentGuid : "ec757279-bcb3-46f4-80ac-fccfc786bc8d",
symbol : "2330",
orderAmount : "0",
childBatchNo : ,
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價大於等於575元,且 台積電成交總量大於等於1001張,且 台積電時間大於等於10:30:00 部份成交為止",
action : "下單(當沖)",
conditionBuySell : "現股買",
conditionSymbol : "台積電 現股買",
conditionPrice :" 576元(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
createTime : "2024-03-14 12:30:02",
startDate : "2024/03/14",
status : "觸發-委託失敗(X)",
errorMessage : "單價輸入錯誤[4385715]",
detailRecordsCount : "0",
detailRecords : [],
tPSLCount : "2",
tPSLRecord : [
{
guid : "c94b552a-22da-43e4-be44-f27a9c2026e1",
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action : "下單(次日回補)",
conditionBuySell : "現股賣",
conditionSymbol : "台積電 現股賣",
conditionPrice : "580元(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
startDate : "2024/03/14",
status : "未生效(W)",
errorMessage :
},
{
guid : "c94b552a-22da-43e4-be44-f27a9c2026e1",
account : "1307515",
conditionContent : "當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止",
action : "下單(次日回補)",
conditionBuySell : "現股賣",
conditionSymbol : "台積電 現股賣",
conditionPrice : "市價(ROD)",
conditionVolume : "5張",
conditionFilledVolume : "0張",
startDate : "2024/03/14",
status : "未生效(W)",
errorMessage :
}
]
}
]
}
```
---
### 多條件單
multiCondition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
// 設計條件內容
const condition = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.MatchedPrice,
triggerValue: "80",
comparison: Operator.LessThan
}
const condition2 = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.TotalQuantity,
triggerValue: "8000",
comparison: Operator.GreaterThan
}
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: ConditionMarketType.Common,
priceType: ConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
};
sdk.stock.multiCondition(account, "20240426", "20240430", StopSign.Full, [condition,condition2], order)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 多條件單包含停損停利
multiCondition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則(例如信用交易資買資賣等)
info
待主單完全成交後,停損停利部分才會啟動
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
// 設計條件內容
const condition = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.MatchedPrice,
triggerValue: "80",
comparison: Operator.LessThan
}
const condition2 = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.TotalQuantity,
triggerValue: "8000",
comparison: Operator.GreaterThan
}
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: ConditionMarketType.Common,
priceType: ConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
};
// 停損停利若為Market , price 則填空值""
const tp = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "85",
price: "85",
// trigger: TriggerContent.MatchPrice // v2.2.0 新增
}
const sl = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "60",
price: "60",
// trigger: TriggerContent.MatchPrice // v2.2.0 新增
}
const tpsl = {
stopSign: StopSign.Full,
tp: tp, // optional field
sl: sl, // optional field
endDate: "20240517", // optional field
intraday: false // optional field
}
sdk.stock.multiCondition(account, "20240426", "20240430", StopSign.Full, [condition,condition2], order, tpsl)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 單一條件單
singleCondition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
// 設計條件內容
const condition = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.MatchedPrice,
triggerValue: "80",
comparison: Operator.LessThan
}
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: ConditionMarketType.Common,
priceType: ConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
};
sdk.stock.singleCondition(account, "20240426", "20240430", StopSign.Full, condition, order)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 單一條件單包含停損停利
singleCondition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則(例如信用交易資買資賣等)
info
待主單完全成交後,停損停利部分才會啟動
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
// 設計條件內容
const condition = {
marketType: TradingType.Reference,
symbol: "2881",
trigger: TriggerContent.MatchedPrice,
triggerValue: "80",
comparison: Operator.LessThan
}
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: ConditionMarketType.Common,
priceType: ConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
};
// 停損停利若為Market , price 則填空值""
const tp = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "85",
price: "85",
// trigger: TriggerContent.MatchPrice // v2.2.0 新增
}
const sl = {
timeInForce: TimeInForce.ROD,
priceType: ConditionPriceType.Limit,
orderType: ConditionOrderType.Stock,
targetPrice: "60",
price: "60",
// trigger: TriggerContent.MatchPrice // v2.2.0 新增
}
const tpsl = {
stopSign: StopSign.Full,
tp: tp, // optional field
sl: sl, // optional field
endDate: "20240517", // optional field
intraday: false // optional field
}
sdk.stock.singleCondition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 分時分量查詢
getTimeSliceOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | ---------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| batchNo | string | 分時分量條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess : false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
sdk.stock.getTimeSliceOrder(account,"1234567")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data :
{
guid: "c4dc90c1-4277-42ea-b585-085dc347eac0",
batchNo: "",
orderLevel: "0",
lastTime: "2024-07-23 17:30:01",
conditionType: "分時分量",
parentGuid: "",
symbol: "2881",
orderAmount: "0",
childBatchNo: "",
account: "1307515",
conditionContent: "當於2024/07/23 定時單時間大於等於08:40:00 全部成交為止",
action: "下單",
conditionBuySell: "現股買",
conditionSymbol: "富邦金 現股買",
conditionPrice: "66元(ROD)",
conditionVolume: "1張",
conditionFilledVolume: "0張",
createTime: "2024-07-22 17:30:03",
startDate: "2024/07/23",
status: "條件單中止(I)",
detailRecordsCount: "0",
detailRecords: [],
tpslCount: "0",
tpslRecord: [],
},
{
guid: "2975702e-f36f-4da4-bab6-1310344ec05d",
batchNo: "",
orderLevel: "0",
lastTime: "2024-07-23 17:30:01",
conditionType: "分時分量",
parentGuid: "",
symbol: "2881",
orderAmount: "0",
childBatchNo: "",
account: "1307515",
conditionContent: "當於2024/07/23 定時單時間大於等於09:10:00 全部成交為止",
action: "下單",
conditionBuySell: "現股買",
conditionSymbol: "富邦金 現股買",
conditionPrice: "66元(ROD)",
conditionVolume: "1張",
conditionFilledVolume: "0張",
createTime: "2024-07-22 17:30:03",
startDate: "2024/07/23",
status: "條件單中止(I)",
detailRecordsCount: "0",
detailRecords: [],
tpslCount: "0",
tpslRecord: [],
}
}
```
---
### 分時分量條件單
timeSliceOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| splitDescription | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#splitdescription) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
// 設計條件內容
const split = {
method: TimeSliceOrderType.Type1,
interval: 300,
singleQuantity: 1000,
totalQuantity: 10000,
startTime: '083000',
};
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: ConditionMarketType.Common,
priceType: ConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
};
sdk.stock.timeSliceOrder(target_account, "20240427","20240516", StopSign.Full, split, order)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
guid : "24080500000002"
}
}
```
---
### 歷史移動鎖利查詢
getTrailHistory
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | -------------------------------------------------------------------------------------------- | ---------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 查詢開始日 |
| end\_date | string | 查詢截止日 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess : false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
sdk.stock.getTrailHistory(account,"20240301","20240601")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data :[
{
guid: "5c154a76-e7ef-4b8f-94b5-80bf08fa4b8e",
batchNo: "",
orderLevel: "0",
lastTime: "2024-08-02 16:45:01",
symbol: "2889",
orderAmount: "0",
childBatchNo: "",
account: "1307515",
conditionContent: "從2024/08/02到2024/08/02內當國票金從1000(原始基準價),下跌達10%,持續至預定張數全部成交或期限到達為止",
action: "下單",
conditionBuySell: "現股買",
conditionSymbol: "國票金 (2889)",
conditionPrice: "成交價(1) 檔(ROD)",
conditionVolume: "1張",
conditionFilledVolume: "0張",
createTime: "2024-08-02 10:07:31",
startDate: "2024/08/02",
status: "條件單中止(I)",
detailRecordsCount: "0",
detailRecords: [],
tpslCount: "0",
tpslRecord: [],
},
{
guid: "c71117c8-aa70-4477-9f04-ff4c73a4fad0",
batchNo: "",
orderLevel: "0",
lastTime: "2024-07-29 17:30:00",
symbol: "2330",
orderAmount: "0",
childBatchNo: "",
account: "1307515",
conditionContent: "從2024/07/29到2024/07/29內當台積電從860(原始基準價),上漲達5%,持續至預定張數全部成交或期限到達為止",
action: "下單",
conditionBuySell: "現股買",
conditionSymbol: "台積電 (2330)",
conditionPrice: "成交價(5) 檔(ROD)",
conditionVolume: "2張",
conditionFilledVolume: "0張",
createTime: "2024-07-29 11:01:49",
startDate: "2024/07/29",
status: "條件單中止(I)",
detailRecordsCount: "0",
detailRecords: [],
tpslCount: "0",
tpslRecord: [],
}
]
}
```
---
### 移動鎖利查詢
getTrailOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | ---- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess : false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
sdk.stock.getTrailOrder(account)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data :[
{
guid: "5c154a76-e7ef-4b8f-94b5-80bf08fa4b8e",
batchNo: "",
orderLevel: "0",
lastTime: "2024-08-02 16:45:01",
symbol: "2889",
orderAmount: "0",
childBatchNo: "",
account: "1307515",
conditionContent: "從2024/08/02到2024/08/02內當國票金從1000(原始基準價),下跌達10%,持續至預定張數全部成交或期限到達為止",
action: "下單",
conditionBuySell: "現股買",
conditionSymbol: "國票金 (2889)",
conditionPrice: "成交價(1) 檔(ROD)",
conditionVolume: "1張",
conditionFilledVolume: "0張",
createTime: "2024-08-02 10:07:31",
startDate: "2024/08/02",
status: "條件單中止(I)",
detailRecordsCount: "0",
detailRecords: [],
tpslCount: "0",
tpslRecord: [],
},
{
guid: "c71117c8-aa70-4477-9f04-ff4c73a4fad0",
batchNo: "",
orderLevel: "0",
lastTime: "2024-07-29 17:30:00",
symbol: "2330",
orderAmount: "0",
childBatchNo: "",
account: "1307515",
conditionContent: "從2024/07/29到2024/07/29內當台積電從860(原始基準價),上漲達5%,持續至預定張數全部成交或期限到達為止",
action: "下單",
conditionBuySell: "現股買",
conditionSymbol: "台積電 (2330)",
conditionPrice: "成交價(5) 檔(ROD)",
conditionVolume: "2張",
conditionFilledVolume: "0張",
createTime: "2024-07-29 11:01:49",
startDate: "2024/07/29",
status: "條件單中止(I)",
detailRecordsCount: "0",
detailRecords: [],
tpslCount: "0",
tpslRecord: [],
}
]
}
```
---
### 移動鎖利條件單
trailProfit
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| trailOrder | [TrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.txt#trailorder) | 移動鎖利條件 |
caution
TrailOrder 內之 基準價 (price) 只可輸入至多小數點後兩位,若超出將造成系統洗價失敗
info
當前股票價格價觸及觸發價時(以基準價計算之漲跌 % 數) 即下單
**例:** 若初始基準價設 100, 向下 5% 下單停損/利,初始觸發價為 95,若價格無上漲超過 100(即基準價無調整), 則市場價為 95 時將觸發條件下單
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ----------- | ------ | ------------ |
| guid | string | 條件單號 |
| reply\_code | string | 回覆狀態代號 |
| advisory | string | 回覆狀態內容 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```js
// 設計條件內容
const trail = {
symbol: "2330",
price: "860",
direction: Direction.Down,
percentage: 5,
buySell: BSAction.Sell,
quantity: 2000,
priceType: ConditionPriceType.MatchedPrice,
diff: 5,
timeInForce: TimeInForce.ROD,
orderType: ConditionOrderType.Stock
};
sdk.stock.trailProfit(target_account, "20240427","20240516", StopSign.Full, trail)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```js
{
isSuccess: true,
data : {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 取消條件單
cancel\_condition\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 CancelResult 欄位[](#委託資訊-cancelresult--欄位 "Direct link to 委託資訊 CancelResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| -------- | ------ | ------------ |
| advisory | string | 回覆狀態內容 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
sdk.stock.cancel_condition_orders(account, "c9df498a-3b28-4b50-a6f2-f7bd524e96df")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : CancelResult {
advisory: "成功筆數:1,失敗筆數:0!",
}
}
```
---
### 當沖條件單查詢
get\_condition\_daytade\_by\_id
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ----------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| creat\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 明細筆數 |
| detail\_records | List | 明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
sdk.stock.get_condition_daytrade_by_id(account,"8ff3472b-185a-488c-be5a-b478deda080c")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data :
ConditionDetail {
guid: "8ff3472b-185a-488c-be5a-b478deda080c",
batch_no: "",
order_level: "1",
last_time: "2024-03-14 12:39:02",
condition_type: "多條件",
parent_guid: "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "580元(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
creat_time: "2024-03-14 12:39:22",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: None,
detail_records_count: "0",
detail_records: [],
tpslCount: "0",
tpslRecord: [],
}
}
```
---
### 當沖多條件單
multi\_condition\_day\_trade
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定回補成功,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合當日沖銷交易規則(例如信用交易使用資券互抵)
當沖條件單查詢
* 使用 guid 查詢當沖條件單請使用***當沖條件單查詢***功能
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| end\_time | string | 父單洗價結束時間 |
| multicondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
| fixSession | bool | 執行定盤回補 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ----------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
#from fubon_neo.sdk import ConditionDayTrade
# 設計條件內容
condition = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.MatchedPrice,
trigger_value = "66",
comparison = Operator.LessThan
)
condition2 = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.TotalQuantity,
trigger_value = "8000",
comparison = Operator.LessThan
)
order = ConditionOrder(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 1000,
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
daytrade_obj = ConditionDayTrade(
day_trade_end_time = "131500", # 收盤前沖銷時間,可設定區間為 130100 ~ 132000
auto_cancel= True,
price = "",
price_type=ConditionPriceType.Market
)
tp = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="85",
price="85",
)
sl = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="60",
price="60",
)
tpsl = TPSLWrapper(
stop_sign= StopSign.Full,
end_date="20240517",
tp=tp,
sl=sl,
intraday=True # ** 設定 True 以啟用當日沖銷洗價
)
sdk.stock.multi_condition_day_trade(account, StopSign.Full, "130000", [condition ,condition2], order, daytrade_obj, tpsl, True)
# 不設定停損停利
# sdk.stock.multi_condition_day_trade(account, StopSign.Full, "130000", [condition ,condition2], order, daytrade_obj, None, True)
# 不設定定盤回補
# sdk.stock.multi_condition_day_trade(account, StopSign.Full, "130000", [condition ,condition2], order, daytrade_obj, tpsl, False)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : ConditionOrderResult {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 當沖單一條件單
single\_condition\_day\_trade
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定回補成功,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合當日沖銷交易規則(例如信用交易使用資券互抵)
當沖條件單查詢
* 使用 guid 查詢當沖條件單請使用***當沖條件單查詢***功能
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| end\_time | string | 父單洗價結束時間 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
| fixSession | bool | 執行定盤回補 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ----------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
# from fubon_neo.sdk import ConditionDayTrade
# 設計條件內容
condition = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.MatchedPrice,
trigger_value = "66",
comparison = Operator.LessThan
)
order = ConditionOrder(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 1000,
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
daytrade_obj = ConditionDayTrade(
day_trade_end_time = "131500", # 收盤前沖銷時間,可設定區間為 130100 ~ 132000
auto_cancel= True,
price = "",
price_type=ConditionPriceType.Market
)
tp = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="85",
price="85",
)
sl = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="60",
price="60",
)
tpsl = TPSLWrapper(
stop_sign= StopSign.Full,
end_date="20240517",
tp=tp,
sl=sl,
intraday =True # ** 設定 true 以啟用當日沖銷洗價
)
sdk.stock.single_condition_day_trade(account, StopSign.Full, "130000", condition, order, daytrade_obj, tpsl, True)
# 不設定停損停利
# sdk.stock.single_condition_day_trade(account, StopSign.Full, "130000", condition, order, daytrade_obj, None, True)
# 不設定定盤回補
# sdk.stock.single_condition_day_trade(account, StopSign.Full, "130000", condition, order, daytrade_obj, tpsl, False)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : ConditionOrderResult {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 參數對照表
#### 類別[](#類別 "Direct link to 類別")
Class
##### Condition Object[](#condition-object "Direct link to Condition Object")
| Parameter | Type | Meaning |
| -------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| market\_type | TradingType | [監控類型](#tradingtype) 可選用參數 : `Reference` 自動參考委託物件、`Scheduled` 時間 |
| symbol | string | 股票代號 |
| trigger | TriggerContent | [觸發條件](#triggercontent) 可選用參數 : `BidPrice` 買進價、`AskPrice` 賣出價、`MatchedPrice` 成交價、`TotalQuantity` 總量、`Time` 時間 |
| trigger\_value | string | 監控條件數值 (若為時間則填入 HHMMSS) |
| comparison | Operator | [比對值](#operator) 可選用參數 `GreaterThanOrEqual` 大於等於、`LessThanOrEqual` 小於等於 、 `GreaterThan` 大於 、 `LessThan` 小於 |
info
1. 選擇 `Reference` 時, trigger 可搭配 `BidPrice` 、`AskPrice` 、`MatchedPrice` 、`TotalQuantity` 、 `Time`,若 trigger 使用 Time,則時間條件達成,且時間範圍內商品有交易產生才觸發
2. 選擇 `Scheduled` 時,symbol 需填入空值"",trigger 需帶入 `Time`,則會使用系統時間判斷,當時間條件達成即觸發
##### ConditionOrder Object[](#conditionorder-object "Direct link to ConditionOrder Object")
| Parameter | Type | Meaning |
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| buy\_sell | BSAction | [買賣別](#bsaction) |
| symbol | string | 股票代號 |
| price | string | 委託價格 |
| quantity | int | 委託數量 |
| market\_type | ConditionMarketType | [盤別](#conditionmarkettype) 可選用參數 `Common` 整股、`Fixing` 定盤、`IntradayOdd` 盤中零股、`Odd` 盤後零股 |
| price\_type | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice` 成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) |
| time\_in\_force | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`ROD`、`IOC`、`FOK` |
| order\_type | ConditionOrderType | [委託類別](#conditionordertype) : 可選參數 :`Stock` 現貨、`Margin` 融資、`Short` 融券 |
##### TPSLOrder Object[](#tpslorder-object "Direct link to TPSLOrder Object")
| Parameter | Type | Meaning |
| ------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| time\_in\_force | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`ROD`、`IOC`、`FOK` |
| price\_type | ConditionPriceType | [價格別](#conditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice` 成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) |
| order\_type | ConditionOrderType | [委託類別](#conditionordertype) : 可選參數 :`Stock` 現貨、`Margin` 融資、`Short` 融券 |
| target\_price | string | 停損/停利觸發價 |
| price | string | 停損/停利委託價 |
| trigger (optional) | TriggerContent | 停損/停利 [觸發條件](#triggercontent) (詳見表末說明) |
info
`priceType` 若為 `limit` 時,`price` 需填入價格;其餘 price 填入空字串 **或** `None` (>= ver. 2.2.4)
停損/停利觸發條件
2.2.0 以後版本新增(***2.1.1 及以前版本無此欄位***),可設定停損/停利觸發價格別為 1. 成交價(MatchedPrice);2. 最佳買價(BidPrice);3. 最佳賣價(AskPrice)
若未設定則預設使用 成交價(MatchedPrice)
##### TPSLWrapper Object[](#tpslwrapper-object "Direct link to TPSLWrapper Object")
| Parameter | Type | Meaning |
| ---------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------- |
| stop\_sign | StopSign | [停止條件](#stopsign) : 可選用 `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| tp | TPSLOrder Object (Optional) | 停利條件內容 |
| sl | TPSLOrder Object (Optional) | 停損條件內容 |
| end\_date | string (Optional : 空值同母單 StartDate) | 條件停止日期 |
| intraday | bool (Optional) | 全部成交後日內當沖 |
日內當沖
使用當沖條件單時,`intraday` 需設定為 `True`
##### TrailOrder[](#trailorder "Direct link to TrailOrder")
| Parameter | Type | Meaning |
| --------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| symbol | string | 股票代號 |
| price | string | 基準價 (Note. 只可輸入至多小數點後兩位,若超出將造成系統洗價失敗) |
| direction | Direction | [方向](#direction) : 可選用 `Up` 上漲、`Down` 下跌 |
| percentage | int | 上漲 / 下跌 % 數 |
| buysell | BSAction | 買賣別 : 可選用 `Buy` 買進 、`Sell` 賣出 |
| quantity | int | 委託股數 |
| price\_type | ConditionPriceType | [價格類別](#conditionpricetype) : 可選用 `BidPrice` 買進價、`AskPrice` 賣出價、`MatchedPrice` 成交價、`Market` 市價、`LimitUp` 漲停價、`LimitDown` 跌停價、`Reference` 參考價(平盤價) |
| diff | int | 買賣價格檔數 (根據 priceType 加減檔數) ,正值為向上加檔數、負值為向下加檔數 |
| time\_in\_force | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` |
| order\_type | ConditionOrderType | [委託類別](#conditionordertype) 可選用參數為 `Stock` 現股、`Margin` 融資、`Short` 融券 |
##### SplitDescription[](#splitdescription "Direct link to SplitDescription")
| Parameter | Type | Meaning |
| ---------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| method | SliceType | [Slice Condition](#slicetype) : 可選用 :
`Type1` 從 `start_time` 開始,每隔幾秒送一筆,總共 `total_quantity`,每筆送 `single_quantity`
`Type2` 從 `start_time` 開始到 `end_time` 結束,每隔 `interval` 秒送一筆,總共 `total_quantity`,剩餘張數加總至最後一筆
`Type3` 從 `start_time` 開始到 `end_time` 結束,每隔 `interval` 秒送一筆,總共 `total_quantity`,剩餘張數從最後一筆往前分配.
|
| interval | int | 下單間隔時間 (秒) |
| single\_quantity | int | 單筆下單量 (股數) |
| total\_quantity | int (Optional) | 總共下單量 (股數) |
| start\_time | string | 開始時間 |
| end\_time | string (Optional) | 結束時間 |
caution
請注意,總共下單量需大於單筆下單量。
##### ConditionOrderResult[](#conditionorderresult "Direct link to ConditionOrderResult")
| Parameter | Type | Meaning |
| --------- | ------ | -------- |
| guid | string | 條件單號 |
##### ConditionDayTrade Object[](#conditiondaytrade-object "Direct link to ConditionDayTrade Object")
| Parameter | Type | Meaning |
| --------------------- | ----------------------------------------- | -------------------------------------------------- |
| day\_trade\_end\_time | string | 收盤前沖銷時間,格式 "HHMMSS" (例 "131500") |
| auto\_cancel | bool | 洗價結束後是否刪除已觸發委託 |
| price | string | 委託價格 (若無指定價格,例如市價單,請填空字串 "") |
| price\_type | [ConditionPriceType](#conditionpricetype) | 委託價格類型 |
關於收盤前沖銷時間
可設定區間為 130100 ~ 132000
#### Constants ( 欄位對應數值 )[](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )")
##### BsAction[](#bsaction "Direct link to BsAction")
買賣別
| Name | Meaning |
| ---- | ------- |
| Buy | 買 |
| Sell | 賣 |
##### ConditionMarketType[](#conditionmarkettype "Direct link to ConditionMarketType")
盤別
| Name | Meaning |
| ----------- | -------- |
| Common | 一般盤 |
| Fixing | 定盤 |
| IntradayOdd | 盤中零股 |
| Odd | 盤後零股 |
##### TradingType[](#tradingtype "Direct link to TradingType")
監控類型
| Name | Meaning |
| --------- | ---------------- |
| Reference | 自動參考委託物件 |
| Scheduled | 時間 |
##### TriggerContent[](#triggercontent "Direct link to TriggerContent")
觸發條件
| Name | Meaning |
| ------------- | ------- |
| BidPrice | 買進價 |
| AskPrice | 賣出價 |
| MatchedPrice | 成交價 |
| TotalQuantity | 總量 |
| Time | 時間 |
##### Operator[](#operator "Direct link to Operator")
| Name | Meaning |
| ------------------ | -------- |
| GreaterThanOrEqual | 大於等於 |
| LessThanOrEqual | 小於等於 |
| GreaterThan | 大於 |
| LessThan | 小於 |
##### StopSign[](#stopsign "Direct link to StopSign")
| Name | Meaning |
| -------- | ------------ |
| Full | 全部成交為止 |
| Partial | 部分成交為止 |
| UntilEnd | 效期結束為止 |
##### TimeInForce[](#timeinforce "Direct link to TimeInForce")
委託條件 (TimeInForce)
| Name | Meaning |
| ---- | ------------------------------------- |
| ROD | 當日有效(Rest of Day) |
| FOK | 全部成交否則取消(Fill-or-Kill) |
| IOC | 立即成交否則取消(Immediate-or-Cancel) |
##### ConditionPriceType[](#conditionpricetype "Direct link to ConditionPriceType")
價格類型 (ConditionPriceType)
| Name | Meaning |
| ------------ | -------------- |
| Limit | 限價 |
| BidPrice | 買進價 |
| AskPrice | 賣出價 |
| Market | 市價 |
| MatchedPrice | 成交價 |
| LimitUp | 漲停價 |
| LimitDown | 跌停價 |
| Reference | 參考價(平盤價) |
##### ConditionOrderType[](#conditionordertype "Direct link to ConditionOrderType")
委託類型 (ConditionOrderType)
| Name | Meaning |
| ------ | ------- |
| Stock | 現貨 |
| Margin | 融資 |
| Short | 融券 |
##### Direction[](#direction "Direct link to Direction")
移動鎖利上漲/下跌追蹤 (direction)
| Name | Meaning |
| ---- | ------- |
| Up | 上漲 |
| Down | 下跌 |
##### SliceType[](#slicetype "Direct link to SliceType")
分單型態 (SliceType)
| Name | Meaning |
| ----- | -------------------------------------------------------------------- |
| Type1 | 從開始時間,每隔幾秒送一筆,總共送 N 筆,每筆送 M 張 |
| Type2 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數加總至最後一筆 |
| Type3 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數從最後一筆往前分配 |
##### ConditionStatus[](#conditionstatus "Direct link to ConditionStatus")
條件單狀態 (ConditionStatus)
| Name | Meaning |
| ------ | ------------ |
| Type1 | 今日相關查詢 |
| Type2 | 尚有效單 |
| Type3 | 條件比對中 |
| Type4 | 委託處理中 |
| Type5 | 委託成功 |
| Type6 | 已通知 |
| Type7 | 委託失敗 |
| Type8 | 已有成交 |
| Type9 | 刪除成功 |
| Type10 | 異常 |
| Type11 | 失效 |
##### HistoryStatus[](#historystatus "Direct link to HistoryStatus")
歷史條件單狀態 (HistoryStatus)
| Name | Meaning |
| ----- | -------------------------------- |
| Type1 | 所有條件單 ( 不包含已刪除、失效) |
| Type2 | 選擇期間內全部成交單 |
| Type3 | 選擇期間內部分成交單 |
| Type4 | 選擇期間刪除單 |
| Type5 | 選擇期間失效單 |
| Type6 | 選擇期間內已觸發記錄 |
---
### 條件單查詢 By Guid
get\_condition\_order\_by\_id
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| creat\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 明細筆數 |
| detail\_records | List | 明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
sdk.stock.get_condition_order_by_id(account,"8ff3472b-185a-488c-be5a-b478deda080c")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data :
ConditionDetail {
guid: "8ff3472b-185a-488c-be5a-b478deda080c",
batch_no: "",
order_level: "1",
last_time: "2024-03-14 12:39:02",
condition_type: "多條件",
parent_guid: "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "580元(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
creat_time: "2024-03-14 12:39:22",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: None,
detail_records_count: "0",
detail_records: [],
tpslCount: "0",
tpslRecord: [],
}
}
```
---
### 歷史條件單查詢
get\_condition\_history
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | -------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 查詢開始日 |
| end\_date | string | 查詢截止日 |
| condition\_history\_status | [History Status](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#historystatus) (Optional) | 歷史條件單狀態 |
info
歷史資料日期以條件單創建日期為準
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| creat\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
sdk.stock.get_condition_history(account,"20240310","20240601")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : [
ConditionDetail {
guid: "8ff3472b-185a-488c-be5a-b478deda080c",
batch_no: "",
order_level: "1",
last_time: "2024-03-14 12:39:02",
condition_type: "多條件",
parent_guid: "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "580元(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
creat_time: "2024-03-14 12:39:22",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: None,
detail_records_count: "0",
detail_records: [],
tpslCount: "0",
tpslRecord: [],
},
ConditionDetail {
guid: "8ff3472b-185a-488c-be5a-b478deda080c",
batch_no: "",
order_level: "1",
last_time: "2024-03-14 12:39:02",
condition_type: "多條件",
parent_guid: "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "市價(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
creat_time: "2024-03-14 12:39:22",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: None,
detail_records_count: "0",
detail_records: [],
tpslCount: "0",
tpslRecord: [],
},
ConditionDetail {
guid: "ec757279-bcb3-46f4-80ac-fccfc786bc8d",
batch_no: "",
order_level: "0",
last_time: "2024-05-21 10:30:00",
condition_type: "多條件",
parent_guid: "ec757279-bcb3-46f4-80ac-fccfc786bc8d",
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價大於等於575元,且 台積電成交總量大於等於1001張,且 台積電時間大於等於10:30:00 部份成交為止",
action: "下單(當沖) ",
condition_buy_sell: "現股買",
condition_symbol: "台積電 現股買",
condition_price: "576元(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
creat_time: "2024-03-14 12:30:02",
start_date: "2024/03/14",
status: "觸發-委託失敗(X)",
error_message: "單價輸入錯誤[4385715]",
detail_records_count: "0",
detail_records: [],
tpslCount: "2",
tpslRecord: [
ParentChildRecord {
guid: "c94b552a-22da-43e4-be44-f27a9c2026e1",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "580元(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: "",
},
ParentChildRecord {
guid: "c94b552a-22da-43e4-be44-f27a9c2026e1",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "市價(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: "",
},
],
}
]
}
```
---
### 條件單查詢
get\_condition\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| condition\_status | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditionstatus) (Optional) | 條件單狀態 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| creat\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 明細筆數 |
| detail\_records | List | 明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
sdk.stock.get_condition_order(account)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : [
ConditionDetail {
guid: "8ff3472b-185a-488c-be5a-b478deda080c",
batch_no: "",
order_level: "1",
last_time: "2024-03-14 12:39:02",
condition_type: "多條件",
parent_guid: "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "580元(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
creat_time: "2024-03-14 12:39:22",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: None,
detail_records_count: "0",
detail_records: [],
tpslCount: "0",
tpslRecord: [],
},
ConditionDetail {
guid: "8ff3472b-185a-488c-be5a-b478deda080c",
batch_no: "",
order_level: "1",
last_time: "2024-03-14 12:39:02",
condition_type: "多條件",
parent_guid: "58e7a51e-9701-4d26-bc16-18a392a840bd",
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "市價(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
creat_time: "2024-03-14 12:39:22",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: None,
detail_records_count: "0",
detail_records: [],
tpslCount: "0",
tpslRecord: [],
},
ConditionDetail {
guid: "ec757279-bcb3-46f4-80ac-fccfc786bc8d",
batch_no: "",
order_level: "0",
last_time: "2024-05-21 10:30:00",
condition_type: "多條件",
parent_guid: "ec757279-bcb3-46f4-80ac-fccfc786bc8d",
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價大於等於575元,且 台積電成交總量大於等於1001張,且 台積電時間大於等於10:30:00 部份成交為止",
action: "下單(當沖) ",
condition_buy_sell: "現股買",
condition_symbol: "台積電 現股買",
condition_price: "576元(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
creat_time: "2024-03-14 12:30:02",
start_date: "2024/03/14",
status: "觸發-委託失敗(X)",
error_message: "單價輸入錯誤[4385715]",
detail_records_count: "0",
detail_records: [],
tpslCount: "2",
tpslRecord: [
ParentChildRecord {
guid: "c94b552a-22da-43e4-be44-f27a9c2026e1",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價大於等於580元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "580元(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: "",
},
ParentChildRecord {
guid: "c94b552a-22da-43e4-be44-f27a9c2026e1",
account: "1307515",
condition_content: "當自2024/03/14至2024/07/04內台積電成交價小於等於570元 全部成交為止",
action: "下單(次日回補) ",
condition_buy_sell: "現股賣",
condition_symbol: "台積電 現股賣",
condition_price: "市價(ROD)",
condition_volume: "5張",
condition_filled_volume: "0張",
start_date: "2024/03/14",
status: "未生效(W)",
error_message: "",
},
],
}
]
}
```
---
### 多條件單
multi\_condition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| MultiCondition | [Condition Array](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
# 設計條件內容
condition = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.MatchedPrice,
trigger_value = "80",
comparison = Operator.LessThan
)
condition2 = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.TotalQuantity,
trigger_value = "8000",
comparison = Operator.LessThan
)
order = ConditionOrder(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 1000,
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
sdk.stock.multi_condition(account, "20240426", "20240430", StopSign.Full, [condition, condition2], order)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : ConditionOrderResult {
guid : "44150047-8977-40b1-953c-ce270f0000"
}
}
```
---
### 多條件單包含停損停利
multiCondition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則(例如信用交易資買資賣等)
info
待主單完全成交後,停損停利部分才會啟動
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
# 設計條件內容
condition = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.MatchedPrice,
trigger_value = "66",
comparison = Operator.LessThan
)
condition2 = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.TotalQuantity,
trigger_value = "8000",
comparison = Operator.LessThan
)
order = ConditionOrder(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 1000,
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock,
)
# 停損停利若為Market , price 則填空值""
tp = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="85",
price="85",
# trigger=TriggerContent.MatchedPrice # v2.2.0 新增
)
sl = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="60",
price="60",
# trigger=TriggerContent.MatchedPrice # v2.2.0 新增
)
tpsl = TPSLWrapper(
stop_sign= StopSign.Full,
tp=tp, # optional field
sl=sl, # optional field
end_date="20240517", # optional field
intraday =False # optional field
)
sdk.stock.multi_condition(account, "20240426", "20240430", StopSign.Full, [condition,condition2], order, tpsl)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : ConditionOrderResult {
guid : "44150047-8977-40b1-953c-ce270f0000"
}
}
```
---
### 單一條件單
single\_condition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
# 設計條件內容
condition = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.MatchedPrice,
trigger_value = "80",
comparison = Operator.LessThan
)
order = ConditionOrder(
buy_sell= BSAction.Sell,
symbol = "2881",
quantity = 1000,
price = "60",
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
res = sdk.stock.single_condition(account, "20240427","20240516", StopSign.Full , condition, order)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : ConditionOrderResult {
guid : "44150047-8977-40b1-953c-ce270f36150"
}
}
```
---
### 單一條件單包含停損停利
single\_condition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則(例如信用交易資買資賣等)
info
待主單完全成交後,停損停利部分才會啟動
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditionorder-object) | 委託內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#tpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
# 設計條件內容
condition = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.MatchedPrice,
trigger_value = "66",
comparison = Operator.LessThan
)
order = ConditionOrder(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 1000,
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
# 停損停利若為Market , price 則填空值""
tp = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="85",
price="85",
# trigger=TriggerContent.MatchedPrice # v2.2.0 新增
)
sl = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="60",
price="60",
# trigger=TriggerContent.MatchedPrice # v2.2.0 新增
)
tpsl = TPSLWrapper(
stop_sign= StopSign.Full,
tp=tp, # optional field
sl=sl, # optional field
end_date="20240517", # optional field
intraday =False # optional field
)
sdk.stock.single_condition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : ConditionOrderResult {
guid : "44150047-8977-40b1-953c-ce2XXXXXX"
}
}
```
---
### 分時分量查詢
get\_time\_slice\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------- | -------------------------------------------------------------------------------------------- | ---------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| batch\_no | string | 分時分量條件單號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| creat\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 明細筆數 |
| detail\_records | List | 明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
sdk.stock.get_time_slice_order(account,"123456")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data :
ConditionDetail {
guid: "c4dc90c1-4277-42ea-b585-085dc347eac0",
batch_no: "",
order_level: "0",
last_time: "2024-07-23 17:30:01",
condition_type: "分時分量",
parent_guid: "",
symbol: "2881",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當於2024/07/23 定時單時間大於等於08:40:00 全部成交為止",
action: "下單",
condition_buy_sell: "現股買",
condition_symbol: "富邦金 現股買",
condition_price: "66元(ROD)",
condition_volume: "1張",
condition_filled_volume: "0張",
create_time: "2024-07-22 17:30:03",
start_date: "2024/07/23",
status: "條件單中止(I)",
error_message: None,
detail_records_count: "0",
detail_records: [],
TPSLCount: "0",
TPSLRecord: [],
}, ConditionDetail {
guid: "2975702e-f36f-4da4-bab6-1310344ec05d",
batch_no: "",
order_level: "0",
last_time: "2024-07-23 17:30:01",
condition_type: "分時分量",
parent_guid: "",
symbol: "2881",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "當於2024/07/23 定時單時間大於等於09:10:00 全部成交為止",
action: "下單",
condition_buy_sell: "現股買",
condition_symbol: "富邦金 現股買",
condition_price: "66元(ROD)",
condition_volume: "1張",
condition_filled_volume: "0張",
create_time: "2024-07-22 17:30:03",
start_date: "2024/07/23",
status: "條件單中止(I)",
error_message: None,
detail_records_count: "0",
detail_records: [],
TPSLCount: "0",
TPSLRecord: [],
}
}
```
---
### 分時分量條件單
time\_slice\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| split\_description | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#splitdescription) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#conditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
# 設計條件內容
split = SplitDescription(
method=TimeSliceOrderType.Type1,
interval= 300,
single_quantity= 1000,
total_quantity= 10000,
start_time='083000',
)
order = ConditionOrder(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 1000,
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
sdk.stock.time_slice_order(target_account, "20240427","20240516", StopSign.Full, split, order)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : ConditionOrderResult {
guid : "24080500000002"
}
}
```
---
### 歷史移動鎖利查詢
get\_trail\_history
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | -------------------------------------------------------------------------------------------- | ---------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 查詢開始日 |
| end\_date | string | 查詢截止日 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| creat\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 查詢明細筆數 |
| detail\_records | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
sdk.stock.get_trail_history(account,"20240310","20240601")
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : [
ConditionDetail {
guid: "5c154a76-e7ef-4b8f-94b5-80bf08fa4b8e",
batch_no: "",
order_level: "0",
last_time: "2024-08-02 16:45:01",
condition_type: None,
parent_guid: None,
symbol: "2889",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "從2024/08/02到2024/08/02內當國票金從1000(原始基準價),下跌達10%,持續至預定張數全部成交或期限到達為止",
action: "下單",
condition_buy_sell: "現股買",
condition_symbol: "國票金 (2889)",
condition_price: "成交價(1) 檔(ROD)",
condition_volume: "1張",
condition_filled_volume: "0張",
create_time: "2024-08-02 10:07:31",
start_date: "2024/08/02",
status: "條件單中止(I)",
error_message: None,
detail_records_count: "0",
detail_records: [],
TPSLCount: "0",
TPSLRecord: [],
}, ConditionDetail {
guid: "c71117c8-aa70-4477-9f04-ff4c73a4fad0",
batch_no: "",
order_level: "0",
last_time: "2024-07-29 17:30:00",
condition_type: None,
parent_guid: None,
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "從2024/07/29到2024/07/29內當台積電從860(原始基準價),上漲達5%,持續至預定張數全部成交或期限到達為止",
action: "下單",
condition_buy_sell: "現股買",
condition_symbol: "台積電 (2330)",
condition_price: "成交價(5) 檔(ROD)",
condition_volume: "2張",
condition_filled_volume: "0張",
create_time: "2024-07-29 11:01:49",
start_date: "2024/07/29",
status: "條件單中止(I)",
error_message: None,
detail_records_count: "0",
detail_records: [],
TPSLCount: "0",
TPSLRecord: [],
}
]
}
```
---
### 有效移動鎖利查詢
get\_trail\_order
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | -------------------------------------------------------------------------------------------- | ---- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---------------------------- | ------ | ---------------- |
| guid | string | 條件單號 |
| batch\_no | string | 分單批號 |
| order\_level | string | 條件單層級 |
| last\_time | string | 更新時間 |
| parent\_guid | string | 父單單號 |
| symbol | string | 商品代號 |
| order\_amount | string | 委託金額 |
| child\_batch\_no | string | 子單分單批號 |
| account | string | 帳號 |
| condition\_content | string | 條件內容 |
| action | string | 處理方式 |
| condition\_buy\_sell | string | 買賣別 |
| condition\_symbol | string | 商品名稱 |
| condition\_price | string | 價格 |
| condition\_volume | string | 委託數量 |
| condition\_filled\_volume | string | 成交數量 |
| creat\_time | string | 建立時間 |
| start\_date | string | 預約開始時間 |
| status | string | 目前狀態 |
| error\_message | string | 目前狀態異常說明 |
| detail\_records\_count | string | 明細筆數 |
| detail\_records | List | 明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> condition\_content | string | 條件內容 |
| >> action | string | 處理方式 |
| >> condition\_buy\_sell | string | 買賣別 |
| >> condition\_symbol | string | 商品名稱 |
| >> condition\_price | string | 價格 |
| >> condition\_volume | string | 委託數量 |
| >> condition\_filled\_volume | string | 成交數量 |
| >> start\_date | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> error\_message | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
sdk.stock.get_trail_order(account)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : [
ConditionDetail {
guid: "5c154a76-e7ef-4b8f-94b5-80bf08fa4b8e",
batch_no: "",
order_level: "0",
last_time: "2024-08-02 16:45:01",
condition_type: None,
parent_guid: None,
symbol: "2889",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "從2024/08/02到2024/08/02內當國票金從1000(原始基準價),下跌達10%,持續至預定張數全部成交或期限到達為止",
action: "下單",
condition_buy_sell: "現股買",
condition_symbol: "國票金 (2889)",
condition_price: "成交價(1) 檔(ROD)",
condition_volume: "1張",
condition_filled_volume: "0張",
create_time: "2024-08-02 10:07:31",
start_date: "2024/08/02",
status: "條件單中止(I)",
error_message: None,
detail_records_count: "0",
detail_records: [],
TPSLCount: "0",
TPSLRecord: [],
}, ConditionDetail {
guid: "c71117c8-aa70-4477-9f04-ff4c73a4fad0",
batch_no: "",
order_level: "0",
last_time: "2024-07-29 17:30:00",
condition_type: None,
parent_guid: None,
symbol: "2330",
order_amount: "0",
child_batch_no: "",
account: "1307515",
condition_content: "從2024/07/29到2024/07/29內當台積電從860(原始基準價),上漲達5%,持續至預定張數全部成交或期限到達為止",
action: "下單",
condition_buy_sell: "現股買",
condition_symbol: "台積電 (2330)",
condition_price: "成交價(5) 檔(ROD)",
condition_volume: "2張",
condition_filled_volume: "0張",
create_time: "2024-07-29 11:01:49",
start_date: "2024/07/29",
status: "條件單中止(I)",
error_message: None,
detail_records_count: "0",
detail_records: [],
TPSLCount: "0",
TPSLRecord: [],
}
]
}
```
---
### 移動鎖利條件單
trail\_profit
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------ | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| trail\_order | [TrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.txt#trailorder) | 移動鎖利條件 |
caution
TrailOrder 內之 基準價 (price) 只可輸入至多小數點後兩位,若超出將造成系統洗價失敗
info
當前股票價格價觸及觸發價時(以基準價計算之漲跌 % 數) 即下單
**例:** 若初始基準價設 100, 向下 5% 下單停損/利,初始觸發價為 95,若價格無上漲超過 100(即基準價無調整), 則市場價為 95 時將觸發條件下單
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```py
# 設計條件內容
trail = TrailOrder(
symbol = "2330",
price = "860",
direction = Direction.Up ,
percentage = 5, # 漲跌 % 數
buy_sell = BSAction.Buy,
quantity = 2000,
price_type = ConditionPriceType.MatchedPrice,
diff = 5, # 向上 or 向下追買 tick數 (向下為負值)
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)
sdk.stock.trail_profit(target_account, "20240427","20240516", StopSign.Full, trail)
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : ConditionOrderResult {
guid : "44150047-8977-40b1-953c-ce270f0000"
}
}
```
---
### 事前準備
本頁重點
* 使用條件單前,需先閱讀使用說明並完成簽署。
* SDK 版本需升級至 v1.3 以上。
* 支援 Python / Node.js 條件單套件引入。
| 項目 | 說明 |
| -------- | ---------------------------------------- |
| 產品 | 富邦新一代 API 條件單 |
| 必要前置 | 閱讀使用說明、簽署條件單同意書、升級 SDK |
| 支援語言 | Python / C# / JavaScript (Node.js) |
| 套件引入 | 僅 Python / JS 需額外引入套件 |
caution
在開始富邦新一代 API 條件單前,請先詳細閱讀 [**使用說明**](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/Agreements.txt) 並完成簽署條件單使用同意書
#### 簽署條件單使用同意書[](#簽署條件單使用同意書 "Direct link to 簽署條件單使用同意書")
使用您的富邦證券帳戶
1. 開啟您的富邦 Online 手機 APP ,點選更多

2. 點選 `M櫃台`

3. 點選條件單同意書

#### 升級您的 SDK 版本至 v1.3 以上[](#升級您的-sdk-版本至-v13-以上 "Direct link to 升級您的 SDK 版本至 v1.3 以上")
SDK 最新版本 : [下載連結](https://www.fbs.com.tw/TradeAPI/docs/download/download-sdk.txt)
#### 引入套件 ( 僅 Python、JS 需要,C#不需額外操作)[](#引入套件--僅-pythonjs-需要c不需額外操作 "Direct link to 引入套件 ( 僅 Python、JS 需要,C#不需額外操作)")
引入條件單相關套件
* Python
* Node.js
```py
from fubon_neo.sdk import FubonSDK, Condition, ConditionDayTrade, ConditionOrder
from fubon_neo.constant import (
TriggerContent, TradingType, Operator, TPSLOrder, TPSLWrapper, SplitDescription,
StopSign, TimeSliceOrderType, ConditionMarketType, ConditionPriceType, ConditionOrderType, TrailOrder, Direction, ConditionStatus, HistoryStatus
)
```
```js
const { FubonSDK, TriggerContent, TradingType, Operator, TPSLOrder, TPSLWrapper, SplitDescription,
StopSign, TimeSliceOrderType, ConditionMarketType, ConditionPriceType, ConditionOrderType, TrailOrder, Direction, ConditionStatus, HistoryStatus } = require('fubon-neo');
```
info
條件單目前不支援期權商品與現貨商品混用
---
### 緊急應變措施
若有因不可抗力之因素或系統異常,而造成無法下單或確認委託成交狀況時,請使用其他平台作為備援
條件單替代平台:
* HTS2
* Online APP
* 營業員
更多訊息請洽富邦證券官網 [網路下單系統無法正常使用之應變措施](https://www.fbs.com.tw/Beginner/TradingNote/)
---
### 停損停利單
富邦新一代 API 支援條件下單後的停損停利單,
停損停利運作機制 : 當觸發的條件單,觸發後,並委託成交,就會啟動停損停利的監控機制,而當停利條件達成時,停損就會失效;反之亦然 (同一般市面上常見 OCO)

#### 程式範例[](#程式範例 "Direct link to 程式範例")
* Python
* Node.js
* C#
```py
# 設計條件內容
condition = Condition(
market_type = TradingType.Reference,
symbol = "TXO20000E4",
trigger = TriggerContent.MatchedPrice,
trigger_value = "100",
comparison = Operator.LessThan
)
order = FutOptConditionOrder(
buy_sell = BSAction.Buy,
symbol = "TXO20000E4",
price = "100",
lot = 1,
market_type = FutOptConditionMarketType.Option,
price_type = FutOptConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = FutOptConditionOrderType.New
)
tp = FutOptTPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=FutOptConditionPriceType.Limit,
order_type=FutOptConditionOrderType.Close,
target_price="85",
price="85"
)
sl = FutOptTPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=FutOptConditionPriceType.Limit,
order_type=FutOptConditionOrderType.Close,
target_price="60",
price="60"
)
tpsl = FutOptTPSLWrapper(
stop_sign= StopSign.Full,
tp=tp, # optional field
sl=sl, # optional field
end_date="20240517" # optional field
)
sdk.futopt.single_condition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)
```
```js
// 設計條件內容
const condition = {
marketType: TradingType.Reference,
symbol: "TXO20000E4",
trigger: TriggerContent.MatchedPrice,
triggerValue: "100",
comparison: Operator.LessThan
}
const order = {
buySell: BSAction.Buy,
symbol: "TXO20000E4",
price: "100",
lot: 1,
marketType: FutOptConditionMarketType.Option,
priceType: FutOptConditionPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: FutOptConditionOrderType.New
};
const tp = {
timeInForce: TimeInForce.ROD,
priceType: FutOptConditionPriceType.Limit,
orderType: FutOptConditionOrderType.Close,
targetPrice: "120",
price: "120"
}
const sl = {
timeInForce: TimeInForce.ROD,
priceType: FutOptConditionPriceType.Limit,
orderType: FutOptConditionOrderType.Close,
targetPrice: "60",
price: "60"
}
const tpsl = {
stopSign: StopSign.Full,
tp: tp, // optional field
sl: sl, // optional field
endDate: "20240517"
}
sdk.futopt.singleCondition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)
```
```cs
// 設計條件內容
var condition = new Condition(
TradingType.Reference,
"TXO20000E4",
TriggerContent.MatchedPrice,
"100",
Operator.LessThan
);
var order = new FutOptConditionOrder(
BSAction.Buy,
"TXO20000E4",
"100",
1,
FutOptConditionMarketType.Option,
FutOptConditionPriceType.Limit,
TimeInForce.Rod,
FutOptConditionOrderType.New
);
var tp = new FutOptTpslOrder(
TimeInForce.Rod,
FutOptConditionPriceType.Limit,
FutOptConditionOrderType.Close,
"120",
"120",
null // 2.2.0 版本新增,暫無相關功能
);
var sl = new FutOptTpslOrder(
TimeInForce.Rod,
FutOptConditionPriceType.Limit,
FutOptConditionOrderType.Close,
"85",
"85",
null // 2.2.0 版本新增,暫無相關功能
);
var tpsl = new FutOptTpslWrapper(
StopSign.Full,
tp,
sl,
"20240517",
false
);
sdk.FutOpt.SingleCondition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl);
```
---
### 移動鎖利條件單
富邦新一代 API 支援移動鎖利單,
移動鎖利運作機制 : 當基準條件觸發後,若設定的回檔幅度未達到,則不會觸發,當後續股價持續往上,則會使用新的價格作為基準,若此時回檔幅度到達設定值,則送出委託

##### 程式範例[](#程式範例 "Direct link to 程式範例")
* Python
* Node.js
* C#
```py
# 設計條件內容
trail = FutOptTrailOrder(
symbol = "TXFL4",
price = "22000",
direction = Direction.Down ,
tick_num = 5, # 漲跌 tick 數
buy_sell = BSAction.Sell,
lot = 2,
price_type = FutOptConditionPriceType.MatchedPrice,
diff = 1, # 向上 or 向下追買 tick數 (向下為負值)
time_in_force = TimeInForce.ROD,
order_type = FutOptConditionOrderType.Close
)
sdk.futopt.trail_profit(target_account, "20240427","20240516", StopSign.Full, trail)
```
```js
// 設計條件內容
const trail = {
symbol: "TXO20000E4",
price: "1050",
direction: Direction.Down,
tickNum: 5,
buysell: BSAction.Sell,
lot: 2,
priceType: FutOptConditionPriceType.MatchedPrice,
diff: 1,
timeInForce: TimeInForce.ROD,
orderType: FutOptConditionOrderType.Close
};
sdk.futopt.trailProfit(target_account, "20240427","20240516", StopSign.Full, trail)
```
```cs
// 設計條件內容
var trail = new FutOptTrailOrder(
"TXO20000E4",
"1050",
Direction.Up ,
5, // 漲跌 tick 數
BSAction.Buy,
2,
FutOptConditionPriceType.MatchedPrice,
1, // 向上 or 向下追買 tick數 (向下為負值)
TimeInForce.Rod,
FutOptConditionOrderType.Close
);
sdk.FutOpt.TrailProfit(target_account, "20240427","20240516", StopSign.Full, trail);
```
---
### 條件單風險聲明
本公司為服務投資人,提供網路下單客戶得預先設定下單條件之條件下單功能服務(以下簡稱本功能或本服務)。本服務不收取任何費用,但本公司保留得隨時調整、修正、暫停或終止此項服務之權利;為確保使用者權益及網路交易安全秩序,請投資人於啟用本功能前,詳細閱讀以下條款,以保障投資人的權利,在投資人點選本使用同意書下方之同意鈕,即視為已經詳閱並接受本同意書之內容。
一、條件下單功能服務具有以下(但不限於此)之風險,投資人應自承以下風險所衍生之損害或損失:。
1 網際網路之傳輸通訊,可能因不可抗力或不可歸責於本公司之事由,包括(但不在此限)斷電、斷線、網路壅塞等因素,導致資料傳輸延遲、停滯、無法發出或無法接收。
2 本功能或服務有可能因病毒、系統或機件發生故障、錯誤、執行障礙,駭客入侵等因素,導致資料或資訊傳送發生遺漏、錯誤、或遭竄改。
3 其他網路交易之風險。
二、條件下單功能服務,係依據投資人設定之個股或期貨商品種類及下單條件,提供即時有效之資訊,並結合既有之網路下單功能,允許投資人在同一網頁操作證券或期貨下單之委託指示。本公司目前所提供之條件下單功能服務包括觸價下單、觸量下單、定時下單、長效停損/停利下單及多條件下單共五種(簡稱為條件下單),不同種類的條件下單,其設定方式、效力有可能不同,或受有特別限制,投資人於設定每一筆條件下單前應詳細閱讀注意事項,審慎為之。
三、經觸發條件下單功能服務「直接下單」功能鍵後,具有與口頭、電話、傳真、網路下單相同之效力,如經成交即不得取消,投資人負有交割義務,以及證券、期貨相關法令所規定之各項責任。
四、投資人得於成交前以網路或電話方式變更或取消委託,投資人於下單前應充分瞭解有關變更或取消委託之操作。因不可抗力或不可歸責於本公司之事由,包括(但不在此限)斷電、斷線、網路壅塞、傳輸干擾等因素,致變更或取消意思表示無法即時送達之風險,由投資人自行負擔。
五、基於網路維運、符合資訊法規及網路規範、確保網路交易安全,或服從主管機關之命令等因素,對於有礙系統正常運作、或可能造成系統資訊不穩定、或其他異常狀況之條件下單,本公司保留刪除之權利。如經決定刪除,本公司將另以電子平台公告、行動簡訊或電子郵件通知投資人,並請投資人至富邦證券網站、HTS 快易點、HTS2 多易點及 Online 查詢條件下單訊息公告。
六、經公告於本公司網站上之其他有關電子下單、客戶資料使用、網站管理、保密措施等規範,於條件下單功能服務均有其適用。如有未盡事宜,悉照中華民國相關法令以及經公告之網際網路交易規範為準據。
七、請投資人依本公司條件下單之下單規則,於完成有效期間條件下單之設定後, 請於該條件下單之有效期間內之每一營業日當日查詢該條件下單狀態;條件下單之詳細狀態僅保留至當日,若投資人對條件下單狀態有疑慮,請於該筆交易當日洽詢所屬分公司營業同仁。如交易當日條件下單有故障或因不可抗力因素導致系統無法送單情形,則該交易視為未下單處理。
注意事項:
1. 如使用條件單訂閱功能,請務必確認各項訂閱條件內容,避免產生錯誤。另提醒投資人,此為訂閱功能,待條件符合,才會觸發下單,如欲查詢訂閱狀況可至富邦 Online/HTS2 多易點/HTS 快易點。
2. 就前述訂閱功能,投資人可設定條件單觸發後,系統以 e-mail 發送觸發通知給投資人,或直接下單。如不熟悉條件單操作流程,建議設定觸發通知,待熟悉後再選擇直接下單。
3. 如使用定時單下最後一盤,建議設定停盤丟單,因條件單主機與交易所主機不同,雖然固定每 3 分鐘進行 1 次網路校時,但難免出現秒差(如設定 13:25 下單,可能會下在 13:24:59),請留意。
4. 條件單接受比對 A 商品下 B 商品,設定 A 商品時會自動帶委託 A 商品,要委託 B 商品請手動調整。
5. 當投資人設定之行情條件觸發且本系統送出投資人設定之委託單後,本公司會將該委託單送至交易所,該委託單將會轉為一般委託,此時無法取消訂閱該筆條件單,請直接使用下單查詢功能,查找觸發後的一般委託進行改單調整。
6. 條件單訂閱冷門商品,有可能會碰到開盤沒報價或價格穩定措施 3 分鐘無行情,這時條件單會進入等價狀況,待有行情才會開始繼續洗價比對。
7. 請留意,使用條件單訂閱功能時,待觸發送單後才會與本公司後台風控進行比對。
8. 請留意,證期權多條件長效單、移動鎖利條件單、庫存停損利條件單之效期最長為 3 個月,定時定額條件單效期最長為 6 個月。
9. 其餘未盡事宜請參閱各條件單介面下方注意事項,確認閱讀內容完畢後始得訂閱條件單。
---
### 錯誤碼與狀態碼對照表
本頁面彙整了富邦新一代 API(期貨條件單)中常見的狀態碼,方便開發者在遇到問題或進行狀態判斷時快速檢索。
#### 條件單狀態 (ConditionStatus)[](#條件單狀態-conditionstatus "Direct link to 條件單狀態 (ConditionStatus)")
條件單的當前狀態。
| 狀態名稱 | 說明 |
| -------- | ------------ |
| `Type1` | 今日相關查詢 |
| `Type2` | 尚有效單 |
| `Type3` | 條件比對中 |
| `Type4` | 委託處理中 |
| `Type5` | 委託成功 |
| `Type6` | 已通知 |
| `Type7` | 委託失敗 |
| `Type8` | 已有成交 |
| `Type9` | 刪除成功 |
| `Type10` | 異常 |
| `Type11` | 失效 |
#### 歷史條件單狀態 (HistoryStatus)[](#歷史條件單狀態-historystatus "Direct link to 歷史條件單狀態 (HistoryStatus)")
歷史條件單的狀態。
| 狀態名稱 | 說明 |
| -------- | ------------------------------- |
| `Type1` | 所有條件單 (不包含已刪除、失效) |
| `Type2` | 選擇期間內全部成交單 |
| `Type3` | 選擇期間內部分成交單 |
| `Type4` | 選擇期間刪除單 |
| `Type5` | 選擇期間失效單 |
| `Type6` | 選擇期間內已觸發記錄 |
---
### 富邦新一代 API 期貨條件單
***
本頁重點
* 本頁介紹富邦新一代 API 期貨條件單功能與支援範圍。
* 提供多種條件單類型,適用期貨自動化策略與風險管理。
* 下一步建議先完成 [事前準備](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/prepare.txt)。
| 項目 | 說明 |
| -------- | -------------------------------------------------------------------------- |
| 產品 | 富邦新一代 API 期貨條件單 |
| 主要功能 | 觸價/觸量、停損停利、分時分量 |
| 平台 | Windows / macOS / Linux |
| 語言 | Python / C# / JavaScript (Node.js) / C++、Go(僅支援證券交易帳務及條件單) |
| 前置 | 需簽署條件單使用同意書 |
#### 概述[](#概述 "Direct link to 概述")
富邦新一代 API 條件單為您的程式交易,提供了更完善的功能,滿足每一位開發者達成條件下單。
提供用戶自由選擇主流開發語言( Python、C#、JavaScript),在創建程式交易的過程中,輕易地取用 API,使用 API 各種功能。
#### 特色[](#特色 "Direct link to 特色")
支援跨平台:
新一代 API 支援 Windows、macOS、Linux。
新一代 API 支援 Python、C#、JavaScript(Node.js)、C++、Go 主流語言(C++、Go 僅支援證券交易帳務及條件單)。
#### 主要功能[](#主要功能 "Direct link to 主要功能")
直接管理交易:建立單一條件觸價觸量單、多條件觸價觸量單、停損停利單、分時分量單···等。
#### 版本支援[](#版本支援 "Direct link to 版本支援")
Python 版本支援:3.7(~v1.3.2)、3.8–3.13(v2.0.1~,不含 3.14)。
Node.js 版本支援 : 目前支援 Node.js 16 以上的版本。
C# 使用 .NET Standard 2.0 開發,建議您使用 .netcoreapp 3.1 以上;如使用 .NET Framework 建議您使用 .NET Framework 4.7.2 以上版本。
---
### 取消條件單
CancelConditionOrders
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 CancelResult 欄位[](#委託資訊-cancelresult--欄位 "Direct link to 委託資訊 CancelResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| -------- | ------ | ------------ |
| advisory | string | 回覆狀態內容 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.FutOpt.CancelConditionOrders(account, "c9df498a-3b28-4b50-a6f2-f7bd524e96df");
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```py
Result {
is_success: True,
message: None,
data : CancelResult {
advisory: "成功筆數:1,失敗筆數:0!",
}
}
```
---
### 參數對照表
#### 類別[](#類別 "Direct link to 類別")
Class
##### Condition Object[](#condition-object "Direct link to Condition Object")
| Parameter | Type | Meaning |
| ------------ | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| marketType | TradingType | [監控類型](#tradingtype) 可選用參數 : `Reference` 自動參考委託物件、`Scheduled` 時間 |
| symbol | string | 股票代號 |
| trigger | TriggerContent | [觸發條件](#triggercontent) 可選用參數 : `BidPrice` 買進價、`AskPrice` 賣出價、`MatchedPrice` 成交價、`TotalQuantity` 總量、`Time` 時間 |
| triggerValue | string | 監控條件數值 (若為時間則填入 HHMMSS) |
| comparison | Operator | [比對值](#operator) 可選用參數 `GreaterThanOrEqual` 大於等於、`LessThanOrEqual` 小於等於 、 `GreaterThan` 大於 、 `LessThan` 小於 |
info
1. 選擇 `Reference` 時, trigger 可搭配 `BidPrice` 、`AskPrice` 、`MatchedPrice` 、`TotalQuantity`
2. 選擇 `Scheduled` 時,symbol 需填入欲觸發之商品,trigger 需帶入 `Time`
##### FutOptConditionOrder Object[](#futoptconditionorder-object "Direct link to FutOptConditionOrder Object")
| Parameter | Type | Meaning |
| ----------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| buySell | BsAction | [買賣別](#bsaction) 可選用參數 `Buy` 買 、 `Sell` 賣 |
| symbol | string | 股票代號 |
| price | string | 委託價格 |
| quantity | int | 委託數量 |
| marketType | FutOptConditionMarketType | [盤別](#futoptconditionmarkettype) 可選用參數 : `Future` 期貨日盤、`Option` 選擇權日盤、`FutureNight` 期貨夜盤、`OptionNight` 選擇權夜盤 (**IMPORTANT:** 以下功能不支援夜盤: 1. 分時分量, 2. 移動鎖利, 3. 時間觸發條件) |
| priceType | FutOptConditionPriceType | [價格別](#futoptconditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice` 成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) 、`RangeMarket` 範圍市價 |
| timeInForce | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`Rod`、`Ioc`、`Fok` |
| orderType | FutOptConditionOrderType | [委託類別](#futoptconditionordertype) : 可選參數 :`New` 新倉、`Close` 平倉 |
caution
以下功能不支援夜盤:
1. 分時分量
2. 移動鎖利
3. 時間觸發條件
##### FutOptTPSLOrder Object[](#futopttpslorder-object "Direct link to FutOptTPSLOrder Object")
| Parameter | Type | Meaning |
| ---------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| timeInForce | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`Rod`、`Ioc`、`Fok` |
| priceType | FutOptConditionPriceType | [價格別](#futoptconditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice` 成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) 、`RangeMarket` 範圍市價 |
| orderType | FutOptConditionOrderType | [委託類別](#futoptconditionordertype) : 可選參數 :`New` 新倉、`Close` 平倉 |
| targetPrice | string | 停損/停利觸發價 |
| price | string | 停損/停利委託價 |
| trigger (**保留欄位**) | TriggerContent | 2.2.0 版本新增欄位,暫無相關功能,請填入 ***null*** |
info
`priceType` 若為 `limit` 時,`price` 需填入價格;其餘 price 填入空字串
##### FutOptTpslWrapper Object[](#futopttpslwrapper-object "Direct link to FutOptTpslWrapper Object")
| Parameter | Type | Meaning |
| --------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------- |
| stopSign | StopSign | [停止條件](#stopsign) : 可選用 `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| TP | FutOptTpslOrder Object (Optional) | 停利條件內容 |
| SL | FutOptTpslOrder Object (Optional) | 停損條件內容 |
| endDate | string (Optional : 空值同母單 StartDate) | 條件停止日期 |
| dayTrade | bool (Optional) | 全部成交後當沖 (期貨固定為 True) |
##### FutOptTrailOrder[](#futopttrailorder "Direct link to FutOptTrailOrder")
| Parameter | Type | Meaning |
| ----------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| symbol | string | 商品代號 |
| price | string | 基準價 |
| direction | Direction | [方向](#direction) : 可選用 `Up` 上漲、`Down` 下跌 |
| tickNum | int | 上漲 / 下跌 ticker 數 |
| buysell | BsAction | 買賣別 : 可選用 `Buy` 買進 、`Sell` 賣出 |
| lot | int | 委託口數 |
| PriceType | FutOptConditionPriceType | [價格類別](#futoptconditionpricetype) : 可選用 `BidPrice` 買進價、`AskPrice` 賣出價、`MatchedPrice` 成交價、`Market` 市價、`LimitUp` 漲停價、`LimitDown` 跌停價、`Reference` 平盤價、`RangeMarket` 範圍市價 |
| diff | int | 買賣價格檔數 (根據 priceType 加減檔數) ,正值為向上加檔數、負值為向下加檔數 |
| timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` |
| orderType | FutOptConditionOrderType | [委託類別](#futoptconditionordertype) 可選用參數為 `New` 新倉、`Close` 平倉 |
##### SplitDescription[](#splitdescription "Direct link to SplitDescription")
| Parameter | Type | Meaning |
| -------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| method | SliceType | [Slice Condition](#slicetype) : 可選用 :
`Type1` 從 `startTime` 開始,每隔幾秒送一筆,總共 `totalQuantity`,每筆送 `singleQuantity`
`Type2` 從 `startTime` 開始到 `endTime` 結束,每隔 `interval` 秒送一筆,總共 `totalQuantity`,剩餘張數加總至最後一筆
`Type3` 從 `startTime` 開始到 `endTime` 結束,每隔 `interval` 秒送一筆,總共 `totalQuantity`,剩餘張數從最後一筆往前分配.
|
| interval | int | 下單間隔時間 |
| singleQuantity | int | 單筆下單量 (股數) |
| totalQuantity | int (Optional) | 總共下單量 (股數) |
| startTime | string | 開始時間 |
| endTime | string (Optional) | 結束時間 |
caution
請注意,總共下單量需大於單筆下單量。
##### ConditionOrderResult[](#conditionorderresult "Direct link to ConditionOrderResult")
| Parameter | Type | Meaning |
| --------- | ------ | -------- |
| guid | string | 條件單號 |
#### Constants ( 欄位對應數值 )[](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )")
##### BSAction[](#bsaction "Direct link to BSAction")
買賣別 (buySell)
| Name | Meaning |
| ---- | ------- |
| Buy | 買 |
| Sell | 賣 |
##### TradingType[](#tradingtype "Direct link to TradingType")
監控類型
| Name | Meaning |
| --------- | ---------------- |
| Reference | 自動參考委託物件 |
| Index | 指數 |
| Scheduled | 時間 |
##### TriggerContent[](#triggercontent "Direct link to TriggerContent")
觸發條件
| Name | Meaning |
| ------------- | ------- |
| BidPrice | 買進價 |
| AskPrice | 賣出價 |
| MatchedPrice | 成交價 |
| TotalQuantity | 總量 |
| Time | 時間 |
##### Operator[](#operator "Direct link to Operator")
| Name | Meaning |
| ------------------ | -------- |
| GreaterThanOrEqual | 大於等於 |
| LessThanOrEqual | 小於等於 |
| GreaterThan | 大於 |
| LessThan | 小於 |
##### StopSign[](#stopsign "Direct link to StopSign")
| Name | Meaning |
| -------- | ------------ |
| Full | 全部成交為止 |
| Partial | 部分成交為止 |
| UntilEnd | 效期結束為止 |
##### TimeInForce[](#timeinforce "Direct link to TimeInForce")
委託條件 (TimeInForce)
| Name | Meaning |
| ---- | ------------------------------------- |
| ROD | 當日有效(Rest of Day) |
| FOK | 全部成交否則取消(Fill-or-Kill) |
| IOC | 立即成交否則取消(Immediate-or-Cancel) |
##### FutOptConditionMarketType[](#futoptconditionmarkettype "Direct link to FutOptConditionMarketType")
盤別 (FutOptConditionMarketType)
| Name | Meaning |
| ------ | ---------- |
| Future | 期貨日盤 |
| Option | 選擇權日盤 |
##### FutOptConditionPriceType[](#futoptconditionpricetype "Direct link to FutOptConditionPriceType")
價格類型 (FutOptConditionPriceType)
| Name | Meaning |
| ------------ | -------------- |
| Limit | 限價 |
| BidPrice | 買進價 |
| AskPrice | 賣出價 |
| Market | 市價 |
| MatchedPrice | 成交價 |
| LimitUp | 漲停價 |
| LimitDown | 跌停價 |
| Reference | 參考價(平盤價) |
| RangeMarket | 範圍市價 |
##### FutOptConditionOrderType[](#futoptconditionordertype "Direct link to FutOptConditionOrderType")
委託類型 (FutOptConditionOrderType)
| Name | Meaning |
| ----- | ------- |
| New | 新倉 |
| Close | 平倉 |
##### Direction[](#direction "Direct link to Direction")
移動鎖利上漲/下跌追蹤 (direction)
| Name | Meaning |
| ---- | ------- |
| Up | 上漲 |
| Down | 下跌 |
##### SliceType[](#slicetype "Direct link to SliceType")
分單型態 (SliceType)
| Name | Meaning |
| ----- | -------------------------------------------------------------------- |
| Type1 | 從開始時間,每隔幾秒送一筆,總共送 N 筆,每筆送 M 張 |
| Type2 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數加總至最後一筆 |
| Type3 | 從開始到結束,每隔 X 秒送一筆,總共 N 張,剩餘張數從最後一筆往前分配 |
##### Operator[](#operator-1 "Direct link to Operator")
| Name | Meaning |
| ------------------ | -------- |
| GreaterThanOrEqual | 大於等於 |
| LessThanOrEqual | 小於等於 |
| GreaterThan | 大於 |
| LessThan | 小於 |
##### ConditionStatus[](#conditionstatus "Direct link to ConditionStatus")
條件單狀態 (ConditionStatus)
| Name | Meaning |
| ------ | ------------ |
| Type1 | 今日相關查詢 |
| Type2 | 尚有效單 |
| Type3 | 條件比對中 |
| Type4 | 委託處理中 |
| Type5 | 委託成功 |
| Type6 | 已通知 |
| Type7 | 委託失敗 |
| Type8 | 已有成交 |
| Type9 | 刪除成功 |
| Type10 | 異常 |
| Type11 | 失效 |
##### HistoryStatus[](#historystatus "Direct link to HistoryStatus")
歷史條件單狀態 (ConditionHistoryStatus)
| Name | Meaning |
| ----- | -------------------------------- |
| Type1 | 所有條件單 ( 不包含已刪除、失效) |
| Type2 | 選擇期間內全部成交單 |
| Type3 | 選擇期間內部分成交單 |
| Type4 | 選擇期間刪除單 |
| Type5 | 選擇期間失效單 |
| Type6 | 選擇期間內已觸發記錄 |
---
### 條件單查詢 By 條件單號
GetConditionOrderById
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 條件單號 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.FutOpt.GetConditionOrderById(account,"8ff3472b-185a-488c-be5a-b478deda080c",FutOptConditionMarketType.Future);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = {
Guid = adada47e-dea3-4a5a-9eff-d36bd7a71e87,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-11-15 10:38:48,
ConditionType = 觸價,
ParentGuid = adada47e-dea3-4a5a-9eff-d36bd7a71e87,
Symbol = FIMTX202411,
OrderAmount = 0,
ChildBatchNo = ,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內台指期202412成交價大於21000點 全部成交為止,
Action = 下單(新倉),
ConditionBuySell = 賣,
ConditionSymbol = 賣 小型台指202411,
ConditionPrice = 範圍市價(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
CreateTime = 2024-11-15 10:38:48,
StartDate = 2024/11/15,
Status = 洗價中(Y),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 2,
TpslRecord =
[
{
Guid = b79084fe-6fdf-461f-a264-0482072237eb,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內小型台指202411買進價大於等於22340元 全部成交為止,
Action = 下單(平倉),
ConditionBuySell = 買,
ConditionSymbol = 買 小型台指202411,
ConditionPrice = 22340(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
StartDate = 2024/11/15,
Status = 未生效(W),
ErrorMessage =
},
{
Guid = b79084fe-6fdf-461f-a264-0482072237eb,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內小型台指202411買進價小於等於22280元 全部成交為止,
Action = 下單(平倉),
ConditionBuySell = 買,
ConditionSymbol = 買 小型台指202411,
ConditionPrice = 22280(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
StartDate = 2024/11/15,
Status = 未生效(W),
ErrorMessage =
}
]
}
}
```
---
### 歷史條件單查詢
GetConditionHistory
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| startDate | string | 查詢開始日 |
| endDate | string | 查詢截止日 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 |
| historyStatus | [ConditionHistoryStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#historystatus) (Optional) | 歷史條件單狀態 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | list | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.FutOpt.GetConditionHistory(account,"20240301","20240601",FutOptConditionMarketType.Future);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = [{
Guid = adada47e-dea3-4a5a-9eff-d36bd7a71e87,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-11-15 10:38:48,
ConditionType = 觸價,
ParentGuid = adada47e-dea3-4a5a-9eff-d36bd7a71e87,
Symbol = FIMTX202411,
OrderAmount = 0,
ChildBatchNo = ,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內台指期202412成交價大於21000點 全部成交為止,
Action = 下單(新倉),
ConditionBuySell = 賣,
ConditionSymbol = 賣 小型台指202411,
ConditionPrice = 範圍市價(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
CreateTime = 2024-11-15 10:38:48,
StartDate = 2024/11/15,
Status = 洗價中(Y),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 2,
TpslRecord =
[
{
Guid = b79084fe-6fdf-461f-a264-0482072237eb,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內小型台指202411買進價大於等於22340元 全部成交為止,
Action = 下單(平倉),
ConditionBuySell = 買,
ConditionSymbol = 買 小型台指202411,
ConditionPrice = 22340(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
StartDate = 2024/11/15,
Status = 未生效(W),
ErrorMessage =
},
{
Guid = b79084fe-6fdf-461f-a264-0482072237eb,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內小型台指202411買進價小於等於22280元 全部成交為止,
Action = 下單(平倉),
ConditionBuySell = 買,
ConditionSymbol = 買 小型台指202411,
ConditionPrice = 22280(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
StartDate = 2024/11/15,
Status = 未生效(W),
ErrorMessage =
}
]
},
...
]
}
```
---
### 條件單查詢
GetConditionOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 |
| conditionStatus | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#conditionstatus) (Optional) | 條件單狀態 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.FutOpt.GetConditionOrder(account, FutOptConditionMarketType.Future);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = [{
Guid = adada47e-dea3-4a5a-9eff-d36bd7a71e87,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-11-15 10:38:48,
ConditionType = 觸價,
ParentGuid = adada47e-dea3-4a5a-9eff-d36bd7a71e87,
Symbol = FIMTX202411,
OrderAmount = 0,
ChildBatchNo = ,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內台指期202412成交價大於21000點 全部成交為止,
Action = 下單(新倉),
ConditionBuySell = 賣,
ConditionSymbol = 賣 小型台指202411,
ConditionPrice = 範圍市價(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
CreateTime = 2024-11-15 10:38:48,
StartDate = 2024/11/15,
Status = 洗價中(Y),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = [],
TpslCount = 2,
TpslRecord =
[
{
Guid = b79084fe-6fdf-461f-a264-0482072237eb,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內小型台指202411買進價大於等於22340元 全部成交為止,
Action = 下單(平倉),
ConditionBuySell = 買,
ConditionSymbol = 買 小型台指202411,
ConditionPrice = 22340(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
StartDate = 2024/11/15,
Status = 未生效(W),
ErrorMessage =
},
{
Guid = b79084fe-6fdf-461f-a264-0482072237eb,
Account = 9974825,
ConditionContent = 當自2024/11/15至2024/11/20內小型台指202411買進價小於等於22280元 全部成交為止,
Action = 下單(平倉),
ConditionBuySell = 買,
ConditionSymbol = 買 小型台指202411,
ConditionPrice = 22280(ROD),
ConditionVolume = 2,
ConditionFilledVolume = 0,
StartDate = 2024/11/15,
Status = 未生效(W),
ErrorMessage =
}
]
},
...
]
}
```
---
### 多條件單
MultiCondition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition1 = new Condition(
TradingType.Reference,
"TXO20000E4",
TriggerContent.MatchedPrice,
"100",
Operator.LessThan
);
var condition2 = new Condition(
TradingType.Reference,
"TXO20000E4",
TriggerContent.TotalQuantity,
"30",
Operator.LessThan
);
List conditions = new List();
conditions.Add(condition1);
conditions.Add(condition2);
var order = new FutOptConditionOrder(
BsAction.Buy,
"TXO20000E4",
"500",
1,
FutOptConditionMarketType.Option,
FutOptConditionPriceType.Limit,
TimeInForce.Rod,
FutOptConditionOrderType.New
);
sdk.FutOpt.MultiCondition(account, "20240426", "20240430", StopSign.Full, conditions, order);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 多條件單
MultiCondition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionorder-object) | 委託內容 |
| TPSLObject | [FutOptTpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futopttpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition1 = new Condition(
TradingType.Reference,
"TXO20000E4",
TriggerContent.MatchedPrice,
"100",
Operator.LessThan
);
var condition2 = new Condition(
TradingType.Reference,
"TXO20000E4",
TriggerContent.TotalQuantity,
"30",
Operator.LessThan
);
List conditions = new List();
conditions.Add(condition1);
conditions.Add(condition2);
var order = new FutOptConditionOrder(
BsAction.Buy,
"TXO20000E4",
"100",
1,
FutOptConditionMarketType.Option,
FutOptConditionPriceType.Limit,
TimeInForce.Rod,
FutOptConditionOrderType.New
);
var tp = new FutOptTpslOrder(
TimeInForce.Rod,
FutOptConditionPriceType.Limit,
FutOptConditionOrderType.Close,
"120",
"120",
null // 2.2.0 版本新增,暫無相關功能
);
var sl = new FutOptTpslOrder(
TimeInForce.Rod,
FutOptConditionPriceType.Limit,
FutOptConditionOrderType.Close,
"85",
"85",
null // 2.2.0 版本新增,暫無相關功能
);
var tpsl = new FutOptTpslWrapper(
StopSign.Full,
tp,
sl,
"20240517",
false
);
sdk.FutOpt.MultiCondition(account, "20240426", "20240430", StopSign.Full, conditions, order, tpsl);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX
}
}
```
---
### 單一條件單
SingleCondition
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| OrderObject | [FutOptConditionOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionorder-object) | 委託內容 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition = new Condition(
TradingType.Reference,
"TXO20000E4",
TriggerContent.MatchedPrice,
"100",
Operator.LessThan
);
var order = new FutOptConditionOrder(
BsAction.Buy,
"TXO20000E4",
"500",
1,
FutOptConditionMarketType.Option,
FutOptConditionPriceType.Limit,
TimeInForce.Rod,
FutOptConditionOrderType.New,
);
sdk.FutOpt.SingleCondition(account, "20240426", "20240430", StopSign.Full, condition, order);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX
}
}
```
---
### 單一條件單包含停損停利
SingleCondition
停損利注意事項
* 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整
* 請確認停損利**委託類別**設定需符合適合之交易規則
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial` 部分成交為止、`UntilEnd` 效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#condition-object) | 觸發條件 |
| OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionorder-object) | 委託內容 |
| TPSLObject | [FutOptTpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futopttpslwrapper-object) | 停損停利條件 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | Object | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionOrderResult 欄位[](#委託資訊-conditionorderresult-欄位 "Direct link to 委託資訊 ConditionOrderResult 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ---- | ------ | -------- |
| guid | string | 條件單號 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
// 設計條件內容
var condition = new Condition(
TradingType.Reference,
"TXO20000E4",
TriggerContent.MatchedPrice,
"100",
Operator.LessThan
);
var order = new FutOptConditionOrder(
BsAction.Buy,
"TXO20000E4",
"100",
1,
FutOptConditionMarketType.Option,
FutOptConditionPriceType.Limit,
TimeInForce.Rod,
FutOptConditionOrderType.New
);
var tp = new FutOptTpslOrder(
TimeInForce.Rod,
FutOptConditionPriceType.Limit,
FutOptConditionOrderType.Close,
"120",
"120",
null // 2.2.0 版本新增,暫無相關功能
);
var sl = new FutOptTpslOrder(
TimeInForce.Rod,
FutOptConditionPriceType.Limit,
FutOptConditionOrderType.Close,
"85",
"85",
null // 2.2.0 版本新增,暫無相關功能
);
var tpsl = new FutOptTpslWrapper(
StopSign.Full,
tp,
sl,
"20240517",
false
);
sdk.FutOpt.SingleCondition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = ConditionOrderResult {
guid = 44150047-8977-40b1-953c-ce2XXXXXX,
}
}
```
---
### 分時分量單查詢
GetTimeSliceOrder
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.txt#account) | 帳號 |
| guid | string | 分時分量單號 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.txt#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 |
#### Result 回傳[](#result-回傳 "Direct link to Result 回傳")
| 參數 | 類別 | 說明 |
| --------- | ------------------- | --------------------------------- |
| isSuccess | bool | 是否成功 |
| data | List | 條件單回傳資訊 |
| message | string ? (optional) | 當 isSuccess = false 回傳錯誤訊息 |
##### 委託資訊 ConditionDetail 欄位[](#委託資訊-conditiondetail--欄位 "Direct link to 委託資訊 ConditionDetail 欄位")
Return type : Object
| 參數 | 類別 | 說明 |
| ------------------------ | ------ | ---------------- |
| guid | string | 條件單號 |
| batchNo | string | 分單批號 |
| orderLevel | string | 條件單層級 |
| lastTime | string | 更新時間 |
| parentGuid | string | 父單單號 |
| symbol | string | 商品代號 |
| orderAmount | string | 委託金額 |
| childBatchNo | string | 子單分單批號 |
| account | string | 帳號 |
| conditionContent | string | 條件內容 |
| action | string | 處理方式 |
| conditionBuySell | string | 買賣別 |
| conditionSymbol | string | 商品名稱 |
| conditionPrice | string | 價格 |
| conditionVolume | string | 委託數量 |
| conditionFilledVolume | string | 成交數量 |
| createTime | string | 建立時間 |
| startDate | string | 預約開始時間 |
| status | string | 目前狀態 |
| errorMessage | string | 目前狀態異常說明 |
| detailRecordsCount | string | 查詢明細筆數 |
| detailRecords | List | 查詢明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
| tpslCount | string | 停損停利筆數 |
| tpslRecord | List | 停損停利明細資料 |
| >> guid | string | 條件單號 |
| >> account | string | 帳號 |
| >> conditionContent | string | 條件內容 |
| >> action | string | 處理方式 |
| >> conditionBuySell | string | 買賣別 |
| >> conditionSymbol | string | 商品名稱 |
| >> conditionPrice | string | 價格 |
| >> conditionVolume | string | 委託數量 |
| >> conditionFilledVolume | string | 成交數量 |
| >> startDate | string | 預約時間 |
| >> status | string | 目前狀態 |
| >> errorMessage | string | 目前狀態異常說明 |
#### 請求範例[](#請求範例 "Direct link to 請求範例")
```cs
sdk.FutOpt.GetTimeSliceOrder(account,"123456",FutOptConditionMarketType.Future);
```
#### 回傳範例[](#回傳範例 "Direct link to 回傳範例")
```cs
{
isSuccess = True,
message = ,
data = [
ConditionDetail{
Guid = f76c49ee-e955-41ac-8e11-02d6d2b78918,
BatchNo = ,
OrderLevel = 0,
LastTime = 2024-08-16 17:13:29,
ConditionType = 定時,
ParentGuid = ,
Symbol = TXO20000H4,
OrderAmount = 0,
ChildBatchNo = ,
Account = 9974825,
ConditionContent = 當於2024/08/16 定時單時間大於等於09:15:00 全部成交為止,
Action = 下單(新倉),
ConditionBuySell = 買,
ConditionSymbol = 買 台指2024年8 月買權履約價:20000,
ConditionPrice = 500(ROD),
ConditionVolume = 1,
ConditionFilledVolume = 0,
CreateTime = 2024-08-16 17:13:28,
StartDate = 2024/08/16,
Status = 預約(N),
ErrorMessage = null,
DetailRecordsCount = 0,
DetailRecords = new List