# 富邦新一代 API|程式交易的新武器
## TradeAPI
### SDK 下載
***
本頁重點
* 提供富邦新一代 API(Fubon Neo API)各語言 SDK 下載。
* 最新版本為 **v2.2.8**,並提供[版本遷移資訊](#%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.md)。
| 項目 | 說明 |
| ------------ | -------------------------------------------------------------------------- |
| 最新版本 | v2.2.8 |
| 支援語言 | 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.md#%E6%B8%AC%E8%A9%A6%E7%92%B0%E5%A2%83) 頁面
2. [網頁憑證匯出](https://www.fbs.com.tw/TradeAPI/docs/key.md)可用於API 登入 (版本要求 >= v2.2.8)
API Key 登入 >= v2.2.7
* [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.md)
* [API Key 申請](https://www.fbs.com.tw/TradeAPI/docs/key.md)
版本注意事項 **>=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 64 位元 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.2.8-cp37-abi3-win_amd64.zip)
* MacOs
* Arm 64 位元 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.2.8-cp37-abi3-macosx_11_0_arm64.zip)
* X86 64 位元 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.2.8-cp37-abi3-macosx_10_12_x86_64.zip)
* Linux 64 位元 [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon_neo-2.2.8-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.2.8.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 以上,或 .NETFramework 4.7.2 以上版本
**SDK:**
* nupkg(64 位元) [下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/FubonNeo.2.2.8.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.2.8_CppSDKPackage.zip)
##### Golang[](#golang "Direct link to Golang")
* [SDK及範例程式碼下載](https://www.fbs.com.tw/TradeAPI_SDK/fubon_binary/fubon-neo-2.2.8.golang.zip)
#### 連線測試[](#連線測試 "Direct link to 連線測試")
**連線測試小幫手:** [程式下載](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/API_Sign_Test.zip) (Windows平台使用)
#### 版本遷移資訊[](#版本遷移資訊 "Direct link to 版本遷移資訊")
##### 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.md)新增**還原股價**選項
* 新增 [LLM 輔助開發](https://www.fbs.com.tw/TradeAPI/docs/welcome/build-with-llm.md) 頁面
版本注意事項 **>=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.md)可用於 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.md)
* [API Key 申請](https://www.fbs.com.tw/TradeAPI/docs/key.md)
##### 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.md) )
##### 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.md))
##### 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.md))
---
### 安裝與版本相容性
本頁重點
* 支援語言: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.md)。
* 本頁提供最小安裝步驟與版本相容性總覽。
#### 支援環境與版本相容性[](#支援環境與版本相容性 "Direct link to 支援環境與版本相容性")
| 語言 | 最低版本 | 支援 OS | 安裝方式 | 備註 |
| -------------------- | --------------------- | ----------------------- | --------------- | -------------------------------------------- |
| Python | 3.8–3.13(v2.0.1 起) | Windows / macOS / Linux | `.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 | `.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 來源。
##### 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.md#%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.md)
* [快速開始](https://www.fbs.com.tw/TradeAPI/docs/trading/quickstart.md)
* [API Key 申請](https://www.fbs.com.tw/TradeAPI/docs/key.md)
---
### 金鑰申請及管理
版本限制
2.2.7版本新增功能
憑證匯出開放
2.2.8版起可使用本頁登入後匯出之憑證登入API,加強跨平台支援
金鑰申請及管理
您仍可使用現有的帳號憑證登入並使用 API。
**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 申請與管理入口。
* 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 |
| --------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------- |
| `data`\* | object\[] | 資本變動資料 |
| `data.symbol` | string | 股票代號 |
| `data.name` | string | 股票名稱 |
| `data.actionType` | string | 事件類型:`etf_split_or_merge` ETF 分割或反分割、`par_value_change` 股票面額變更 、`capital_reduction` 減資 |
| `data.effectiveDate` | string | 恢復買賣日期 (YYYY-MM-DD) |
| `data.adjustmentFactor` | number | 調整係數 |
| `data.haltDate` | string | 停止買賣日期 (YYYY-MM-DD) |
| `data.resumeDate` | string | 恢復買賣日期 (YYYY-MM-DD) |
| `data.raw` | object | 原始資料 |
| `data.raw.exchangeRatio` | number | 換股比例 (面額變更、減資時才有值) |
| `data.raw.parValueBefore` | number | 變更前面額 (面額變更時才有值) |
| `data.raw.parValueAfter` | number | 變更後面額 (面額變更時才有值) |
| `data.raw.lastClosePrice` | number | 停止買賣前收盤價 |
| `data.raw.referencePrice` | number | 恢復買賣參考價 |
| `data.raw.limitUpPrice` | number | 漲停價格 |
| `data.raw.limitDownPrice` | number | 跌停價格 |
| `data.raw.openingReferencePrice` | number | 開盤競價基準 |
| `data.raw.splitType` | string | 分割類型:`分割`、`反分割` |
| `data.raw.reductionReason` | string | 減資原因 (減資時才有值) |
| `data.raw.refundPerShare` | number | 每股退還股款 (元) (減資時才有值) |
| `data.raw.rightsOfferingRatio` | number | 減資後現金增資配股率 (減資時才有值) |
| `data.raw.rightsOfferingPrice` | number | 現金增資認購價 (元) (減資時才有值) |
| `data.raw.exRightsReferencePrice` | 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.md) )
#### 功能列表[](#功能列表 "Direct link to 功能列表")
功能列表依資料類型可分為 **盤中行情(intraday)**、**行情快照(snapshot)**、**歷史行情(historical)**。富邦行情 Web API 提供的功能如下:
* `/intraday/tickers` - [股票或指數列表(依條件查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/tickers.md)
* `/intraday/ticker/{symbol}` - [股票基本資料(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/ticker.md)
* `/intraday/quote/{symbol}` - [股票即時報價(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/quote.md)
* `/intraday/candles/{symbol}` - [股票價格K線(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/candles.md)
* `/intraday/trades/{symbol}` - [股票成交明細(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/trades.md)
* `/intraday/volumes/{symbol}` - [股票分價量表(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/intraday/volumes.md)
* `/snapshot/quotes/{market}` - [股票行情快照(依市場別)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/snapshot/quotes.md)
* `/snapshot/movers/{market}` - [股票漲跌幅排行(依市場別)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/snapshot/movers.md)
* `/snapshot/actives/{market}` - [股票成交量值排行(依市場別)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/snapshot/actives.md)
* `/historical/candles/{symbol}` - [取得 1 年內歷史股價(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/historical/candles.md)
* `/historical/stats/{symbol}` - [取得近 52 週股價數據(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data/http-api/historical/stats.md)
#### 使用 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 年!
```text
historical/candles/{symbol}
```
#### 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;`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` ***(v2.2.8 新增)*** |
| `fields` | string | 欄位,可選:`open,high,low,close,volume,turnover,change` |
| `sort` | string | 時間排序,預設為 `desc` 降冪;可選 `asc` 升冪 |
caution
目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近五日資料,並且無法選擇 turnover 與 change 的欄位。
#### 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.candles(**{"symbol": "0050", "from": "2023-02-06", "to": "2023-02-08"}) # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.historical.candles(**{"symbol": "0050", "from": "2023-02-06", "to": "2023-02-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"}
```
```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: '2023-02-06', to: '2023-02-08', fields: 'open,high,low,close,volume,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("2330", new(DateTime.Today.AddDays(-100),DateTime.Today,HistoryTimeFrame.Week,FieldsType.High|FieldsType.Low));
var candle_con = candle.Content.ReadAsStringAsync().Result;
Console.WriteLine(candle_con);
```
Response Body:
```json
{
"symbol": "0050",
"type": "EQUITY",
"exchange": "TWSE",
"market": "TSE",
"data": [
{
"date": "2023-02-08",
"open": 120.1,
"high": 120.95,
"low": 120,
"close": 120.85,
"volume": 9239321,
"change": 1.85
},
{
"date": "2023-02-07",
"open": 119.1,
"high": 119.25,
"low": 118.55,
"close": 119,
"volume": 8787291,
"change": -0.25
},
{
"date": "2023-02-06",
"open": 120.1,
"high": 120.1,
"low": 119.25,
"close": 119.25,
"volume": 14297030,
"change": -1.75
}
]
}
```
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------ | ------ | ----------- |
| `date`\* | string | 日期 |
| `type`\* | string | 證券類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 股票代號 |
| `timeframe*` | string | K線週期 |
| `data` | Candle | K線資料 |
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;`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 | 最後一筆成交時間 |
| `lastTrial` | object | 最後一筆試撮資訊 |
| >> `bid` | number | 最後一筆試撮買價 |
| >> `ask` | number | 最後一筆試撮賣價 |
| >> `price` | number | 最後一筆試撮價格 |
| >> `size` | number | 最後一筆試撮數量 |
| >> `time` | number | 最後一筆試撮時間 |
| `opHaltStatus` | 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 | 最後更新時間 |
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 | 收盤時間(限指數) |
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.ticker(symbol='2330') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
reststock.intraday.ticker(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.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` | 一般股票 | `24` | ETF |
| `02` | 轉換公司債 | `25` | ETF(外幣計價) |
| `03` | 交換公司債或交換金融債 | `26` | 槓桿型ETF |
| `04` | 一般特別股 | `27` | 槓桿型 ETF(外幣計價) |
| `05` | 可交換特別股 | `28` | 反向型 ETF |
| `06` | 認股權憑證 | `29` | 反向型 ETF(外幣計價) |
| `07` | 附認股權特別股 | `30` | 期信託 ETF |
| `08` | 附認股權公司債 | `31` | 期信託 ETF(外幣計價) |
| `09` | 附認股權公司債履約或分拆後之公司債 | `32` | 債券 ETF |
| `10` | 國內標的認購權證 | `33` | 債券 ETF(外幣計價) |
| `11` | 國內標的認售權證 | `34` | 金融資產證券化受益證券 |
| `12` | 外國標的認購權證 | `35` | 不動產資產信託受益證券 |
| `13` | 外國標的認售權證 | `36` | 不動產投資信託受益證券 |
| `14` | 國內標的下限型認購權證 | `37` | ETN |
| `15` | 國內標的上限型認售權證 | `38` | 槓桿型 ETN |
| `16` | 國內標的可展延下限型認購權證 | `39` | 反向型 ETN |
| `17` | 國內標的可展延上限型認售權證 | `40` | 債券型 ETN |
| `18` | 受益憑證(封閉式基金) | `41` | 期權策略型 ETN |
| `19` | 存託憑證 | `42` | 中央登錄公債 |
| `20` | 存託憑證可轉換公司債 | `43` | 外國債券 |
| `21` | 存託憑證附認股權公司債 | `44` | 黃金現貨 |
| `22` | 存託憑證附認股權公司債履約或分拆後之公司債 | `00` | 未知或保留代碼 |
| `23` | 存託憑證認股權憑證 | | |
---
### 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` 臺灣創新板;`PSB` 興櫃戰略新板 |
| `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
'\*' 表示必揭示欄位。
#### 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 | 限制量 |
#### 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 | 成交時間 |
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
}
]
}
```
---
### Snapshot Actives
股票成交量值排行(依市場別)
```text
snapshot/actives/{market}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ------------------------------------------------------------------------------------------- |
| `market`\* | string | 市場別,可選 `TSE` 上市;`OTC` 上櫃;`ESB` 興櫃一般板;`TIB` 臺灣創新板;`PSB` 興櫃戰略新板 |
| `trade`\* | string | 成交量/成交值,可選 `volume` 成交量;`value` 成交值 |
| `type` | string | 標的類型,可選 `ALLBUT099` 包含一般股票、特別股及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 | 標的類型,可選 `ALLBUT099` 包含一般股票、特別股及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` 臺灣創新板;`PSB` 興櫃戰略新板 |
| `type` | string | 標的類型,可選 `ALLBUT099` 包含一般股票、特別股及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;`5` 5分K;`10` 10分K;`15` 15分K;`30` 30分K;`60` 60分K;`D` 日K;`W` 週K;`M` 月K |
| `period`\* | number | Bolling 週期 |
caution
目前分K無法指定開始日期(from) 與 結束日期(to),一律回傳近 30 日資料。
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------- | ------ | ------------ |
| `symbol`\* | string | 股票代號 |
| `from`\* | string | 開始日期 |
| `to`\* | string | 結束日期 |
| `timeframe`\* | string | K線週期 |
| `period`\* | string | RSI 週期 |
| `data` | Object | RSI 資料 |
| >> `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;`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;`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 | RSI 資料 |
| >> `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;`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`\* | string | 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;`5` 5分K;`10` 10分K;`15` 15分K;`30` 30分K;`60` 60分K;`D` 日K;`W` 週K;`M` 月K |
| `period`\* | int | 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`\* | string | 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.md) 或 [WebSocket API](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/getting-started.md) 開始。
| 項目 | 說明 |
| -------- | ------------------------------------------------ |
| 服務 | 新一代 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.md) 提供開發者友善的 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.md) 提供台股即時行情服務。透過 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 行情連線(上限 5 條)。
* Web API 速率限制共用,WebSocket 每條連線可訂閱 200 檔。
以下範例程式碼示範如何同時建立 5 條行情 WebSocket 連線。
info
一般僅 WebSocket 需要同時啟用多條連線,若使用 Web API 則建議使用單一連線方便管理。 Web API 速率限制為所有連線共用;WebSocket 每條連線各可訂閱 200 檔標的。
* 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(5): # 建立 5 條連線
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 介面列表
// 建立 5 條行情連線
for (let i = 0; i < 5; 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(); // (期貨)
// 建立 5 條行情連線
for (int i = 0; i < 5; 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 | 單一連線 200 訂閱數;可同時開啟 5 連線 |
富邦新一代 API 行情服務提供 Web API 與 WebSocket,並設定了以下存取的限制
* 日內行情 : 300 / min
* WebSocket : 單一連線 200 訂閱數;可同時開啟 5 連線
* 行情快照 : 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每五秒,將自動發送ping到server中, 也可自行發送ping ,另外額外自訂 `state` (state 為optioanal參數) :
* 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.md)
* `books` - [接收訂閱股票最新最佳五檔委買委賣資訊](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/market-data-channels/books.md)
* `indices` - [接收訂閱股票最新指數行情資料](https://www.fbs.com.tw/TradeAPI/docs/market-data/websocket-api/market-data-channels/indices.md)
##### 訂閱頻道[](#訂閱頻道 "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 錯誤處理")
當您所訂閱或處理的WebSocket Callback有異常時,您可補充處理錯誤訊息如下 :
* Python
* Node.js
* C#
```python
def handle_connect():
print('market data connected')
def handle_disconnect(code, message):
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)
```
```js
stock.on("connect", (message) => {
const connect_msg = JSON.parse(message);
console.log(connect_msg);
});
stock.on("disconnect", (message) => {
console.log(message);
});
stock.on("error", (message) => {
const err_msg = JSON.parse(message);
console.log(err_msg);
});
```
```cs
stock.OnError += (errmsg) => Console.WriteLine($"handle error: {errmsg}");
stock.OnConnected += (connmsg) => Console.WriteLine($"Connect: {connmsg}");
stock.OnDisconnected += (disconmsg) => Console.WriteLine($"Disconnect: {disconmsg}");
```
##### 斷線重連[](#斷線重連 "Direct link to 斷線重連")
以下將用簡單範例,利用上述定義之錯誤處理方法,接收到斷線事件,程式自動進行連線
* Python
* Node.js
* C#
```python
def handle_disconnect(code, message):
print(f'market data disconnect: {code}, {message}')
stock.connect()
print("Reconnected Succuess")
print("Resubscribe")
stock.subscribe({ # 重新訂閱您已訂閱過的Channel與Symbol
'channel': '',
'symbol': ''
})
```
```js
stock.on("disconnect", (message) => {
console.log(message);
stock.connect()
console.log("Reconnected Succuess");
stock.subscribe({ channel: '', symbol: '' }); //重新訂閱您已訂閱過的Channel與Symbol
});
```
```cs
stock.OnDisconnected += async (msg) =>
{
Console.WriteLine($"disconnected at {DateTime.Now}");
await Task.Delay(10);
Console.WriteLine("Try Reconnected");
await stock.Connect();
Console.WriteLine("Reconnected Success");
Console.WriteLine("Resubscribe...");
await stock.Subscribe(StockChannel., ""); //重新訂閱您已訂閱過的Channel與Symbol
Console.WriteLine("Resubscribe Success");
};
```
---
### 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.md#%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 | 最佳五檔委賣數量 |
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.md#%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 | 股票代號 |
| `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) # 建立行情連線
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.md#%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.md#%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` |
| `time` | number | 成交時間 |
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.md#%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 期貨行情服務)提供期貨與期權日內資料查詢。
* 超過速率限制會回應 `429`。
* 提供 Python / Node.js / C# SDK 範例。
* 下一步可從功能列表選擇對應 API 端點。
| 項目 | 說明 |
| -------- | --------------------- |
| 介面 | Web API |
| 市場 | 期貨 / 期權 |
| 資料類型 | 日內 |
| 速率限制 | 超過回應 `429` |
| SDK | Python / Node.js / C# |
富邦行情 Web API 提供開發者友善的 API 服務。您可以查詢期貨與期權日內行情等數據。
#### 速率限制[](#速率限制 "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.md)
* `/intraday/tickers` - [期權商品列表(依條件查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/tickers.md)
* `/intraday/quote/{symbol}` - [期貨即時報價(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/quote.md)
* `/intraday/candles/{symbol}` - [期貨價格K線(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/candles.md)
* `/intraday/trades/{symbol}` - [期貨成交明細(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/trades.md)
* `/intraday/volumes/{symbol}` - [期貨分價量表(依代碼查詢)](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/http-api/intraday/volumes.md)
#### 使用 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;
```
---
### 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 | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 期權代碼 |
| `timeframe`\* | string | K線週期 |
| `data`\* | object\[] | K線資料 |
| >> `time` | number | 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 | 期權代碼 |
| `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 | 最後成交價漲跌 |
| `changePercnet` | number | 最後成交價漲跌幅 |
| `amplitude` | number | 當日振幅 |
| `lastPrice` | number | 最後一筆成交價(含試撮) |
| `lastSize` | number | 最後一筆成交數量(含試撮) |
| `total` | object | 統計時間 |
| >> `tradeVolume` | number | 累計成交量 |
| >> `totalBidMatch` | number | 委買成筆 |
| >> `totalAskMatch` | number | 委賣成筆 |
| `lastTrade` | object | 最後一筆成交資訊 |
| >> `bid` | number | 最後一筆成交買價 |
| >> `ask` | number | 最後一筆成交賣價 |
| >> `price` | number | 最後一筆成交價格 |
| >> `size` | number | 最後一筆成交數量 |
| >> `time` | number | 最後一筆成交時間 |
| >> `serial` | number | 最後一筆成交流水號 |
| `serial` | 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() # 建立行情連線
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"
},
"serial": 165753,
"lastUpdated": 1702359886936000
}
```
---
### Intraday Ticker
期權基本資料(依條件查詢)
```text
intraday/ticker/
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | ---------------------------------------------------------- |
| `symbol`\* | string | 商品代碼 |
| `session` | string | 交易時段,可選 `REGULAR` 一般交易 或 `AFTERHOURS` 盤後交易 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ---------------- | ------ | ----------- |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange`\* | string | 交易所 |
| `symbol`\* | string | 商品代號 |
| `name`\* | string | 商品名稱 |
| `referencePrice` | string | 參考價 |
| `settlementDate` | string | 最後結算日 |
| >> `startDate` | string | 上市日期 |
| >> `endDate` | string | 下市日期 |
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() # 建立行情連線
restfut = sdk.marketdata.rest_client.futopt
# restfut.intraday.ticker(symbol='TXFI4') # 2.2.3 及以前版本
## 2.2.4 及以後版本 (使用 Exception 進行例外處理)
from fubon_neo.fugle_marketdata.rest.base_rest import FugleAPIError
try:
restfut.intraday.ticker(symbol='TXFI4')
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: 'TXFI4'})
.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("TXFI4", new(){
Session=TradeSession.AfterHours
});
var contracts_cont = contracts.Content.ReadAsStringAsync().Result;
Console.WriteLine(contracts_cont);
```
Response Body:
```json
{
"date": "2024-09-18",
"type": "FUTURE",
"exchange": "TAIFEX",
"symbol": "TXFI4",
"name": "臺股期貨094",
"referencePrice": 21703,
"settlementDate": "2024-09-18",
"startDate": "2023-09-21",
"endDate": "2024-09-18"
}
```
---
### 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` 匯率類 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| --------------------- | --------- | -------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange` | string | 交易所 |
| `session` | string | 交易時段 |
| `contractType` | string | 契約類別 |
| `data` | object\[] | 契約列表 |
| >> `type` | string | 期權類型 |
| >> `symbol` | string | 商品代號 |
| >> `name` | string | 商品名稱 |
| >> `referencePrice` | string | 參考價 |
| >> `contractType` | string | 契約類別 |
| >> `startDate` | string | 上市日期 |
| >> `endDate` | string | 下市日期 |
| >> `flowGroup` | string | 流程群組 |
| >> `settlementDate` | string | 最後結算日 |
| >> `isDynamicBanding` | boolean | 是否適用動態價格穩定 |
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() # 建立行情連線
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": "RHFA4",
"type": "FUTURE",
"contractType": "E",
"endDate": "2024-01-17",
"flowGroup": 5,
"isDynamicBanding": true,
"name": "美元兌人民幣期貨014",
"referencePrice": 7.1387,
"settlementDate": "2024-01-17",
"startDate": "2023-11-16"
},
{
"symbol": "RHFC4",
"type": "FUTURE",
"contractType": "E",
"endDate": "2024-03-20",
"flowGroup": 5,
"isDynamicBanding": true,
"name": "美元兌人民幣期貨034",
"referencePrice": 7.108,
"settlementDate": "2024-03-20",
"startDate": "2023-01-31"
},
{
"symbol": "RHFF4",
"type": "FUTURE",
"contractType": "E",
"endDate": "2024-06-19",
"flowGroup": 5,
"isDynamicBanding": true,
"name": "美元兌人民幣期貨064",
"referencePrice": 7.0619,
"settlementDate": "2024-06-19",
"startDate": "2023-04-20"
},
{
"symbol": "RHFI4",
"type": "FUTURE",
"contractType": "E",
"endDate": "2024-09-19",
"flowGroup": 5,
"isDynamicBanding": true,
"name": "美元兌人民幣期貨094",
"referencePrice": 7.0189,
"settlementDate": "2024-09-19",
"startDate": "2023-07-20"
},
{
"symbol": "RHFL3",
"type": "FUTURE",
"contractType": "E",
"endDate": "2023-12-20",
"flowGroup": 5,
"isDynamicBanding": true,
"name": "美元兌人民幣期貨123",
"referencePrice": 7.1531,
"settlementDate": "2023-12-20",
"startDate": "2022-10-20"
},
......
]
}
```
---
### Intraday Trades
期權成交明細(依代碼查詢)
```text
intraday/trades/{symbol}
```
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| ---------- | ------ | -------------------------------- |
| `symbol`\* | string | 期權代碼 |
| `session` | string | 交易時段,可選 `afterhours` 夜盤 |
| `offset` | number | 偏移量 |
| `limit` | number | 限制量 |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------ | --------- | ----------- |
| `date`\* | string | 日期 |
| `type`\* | string | 期權類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `symbol`\* | string | 商品代號 |
| `data`\* | object\[] | 成交明細 |
| >> `price` | number | 成交價格 |
| >> `size` | number | 成交單量 |
| >> `time` | 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.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 | 交易所 |
| `market` | 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.md) 或 [WebSocket API](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/getting-started.md) 開始。
| 項目 | 說明 |
| -------- | ------------------------------------------------ |
| 服務 | 新一代 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.md) 提供開發者友善的 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.md) 提供期貨即時行情服務。透過 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 建立行情連線")
以下範例程式碼示範如何同時建立 5 條行情 WebSocket 連線。
info
一般僅 WebSocket 需要同時啟用多條連線,若使用 Web API 則建議使用單一連線方便管理。 Web API 速率限制為所有連線共用;WebSocket 每條連線各可訂閱 200 檔標的。
* 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(5): # 建立 5 條連線
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 介面列表
// 建立 5 條行情連線
for (let i = 0; i < 5; 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(); // (期貨)
// 建立 5 條行情連線
for (int i = 0; i < 5; 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 | 200 訂閱數;5 連線數 |
富邦新一代 API 期貨行情服務提供 Web API 與 WebSocket,並設定了以下存取的限制
* 日內行情 : 300 / min
* WebSocket : 200 訂閱數;5連線數
* 行情快照 : 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
* 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)
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)
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)
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每五秒,將自動發送ping到server中, 也可自行發送ping ,另外額外自訂 `state` (state 為optioanal參數) :
* 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.md)
* `books` - [接收訂閱期權商品最新最佳五檔委買委賣資訊](https://www.fbs.com.tw/TradeAPI/docs/market-data-future/websocket-api/market-data-channels/books.md)
##### 訂閱頻道[](#訂閱頻道 "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 取消訂閱")
要取消頻道可用下方範例進行取消:
* 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 錯誤處理")
當您所訂閱或處理的WebSocket Callback有異常時,您可補充處理錯誤訊息如下 :
* Python
* Node.js
* C#
```python
def handle_connect():
print('market data connected')
def handle_disconnect(code, message):
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)
```
```js
futopt.on("connect", (message) => {
const connect_msg = JSON.parse(message);
console.log(connect_msg);
});
futopt.on("disconnect", (message) => {
console.log(message);
});
futopt.on("error", (message) => {
const err_msg = JSON.parse(message);
console.log(err_msg);
});
```
```cs
futopt.OnError += (errmsg) => Console.WriteLine($"handle error: {errmsg}");
futopt.OnConnected += (connmsg) => Console.WriteLine($"Connect: {connmsg}");
futopt.OnDisconnected += (disconmsg) => Console.WriteLine($"Disconnect: {disconmsg}");
```
##### 斷線重連[](#斷線重連 "Direct link to 斷線重連")
以下將用簡單範例,利用上述定義之錯誤處理方法,接收到斷線事件,程式自動進行連線
* Python
* Node.js
* C#
```python
def handle_disconnect(code, message):
print(f'market data disconnect: {code}, {message}')
futopt.connect()
print("Reconnected Succuess")
print("Resubscribe")
futopt.subscribe({ # 重新訂閱您已訂閱過的Channel與Symbol
'channel': '',
'symbol': ''
})
```
```js
futopt.on("disconnect", (message) => {
console.log(message);
futopt.connect()
console.log("Reconnected Succuess");
futopt.subscribe({ channel: '', symbol: '' }); //重新訂閱您已訂閱過的Channel與Symbol
});
```
```cs
futopt.OnDisconnected += async (msg) =>
{
Console.WriteLine($"disconnected at {DateTime.Now}");
await Task.Delay(10);
Console.WriteLine("Try Reconnected");
await futopt.Connect();
Console.WriteLine("Reconnected Success");
Console.WriteLine("Resubscribe...");
await futopt.Subscribe(FutureOptionChannel., ""); //重新訂閱您已訂閱過的Channel與Symbol
Console.WriteLine("Resubscribe Success");
};
```
---
### Aggregates
接收訂閱期權聚合數據的行情資訊
#### Parameters[](#parameters "Direct link to Parameters")
| Name | Type | Description |
| -------------- | ------ | ------------------------------------------------------------- |
| `channel`\* | string | 訂閱頻道:`trades`, `books`, `aggregates`, `candles` |
| `symbol`\* | string | 期權代碼 |
| `afterHours`\* | bool | 訂閱夜盤行情 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 | 最後成交價漲跌 |
| `changePercnet` | number | 最後成交價漲跌幅 |
| `amplitude` | number | 當日振幅 |
| `lastPrice` | number | 最後一筆成交價(含試撮) |
| `lastSize` | number | 最後一筆成交數量(含試撮) |
| `total` | object | 統計時間 |
| >> `tradeVolume` | number | 累計成交量 |
| >> `tradeVolumeAtBid` | number | 委買成筆量 |
| >> `tradeVolumeAtAsk` | number | 委賣成筆量 |
| `lastTrade` | object | 最後一筆成交資訊 |
| >> `price` | number | 最後一筆成交價格 |
| >> `size` | number | 最後一筆成交數量 |
| >> `time` | number | 最後一筆成交時間 |
| >> `serial` | number | 最後一筆成交流水號 |
| `serial` | number | 流水號 |
| `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) # 建立行情連線
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.md#%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"
},
"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`\* | bool | 訂閱夜盤行情 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 | 最佳五檔委賣數量 |
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() # 建立行情連線
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.md#%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
}
],
"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`\* | bool | 訂閱夜盤行情 true : 夜盤行情 false : 日盤行情 default : false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------- | ------ | -------------------------------------------------------------------------- |
| `date`\* | string | 日期 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | 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.md#%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`\* | bool | 訂閱夜盤行情 true : 夜盤行情 false : 日盤行情 default : false |
#### Response[](#response "Direct link to Response")
| Name | Type | Description |
| ------------------ | ------ | ----------- |
| `symbol`\* | string | 商品代號 |
| `type`\* | string | Ticker 類型 |
| `exchange`\* | string | 交易所 |
| `market` | string | 市場別 |
| `trades` | object | 成交報價 |
| >> `price` | number | 成交價格 |
| >> `size` | number | 成交單量 |
| >> `bid` | number | 成交買價 |
| >> `ask` | number | 成交賣價 |
| `total` | object | 成交量 |
| >> `tradeVolume` | number | 成交總量 |
| >> `totalBidMatch` | number | 委買成筆 |
| >> `totalAskMatch` | number | 委賣成筆 |
| `time`\* | number | 時間 |
| `serial`\* | number | 流水號 |
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() # 建立行情連線
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.md#%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"
}
```
---
### 模式切換
**適用版本 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 條件單
本頁重點
* 本頁介紹富邦新一代 API 條件單功能與支援範圍。
* 提供多種條件單類型,適用自動化策略與風險管理。
* 下一步建議先完成[事前準備](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/prepare.md)。
| 項目 | 說明 |
| -------- | -------------------------------------------------------------------------- |
| 產品 | 富邦新一代 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 以上;如使用.NETFramework 建議您使用.NETFramework 4.7.2以上版本。
---
### 取消條件單
cancel\_condition\_orders
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ------- | ----------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL`部分成交為止、`UNTIL_END`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#conditiondaytrade-object) | 當沖委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL`部分成交為止、`UNTIL_END`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#conditiondaytrade-object) | 當沖委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| startDate | string | 查詢條件單創建日 |
| endDate | string | 查詢截止日 |
| conditionHistoryStatus | [History Status](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#account) | 帳號 |
| conditionStatus | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL`部分成交為止、`UNTIL_END`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL`部分成交為止、`UNTIL_END`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#conditionorder-object) | 委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL`部分成交為止、`UNTIL_END`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#stopsign) | 條件停止條件 :`FULL` 全部成交為止、`PARTIAL`部分成交為止、`UNTIL_END`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#conditionorder-object) | 委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| splitDescription | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#splitdescription) | 分單條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| TrailOrder | [TrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/cpp/EnumMatrix.md#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.md#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.md#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.md#account) | 帳號 |
| stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| endTime | string | 父單洗價結束時間 |
| multicondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| endTime | string | 父單洗價結束時間 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| startDate | string | 查詢條件單創建日 |
| endDate | string | 查詢截止日 |
| conditionHistoryStatus | [History Status](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| conditionStatus | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#conditionorder-object) | 委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#conditionorder-object) | 委託內容 |
| TPSLObject | [TpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| splitDescription | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#splitdescription) | 分單條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| TrailOrder | [TrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/csharp/EnumMatrix.md#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.md#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.md#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.md#account) | 帳號 |
| stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| endTime | string | 父單洗價結束時間 |
| multicondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#account) | 帳號 |
| stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| endTime | string | 父單洗價結束時間 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 查詢開始日 |
| end\_date | string | 查詢截止日 |
| condition\_history\_status | [History Status](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#account) | 帳號 |
| conditionStatus | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#conditionorder-object) | 委託內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#conditionorder-object) | 委託內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| splitDescription | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#splitdescription) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| trailOrder | [TrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/nodejs/EnumMatrix.md#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.md#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.md#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.md#account) | 帳號 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| end\_time | string | 父單洗價結束時間 |
| multicondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#account) | 帳號 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| end\_time | string | 父單洗價結束時間 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#condition-object) | 觸發條件 |
| orderObject | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#conditionorder-object) | 委託內容 |
| ConditionDayTrade Object | [ConditionDayTrade](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#conditiondaytrade-object) | 當沖回補內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 查詢開始日 |
| end\_date | string | 查詢截止日 |
| condition\_history\_status | [History Status](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#account) | 帳號 |
| condition\_status | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| MultiCondition | [Condition Array](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#conditionorder-object) | 委託內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#condition-object) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#conditionorder-object) | 委託內容 |
| TPSLObject | [TPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| split\_description | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#splitdescription) | 觸發條件 |
| ConditionOrder Object | [ConditionOrder Object](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md#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.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| trail\_order | [TrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition/library/python/EnumMatrix.md#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.md) 並完成簽署條件單使用同意書
#### 簽署條件單使用同意書[](#簽署條件單使用同意書 "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.md)
#### 引入套件 ( 僅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 期貨條件單
***
本頁重點
* 本頁介紹富邦新一代 API 期貨條件單功能與支援範圍。
* 提供多種條件單類型,適用期貨自動化策略與風險管理。
* 下一步建議先完成[事前準備](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/prepare.md)。
| 項目 | 說明 |
| -------- | -------------------------------------------------------------------------- |
| 產品 | 富邦新一代 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 以上;如使用.NETFramework 建議您使用.NETFramework 4.7.2以上版本。
---
### 取消條件單
CancelConditionOrders
#### 輸入參數[](#輸入參數 "Direct link to 輸入參數")
| 參數 | 類別 | 說明 |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 |
| guid | string | 條件單號 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| guid | string | 條件單號 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| startDate | string | 查詢開始日 |
| endDate | string | 查詢截止日 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 |
| historyStatus | [ConditionHistoryStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 |
| conditionStatus | [ConditionStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#futoptconditionorder-object) | 委託內容 |
| TPSLObject | [FutOptTpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| OrderObject | [FutOptConditionOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| start\_date | string | 條件開始監控時間 |
| end\_date | string | 條件結束監控時間 |
| stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 |
| condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#condition-object) | 觸發條件 |
| OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#futoptconditionorder-object) | 委託內容 |
| TPSLObject | [FutOptTpslWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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.md#account) | 帳號 |
| guid | string | 分時分量單號 |
| marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#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