# 富邦新一代 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. 輸入您的身分證字號、電子平台密碼 ![key\_login\_step2](/TradeAPI/assets/images/key_login_step2-516ea7a99d80eba338fd760b77a2bc93.png) 2. 申請網頁版憑證,收取 OTP ![OTP](/TradeAPI/assets/images/OTP-3771c5ab5c12c603f48994c14e130c77.png) 3. 申請完憑證後,即可進行憑證匯出與新增金鑰 ![key\_login\_step3](/TradeAPI/assets/images/key_login_step3-48c99a5a670c60ce55e5d09a4fb097eb.png) 使用預設密碼憑證 在系統提示輸入憑證密碼時,請使用您的登入 ID 4. 進行金鑰申請 * 點擊新增金鑰
![add\_key](/TradeAPI/assets/images/add_key-ce15b3f601484f2a96499f2a85150398.png) * 設置控制權限 ( IP或有效期限若不輸入,則為無限制 ) ![add\_key\_step2](/TradeAPI/assets/images/add_key_step2-ee688b483e6d020bb1ad988c42cd2325.png) * 設置成功,顯示 Secret Key ( Secret Key 關閉後即不再顯示 ) ![add\_key\_step3](/TradeAPI/assets/images/add_key_step3-6913c4ffe9e7e563c740c6ae15f80cbe.png) 5. 可檢視先前申請的 Key 內容或停用 ( Key 最多申請 30 把 ) ![key\_list](/TradeAPI/assets/images/key_list-7e65381ef6623e6c61a53a7cef01bf94.png) 本頁重點 * 本頁提供富邦新一代 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) ![TPSL](/TradeAPI/assets/images/TPSL-c929bfde158264f3327c48f316c32bde.png) #### 程式範例[​](#程式範例 "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 支援移動鎖利單, 移動鎖利運作機制 : 當基準條件觸發後,若設定的回檔幅度未達到,則不會觸發,當後續股價持續往上,則會使用新的價格作為基準,若此時回檔幅度到達設定值,則送出委託 ![trailProfit](/TradeAPI/assets/images/TrailProfit-57d72c840dd40176b183a22ef955bfdc.png) ##### 程式範例[​](#程式範例 "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 ,點選更多
![線上簽署1](/TradeAPI/assets/images/signagree1-344762a81c78861fa652f3bd8d11d735.png) 2. 點選 `M櫃台`
![線上簽署2](/TradeAPI/assets/images/signagree2-f228860054133c73f3f12e482545cc55.png) 3. 點選條件單同意書
![線上簽署3](/TradeAPI/assets/images/signagree3-ea03b7b52731323e65fe28d393dd2432.png) #### 升級您的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) ![TPSL](/TradeAPI/assets/images/TPSL-c929bfde158264f3327c48f316c32bde.png) #### 程式範例[​](#程式範例 "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 支援移動鎖利單, 移動鎖利運作機制 : 當基準條件觸發後,若設定的回檔幅度未達到,則不會觸發,當後續股價持續往上,則會使用新的價格作為基準,若此時回檔幅度到達設定值,則送出委託 ![trailProfit](/TradeAPI/assets/images/TrailProfit-62f309ff8f8104114c69c2fc69bb96d1.png) ##### 程式範例[​](#程式範例 "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(), TpslCount = 0, TpslRecord = new List() } ] } ``` --- ### 分時分量條件單 TimeSliceOrder #### 輸入參數[​](#輸入參數 "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`效期結束為止 | | splitDescription | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#splitdescription) | 分單條件 | | 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 split = new SplitDescription( TimeSliceOrderType.Type1, 300, 1, 10, "083000", null ); var order = new FutOptConditionOrder( BsAction.Buy, "TXO20000E4", "100", 1, FutOptConditionMarketType.Option, FutOptConditionPriceType.Limit, TimeInForce.Rod, FutOptConditionOrderType.New ); sdk.FutOpt.TimeSliceOrder(target_account, "20240427","20240516", StopSign.Full, split, order); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = ConditionOrderResult { guid = 24081200000006 } } ``` --- ### 歷史移動鎖利查詢 GetTrailHistory #### 輸入參數[​](#輸入參數 "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 | 查詢截止日 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#futoptconditionmarkettype) | 盤別 | #### 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.GetTrailHistory(account,"20240301","20240601",FutOptConditionMarketType.Future); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ { Guid = 1d97125b-9847-4b30-a066-2b490be17b2d, BatchNo = , OrderLevel = 0, LastTime = 2024-09-15 10:33:33, ConditionType = 移動鎖利, ParentGuid = , Symbol = FITX202411, OrderAmount = 0, ChildBatchNo = , Account = 9974825, ConditionContent = 當自2024/09/15至2024/11/16內台指期202411成交價小於等於20000點 全部成交為止, Action = 下單(新倉), ConditionBuySell = 買, ConditionSymbol = 台指期202411 買, ConditionPrice = 賣出價(3) 檔(ROD), ConditionVolume = 1, ConditionFilledVolume = 0, CreateTime = 2024-09-15 10:33:33, StartDate = 2024/09/15, Status = 洗價中(Y), ErrorMessage = null, DetailRecordsCount = 0, DetailRecords = new List(), TpslCount = 0, TpslRecord = new List() }, ... ] } ``` --- ### 移動鎖利查詢 GetTrailOrder #### 輸入參數[​](#輸入參數 "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) | 盤別 | #### 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.GetTrailOrder(account, FutOptConditionMarketType.Future); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ { Guid = 1d97125b-9847-4b30-a066-2b490be17b2d, BatchNo = , OrderLevel = 0, LastTime = 2024-09-15 10:33:33, ConditionType = 移動鎖利, ParentGuid = , Symbol = FITX202411, OrderAmount = 0, ChildBatchNo = , Account = 9974825, ConditionContent = 當自2024/09/15至2024/11/16內台指期202411成交價小於等於20000點 全部成交為止, Action = 下單(新倉), ConditionBuySell = 買, ConditionSymbol = 台指期202411 買, ConditionPrice = 賣出價(3) 檔(ROD), ConditionVolume = 1, ConditionFilledVolume = 0, CreateTime = 2024-09-15 10:33:33, StartDate = 2024/09/15, Status = 洗價中(Y), ErrorMessage = null, DetailRecordsCount = 0, DetailRecords = new List(), TpslCount = 0, TpslRecord = new List() }, ... ] } ``` --- ### 移動鎖利條件單 TrailProfit caution 僅支援日盤交易 #### 輸入參數[​](#輸入參數 "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`效期結束為止 | | FutOptTrailOrder | [FutOptTrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/csharp/EnumMatrix.md#futopttrailorder) | 分單條件 | #### 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 FutOptTrailOrder( "TXO20000E4", "100", Direction.Up , 5, // 漲跌 tick 數 BsAction.Buy, 2, FutOptConditionPriceType.MatchedPrice, 5, // 向上 or 向下追買 tick數 (向下為負值) TimeInForce.Rod, FutOptConditionOrderType.Close ); sdk.FutOpt.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-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | guid | string | 條件單號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/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 請求範例") ```js sdk.FutOpt.cancelConditionOrders(account, "c9df498a-3b28-4b50-a6f2-f7bd524e96df", ) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data : { 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 版本新增欄位,暫無相關功能,可忽略 | 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") 買賣別 | 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張,剩餘張數從最後一筆往前分配 | ##### 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-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | guid | string | 條件單號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/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 請求範例") ```js sdk.futopt.getConditionOrderById(account,"8ff3472b-185a-488c-be5a-b478deda080c") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, 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)", 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/nodejs/EnumMatrix.md#account) | 帳號 | | start\_date | string | 查詢開始日 | | end\_date | string | 查詢截止日 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 | | history\_status | [HistoryStatus](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 請求範例") ```js sdk.futopt.getConditionHistory(account,"20240301","20240601") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, 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/nodejs/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 | | 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.futopt.getConditionOrder(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, 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)", 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/nodejs/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/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 請求範例") ```js // 設計條件內容 const condition = { marketType: TradingType.Reference, symbol: "TXO20000E4", trigger: TriggerContent.MatchedPrice, triggerValue: "100", comparison: Operator.LessThan } const condition2 = { marketType: TradingType.Reference, symbol: "TXO20000E4", trigger: TriggerContent.TotalQuantity, triggerValue: "30", comparison: Operator.GreaterThan } const order = { buySell: BSAction.Buy, symbol: "TXO20000E4", price: "500", lot: 1, marketType: FutOptConditionMarketType.Option, priceType: FutOptConditionPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutOptConditionOrderType.New, }; sdk.futopt.multiCondition(account, "20240426", "20240430", StopSign.Full, [condition,condition2], order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data : { guid : "44150047-8977-40b1-953c-ce2XXXXXX" } } ``` --- ### 多條件單包含停損停利 multiCondition 停損利注意事項 * 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整 * 請確認停損利**委託類別**設定需符合適合之交易規則 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#futoptconditionorder-object) | 委託內容 | | TPSLObject | [FutOptTPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/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 請求範例") ```js // 設計條件內容 const condition = { marketType: TradingType.Reference, symbol: "TXO20000E4", trigger: TriggerContent.MatchedPrice, triggerValue: "100", comparison: Operator.LessThan } const condition2 = { marketType: TradingType.Reference, symbol: "TXO20000E4", trigger: TriggerContent.TotalQuantity, triggerValue: "30", comparison: Operator.GreaterThan } 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" // optional field } sdk.futopt.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-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/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 請求範例") ```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 }; sdk.futopt.singleCondition(account, "20240426", "20240430", StopSign.Full, condition, order) ``` #### 回傳範例[​](#回傳範例 "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-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#condition-object) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#futoptconditionorder-object) | 委託內容 | | TPSLObject | [FutOptTPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/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 請求範例") ```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" // optional field } sdk.futopt.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-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | batchNo | string | 分時分量條件單號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/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 請求範例") ```js sdk.futopt.getTimeSliceOrder(account,"1234567") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data : [ { 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)", detailRecordsCount: "0", detailRecords: [], tpslCount: "0", tpslRecord: [] } ] } ``` --- ### 分時分量條件單 timeSliceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | splitDescription | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#splitdescription) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/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 請求範例") ```js // 設計條件內容 const split = { method: TimeSliceOrderType.Type1, interval: 300, singleQuantity: 1, totalQuantity: 10, startTime: '083000', }; const order = { buySell: BSAction.Buy, symbol: "TXO20000E4", price: "500", lot: 1, marketType: FutOptConditionMarketType.Option, priceType: FutOptConditionPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutOptConditionOrderType.New, }; sdk.futopt.timeSliceOrder(target_account, "20240427","20240516", StopSign.Full, split, order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data : { guid : "24081200000006" } } ``` --- ### 歷史移動鎖利查詢 getTrailHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | start\_date | string | 查詢開始日 | | end\_date | string | 查詢截止日 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#futoptconditionmarkettype) | 盤別 | #### 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.futopt.getTrailHistory(account,"20240301","20240601", FutOptConditioMarketType.Future) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data :[ { guid: "1d97125b-9847-4b30-a066-2b490be17b2d", batchNo: "", orderLevel: "0", lastTime: "2024-09-15 10:33:33", conditionType: "移動鎖利", parentGuid: "", symbol: "FITX202411", orderAmount: "0", childBatchNo: "", account: "9974825", conditionContent: "當自2024/09/15至2024/11/16內台指期202411成交價小於等於20000點 全部成交為止", action: "下單(新倉)", conditionBuySell: "買", conditionSymbol: "台指期202411 買", conditionPrice: "賣出價(3) 檔(ROD)", conditionVolume: "1口", conditionFilledVolume: "0口", createTime: "2024-09-15 10:33:33", startDate: "2024/09/15", status: "洗價中(Y)", detailRecordsCount: "0", detailRecords: [], tpslCount: "0", tpslRecord: [], }, ... ] } ``` --- ### 移動鎖利查詢 getTrailOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#futoptconditionmarkettype) | 盤別 | #### 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.futopt.getTrailOrder(account, FutOptConditionMarketType.Future) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data :[ { guid: "1d97125b-9847-4b30-a066-2b490be17b2d", batchNo: "", orderLevel: "0", lastTime: "2024-09-15 10:33:33", conditionType: "移動鎖利", parentGuid: "", symbol: "FITX202411", orderAmount: "0", childBatchNo: "", account: "9974825", conditionContent: "當自2024/09/15至2024/11/16內台指期202411成交價小於等於20000點 全部成交為止", action: "下單(新倉)", conditionBuySell: "買", conditionSymbol: "台指期202411 買", conditionPrice: "賣出價(3) 檔(ROD)", conditionVolume: "1口", conditionFilledVolume: "0口", createTime: "2024-09-15 10:33:33", startDate: "2024/09/15", status: "洗價中(Y)", detailRecordsCount: "0", detailRecords: [], tpslCount: "0", tpslRecord: [], }, ... ] } ``` --- ### 移動鎖利條件單 caution 僅支援日盤交易 trailProfit #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | startDate | string | 條件開始監控時間 | | endDate | string | 條件結束監控時間 | | stopSign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | futoptTrailOrder | [FutOptTrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/nodejs/EnumMatrix.md#futopttrailorder) | 移動鎖利條件 | #### 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: "TXO20000E4", price: "100", direction: Direction.Down, tickNum: 5, buySell: BSAction.Sell, lot: 2, priceType: FutOptConditionPriceType.MatchedPrice, diff: 5, timeInForce: TimeInForce.ROD, orderType: FutOptConditionOrderType.Close }; sdk.futopt.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-future/library/python/EnumMatrix.md#account) | 帳號 | | guid | string | 條件單號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 請求範例") ```py sdk.futopt.cancel_condition_orders(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 | | -------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- | | 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` 2. 選擇`Scheduled` 時,symbol需填入欲觸發之商品,trigger需帶入`Time` ##### FutOptConditionOrder Object[​](#futoptconditionorder-object "Direct link to FutOptConditionOrder Object") | Parameter | Type | Meaning | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | buy\_sell | BSAction | [買賣別](#bsaction) 可選用參數`Buy` 買 、 `Sell` 賣 | | symbol | string | 股票代號 | | price | string | 委託價格 | | quantity | int | 委託數量 | | market\_type | FutOptConditionMarketType | [盤別](#futoptconditionmarkettype) 可選用參數 : `Future` 期貨日盤、`Option` 選擇權日盤、`FutureNight` 期貨夜盤、`OptionNight` 選擇權夜盤 (**IMPORTANT:** 以下功能不支援夜盤: 1. 分時分量, 2. 移動鎖利, 3. 時間觸發條件) | | price\_type | FutOptConditionPriceType | [價格別](#futoptconditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice`成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) 、`RangeMarket` 範圍市價 | | time\_in\_force | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`ROD`、`IOC`、`FOK` | | order\_type | FutOptConditionOrderType | [委託類別](#futoptconditionordertype) : 可選參數 :`New` 新倉、`Close` 平倉 | caution 以下功能不支援夜盤: 1. 分時分量 2. 移動鎖利 3. 時間觸發條件 ##### FutOptTPSLOrder Object[​](#futopttpslorder-object "Direct link to FutOptTPSLOrder Object") | Parameter | Type | Meaning | | ---------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | time\_in\_force | TimeInforce | [委託條件](#timeinforce) : 可選參數 :`ROD`、`IOC`、`FOK` | | price\_type | FutOptConditionPriceType | [價格別](#futoptconditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice`成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) 、`RangeMarket` 範圍市價 | | order\_type | FutOptConditionOrderType | [委託類別](#futoptconditionordertype) : 可選參數 :`New` 新倉、`Close` 平倉 | | target\_price | string | 停損/停利觸發價 | | price | string | 停損/停利委託價 | | trigger (**保留欄位**) | TriggerContent | 2.2.0 版本新增欄位,暫無相關功能,可忽略 | info `priceType` 若為`limit`時,`price`需填入價格;其餘price填入空字串 ##### FutOptTPSLWrapper Object[​](#futopttpslwrapper-object "Direct link to FutOptTPSLWrapper Object") | Parameter | Type | Meaning | | ---------- | --------------------------------------- | ------------------------------------------------------------------------------------------------- | | stop\_sign | StopSign | [停止條件](#stopsign) : 可選用 `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | TP | FutOptTPSLOrder Object (Optional) | 停利條件內容 | | SL | FutOptTPSLOrder Object (Optional) | 停損條件內容 | | end\_date | string (Optional : 空值同母單StartDate) | 條件停止日期 | | day\_trade | bool (Optional) | 全部成交後當沖 (期貨固定為True) | ##### FutOptTrailOrder[​](#futopttrailorder "Direct link to FutOptTrailOrder") | Parameter | Type | Meaning | | --------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | symbol | string | 商品代號 | | price | string | 基準價 | | direction | Direction | [方向](#direction) : 可選用 `Up` 上漲、`Down` 下跌 | | tick\_num | int | 上漲 / 下跌 ticker 數 | | buysell | BSAction | 買賣別 : 可選用 `Buy` 買進 、`Sell` 賣出 | | lot | int | 委託口數 | | price\_type | FutOptConditionPriceType | [價格別](#futoptconditionpricetype) : 可選參數 :`BidPrice` 買進價、 `AskPrice` 賣出價、`MatchedPrice`成交價、`Limit` 限價、`LimitUp` 漲停、`LimitDown` 跌停、`Market` 市價、`Reference` 參考價(平盤價) 、`RangeMarket` 範圍市價 | | diff | int | 買賣價格檔數 (根據 priceType 加減檔數) ,正值為向上加檔數、負值為向下加檔數 | | time\_in\_force | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` | | order\_type | FutOptConditionOrderType | [委託類別](#futoptconditionordertype) : 可選參數 :`New` 新倉、`Close` 平倉 | ##### 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 | 條件單號 | #### Constants ( 欄位對應數值 )[​](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )") ##### BSAction[​](#bsaction "Direct link to BSAction") 買賣別 (buySell) | 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 | 自動參考委託物件 | | 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張,剩餘張數從最後一筆往前分配 | ##### 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-future/library/python/EnumMatrix.md#account) | 帳號 | | guid | string | 條件單號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 | 條件單號 | | 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.futopt.get_condition_order_by_id(account,"8ff3472b-185a-488c-be5a-b478deda080c") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data :[ ConditionDetail { guid: "adada47e-dea3-4a5a-9eff-d36bd7a71e87", batch_no: "", order_level: "0", last_time: "2024-11-15 10:38:48", condition_type: "觸價", parent_guid: "adada47e-dea3-4a5a-9eff-d36bd7a71e87", symbol: "FIMTX202411", order_amount: "0", child_batch_no: "", account: "9974825", condition_content: "當自2024/11/15至2024/11/20內台指期202412成交價大於21000點 全部成交為止", action: "下單(新倉)", condition_buy_sell: "賣", condition_symbol: "賣 小型台指202411", condition_price: "範圍市價(ROD)", condition_volume: "2口", condition_filled_volume: "0口", create_time: "2024-11-15 10:38:48", start_date: "2024/11/15", status: "洗價中(Y)", error_message: None, detail_records_count: "0", detail_records: [], TPSLCount: "2", TPSLRecord: [ ParentChildRecord { guid: "b79084fe-6fdf-461f-a264-0482072237eb", account: "9974825", condition_content: "當自2024/11/15至2024/11/20內小型台指202411買進價大於等於22340元 全部成交為止", action: "下單(平倉)", condition_buy_sell: "買", condition_symbol: "買 小型台指202411", condition_price: "22340(ROD)", condition_volume: "2口", condition_filled_volume: "0口", start_date: "2024/11/15", status: "未生效(W)", error_message: "", }, ParentChildRecord { guid: "b79084fe-6fdf-461f-a264-0482072237eb", account: "9974825", condition_content: "當自2024/11/15至2024/11/20內小型台指202411買進價小於等於22280元 全部成交為止", action: "下單(平倉)", condition_buy_sell: "買", condition_symbol: "買 小型台指202411", condition_price: "22280(ROD)", condition_volume: "2口", condition_filled_volume: "0口", start_date: "2024/11/15", status: "未生效(W)", error_message: "", }, ], } ] } ``` --- ### 歷史條件單查詢 get\_condition\_history #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 查詢開始日 | | end\_date | string | 查詢截止日 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 | | history\_status | [HistoryStatus](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 | 條件單號 | | 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.futopt.get_condition_history(account,"20240310","20240601") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data :[ ConditionDetail { guid: "1d97125b-9847-4b30-a066-2b490be17b2d", batch_no: "", order_level: "0", last_time: "2024-09-15 10:33:33", condition_type: "移動鎖利", parent_guid: "", symbol: "FITX202411", order_amount: "0", child_batch_no: "", account: "9974825", condition_content: "當自2024/09/15至2024/11/16內台指期202411成交價小於等於20000點 全部成交為止", action: "下單(新倉)", condition_buy_sell: "買", condition_symbol: "台指期202411 買", condition_price: "賣出價(3) 檔(ROD)", condition_volume: "1口", condition_filled_volume: "0口", create_time: "2024-09-15 10:33:33", start_date: "2024/09/15", status: "洗價中(Y)", error_message: None, detail_records_count: "0", detail_records: [], TPSLCount: "0", TPSLRecord: [], } ... ] } ``` --- ### 條件單查詢 get\_condition\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#futoptconditionmarkettype) (Optional) default : 日盤 | 盤別 | | 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.futopt.get_condition_order(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ ConditionDetail { guid: "1d97125b-9847-4b30-a066-2b490be17b2d", batch_no: "", order_level: "0", last_time: "2024-09-15 10:33:33", condition_type: "移動鎖利", parent_guid: "", symbol: "FITX202411", order_amount: "0", child_batch_no: "", account: "9974825", condition_content: "當自2024/09/15至2024/11/16內台指期202411成交價小於等於20000點 全部成交為止", action: "下單(新倉)", condition_buy_sell: "買", condition_symbol: "台指期202411 買", condition_price: "賣出價(3) 檔(ROD)", condition_volume: "1口", condition_filled_volume: "0口", create_time: "2024-09-15 10:33:33", start_date: "2024/09/15", status: "洗價中(Y)", error_message: None, detail_records_count: "0", detail_records: [], TPSLCount: "0", TPSLRecord: [], }, ... ] } ``` --- ### 多條件單 multi\_condition #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | MultiCondition | [Condition Array](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#condition-object) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 請求範例") ```py # 設計條件內容 condition = Condition( market_type = TradingType.Reference, symbol = "TXO20000E4", trigger = TriggerContent.MatchedPrice, trigger_value = "100", comparison = Operator.LessThan ) condition2 = Condition( market_type = TradingType.Reference, symbol = "TXO20000E4", trigger = TriggerContent.TotalQuantity, trigger_value = "30", comparison = Operator.LessThan ) order = FutOptConditionOrder( buy_sell = BSAction.Buy, symbol = "TXO20000E4", price = "500", lot = 1, market_type = FutOptConditionMarketType.Option, price_type = FutOptConditionPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptConditionOrderType.New ) sdk.futopt.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 停損利注意事項 * 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整 * 請確認停損利**委託類別**設定需符合適合之交易規則 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | MultiCondition | [Condition List](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#condition-object) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#futoptconditionorder-object) | 委託內容 | | TPSLObject | [FutOptTPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 請求範例") ```py # 設計條件內容 condition = Condition( market_type = TradingType.Reference, symbol = "TXO20000E4", trigger = TriggerContent.MatchedPrice, trigger_value = "100", comparison = Operator.LessThan ) condition2 = Condition( market_type = TradingType.Reference, symbol = "TXO20000E4", trigger = TriggerContent.TotalQuantity, trigger_value = "30", 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="120", price="120" ) 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.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-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#condition-object) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 請求範例") ```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 = "500", lot = 1, market_type = FutOptConditionMarketType.Option, price_type = FutOptConditionPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptConditionOrderType.New ) res = sdk.futopt.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 停損利注意事項 * 停損利設定僅為觸發送單,不保證必定成交,需視市場狀況自行調整 * 請確認停損利**委託類別**設定需符合適合之交易規則 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | condition | [Condition](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#condition-object) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#futoptconditionorder-object) | 委託內容 | | TPSLObject | [FutOptTPSLWrapper](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 請求範例") ```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) ``` #### 回傳範例[​](#回傳範例 "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-future/library/python/EnumMatrix.md#account) | 帳號 | | batch\_no | string | 分時分量條件單號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 | 條件單號 | | 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.futopt.get_time_slice_order(account,"123456") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data :[ ConditionDetail { guid: "f76c49ee-e955-41ac-8e11-02d6d2b78918", batch_no: "", order_level: "0", last_time: "2024-08-16 17:13:29", condition_type: "定時", parent_guid: "", symbol: "TXO20000H4", order_amount: "0", child_batch_no: "", account: "9974825", condition_content: "當於2024/08/16 定時單時間大於等於09:15:00 全部成交為止", action: "下單(新倉)", condition_buy_sell: "買", condition_symbol: "買 台指2024年8 月買權履約價:20000", condition_price: "500(ROD)", condition_volume: "1口", condition_filled_volume: "0口", create_time: "2024-08-16 17:13:28", start_date: "2024/08/16", status: "預約(N)", 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-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#stopsign) | 條件停止條件 : `Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | split\_description | [SplitDescription](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#splitdescription) | 觸發條件 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/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 請求範例") ```py # 設計條件內容 split = SplitDescription( method=TimeSliceOrderType.Type1, interval= 300, single_quantity= 1, total_quantity= 10, start_time='083000' ) order = FutOptConditionOrder( buy_sell = BSAction.Buy, symbol = "TXO20000E4", price = "500", lot = 1, market_type = FutOptConditionMarketType.Option, price_type = FutOptConditionPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptConditionOrderType.New, ) sdk.futopt.time_slice_order(target_account, "20240427","20240516", StopSign.Full, split, order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : ConditionOrderResult { guid : "24081200000006" } } ``` --- ### 歷史移動鎖利查詢 get\_trail\_history #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 查詢開始日 | | end\_date | string | 查詢截止日 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#futoptconditionmarkettype) | 盤別 | #### 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.futopt.get_trail_history(account,"20240310","20240601") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ ConditionDetail { guid: "1d97125b-9847-4b30-a066-2b490be17b2d", batch_no: "", order_level: "0", last_time: "2024-09-15 10:33:33", condition_type: "移動鎖利", parent_guid: "", symbol: "FITX202411", order_amount: "0", child_batch_no: "", account: "9974825", condition_content: "當自2024/09/15至2024/11/16內台指期202411成交價小於等於20000點 全部成交為止", action: "下單(新倉)", condition_buy_sell: "買", condition_symbol: "台指期202411 買", condition_price: "賣出價(3) 檔(ROD)", condition_volume: "1口", condition_filled_volume: "0口", create_time: "2024-09-15 10:33:33", start_date: "2024/09/15", status: "洗價中(Y)", 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-future/library/python/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptConditionMarketType](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#futoptconditionmarkettype) | 盤別 | #### 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.futopt.get_trail_order(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ ConditionDetail { guid: "1d97125b-9847-4b30-a066-2b490be17b2d", batch_no: "", order_level: "0", last_time: "2024-09-15 10:33:33", condition_type: "移動鎖利", parent_guid: "", symbol: "FITX202411", order_amount: "0", child_batch_no: "", account: "9974825", condition_content: "當自2024/09/15至2024/11/16內台指期202411成交價小於等於20000點 全部成交為止", action: "下單(新倉)", condition_buy_sell: "買", condition_symbol: "台指期202411 買", condition_price: "賣出價(3) 檔(ROD)", condition_volume: "1口", condition_filled_volume: "0口", create_time: "2024-09-15 10:33:33", start_date: "2024/09/15", status: "洗價中(Y)", error_message: None, detail_records_count: "0", detail_records: [], TPSLCount: "0", TPSLRecord: [], } ... ] } ``` --- ### 移動鎖利條件單 trail\_profit caution 僅支援期貨日盤交易 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 條件開始監控時間 | | end\_date | string | 條件結束監控時間 | | stop\_sign | [StopSign](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#stopsign) | 條件停止條件 :`Full` 全部成交為止、`Partial`部分成交為止、`UntilEnd`效期結束為止 | | fut\_opt\_trail\_order | [FutOptTrailOrder](https://www.fbs.com.tw/TradeAPI/docs/smart-condition-future/library/python/EnumMatrix.md#futopttrailorder) | 移動鎖利條件 | #### 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 = FutOptTrailOrder( symbol = "TXFL4", price = "20000", direction = Direction.Up , tick_num = 5, # 漲跌 tick 數 buy_sell = BSAction.Buy, lot = 2, price_type = FutOptConditionPriceType.MatchedPrice, diff = 5, # 向上 or 向下追買 tick數 (向下為負值) time_in_force = TimeInForce.ROD, order_type = FutOptConditionOrderType.Close ) sdk.futopt.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" } } ``` --- ### 事前準備 caution 在開始富邦新一代 API 條件單前,您必須完成簽署條件單智慧單 #### 簽署條件單風險預告書[​](#簽署條件單風險預告書 "Direct link to 簽署條件單風險預告書") 登入富邦證券簽署中心,選擇期貨,簽署期貨條件單 ![線上簽署](/TradeAPI/assets/images/futurecondition-28d403275883db4916ae8c3d249373c3.png) #### 引入套件 ( 僅Python、JS需要,C#不需額外操作)[​](#引入套件--僅pythonjs需要c不需額外操作 "Direct link to 引入套件 ( 僅Python、JS需要,C#不需額外操作)") 引入條件單相關套件 * Python * Node.js ```py from fubon_neo.sdk import FubonSDK, Condition, FutOptConditionOrder from fubon_neo.constant import ( TriggerContent, TradingType, Operator, FutOptTPSLOrder, FutOptTPSLWrapper, SplitDescription, StopSign, TimeSliceOrderType, FutOptConditionPriceType, FutOptConditionOrderType, FutOptConditionMarketType, TrailOrder, Direction, FutOptTrailOrder, ConditionStatus, HistoryStatus ) ``` ```js const { FubonSDK, TriggerContent, TradingType, Operator, FutOptTPSLOrder, FutOptTPSLWrapper, SplitDescription, StopSign, TimeSliceOrderType, FutOptConditionPriceType, FutOptConditionOrderType, FutOptConditionMarketType, TrailOrder, Direction, FutOptTrailOrder, ConditionStatus, HistoryStatus } = require('fubon-neo'); ``` info 條件單目前不支援期權商品與現貨商品混用 --- ### 緊急應變措施 若有因不可抗力之因素或系統異常,而造成無法下單或確認委託成交狀況時,請使用其他平台作為備援 條件單替代平台: * HTS2 * Online APP * 營業員 更多訊息請洽富邦證券官網[「網路下單系統無法正常使用之應變措施」](https://www.fbs.com.tw/Beginner/TradingNote) --- ### API Key 說明 版本限制 2.2.7版本新增功能 您仍可使用現有的帳號憑證登入並使用 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. 進入[金鑰申請及管理](https://www.fbs.com.tw/TradeAPI/docs/key.md) ![key\_login\_step1](/TradeAPI/assets/images/key_login_step1-d6356e971b19e5a35f3a1b089bf2a6a7.png) 2. 輸入您的身分證字號、電子平台密碼 ![key\_login\_step2](/TradeAPI/assets/images/key_login_step2-516ea7a99d80eba338fd760b77a2bc93.png) 3. 申請網頁版憑證,收取 OTP ![OTP](/TradeAPI/assets/images/OTP-3771c5ab5c12c603f48994c14e130c77.png) 4. 申請完憑證後,即可進行憑證匯出與新增金鑰 ![key\_login\_step3](/TradeAPI/assets/images/key_login_step3-48c99a5a670c60ce55e5d09a4fb097eb.png) 使用預設密碼憑證 在系統提示輸入憑證密碼時,請使用您的登入 ID 5. 進行金鑰申請 * 點擊新增金鑰
![add\_key](/TradeAPI/assets/images/add_key-ce15b3f601484f2a96499f2a85150398.png) * 設置控制權限 ( IP或有效期限若不輸入,則為無限制 ) ![add\_key\_step2](/TradeAPI/assets/images/add_key_step2-ee688b483e6d020bb1ad988c42cd2325.png) * 設置成功,顯示 Secret Key ( Secret Key 關閉後即不再顯示 ) ![add\_key\_step3](/TradeAPI/assets/images/add_key_step3-6913c4ffe9e7e563c740c6ae15f80cbe.png) 6. 可檢視先前申請的 Key 內容或停用 ( Key 最多申請 30 把 ) ![key\_list](/TradeAPI/assets/images/key_list-7e65381ef6623e6c61a53a7cef01bf94.png) --- ### 帳務 *** 我們可以透過成交及庫存查詢來確認損益等資訊。 info 查詢發送的次數為每秒5次,若超出上限,請稍後再試試! #### 庫存查詢[​](#庫存查詢 "Direct link to 庫存查詢") * Python * Node.js * C# ```python inventories = sdk.accounting.inventories(accounts.data[0]) print(inventories) ``` ```py Result { is_success: true, message: None, data : [ Inventory{ date: "2023/09/20", # 查詢庫存日期 (string) account: "26", # 帳號 (string) branch_no: "6460", # 分公司代號 (string) stock_no: "1101", # 股票代號 (string) order_type: Stock, # 委託類別 (OrderType) lastday_qty: 2000, # 昨日整股餘額 (int) buy_qty: 0, # 整股委買股數 (int) buy_filled_qty: 0, # 整股買進成交股數 (int) buy_value: 0, # 整股買進成交價金 (int) today_qty: 2000, # 整股餘額 (int) tradable_qty: 2000, #可委託整股庫存數 (int) sell_qty: 0, # 整股委賣股數 (int) sell_filled_qty: 0, # 整股賣出成交股數 (int) sell_value: 0, # 整股賣出成交價金 (int) odd: InventoryOdd{ # 零股 lastday_qty: 0, # 昨日零股餘額 (int) buy_qty: 0, # 零股委買股數 (int) buy_filled_qty: 0, # 零股買進成交股數 (int) buy_value: 0, # 零股買進成交價金 (int) today_qty: 0, # 零股餘額 (int) tradable_qty: 0, # 可委託零股餘額 (int) sell_qty: 0, # 零股委賣股數 (int) sell_filled_qty: 0, # 零股賣出成交股數 (int) sell_value: 0 # 零股賣出成交價金 (int) }}, ... ] } ``` ```js const inventory = sdk.accounting.inventories(accounts.data[0]) console.log(inventory) ``` ```js { isSuccess: true, data:[ { date: '2023/10/13', account: '26', branchNo: '6460', stockNo: '1101', orderType: Stock, lastdayQty: 2000, buyQty: 0, buyFilledQty: 0, buyValue: 0, todayQty: 2000, tradableQty: 2000, sellQty: 0, sellFilledQty: 0, sellValue: 0, odd: { lastdayQty: 0, buyQty: 0, buyFilledQty: 0, buyValue: 0, todayQty: 0, tradableQty: 0, sellQty: 0, sellFilledQty: 0, sellValue: 0 } }, ... ] } ``` ```cs var inventories = sdk.Accounting.Inventoies(accounts.data[0]); foreach (var inventory in inventories.data) { Console.WriteLine(inventory); } ``` ```cs { date = 2023/09/21, // 查詢庫存日期 (string) account = 26, // 帳號 (string) branchNo = 6460, // 分公司代號 (string) stockNo = 1101, // 股票代號 (string) orderType = Stock, // 委託類別 (OrderType)) lastdayQty = 2000, // 昨日整股餘額 (int) buyQty = 0, // 整股委買股數 (int) buyFilledQty = 0, // 整股買進成交股數 (int) buyValue = 0, // 整股買進成交價金 (int) todayQty = 2000, // 整股餘額 (int) tradableQty = 2000, // 可委託整股庫存數 (int) sellQty = 0, // 整股委賣股數 (int) sellFilledQty = 0, // 整股賣出成交股數 (int) sellValue = 0, // 整股賣出成交價金 (int) odd = InventoryOdd { // 零股 lastdayQty = 0, // 昨日零股餘額 (int) buyQty = 0, // 零股委買股數 (int) buyFilledQty = 0, // 零股買進成交股數 (int) buyValue = 0, // 零股買進成交價金 (int) todayQty = 0, // 零股餘額 (int) tradableQty = 0, // 可委託零股餘額 (int) sellQty = 0, // 零股委賣股數 (int) sellFilledQty = 0, // 零股賣出成交股數 (int) sellValue = 0 // 零股賣出成交價金 (int) } } ``` * 以下範例回傳僅擷取data內容 #### 未實現損益查詢[​](#未實現損益查詢 "Direct link to 未實現損益查詢") * Python * Node.js * C# ```python unrealized_pnl = sdk.accounting.unrealized_gains_and_loses(accounts.data[0]) print(unrealized_pnl.data) ``` ```py [UnrealizedData({ date: "2023/05/23", # 查詢當天日期 (string) account: "482", # 帳號 (string) branch_no: "6460", # 分公司代號 (string) stock_no: "2442", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) order_type: Margin, # 委託類別 (OrderType) cost_price: 19.95, # 成本價 (int) tradable_qty: 6000, # 可委託庫存數 (int) unrealized_profit: 0, # 未實現獲利 (int) unrealized_loss: 10002 # 未實現損失 (int) }), ... ] ``` ```js const unrealizedPNL = sdk.accounting.unrealizedGainsAndLoses(accounts.data[0]) console.log(unrealizedPNL.data) ``` ```js [ { date: '2021/08/09', account: '26', branchNo: '6460', stockNo: '2303', buySell: Buy, orderType: Margin, costPrice: 50, tradableQty: 1000, todayQty: 1000, unrealizedProfit: 47000, unrealizedLoss: 0 }, ... ] ``` ```cs var unrealizedPNL = sdk.Accounting.UnrealizedGainsAndLoses(accounts.data[0]); foreach (var unrealized in unrealizedPNL.data) { Console.WriteLine(unrealized); } ``` ```cs { date = 2021/08/09, // 查詢當天日期 (string) account = 26, // 帳號 (string) branchNo = 6460, // 分公司代號 (string) stockNo = 2303, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) orderType = Margin, // 委託類別 (OrderType) costPrice = 50, // 成本價 (double) tradableQty = 1000, // 可委託庫存數 (int) unrealizedProfit = 45600, // 未實現獲利 (int) unrealizedLoss = 0 // 未實現損失 (int) } ``` #### 交割資訊[​](#交割資訊 "Direct link to 交割資訊") 可以查詢交割資訊,確認我們今日或近三日的應收付金額。 * Python * Node.js * C# ```python settlement = sdk.accounting.query_settlement(accounts.data[0],"0d") print(settlement.data) ``` ```js const settlement = sdk.accounting.querySettlement(accounts.data[0],"0d") console.log(settlement.data) ``` ```cs var settlement = sdk.Accounting.QuerySettlement(accounts.data[0],"0d"); Console.WriteLine(settlement.data); Console.WriteLine(settlement.data.settle); ``` 以下查詢的結果代表9/12時應付1,429,513元交割款: * Python * Node.js * C# ```py SettlementData{ account: AccountRes{ # 帳號資訊 branch_no: "6460", # 帳號 (string) account: "26" # 分公司代號 (string) }, details: [ # 交割資訊 { date: "2023/09/08", # 查詢日期 (string) settlement_date: "2023/09/12", # 交割日期 (string) buy_value: 735500, # 買進金額 (int) buy_fee: 313, # 買進手續費 (int) buy_settlement: -1429513, # 買進應收付款 (int) buy_tax: 0, # 買進交易稅 (int) sell_value: 770500, # 賣出金額 (int) sell_fee: 320, # 賣出手續費 (int) sell_settlement: 0, # 賣出應收付款 (int) sell_tax: 2309, # 賣出交易稅 (int) total_bs_value: 1506000, # 合計買賣金額 (int) total_fee: 633, # 合計手續費 (int) total_tax: 2309, # 合計交易稅 (int) total_settlement_amount: -1429513, # 合計交割金額 (int) currency: "TWD", # 幣別 (string) } ] } ``` ```js { account: { // 帳號資訊 branch_no: '6460', // 帳號 (string) account: '26' // 分公司代號 (string) }, details: [ // 交割資訊 { date: '2023/09/08', // 查詢日期 (string) settlement_date: '2023/09/12', // 交割日期 (string) buyValue: 735500, // 買進金額 (number) buyFee: 313, // 買進手續費 (int) buySettlement: -1429513, // 買進應收付款 (int) buyTax: 0, // 買進交易稅 (int) sellValue: 770500, // 賣出金額 (int) sellFee: 320, // 賣出手續費 (int) sellSettlement: 0, // 賣出應收付款 (int) sellTax: 2309, // 賣出交易稅 (int) totalBsValue: 1506000, // 合計買賣金額 (int) totalFee: 633, // 合計手續費 (int) totalSettlementAmount: -1429513, // 合計交割金額 (int) totalTax: 2309, // 合計交易稅 (int) currency: "TWD" // 幣別 (string) } ] } ``` ```cs { account = AccountRes { // 帳號資訊 account = 26, // 帳號 (string) branchNo = 6460 // 分公司代號 (string) }, details = [ // 交割資訊 date = 2023/09/08, // 查詢日期 (string) settlementDate = 2023/09/12, // 交割日期 (string) buyValue = 735500, // 買進金額 (int) buyFee = 313, // 買進費用 (int) buySettlement = -1429513, // 買進應收付款 (int) buyTax = 0, // 買進交易稅 (int) sellValue = 770500, // 賣出金額 (int) sellFee = 320, // 賣出費用 (int) sellSettlement = 0, // 賣出應收付款 (int) sellTax = 2309, // 賣出交易稅 (int) totalBsValue = 1506000, // 合計買賣金額 (int) totalFee = 633, // 合計手續費 (int) totalSettlementAmount = -1429513, // 合計交割款金額 (int) totalTax = 2309, // 合計交易稅 (int) currency = TWD // 幣別 (string) ] } ``` --- ### 非阻塞下單 首先,我們先理解阻塞與非阻塞的概念, 阻塞(Block)和非阻塞(Unblock)是用來描述事件、操作或通信方式的兩種不同方式,以下是它們的基本概念和區別: info 非阻塞模式一般搭配主動回報進行委託單管理 info 阻塞(Block)模式亦可搭配並行(concurrency)程式設計,達到同時送出多筆指令的效果 請參考 [**並行(concurrency)程式設計下單範例**](#%E4%B8%A6%E8%A1%8Cconcurrency%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E4%B8%8B%E5%96%AE%E7%AF%84%E4%BE%8B) ##### 阻塞(Block):[​](#阻塞block "Direct link to 阻塞(Block):") 阻塞操作是指事件或操作按照預定的順序進行,並且一個操作完成後,才會回覆結果。 ![sync](/TradeAPI/assets/images/normal-24db51cb3aa3d4c74d40c79d4ab38ac8.png) ##### 非阻塞(Unblock):[​](#非阻塞unblock "Direct link to 非阻塞(Unblock):") 非阻塞操作是指事件或操作不必按照固定的順序進行,可以並行執行,且一個操作不需要等待另一個操作的完成。 當API server接收到您發出的Request後就直接回覆,即為非阻塞。 ![async](/TradeAPI/assets/images/async-f1632167c6d8f31259864d28445e3ffc.png) ##### 使用阻塞機制下單[​](#使用阻塞機制下單 "Direct link to 使用阻塞機制下單") 委託後,回覆的Order Response即會帶回完整的資料內容。 * Python * Node.js * C# ```py #建立委託單內容 order = Order( buy_sell = BSAction.Buy, symbol = "2881", price = "66", quantity = 2000, market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force = TimeInForce.ROD, order_type = OrderType.Stock, user_def = "From_Py" # optional field ) sdk.stock.place_order(accounts.data[0], order) #下單委託 #或採用 #sdk.stock.place_order(accounts.data[0], order, False) ``` ```js const order = { buySell: BSAction.Buy, symbol: "2881", price: "66", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" }; sdk.stock.placeOrder(accounts.data[0], order); // 或採用 //sdk.stock.placeOrder(accounts.data[0], order, false); ``` ```cs var order = new Order( BsAction.Buy, "2881", "66", 2000, MarketType.Common, PriceType.Limit, TimeInForce.Rod, OrderType.Stock, null ); sdk.Stock.PlaceOrder(accounts.data[0] ,order); // 使用阻塞委託下單 // 或採用 //sdk.stock.placeOrder(accounts.data[0], order, false); ``` ##### 使用非阻塞機制下單[​](#使用非阻塞機制下單 "Direct link to 使用非阻塞機制下單") 委託後,回覆的Order Response可能會少帶出委託書號···等資訊。 * Python * Node.js * C# ```py #建立委託單內容 order = Order( buy_sell = BSAction.Buy, symbol = "2881", price = "66", quantity = 2000, market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force = TimeInForce.ROD, order_type = OrderType.Stock, user_def = "From_Py" # optional field ) sdk.stock.place_order(accounts.data[0], order, True) #下單委託 ``` ```js const order = { buySell: BSAction.Buy, symbol: "2881", price: "66", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" }; sdk.stock.placeOrder(accounts.data[0], order, true); ``` ```cs var order = new Order( BsAction.Buy, "2881", "66", 2000, MarketType.Common, PriceType.Limit, TimeInForce.Rod, OrderType.Stock, null ); sdk.Stock.PlaceOrder(accounts.data[0] ,order, true); // 使用非阻塞委託下單 ``` 以下為支援非阻塞委託的函數 * PlaceOrder - 下單委託 * ModifyPrice - 修改委託價格 * ModifyQuantity - 修改委託數量 * CancelOrder - 取消委託 ##### 並行(concurrency)程式設計下單範例[​](#並行concurrency程式設計下單範例 "Direct link to 並行(concurrency)程式設計下單範例") * Python * Node.js * C# ```py import concurrent.futures #Create Order Object order = Order( buy_sell = BSAction.Buy, symbol = "2881", price = "66", quantity = 2000, market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force = TimeInForce.ROD, order_type = OrderType.Stock, user_def = "From_Py" # optional ) # 下單 def my_place_order(): sdk.stock.place_order(accounts.data[0], order) #Place Order with concurrent.futures.ThreadPoolExecutor() as executor: # Submit 20 tasks futures = [executor.submit(my_place_order) for _ in range(20)] # Wait for all tasks to complete concurrent.futures.wait(futures) ``` ```js //Create Order Object const order = { buySell: BSAction.Buy, symbol: "2881", price: "66", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" }; // 下單 function my_place_order() { return new Promise((resolve) => { sdk.stock.placeOrder(accounts.data[0], order); resolve(); }); } async function main() { const tasks = []; for (let i = 0; i < 20; i++) { tasks.push(my_place_order()); } await Promise.all(tasks); // Wait for all tasks to complete } main().then(() => { console.log("All tasks completed") }); ``` ```cs using System; using System.Threading.Tasks; // Create Order Object var order = new Order( BsAction.Buy, "2881", "66", 2000, MarketType.Common, PriceType.Limit, TimeInForce.Rod, OrderType.Stock, null ); // 下單 Task[] tasks = new Task[20]; for (int i = 0; i < 20; i++) { tasks[i] = Task.Run(() => sdk.Stock.PlaceOrder(accounts.data[0], order)); } Task.WaitAll(tasks); ``` --- ### 主動回報範例(輕量風控版) info 輕量風控為大戶下單服務,需另外申請開通,詳情請洽所屬營業員 以下列舉主動回報範例,包含阻塞式 (non-async, unblock=False) 及 非阻塞式 (async, unblock=True) 功能 ( 關於阻塞式與非阻塞式功能,請參考 [非阻塞下單](https://www.fbs.com.tw/TradeAPI/docs/trading/guide/advance/asyn_order.md) ) caution 此文件僅提供常見使用場景對應範例,不保證包含所有例外情況 #### 單筆下單[​](#單筆下單 "Direct link to 單筆下單") ##### 單筆新單[​](#單筆新單 "Direct link to 單筆新單") ###### 阻塞式 (non-async, unblock=False)[​](#阻塞式-non-async-unblockfalse "Direct link to 阻塞式 (non-async, unblock=False)") 1. 下單成功 * 主動回報(兩筆): 第一筆 status 顯示為 8,表示後台準備送出委託單;第二筆 status 顯示為 10,下單成功 ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000023", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 8, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test45", last_time: "10:44:05.796", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000023", branch_no: "20603", account: "9809789", order_no: "KQ008", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test45", last_time: "10:44:05.797", details: None, error_message: None, } ======== ``` * 函式回傳值 (return): ```py Result { is_success: True, message: None, data: OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000023", branch_no: "20603", account: "9809789", order_no: "KQ008", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test45", last_time: "10:44:05.798", details: None, error_message: None, } } ``` 2. 下單失敗 * 主動回報(兩筆): 第一筆 status 顯示為 8,表示後台準備送出委託單;第二筆 status 顯示為 90,下單異常 ```py ==下單主動回報== 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000024", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 20, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 8, after_price_type: Limit, after_price: 20, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 20, user_def: "Test97", last_time: "10:45:04.122", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 90, date: "2024/10/17", seq_no: "00098000024", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 20, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 90, after_price_type: Limit, after_price: 20, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 20, user_def: "Test97", last_time: "10:45:04.124", details: None, error_message: "超過跌停價[5656-後檯]", } ======== ``` * 函式回傳值 (return): 下單失敗,無委託單資料回傳 ```py Result { is_success: False, message: 超過跌停價, data: None } ``` ###### 非阻塞 (async, unblock=True)[​](#非阻塞-async-unblocktrue "Direct link to 非阻塞 (async, unblock=True)") 1. 下單成功 * 主動回報(三筆): 第一筆為ACK,表示系統將執行請求(status 4),第二筆表示後台準備送單(status 8),此時皆無 order\_no(尚未確認下單成功),可用 seq\_no 進行後續比對;最後確認下單狀態(成功為 status 10) ```py ==下單主動回報== 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test47", last_time: "10:45:44.303", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 8, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test47", last_time: "10:45:44.305", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test47", last_time: "10:45:44.305", details: None, error_message: None, } ======== ``` * 函式回傳值 (return): 因使用非阻塞,函式收到 ACK 即回傳 (status 4) ```py Result { is_success: True, message: None, data: OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test47", last_time: "10:45:44.303", details: None, error_message: None, } } ``` 2. 下單失敗 * 主動回報(三筆): 第一筆為ACK,表示系統將執行請求(status 4),第二筆表示後台準備送單(status 8),此時皆無 order\_no(尚未確認下單成功),可用 seq\_no 進行後續比對;最後確認下單狀態(失敗為 status 90) ```py ==下單主動回報== 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000026", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 430, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 430, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 430, user_def: "Test77", last_time: "10:46:24.101", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000026", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 430, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 8, after_price_type: Limit, after_price: 430, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 430, user_def: "Test77", last_time: "10:46:24.102", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 90, date: "2024/10/17", seq_no: "00098000026", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 430, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 90, after_price_type: Limit, after_price: 430, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 430, user_def: "Test77", last_time: "10:46:24.103", details: None, error_message: "超過漲停價[5655-後檯]", } ======== ``` * 函式回傳值 (return): 因使用非阻塞,函式收到 ACK 即回傳 (status 4) ```py Result { is_success: True, message: None, data: OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000026", branch_no: "20603", account: "9809789", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 430, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 430, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 430, user_def: "Test77", last_time: "10:46:24.101", details: None, error_message: None, } } ``` ##### 修改委託單價格[​](#修改委託單價格 "Direct link to 修改委託單價格") info 改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報 阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到該筆回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳 ###### 阻塞[​](#阻塞 "Direct link to 阻塞") 1. 改價成功 * 主動回報(兩筆): 改價 function\_type 15,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 43, user_def: "Test47", last_time: "10:47:24.816", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 43, user_def: "Test47", last_time: "10:47:24.817", details: None, error_message: None, } ======== ``` * 函式回傳 (return): ```py Result { is_success: True, message: None, data: OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 43, user_def: "Test47", last_time: "10:47:24.817", details: None, error_message: None, } } ``` 2. 改價失敗 * 主動回報(兩筆): 第一筆系統將執行請求 status 4;第二筆改價失敗回報 status 19 info 此範例由後台擋回請求,因此有 status 4 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test47", last_time: "10:48:00.682", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code [DT3_10104]超過漲停價 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 19, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test47", last_time: "10:48:00.683", details: None, error_message: "超過漲停價", } ======== ``` * 函式回傳 (return): 改價失敗,無委託單資料回傳 ```py Result { is_success: False, message: 超過漲停價, data: None } ``` ###### 非阻塞[​](#非阻塞 "Direct link to 非阻塞") 1. 改價成功 * 主動回報(兩筆): 改價 function\_type 15,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test47", last_time: "10:50:55.480", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test47", last_time: "10:50:55.481", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 因為使用非阻塞,函式收到 ACK(status 4)即回傳 ```py Result { is_success: True, message: None, data: OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test47", last_time: "10:50:55.479", details: None, error_message: None, } } ``` 2. 改價失敗 * 主動回報(一筆): 改價失敗 status 19 info 此範例由系統直接擋回請求,因此**無** status 4 ```py ==改單主動回報== Code [154]證券改價限價格格和原價格相同==>[00098000025] 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 19, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: None, user_def: "Test47", last_time: "10:51:31.697", details: None, error_message: "證券改價限價格格和原價格相同==>[00098000025]", } ======== ``` * 函式回傳 (return): 改價失敗,無委託單資料回傳 ```py Result { is_success: False, message: 證券改價限價格格和原價格相同==>[00098000025], data: None } ``` ##### 修改委託單數量[​](#修改委託單數量 "Direct link to 修改委託單數量") info 改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報 阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到該筆回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳 ###### 阻塞[​](#阻塞-1 "Direct link to 阻塞") 1. 改量成功 * 主動回報(兩筆): 改量 function\_type 20,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test47", last_time: "10:53:11.924", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test47", last_time: "10:53:11.925", details: None, error_message: None, } ======== ``` * 函式回傳 (return): ```py Result { is_success: True, message: None, data: OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test47", last_time: "10:53:11.926", details: None, error_message: None, } } ``` 2. 改量失敗 * 主動回報(一筆): 改量 function\_type 20,回報失敗 status 29 (由系統直接擋回請求,因此無 status 4) ```py ==改單主動回報== Code [164]證券減量使用剩餘數量大於有效單位數量==>[00098000025] 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 29, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: None, user_def: "Test47", last_time: "10:53:48.940", details: None, error_message: "證券減量使用剩餘數量大於有效單位數量==>[00098000025]", } ======== ``` * 函式回傳 (return): 改量失敗,無委託單資料回傳 ```py Result { is_success: False, message: 證券減量使用剩餘數量大於有效單位數量==>[00098000025], data: None } ``` ###### 非阻塞[​](#非阻塞-1 "Direct link to 非阻塞") 1. 改量成功 * 主動回報(兩筆): 改量 function\_type 20,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: 3000, before_price: None, user_def: "Test47", last_time: "10:54:17.774", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: None, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 3000, before_price: None, user_def: "Test47", last_time: "10:54:17.775", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 因使用非阻塞,函式收到 ACK (status 4) 即回傳 ```py Result { is_success: True, message: None, data: OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: 3000, before_price: None, user_def: "Test47", last_time: "10:54:17.773", details: None, error_message: None, } } ``` 2. 改量失敗 * 主動回報(一筆): 改量 function\_type 20,回報失敗 status 29 (由系統直接擋回請求,因此無 status 4) ```py ==改單主動回報== Code [164]證券減量使用剩餘數量大於有效單位數量==>[00098000025] 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 29, after_price_type: None, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: None, user_def: "Test47", last_time: "10:54:54.455", details: None, error_message: "證券減量使用剩餘數量大於有效單位數量==>[00098000025]", } ======== ``` * 函式回傳 (return): 改量失敗,無委託單資料回傳 ```py response: Result { is_success: False, message: 證券減量使用剩餘數量大於有效單位數量==>[00098000025], data: None } ``` ##### 刪除委託單[​](#刪除委託單 "Direct link to 刪除委託單") caution 若委託單已**部分成交**, 刪單成功狀態代碼為 40, 其餘為 30 info 改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報 阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到該筆回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳 ###### 阻塞[​](#阻塞-2 "Direct link to 阻塞") 1. 刪單成功 * 主動回報(兩筆): 刪單 function\_type 30,回報第一筆為系統將執行請求(status 4);第二筆刪單成功 status 30 (若已有部分成交 status 40) ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "Test47", last_time: "10:55:39.567", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 43, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "Test47", last_time: "10:55:39.568", details: None, error_message: None, } ======== ``` * 函式回傳 (return): ```py Result { is_success: True, message: None, data: OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000025", branch_no: "20603", account: "9809789", order_no: "KQ009", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 43, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "Test47", last_time: "10:55:39.569", details: None, error_message: None, } } ``` 2. 刪單失敗 * 主動回報(一筆): 刪單 function\_type 30,回報刪單失敗 status 39 (由系統直接擋回請求,因此無 status 4) ```py ==改單主動回報== Code [115]證券委託目前狀態部分成交單已不允許取消交易 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00090000080", branch_no: "20603", account: "9809789", order_no: "KQ00A", asset_type: 1, market: None, market_type: UnSupported, stock_no: "1102", buy_sell: None, price_type: None, price: None, quantity: None, time_in_force: None, order_type: None, is_pre_order: false, status: 39, after_price_type: None, after_price: None, unit: None, after_qty: None, filled_qty: None, filled_money: None, before_qty: None, before_price: None, user_def: None, last_time: "10:59:25.982", details: None, error_message: "證券委託目前狀態部分成交單已不允許取消交易", } ======== ``` * 函式回傳 (return): 刪單失敗,無委託單資料回傳 ```py Result { is_success: False, message: 證券委託目前狀態部分成交單已不允許取消交易, data: None } ``` ###### 非阻塞[​](#非阻塞-2 "Direct link to 非阻塞") 1. 刪單成功 * 主動回報(兩筆): 刪單 function\_type 30,回報第一筆為系統將執行請求(status 4);第二筆刪單成功 status 30 (若已有部分成交 status 40) ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000023", branch_no: "20603", account: "9809789", order_no: "KQ008", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test45", last_time: "11:00:06.415", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000023", branch_no: "20603", account: "9809789", order_no: "KQ008", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 43, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test45", last_time: "11:00:06.416", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 因為使用非阻塞,函式回傳ACK (status 4) ```py Result { is_success: True, message: None, data: OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000023", branch_no: "20603", account: "9809789", order_no: "KQ008", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test45", last_time: "11:00:06.414", details: None, error_message: None, } } ``` 2. 刪單失敗 * 主動回報(一筆): 刪單 function\_type 30,回報刪單失敗 status 39 (由系統直接擋回請求,因此無 status 4) ```py ==改單主動回報== Code [115]證券委託目前狀態取消單已不允許取消交易 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000023", branch_no: "20603", account: "9809789", order_no: "KQ008", asset_type: 1, market: None, market_type: UnSupported, stock_no: "1102", buy_sell: None, price_type: None, price: None, quantity: None, time_in_force: None, order_type: None, is_pre_order: false, status: 39, after_price_type: None, after_price: None, unit: None, after_qty: None, filled_qty: None, filled_money: None, before_qty: None, before_price: None, user_def: None, last_time: "11:00:35.797", details: None, error_message: "證券委託目前狀態取消單已不允許取消交易", } ======== ``` * 函式回傳 (return): 刪單失敗,無委託單資料回傳 ```py Result { is_success: False, message: 證券委託目前狀態取消單已不允許取消交易, data: None } ``` #### 批次下單[​](#批次下單 "Direct link to 批次下單") **批次功能由系統收到請求後以多線程 (threads) 方式運作** 後續批次範例以下委託單列表為例: ```py [Order { buy_sell: Buy, symbol: "1102", price: "42", quantity: 2000, market_type: Common, price_type: Limit, time_in_force: ROD, order_type: Stock, user_def: "batch1", }, Order { buy_sell: Buy, symbol: "1101", price: "32", quantity: 1000, market_type: Common, price_type: Limit, time_in_force: ROD, order_type: Stock, user_def: "batch2", }, Order { buy_sell: Buy, symbol: "2330", price: None, quantity: 1000, market_type: Common, price_type: Market, time_in_force: ROD, order_type: Stock, user_def: "batch3", }] ``` ##### 新委託單下單[​](#新委託單下單 "Direct link to 新委託單下單") * 主動回報(六筆): 包含三筆後台準備送出委託單回報(status 8);三筆下單成功確認(status 10) ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 0, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 8, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 42, user_def: "batch1", last_time: "16:21:19", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 0, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 8, after_price_type: Limit, after_price: 32, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 32, user_def: "batch2", last_time: "16:21:19", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 0, date: "2024/10/18", seq_no: "00098000012", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: None, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 8, after_price_type: Market, after_price: None, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: None, user_def: "batch3", last_time: "16:21:19", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 10, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: "x0006", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 32, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 32, user_def: "batch2", last_time: "16:21:18.962", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 10, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: "x0005", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 42, user_def: "batch1", last_time: "16:21:18.963", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 10, date: "2024/10/18", seq_no: "00098000012", branch_no: "20706", account: "9809268", order_no: "x0007", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: 0, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Market, after_price: 0, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 0, user_def: "batch3", last_time: "16:21:19", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 批次委託新單,回傳值皆為 ACK (status 4),並無委託書號 (order\_no),後續可用流水號 (seq\_no) 進行比對 ```py Result { is_success: True, message: None, data: [OrderResult { function_type: 0, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 42, user_def: "batch1", last_time: "16:21:18.999", details: None, error_message: None, }, OrderResult { function_type: 0, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: None, asset_type: None, market: None, market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 32, unit: None, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 32, user_def: "batch2", last_time: "16:21:18.999", details: None, error_message: None, }, OrderResult { function_type: 0, date: "2024/10/18", seq_no: "00098000012", branch_no: "20706", account: "9809268", order_no: None, asset_type: None, market: None, market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: None, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Market, after_price: None, unit: None, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: None, user_def: "batch3", last_time: "16:21:18.999", details: None, error_message: None, }] } ``` ##### 修改委託單價格[​](#修改委託單價格-1 "Direct link to 修改委託單價格") **委託單列表中不可含市價單,若含市價單則整批請求不執行,並回傳錯誤訊息** * 主動回報(四筆,此處無納入市價委託單): 兩筆 ACK (status 4);兩筆確認 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: "x0006", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 32, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 32, user_def: "batch2", last_time: "16:23:11.710", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: "x0005", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "batch1", last_time: "16:23:11.710", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: "x0006", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 33, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 32, user_def: "batch2", last_time: "16:23:11.673", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: "x0005", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "batch1", last_time: "16:23:11.683", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 批次委託回傳值皆為 ACK (status 4) ```py Result { is_success: True, message: None, data: [OrderResult { function_type: 15, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: "x0006", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 33, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 32, user_def: "batch2", last_time: "16:23:11.708", details: None, error_message: None, }, OrderResult { function_type: 15, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: "x0005", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "batch1", last_time: "16:23:11.708", details: None, error_message: None, }] } ``` ##### 修改數量及刪單[​](#修改數量及刪單 "Direct link to 修改數量及刪單") 此處部分委託單改量為 0,視同刪單;若使用刪單功能,則主動回報及函式回傳值與改量為 0 同 * 主動回報(六筆): 三筆 ACK (status 4);改量 function\_type 20, 改量成功 status 10; 刪單 function\_type 30, 刪單成功 status 30 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: "x0006", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 33, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch2", last_time: "16:24:16.494", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/18", seq_no: "00098000012", branch_no: "20706", account: "9809268", order_no: "x0007", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: 0, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 0, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch3", last_time: "16:24:16.494", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: "x0005", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "batch1", last_time: "16:24:16.494", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: "x0005", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: None, after_price: 43, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "batch1", last_time: "16:24:16.554", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: "x0006", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 33, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch2", last_time: "16:24:16.558", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/18", seq_no: "00098000012", branch_no: "20706", account: "9809268", order_no: "x0007", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: 0, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 0, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch3", last_time: "16:24:16.558", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 批次委託回傳值皆為 ACK (status 4) ```py Result { is_success: True, message: None, data: [OrderResult { function_type: 30, date: "2024/10/18", seq_no: "00098000012", branch_no: "20706", account: "9809268", order_no: "x0007", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: 0, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 0, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch3", last_time: "16:24:16.492", details: None, error_message: None, }, OrderResult { function_type: 30, date: "2024/10/18", seq_no: "00098000011", branch_no: "20706", account: "9809268", order_no: "x0006", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 33, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch2", last_time: "16:24:16.492", details: None, error_message: None, }, OrderResult { function_type: 20, date: "2024/10/18", seq_no: "00098000010", branch_no: "20706", account: "9809268", order_no: "x0005", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "batch1", last_time: "16:24:16.492", details: None, error_message: None, }] } ``` #### 成交主動回報[​](#成交主動回報 "Direct link to 成交主動回報") 成交主動回報包含委託書號 (order\_no) 及流水號 (seq\_no) 以供比對 ```py ==成交主動回報== Code None FilledData { date: "2024/10/17", branch_no: "20603", account: "9809789", order_no: "KQ00B", stock_no: "1102", buy_sell: Sell, order_type: Stock, seq_no: "00090000081", filled_no: "00000000002", filled_avg_price: 45.0, filled_qty: 2000, filled_price: 45.0, filled_time: "10:57:49.331", user_def: None, } ======== ``` --- ### 主動回報範例(標準版) 以下列舉主動回報範例,包含阻塞式 (non-async, unblock=False) 及 非阻塞式 (async, unblock=True) 功能 ( 關於阻塞式與非阻塞式功能,請參考 [非阻塞下單](https://www.fbs.com.tw/TradeAPI/docs/trading/guide/advance/asyn_order.md) ) caution 此文件僅提供常見使用場景對應範例,不保證包含所有例外情況 #### 單筆下單[​](#單筆下單 "Direct link to 單筆下單") ##### 單筆新單[​](#單筆新單 "Direct link to 單筆新單") ###### 阻塞式 (non-async, unblock=False)[​](#阻塞式-non-async-unblockfalse "Direct link to 阻塞式 (non-async, unblock=False)") 1. 下單成功 * 主動回報(一筆): 下單成功,status 顯示為 10 ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00000394159", branch_no: "20706", account: "9809268", order_no: "x0002", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test50", last_time: "11:24:40.378", details: None, error_message: None, } ======== ``` * 函式回傳值 (return): ```py Result { is_success: True, message: None, data: OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00000394159", branch_no: "20706", account: "9809268", order_no: "x0002", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test50", last_time: "11:24:40.378", details: None, error_message: None, } } ``` 2. 下單失敗 * 主動回報(一筆): 下單異常,status 顯示為 90 ```py ==下單主動回報== Code [4385715]單價輸入錯誤[4385715] 內容 OrderResult { function_type: 90, date: "2024/10/17", seq_no: "00000394160", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 430, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 90, after_price_type: Limit, after_price: 430, unit: 1000, after_qty: 0, filled_qty: None, filled_money: None, before_qty: 0, before_price: 430, user_def: "Test25", last_time: "11:25:25.670", details: None, error_message: "單價輸入錯誤[4385715]", } ======== ``` * 函式回傳值 (return): 下單失敗,無委託單資料回傳 ```py Result { is_success: False, message: 單價輸入錯誤[4385715], data: None } ``` ###### 非阻塞 (async, unblock=True)[​](#非阻塞-async-unblocktrue "Direct link to 非阻塞 (async, unblock=True)") 1. 下單成功 * 主動回報(三筆): 第一筆為ACK,表示系統將執行請求(status 4),第二筆表示後台準備送單(status 8),此時皆無 order\_no(尚未確認下單成功),可用 seq\_no 進行後續比對;最後確認下單狀態(成功為 status 10) ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test70", last_time: "11:25:54.188", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 8, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test70", last_time: "11:25:54.189", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test70", last_time: "11:25:54.163", details: None, error_message: None, } ======== ``` * 函式回傳值 (return): 因使用非阻塞,函式收到 ACK 即回傳 (status 4) ```py Result { is_success: True, message: None, data: OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 43, user_def: "Test70", last_time: "11:25:54.188", details: None, error_message: None, } } ``` 2. 下單失敗 * 主動回報(三筆): 第一筆為ACK,表示系統將執行請求(status 4),第二筆表示後台準備送單(status 8),此時皆無 order\_no(尚未確認下單成功),可用 seq\_no 進行後續比對;最後確認下單狀態(異常為 status 90) ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000032", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 20, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 20, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 20, user_def: "Test64", last_time: "11:26:59.651", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code None 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000032", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 20, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 8, after_price_type: Limit, after_price: 20, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 20, user_def: "Test64", last_time: "11:26:59.652", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== Code [4385715]單價輸入錯誤[4385715] 內容 OrderResult { function_type: 90, date: "2024/10/17", seq_no: "00098000032", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 20, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 90, after_price_type: Limit, after_price: 20, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 20, user_def: "Test64", last_time: "11:26:59.658", details: None, error_message: "單價輸入錯誤[4385715]", } ======== ``` * 函式回傳值 (return): 因使用非阻塞,函式收到 ACK 即回傳 (status 4) ```py Result { is_success: True, message: None, data: OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000032", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 20, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 20, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 20, user_def: "Test64", last_time: "11:26:59.651", details: None, error_message: None, } } ``` ##### 修改委託單價格[​](#修改委託單價格 "Direct link to 修改委託單價格") info 改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報 阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到該筆回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳 ###### 阻塞[​](#阻塞 "Direct link to 阻塞") 1. 改價成功 * 主動回報(兩筆): 改價 function\_type 15,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 43, user_def: "Test70", last_time: "11:27:47.512", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 43, user_def: "Test70", last_time: "11:27:47.407", details: None, error_message: None, } ======== ``` * 函式回傳 (return): ```py Result { is_success: True, message: None, data: OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: 43, user_def: "Test70", last_time: "11:27:47.407", details: None, error_message: None, } } ``` 2. 改價失敗 * 主動回報(兩筆,後台擋單): 改價 function\_type 15,回報第一筆為系統將執行請求(status 4);第二筆改價失敗 status 19 info 此案例由後台擋單,因此有第一筆回報 status 4 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test70", last_time: "11:28:46.753", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code [4385715]單價輸入錯誤[4385715] 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 19, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test70", last_time: "11:28:46.754", details: None, error_message: "單價輸入錯誤[4385715]", } ======== ``` * 函式回傳 (return): 改價失敗,無委託單資料回傳 ```py Result { is_success: False, message: 單價輸入錯誤[4385715], data: None } ``` ###### 非阻塞[​](#非阻塞 "Direct link to 非阻塞") 1. 改價成功 * 主動回報(兩筆): 改價 function\_type 15,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test70", last_time: "11:29:43.593", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test70", last_time: "11:29:43.682", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 因使用非阻塞,函式收到 ACK 即回傳 (status 4) ```py Result { is_success: True, message: None, data: OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "Test70", last_time: "11:29:43.592", details: None, error_message: None, } } ``` 2. 改價失敗 * 主動回報(一筆): 改價 function\_type 15,改價失敗 status 19 info 此案例由系統擋單,因此**無** status 4 回報 ```py ==改單主動回報== Code [154]證券改價限價格格和原價格相同==>[00098000031] 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 19, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: None, user_def: "Test70", last_time: "11:30:20.330", details: None, error_message: "證券改價限價格格和原價格相同==>[00098000031]", } ======== ``` * 函式回傳 (return): 改價失敗,無委託單資料回傳 ```py response: Result { is_success: False, message: 證券改價限價格格和原價格相同==>[00098000031], data: None } ``` ##### 修改委託單數量[​](#修改委託單數量 "Direct link to 修改委託單數量") info 改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報 阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到該筆回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳 ###### 阻塞[​](#阻塞-1 "Direct link to 阻塞") 1. 改量成功 * 主動回報(兩筆): 改量 function\_type 20,回報第一筆為系統將執行請求(status 4);第二筆改量成功 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test70", last_time: "11:31:00.211", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test70", last_time: "11:31:00.332", details: None, error_message: None, } ======== ``` * 函式回傳 (return): ```py Result { is_success: True, message: None, data: OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: 43, user_def: "Test70", last_time: "11:31:00.332", details: None, error_message: None, } } ``` 2. 改量失敗 * 主動回報(一筆): 改量 function\_type 20,失敗回報 status 29(系統擋單,因此無 status 4 回報) ```py ==改單主動回報== Code [164]證券減量使用剩餘數量大於有效單位數量==>[00098000031] 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 29, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: None, user_def: "Test70", last_time: "11:31:51.980", details: None, error_message: "證券減量使用剩餘數量大於有效單位數量==>[00098000031]", } ======== ``` * 函式回傳 (return): 改量失敗,無委託單資料回傳 ```py Result { is_success: False, message: 證券減量使用剩餘數量大於有效單位數量==>[00098000031], data: None } ``` ###### 非阻塞[​](#非阻塞-1 "Direct link to 非阻塞") 1. 改量成功 * 主動回報(兩筆): 改量 function\_type 20,回報第一筆為系統將執行請求(status 4);第二筆改量成功 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: 3000, before_price: None, user_def: "Test70", last_time: "11:32:33.047", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: None, after_price: 43, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 3000, before_price: None, user_def: "Test70", last_time: "11:32:33.215", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 因使用非阻塞,函式收到 ACK 即回傳 (status 4) ```py Result { is_success: True, message: None, data: OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 3000, filled_qty: 0, filled_money: 0, before_qty: 3000, before_price: None, user_def: "Test70", last_time: "11:32:33.045", details: None, error_message: None, } } ``` 2. 改量失敗 * 主動回報(一筆): 改量 function\_type 20,失敗回報 status 29 (系統擋單,因此無 status 4 回報) ```py ==改單主動回報== Code [164]證券減量使用剩餘數量大於有效單位數量==>[00098000031] 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 29, after_price_type: None, after_price: 43, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: None, user_def: "Test70", last_time: "11:33:18.679", details: None, error_message: "證券減量使用剩餘數量大於有效單位數量==>[00098000031]", } ======== ``` * 函式回傳 (return): 由系統擋單改量失敗,無委託單資料回傳 ```py Result { is_success: False, message: 證券減量使用剩餘數量大於有效單位數量==>[00098000031], data: None } ``` ##### 刪除委託單[​](#刪除委託單 "Direct link to 刪除委託單") caution 若委託單已**部分成交**, 刪單成功狀態代碼為 40, 其餘為 30 info 改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報 阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到 status 4 回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳 ###### 阻塞[​](#阻塞-2 "Direct link to 阻塞") 1. 刪單成功 * 主動回報(兩筆): 刪單 function\_type 30,回報第一筆為系統將執行請求(status 4);第二筆刪單成功 status 30 (若已有部分成交 status 40) ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "Test70", last_time: "11:36:14.561", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 43, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "Test70", last_time: "11:36:14.499", details: None, error_message: None, } ======== ``` * 函式回傳 (return): ```py Result { is_success: True, message: None, data: OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000031", branch_no: "20706", account: "9809268", order_no: "x0003", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 43, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: 43, user_def: "Test70", last_time: "11:36:14.499", details: None, error_message: None, } } ``` 2. 刪單失敗 * 主動回報(一筆): 刪單 function\_type 30,刪單失敗 status 39(系統擋單,因此無 status 4 回報) ```py ==改單主動回報== Code [115]證券委託目前狀態部分成交單已不允許取消交易 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00000394165", branch_no: "20706", account: "9809268", order_no: "x0007", asset_type: 1, market: None, market_type: UnSupported, stock_no: "1102", buy_sell: None, price_type: None, price: None, quantity: None, time_in_force: None, order_type: None, is_pre_order: false, status: 39, after_price_type: None, after_price: None, unit: None, after_qty: None, filled_qty: None, filled_money: None, before_qty: None, before_price: None, user_def: None, last_time: "11:39:57.468", details: None, error_message: "證券委託目前狀態部分成交單已不允許取消交易", } ======== ``` * 函式回傳 (return): 系統擋單而刪單失敗,無委託單資料回傳 ```py Result { is_success: False, message: 證券委託目前狀態部分成交單已不允許取消交易, data: None } ``` ###### 非阻塞[​](#非阻塞-2 "Direct link to 非阻塞") 1. 刪單成功 * 主動回報(兩筆): 刪單 function\_type 30,回報第一筆為系統將執行請求(status 4);第二筆刪單成功 status 30 (若已有部分成交 status 40) ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000033", branch_no: "20706", account: "9809268", order_no: "x0008", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 41, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 41, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test4", last_time: "11:42:24.961", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000033", branch_no: "20706", account: "9809268", order_no: "x0008", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 41, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 41, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test4", last_time: "11:42:25.125", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 因使用非阻塞,函式收到 ACK 即回傳 (status 4) ```py Result { is_success: True, message: None, data: OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000033", branch_no: "20706", account: "9809268", order_no: "x0008", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 41, quantity: 5000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 41, unit: 1000, after_qty: 5000, filled_qty: 0, filled_money: 0, before_qty: 5000, before_price: None, user_def: "Test4", last_time: "11:42:24.960", details: None, error_message: None, } } ``` 2. 刪單失敗 * 主動回報(一筆): 刪單 function\_type 30,回報刪單失敗 status 39 (由系統直接擋回請求,因此無 status 4) ```py ==改單主動回報== Code [115]證券委託目前狀態取消單已不允許取消交易 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000033", branch_no: "20706", account: "9809268", order_no: "x0008", asset_type: 1, market: None, market_type: UnSupported, stock_no: "1102", buy_sell: None, price_type: None, price: None, quantity: None, time_in_force: None, order_type: None, is_pre_order: false, status: 39, after_price_type: None, after_price: None, unit: None, after_qty: None, filled_qty: None, filled_money: None, before_qty: None, before_price: None, user_def: None, last_time: "11:48:06.850", details: None, error_message: "證券委託目前狀態取消單已不允許取消交易", } ======== ``` * 函式回傳 (return): 系統擋單而刪單失敗,無委託單資料回傳 ```py Result { is_success: False, message: 證券委託目前狀態取消單已不允許取消交易, data: None } ``` #### 批次下單[​](#批次下單 "Direct link to 批次下單") **批次功能由系統收到請求後以多線程 (threads) 方式運作** 後續批次範例以下委託單列表為例: ```py [Order { buy_sell: Buy, symbol: "1102", price: "42", quantity: 2000, market_type: Common, price_type: Limit, time_in_force: ROD, order_type: Stock, user_def: "batch1", }, Order { buy_sell: Buy, symbol: "1101", price: "32", quantity: 1000, market_type: Common, price_type: Limit, time_in_force: ROD, order_type: Stock, user_def: "batch2", }, Order { buy_sell: Buy, symbol: "2330", price: None, quantity: 1000, market_type: Common, price_type: Market, time_in_force: ROD, order_type: Stock, user_def: "batch3", }] ``` ##### 新委託單下單[​](#新委託單下單 "Direct link to 新委託單下單") * 主動回報(六筆): 包含三筆後台準備送出委託單回報(status 8);三筆下單成功確認(status 10) ```py ==下單主動回報== 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 8, after_price_type: Limit, after_price: 32, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 32, user_def: "batch2", last_time: "11:50:24.656", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 8, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 42, user_def: "batch1", last_time: "11:50:24.656", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000042", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: None, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 8, after_price_type: Market, after_price: None, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: None, user_def: "batch3", last_time: "11:50:24.656", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: "x0014", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 42, user_def: "batch1", last_time: "11:50:24.796", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: "x0013", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 32, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 32, user_def: "batch2", last_time: "11:50:24.796", details: None, error_message: None, } ======== ``` ```py ==下單主動回報== 內容 OrderResult { function_type: 10, date: "2024/10/17", seq_no: "00098000042", branch_no: "20706", account: "9809268", order_no: "x0015", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: 0, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Market, after_price: 0, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 0, user_def: "batch3", last_time: "11:50:24.806", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 批次委託新單,回傳值皆為 ACK (status 4),並無委託書號 (order\_no),後續可用流水號 (seq\_no) 進行比對 ```py Result { is_success: True, message: None, data: [OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: None, asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 42, user_def: "batch1", last_time: "11:50:24.655", details: None, error_message: None, }, OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: None, asset_type: None, market: None, market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Limit, after_price: 32, unit: None, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 32, user_def: "batch2", last_time: "11:50:24.655", details: None, error_message: None, }, OrderResult { function_type: 0, date: "2024/10/17", seq_no: "00098000042", branch_no: "20706", account: "9809268", order_no: None, asset_type: None, market: None, market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: None, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: true, status: 4, after_price_type: Market, after_price: None, unit: None, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: None, user_def: "batch3", last_time: "11:50:24.655", details: None, error_message: None, }] } ``` ##### 修改委託單價格[​](#修改委託單價格-1 "Direct link to 修改委託單價格") **委託單列表中不可含市價單,若含市價單則整批請求不執行,並回傳錯誤訊息** * 主動回報(四筆,此處無納入市價委託單): 兩筆 ACK (status 4);兩筆確認 status 10 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: "x0013", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 32, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 32, user_def: "batch2", last_time: "11:52:24.985", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: "x0014", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 42, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "batch1", last_time: "11:52:24.985", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: "x0013", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 33, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 32, user_def: "batch2", last_time: "11:52:25.156", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: "x0014", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "batch1", last_time: "11:52:25.162", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 批次委託回傳值皆為 ACK (status 4) ```py Result { is_success: True, message: None, data: [OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: "x0013", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 33, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 32, user_def: "batch2", last_time: "11:52:24.984", details: None, error_message: None, }, OrderResult { function_type: 15, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: "x0014", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: Limit, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: None, before_price: 42, user_def: "batch1", last_time: "11:52:24.984", details: None, error_message: None, }] } ``` ##### 修改數量及刪單[​](#修改數量及刪單 "Direct link to 修改數量及刪單") 此處部分委託單改量為 0,視同刪單;若使用刪單功能,則主動回報及函式回傳值與改量為 0 同 * 主動回報(六筆): 三筆 ACK (status 4);改量 function\_type 20, 改量成功 status 10; 刪單 function\_type 30, 刪單成功 status 30 ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000042", branch_no: "20706", account: "9809268", order_no: "x0015", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: 0, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 0, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch3", last_time: "11:53:37.765", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: "x0014", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "batch1", last_time: "11:53:37.765", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: "x0013", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 33, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch2", last_time: "11:53:37.765", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000042", branch_no: "20706", account: "9809268", order_no: "x0015", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: 0, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 0, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch3", last_time: "11:53:37.790", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: "x0013", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 30, after_price_type: None, after_price: 33, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch2", last_time: "11:53:37.789", details: None, error_message: None, } ======== ``` ```py ==改單主動回報== Code None 內容 OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: "x0014", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: None, after_price: 43, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "batch1", last_time: "11:53:37.790", details: None, error_message: None, } ======== ``` * 函式回傳 (return): 批次委託回傳值皆為 ACK (status 4) ```py Result { is_success: True, message: None, data: [OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000042", branch_no: "20706", account: "9809268", order_no: "x0015", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2330", buy_sell: Buy, price_type: Market, price: 0, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 0, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch3", last_time: "11:53:37.763", details: None, error_message: None, }, OrderResult { function_type: 30, date: "2024/10/17", seq_no: "00098000041", branch_no: "20706", account: "9809268", order_no: "x0013", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1101", buy_sell: Buy, price_type: Limit, price: 32, quantity: 1000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 33, unit: 1000, after_qty: 0, filled_qty: 0, filled_money: 0, before_qty: 1000, before_price: None, user_def: "batch2", last_time: "11:53:37.763", details: None, error_message: None, }, OrderResult { function_type: 20, date: "2024/10/17", seq_no: "00098000040", branch_no: "20706", account: "9809268", order_no: "x0014", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "1102", buy_sell: Buy, price_type: Limit, price: 42, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 4, after_price_type: None, after_price: 43, unit: 1000, after_qty: 1000, filled_qty: 0, filled_money: 0, before_qty: 2000, before_price: None, user_def: "batch1", last_time: "11:53:37.763", details: None, error_message: None, }] } ``` #### 成交主動回報[​](#�成交主動回報 "Direct link to 成交主動回報") 成交主動回報包含委託書號 (order\_no) 及流水號 (seq\_no) 以供比對 ```py ==成交主動回報== Code None FilledData { date: "2024/10/17", branch_no: "20706", account: "9809268", order_no: "x0007", stock_no: "1102", buy_sell: Sell, order_type: Stock, seq_no: "00000394165", filled_no: "00000000061", filled_avg_price: 43.0, filled_qty: 2000, filled_price: 43.0, filled_time: "11:38:08.535", user_def: None, } ======== ``` --- ### 連線參數修改 新一代 API SDK 使用 WebSocket 安全連線方式與富邦伺服器主機建立連線,使用標準的 ping/pong control frames 進行連線確認。預設每 30 秒發送 ping frame 給伺服器,若達連續兩次無收到伺服器 pong 回應即判斷連線品質較弱,並進行斷線與提示。 為能更廣泛適用於不同使用者場景,自 `2.2.1` 版以後,使用者可自行設定此部分參數。在建立連線時可選擇自定參數,例如設定每 300 秒發送 ping frame,並若連續三次無回應即斷線,則連線功能呼叫方式如下: * Python * Node.js * C# ```python sdk = FubonSDK(300, 3) ``` ```js var sdk = new FubonSDK(300, 3); ``` ```cs var sdk = new FubonSDK(300, 3, "wss://neoapi.fbs.com.tw/TASP/XCPXWS"); ``` 其中第一個參數為間隔秒數,第二個參數為最大可忍受無回應次數。 參數設定建議 因網際網路難免時有雍塞情形,參數設定建議不小於預設值 (30,2),以免對於連線品質判斷過於敏感,導致不必要的連線中斷。 測試環境連線 使用測試環境需以下進行連線(`2.2.1`版以後): ```python # "wss://neoapitest.fbs.com.tw/TASP/XCPXWS" 為測試環境連線 url sdk = FubonSDK(30, 3, "wss://neoapitest.fbs.com.tw/TASP/XCPXWS") # C# 或 JavaScript, 使用 # var sdk = new FubonSDK(30, 3, "wss://neoapitest.fbs.com.tw/TASP/XCPXWS"); ``` 註:前兩個參數之值僅為範例參考,可依需求自由調整。 --- ### Python主動回報例外處理 使用 Python 主動回報時,因為主動回報機制於獨自的 thread 中運行,因此若主動回報 callback function 內自己寫的程式碼執行產生錯誤,不會自動丟回錯誤訊息,可能造成程式 DEBUG 上的障礙。 這個時候可以在 callback function 上面加入以下 decorator,當其中程式碼發生錯誤時,錯誤將如往常一樣顯示在 console 內: ```python import os import sys import traceback import functools def handle_exceptions(func): @functools.wraps(func) def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as exp: # Extract the full traceback tb_lines = traceback.format_exc().splitlines() # Find the index of the line related to the original function func_line_index = next((i for i, line in enumerate(tb_lines) if func.__name__ in line), -1) # Highlight the specific part in the traceback where the exception occurred relevant_tb = "\n".join(tb_lines[func_line_index:]) # Include traceback from the function name error_text = f"{func.__name__} exception: {exp}\nTraceback (most recent call last):\n{relevant_tb}" print(error_text, file=sys.stderr) # 若要程式完全跳出,可加入下行 (P.S. jupyter 環境不適用) # os._exit(-1) return wrapper def on_event(code, content): print("===event=====") print(code) print(content) print("========") @handle_exceptions def on_order(code, content): print("==Order==") print(code) print(content) print("========") # Add some code that would cause exceptions test = {} print(test["key"]) # 這行會產生錯誤 ``` 以上範例程式碼中,我們故意在 on\_order 中放入一行 `print(test["key"])`,因為 `"key"` 沒有在字典 `test` 裡面,所以會產生錯誤。 這時因為我們有加入 `@handle_exceptions` decorator,所以收到新單主動回報後, console 會印出: ```python on_order exception: 'key' Traceback (most recent call last): File "xxx.py", line 47, in on_order print(test["key"]) ~~~~^^^^^^^ KeyError: 'key' ``` --- ### 斷線重連 以下將用簡單示範,利用callback偵測交易Socket,接收到斷線事件後,程式自動進行Socket重新連線: * Python * Node.js * C# ```py from fubon_neo.sdk import FubonSDK import threading # === 請填入你的真實憑證資料 === USER_ID = "您的身分證字號" USER_PW = "您的登入密碼" CERT_PATH = "您的憑證位置" CERT_PW = "您的憑證密碼" # --- 若有行情 WebSocket 需要重連,可以在這裡實作 --- def handle_marketdata_ws_disconnect(code, msg): print(f"[行情WS] 重新建立連線,原因: {code}, {msg}") # === 全域鎖定,避免同時重複觸發重連 === relogin_lock = threading.Lock() # === 建立 FubonSDK 實例(全域使用,重複利用) === sdk = FubonSDK() accounts = None # 登入後會儲存帳號資訊 # === 下單與成交等事件的處理函式(可自訂) === def on_order(code, msg): pass def on_order_changed(code, msg): pass def on_filled(code, msg): pass def re_login(): """ 當連線異常時,自動重新登入並重設事件 callback。 用 lock 確保同時間只會有一個重連動作。 """ if not relogin_lock.acquire(blocking=False): print("[自動重連] 目前已有重連程序執行中,這次略過。") return try: global accounts, sdk print("[自動重連] 登出並重新登入...") try: sdk.logout() except Exception as e: print("[自動重連] 登出時發生例外:", e) try: sdk = FubonSDK() accounts = sdk.login(USER_ID, USER_PW, CERT_PATH, CERT_PW) except Exception as e: print("[自動重連] 登入時發生例外:", e) return if accounts.is_success: print("[自動重連] 重新登入成功,重新設定所有事件 callback。") # 很重要:重新登入後一定要重設事件 callback! sdk.set_on_event(on_event) sdk.set_on_order(on_order) sdk.set_on_order_changed(on_order_changed) sdk.set_on_filled(on_filled) # 若有行情 WS 也需要重連,可自行呼叫 handle_marketdata_ws_disconnect(-9000, "交易WS已重連") else: print("[自動重連] 重新登入失敗。") finally: relogin_lock.release() def on_event(code, content): """ FubonSDK 的事件通知 callback。 """ print("[事件通知] 代碼:", code, "| 內容:", content) if code == "300": print("[事件通知] 偵測到斷線(代碼300),啟動自動重連。") re_login() # === 一開始就要先登入並註冊各種 callback === accounts = sdk.login(USER_ID, USER_PW, CERT_PATH, CERT_PW) if accounts.is_success: print("[主程式] 登入成功,開始註冊事件 callback...") sdk.set_on_event(on_event) sdk.set_on_order(on_order) sdk.set_on_order_changed(on_order_changed) sdk.set_on_filled(on_filled) # 範例:可以指定預設帳號(如果有多個) acc = accounts.data[0] if hasattr(accounts, "data") else None else: print("[主程式] 登入失敗!") # === 範例:手動模擬斷線事件,測試自動重連機制 === on_event("300", "測試:WebSocket 已斷線") on_event("300", "測試:再觸發一次斷線,理論上 lock 會防止重複重連") # --- 範例結束 --- ``` ```js const { FubonSDK } = require('fubon-neo'); // === 請填入你的真實憑證資料 === const USER_ID = "您的身分證字號"; const USER_PW = "您的登入密碼"; const CERT_PATH = "您的憑證路徑"; const CERT_PW = "您的憑證密碼"; // === 全域鎖,避免同時重複觸發重連 === let reloginLock = false; // === 建立 SDK 實例(全域用)=== let sdk = new FubonSDK(); let accounts = null; // === 下單與成交等事件的處理函式(可依需求擴充) === function onOrder(code, msg) {} function onOrderChanged(code, msg) {} function onFilled(code, msg) {} // --- 若有行情 WS 需要重連,可在這裡擴充 --- function handleMarketdataWsDisconnect(code, msg) { console.log(`[行情WS] 重新建立連線,原因: ${code}, ${msg}`); } function reLogin() { // 用 flag 防止同時多次重連 if (reloginLock) { console.log("[自動重連] 目前已有重連程序執行中,這次略過。"); return; } reloginLock = true; console.log("[自動重連] 登出並重新登入..."); try { // 取消 callback 註冊 sdk.setOnEvent(() => {}); sdk.setOnOrder(() => {}); sdk.setOnOrderChanged(() => {}); sdk.setOnFilled(() => {}); sdk.logout(); // 若沒登入也沒關係 } catch (e) { console.log("[自動重連] 登出時發生例外:", e); } try { // 重新建立 SDK 實例是好習慣 sdk = new FubonSDK(); accounts = sdk.login(USER_ID, USER_PW, CERT_PATH, CERT_PW); } catch (e) { console.log("[自動重連] 登入時發生例外:", e); reloginLock = false; return; } if (accounts && accounts.isSuccess) { console.log("[自動重連] 重新登入成功,重新設定所有事件 callback。"); // 重新註冊所有事件 callback(非常重要) sdk.setOnEvent(onEvent); sdk.setOnOrder(onOrder); sdk.setOnOrderChanged(onOrderChanged); sdk.setOnFilled(onFilled); // 如需行情WS,也可在這裡呼叫 handleMarketdataWsDisconnect(-9000, "交易WS已重連"); } else { console.log("[自動重連] 重新登入失敗。"); } reloginLock = false; } function onEvent(code, content) { // 事件通知 callback console.log("[事件通知] 代碼:", code, "| 內容:", content); if (code === "300") { console.log("[事件通知] 偵測到斷線(代碼300),啟動自動重連。"); reLogin(); } } // === 一開始先登入並註冊 callback === accounts = sdk.login(USER_ID, USER_PW, CERT_PATH, CERT_PW); if (accounts && accounts.isSuccess) { console.log("[主程式] 登入成功,開始註冊事件 callback..."); sdk.setOnEvent(onEvent); sdk.setOnOrder(onOrder); sdk.setOnOrderChanged(onOrderChanged); sdk.setOnFilled(onFilled); // 範例:可取得預設帳號 let acc = (accounts.data && accounts.data.length > 0) ? accounts.data[0] : null; } else { console.log("[主程式] 登入失敗!"); } // === 範例:手動觸發斷線事件,測試自動重連 === Promise.all([ Promise.resolve().then(() => onEvent("300", "測試:WebSocket 已斷線")), ]); // --- 範例結束 --- ``` ```cs using System; using System.Threading; using FubonNeo.Sdk; class Program { // === 請填入你的真實憑證資料 === static string USER_ID = "您的身分證字號"; static string USER_PW = "您的登入密碼"; static string CERT_PATH = "您的憑證位置"; static string CERT_PW = "您的憑證密碼"; // === 全域 lock,避免同時重複觸發重連 === static object reloginLock = new object(); static bool isReloginRunning = false; // === 全域 SDK 物件(重複利用)=== static FubonSDK sdk = new FubonSDK(); static dynamic accounts = null; // SDK 回傳型別需依實際狀況確認 // === 下單與成交等事件處理器(可自行擴充)=== static void OnOrder(string code, OrderResult data) { } static void OnOrderChanged(string code, OrderResult data) { } static void OnFilled(string code, FilledData data) { } // --- 若有行情 WS 需要重連,可在這裡擴充 --- static void HandleMarketdataWsDisconnect(int code, string msg) { Console.WriteLine($"[行情WS] 重新建立連線,原因: {code}, {msg}"); } static void ReLogin() { // 避免同時重複重連,用 lock 與旗標 lock (reloginLock) { if (isReloginRunning) { Console.WriteLine("[自動重連] 目前已有重連程序執行中,這次略過。"); return; } isReloginRunning = true; } try { Console.WriteLine("[自動重連] 登出並重新登入..."); try { sdk.Logout(); } catch (Exception e) { Console.WriteLine("[自動重連] 登出時發生例外:" + e.Message); } try { sdk = new FubonSDK(); accounts = sdk.Login(USER_ID, USER_PW, CERT_PATH, CERT_PW); } catch (Exception e) { Console.WriteLine("[自動重連] 登入時發生例外:" + e.Message); return; } if (accounts != null && accounts.isSuccess) { Console.WriteLine("[自動重連] 重新登入成功,重新設定所有事件 callback。"); // 重新設定 callback sdk.OnEvent = OnEvent; sdk.OnOrder = OnOrder; sdk.OnOrderChanged = OnOrderChanged; sdk.OnFilled = OnFilled; // 行情WS重連(如需) HandleMarketdataWsDisconnect(-9000, "交易WS已重連"); } else { Console.WriteLine("[自動重連] 重新登入失敗。"); } } finally { lock (reloginLock) { isReloginRunning = false; } } } static void OnEvent(string code, string content) { Console.WriteLine("[事件通知] 代碼:" + code + " | 內容:" + content); if (code == "300") { Console.WriteLine("[事件通知] 偵測到斷線(代碼300),啟動自動重連。"); ReLogin(); } } static void Main(string[] args) { // === 一開始登入並註冊 callback === accounts = sdk.Login(USER_ID, USER_PW, CERT_PATH, CERT_PW); if (accounts != null && accounts.isSuccess) { Console.WriteLine("[主程式] 登入成功,開始註冊事件 callback..."); sdk.OnEvent = OnEvent; sdk.OnOrder = OnOrder; sdk.OnOrderChanged = OnOrderChanged; sdk.OnFilled = OnFilled; // 取得預設帳號(如果有多個) var acc = (accounts.data != null && accounts.data.Count > 0) ? accounts.data[0] : null; } else { Console.WriteLine("[主程式] 登入失敗!"); } // === 範例:手動觸發斷線事件,測試自動重連 === OnEvent("300", "測試:WebSocket 已斷線"); OnEvent("300", "測試:再觸發一次斷線,lock 應該會防止重複重連"); // 讓主程式暫停,觀察結果(可依需求移除) Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } } ``` --- ### 主動回報 *** 主動回報範例 詳細回傳內容,可參考[主動回報範例](https://www.fbs.com.tw/TradeAPI/docs/trading/guide/advance/callback/callback_example_standard.md);物件說明可參照[SDK Reference 參數對照表](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) #### 訂閱委託回報[​](#訂閱委託回報 "Direct link to 訂閱委託回報") * Python * Node.js * C# * C++ * Go ```py # A callback to receive order data def on_order(code, content): print("==Order==") print(code) print(content) # print(content.seq_no) # 印出委託單流水號 print("========") sdk.set_on_order(on_order) ``` info 回傳物件說明,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderresult) ```js //Callback to receive order data sdk.setOnOrder(function(code, content) { console.log("====order===\n",code, content)}); ``` info 回傳物件說明,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderresult) ```cs public void OnOrder(string code, OrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine("On Order" + response); } } ``` 或使用下方方法 ```cs sdk.OnOrder += (code, ordeResult) => { Console.WriteLine(code + ordeResult.ToString()); } ``` info 回傳物件說明,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) ```cpp void on_order(std::optional err, const OrderResult& data) override { if (err.has_value()) { std::cerr << "Error in on_order: " << err.value() << ", status: " << data.status.value() << std::endl; return; } if (data.order_no.has_value()) { // 或者更簡潔的 if (data.order_no) std::cout << "on order: order_no - " << data.order_no.value() << ". status - " << data.status.value() << std::endl; } else { std::cout << "on order: order_no is not available. status - " << data.status.value() << std::endl; } }; ``` info 回傳物件說明,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) ```go sdk.OnOrder = func(err *string, data fubon.OrderResult) { s, _ := json.MarshalIndent(data, "", " ") fmt.Println("On Order: ", string(s)) if err != nil { fmt.Printf(" Error: %s\n", *err) } } ``` info 詳細回傳內容,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) #### 訂閱改價/改量/刪單回報[​](#訂閱改價改量刪單回報 "Direct link to 訂閱改價/改量/刪單回報") * Python * Node.js * C# * C++ * Go ```py def on_order_changed(code, content): print("=Modified==") print(code) print(content) # print(content.seq_no) # 印出委託單流水號 print("========") sdk.set_on_order_changed(on_order_changed) ``` info 回傳物件說明,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderresult) ```js //Callback to receive Modified data sdk.setOnOrderChanged(function(code, content) { console.log("===Modified===\n", code, content)}); ``` info 回傳物件說明,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderresult) ```cs public void OnOrderChanged(string code, OrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Modified" + response); } } ``` 或使用下方方法 ```cs sdk.OnOrderChanged += (code, ordeResult) => { Console.WriteLine(code + ordeResult.ToString()); } ``` info 詳細回傳內容,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) ```cpp void on_order_changed(std::optional err, const OrderResult& data) override { if (data.error_message.has_value()) { std::cout << "on_order_changed: " << data.order_no.value() << ", status: " << data.status.value() << ", message: " << data.error_message.value() << std::endl; } else { std::cout << "on_order_changed: " << data.order_no.value() << ", status: " << data.status.value() << std::endl; } }; ``` info 回傳物件說明,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) ```go sdk.OnOrderChanged = func(err *string, data fubon.OrderResult) { s, _ := json.MarshalIndent(data, "", " ") fmt.Println("On Change ", string(s)) if err != nil { fmt.Printf(" Error: %s\n", *err) } } ``` info 詳細回傳內容,可參照[OrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) #### 訂閱成交回報[​](#訂閱成交回報 "Direct link to 訂閱成交回報") * Python * Node.js * C# * C++ * Go ```py def on_filled(code, content): print("==Filled==") print(code) print(content) # print(content.filled_no) # 印出成交流水號 print("========") sdk.set_on_filled(on_filled) ``` info 回傳物件說明,可參照[FilledData Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#filleddata) ```js sdk.setOnFilled(function(code, content) { console.log("===Filled===\n",code, content)}) ``` info 回傳物件說明,可參照[FilledData Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#filleddata) ```cs public void OnFilled(string code, FilledData data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Filled" + response); } } ``` 或使用下方方法 ```cs sdk.OnFilled += (code, filledData) => { Console.WriteLine(code + filledData.ToString()); } ``` info 回傳物件說明,可參照[FilledData Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#filleddata) ```cpp void on_filled(std::optional err, const FilledData& data) override { if (err.has_value()) { std::cerr << "Error in on_order: " << err.value() << std::endl; return; } if (data.order_no.has_value()) { std::cout << "on order: " << data.order_no.value() << std::endl; } else { std::cout << "on order: order_no is not available." << std::endl; } }; ``` info 詳細回傳內容,可參照[FilledData Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#filleddata) ```go sdk.OnFilled = func(err *string, data fubon.FilledData) { s, _ := json.MarshalIndent(data, "", " ") fmt.Println("On Filled ", string(s)) if err != nil { fmt.Printf(" Error: %s\n", *err) } } ``` info 詳細回傳內容,可參照[FilledData Object](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#filleddata) #### 訂閱事件通知[​](#訂閱事件通知 "Direct link to 訂閱事件通知") * Python * Node.js * C# * C++ * Go ```py def on_event(code, content): print("===event=====") print(code) print(content) print("========") sdk.set_on_event(on_event) ``` ```js sdk.setOnEvent(function(code, content) { console.log("===Event===\n",code, content)}) ``` ```cs public void OnEvent(String code, String data) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Event" + response); } ``` 或使用下方方法 ```cs sdk.OnEvent += (code, msg) => { Console.WriteLine(code + msg ); }; ``` ```cpp void on_event(const std::string& code, const std::string& data) override { std::cout << code << " " << data << std::endl; } ``` ```go sdk.OnEvent = func(data string, eventType string) { fmt.Printf("📡 OnEvent - Type: %s, Data: %s\n", eventType, data) if eventType == "disconnect" { fmt.Println("⚠️ Connection lost!") } } ``` 事件包含以下情況回傳 | 回傳代碼 | 意義 | | -------- | -------------------------------------------------- | | 100 | 連線建立成功 | | 200 | 登入成功 | | 201 | 登入警示 , Ex : 90天未更換密碼 | | 300 | 斷線 | | 301 | 未收到連線pong回傳 | | 302 | 用戶執行登出 , 並斷線 | | 304 | API Key 異動 (Revoked), 已強制登出 (2.2.7版本新增) | | 500 | 錯誤 | #### 訂閱範例[​](#訂閱範例 "Direct link to 訂閱範例") 使用者可訂閱不同的callback,來接收系統主動發送的委託及成交通知。 * Python * Node.js * C# * C++ * Go ```py # A callback to receive order data def on_order(code, content): print("==Order==") print(code) print(content) print("========") sdk.set_on_order(on_order) # A callback to receive Modified data def on_order_changed(code, content): print("=Modified==") print(code) print(content) print("========") sdk.set_on_order_changed(on_order_changed) # A callback to receive Filled data def on_filled(code, content): print("==Filled==") print(code) print(content) print("========") sdk.set_on_filled(on_filled) # A callback to receive Event data def on_event(code, content): print("===event=====") print(code) print(content) print("========") sdk.set_on_event(on_event) ``` ```js //Callback to receive order data sdk.setOnOrder(function(code, content) { console.log("====order===\n",code, content)}); //Callback to receive Modified data sdk.setOnOrderChanged(function(code, content) { console.log("===Modified===\n", code, content)}); //Callback to receive Filled data sdk.setOnFilled(function(code, content) { console.log("===Filled===\n",code, content)}) //Callback to receive Event data sdk.setOnEvent(function(code, content) { console.log("===Event===\n",code, content)}) ``` ```cs public class MyCallback : Callback { public string code =""; public string response = ""; //Callback to receive order data public void OnOrder(string code, OrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine("On Order" + response); } } //Callback to receive Modified data public void OnOrderChanged(string code, OrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Modified" + response); } } //Callback to receive Filled data public void OnFilled(string code, FilledData data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Filled" + response); } } //Callback to receive Event data public void OnEvent(String code, String data) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Event" + response); } } var callback = new MyCallback(); sdk.RegisterCallback(callback); ``` 或使用下方方法分別訂閱 ```cs sdk.OnEvent += (code, msg) => { Console.WriteLine(code + msg ); }; sdk.OnOrder += (code, ordeResult) => { Console.WriteLine(code + ordeResult.ToString()); } sdk.OnOrderChanged += (code, ordeResult) => { Console.WriteLine(code + ordeResult.ToString()); } sdk.OnFilled += (code, filledData) => { Console.WriteLine(code + filledData.ToString()); } ``` ```cpp struct CustomCallback : public fubon::Callback { void on_event(const std::string& code, const std::string& data) override { std::cout << code << " " << data << std::endl; } void on_order(std::optional err, const OrderResult& data) override { if (err.has_value()) { std::cerr << "Error in on_order: " << err.value() << ", status: " << data.status.value() << std::endl; return; } if (data.order_no.has_value()) { // 或者更簡潔的 if (data.order_no) std::cout << "on order: order_no - " << data.order_no.value() << ". status - " << data.status.value() << std::endl; } else { std::cout << "on order: order_no is not available. status - " << data.status.value() << std::endl; } }; void on_order_changed(std::optional err, const OrderResult& data) override { if (data.error_message.has_value()) { std::cout << "on_order_changed: " << data.order_no.value() << ", status: " << data.status.value() << ", message: " << data.error_message.value() << std::endl; } else { std::cout << "on_order_changed: " << data.order_no.value() << ", status: " << data.status.value() << std::endl; } }; void on_filled(std::optional err, const FilledData& data) override { std::cout << data.order_no << " " << std::endl; }; void on_futopt_order(std::optional err, const FutOptOrderResult& data) override { return; //if (err.has_value()) { // std::cerr << "Error in on_order: " << err.value() << std::endl; // return; //} //if (data.order_no.has_value()) { // 或者更簡潔的 if (data.order_no) // std::cout << "on order: " << data.order_no.value() << std::endl; //} //else { // std::cout << "on order: order_no is not available." << std::endl; //} }; void on_futopt_order_changed(std::optional err, const FutOptOrderResult& data) override { /*std::cout << data.order_no.value() << " " << std::endl;*/ return; }; void on_futopt_filled(std::optional err, const FutOptFilledData& data) override { //std::cout << data.order_no << " " << std::endl; return; }; }; int main() { auto callback = std::make_shared(); auto sdk = new FubonSDK(); sdk->register_callback(callback); /// 以下略 ... /// ... return 0; } ``` ```go import ( "encoding/json" "fmt" "fubon" "strings" ) func main(){ sdk.OnOrder = func(err *string, data fubon.OrderResult) { s, _ := json.MarshalIndent(data, "", " ") fmt.Println("On Order: ", string(s)) if err != nil { fmt.Printf(" Error: %s\n", *err) } } sdk.OnOrderChanged = func(err *string, data fubon.OrderResult) { s, _ := json.MarshalIndent(data, "", " ") fmt.Println("On Change ", string(s)) if err != nil { fmt.Printf(" Error: %s\n", *err) } } sdk.OnFilled = func(err *string, data fubon.FilledData) { s, _ := json.MarshalIndent(data, "", " ") fmt.Println("On Filled ", string(s)) if err != nil { fmt.Printf(" Error: %s\n", *err) } } sdk.OnEvent = func(data string, eventType string) { fmt.Printf("📡 OnEvent - Type: %s, Data: %s\n", eventType, data) if eventType == "disconnect" { fmt.Println("⚠️ Connection lost!") } } } ``` --- ### 交易 *** 此篇教學將示範如何進行一個完整的買賣流程 #### 買入股票[​](#買入股票 "Direct link to 買入股票") 假設今天開盤後,我們想以66.00元買進2張富邦金,我們可以這樣撰寫程式並執行: * Python * Node.js * C# ```python from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction sdk = FubonSDK() accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證位置", "您的憑證密碼") #若有歸戶,則會回傳多筆帳號資訊 #建立委託單內容 order = Order( buy_sell = BSAction.Buy, symbol = "2881", price = "66", quantity = 2000, market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force= TimeInForce.ROD, order_type = OrderType.Stock, user_def = "From_Py" # optional field ) sdk.stock.place_order(accounts.data[0], order) #下單委託 ``` info 整股與零股之委託,請參考各語言Libary [Python Libary](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); const sdk = new FubonSDK(); const accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證路徑" ,"您的憑證密碼"); const order = { buySell: BSAction.Buy, symbol: "2881", price: "66", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" }; sdk.stock.placeOrder(accounts.data[0],order); ``` info 整股與零股之委託,請參考各語言Libary [Node.Js Libary](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var accounts = sdk.Login("您的身分證字號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼"); // 若有歸戶,則會回傳多筆帳號資訊 var order = new Order( BsAction.Buy, "2881", "66", 2000, MarketType.Common, PriceType.Limit, TimeInForce.Rod, OrderType.Stock, null ); sdk.Stock.PlaceOrder(accounts.data[0],order); // 使用阻塞委託下單 ``` info 整股與零股之委託,請參考各語言Libary [C# Libary](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) #### 確認委託與成交回報[​](#確認委託與成交回報 "Direct link to 確認委託與成交回報") 若要確定該筆的狀態,可以依照下方範例查詢指定的委託單: * Python * Node.js * C# ```python orderResults = sdk.stock.get_order_results(accounts.data[0]) print(orderResults) ``` ```js const orderResults = sdk.stock.getOrderResults(accounts.data[0]) console.log(orderResults) ``` ```cs var orderResults = sdk.Stock.GetOrderResults(accounts.data[0]); Console.WriteLine(orderResults); foreach (var results in orderResults) { Console.WriteLine(results); } ``` 根據回報的結果,我們可以判斷此筆委託是否成交,成交了多少數量: * Python * Node.js * C# ```py Result { is_success: true, message: None, data : [ OrderResult{ ... buy_sell: Buy, #買賣別 (BSAction) price: 66, #原始委託價格 (float) quantity: 2000, #原始委託數量 (int) after_price: 66, #有效委託價格 (float) after_qty: 2000, #有效委託數量 (int) filled_qty: 0, #已成交數量 (int) filled_money: 0, #成交價金 (int) symbol: "2881", #股票代號 (string) order_no: "bA888", #委託書號 (string) last_time: "10:10:10.123", #最後異動時間 (string) ... } ] } ``` ```js { isSuccess: true, data:[ { ... buySell: 'Buy', //買賣別 (string) price: 66, //原始委託價格 (number) quantity: 2000, //原始委託數量 (number) afterPrice: 66, //有效委託價格 (number) afterQty: 2000, //有效委託數量 (number) filledQty: 0, //已成交數量 (number) filledMoney: 0, //成交價金 (number) symbol: '2881', //股票代號 (string) orderNo: 'bA888', //委託書號 (string) lastTime: '10:10:10.123', //最後異動時間 (string) ... } ] } ``` ```cs { isSuccess = True, message = , data = [ OrderResult{ ... buySell = Buy, //買賣別 (BsAction) price = 66, //原始委託價格 (double) quantity = 2000, //原始委託數量 (int) afterPrice = 66, //有效委託價格 (double) afterQty = 2000, //有效委託數量 (int) filledQty = 0, //已成交數量 (int) filledMoney = 0, //成交價金 (int) symbol = 2881, //股票代號 (string) orderNo = bA888, //委託書號 (string) lastTime = 10:10:10.123, //最後異動時間 (string) ... } ] } ``` #### 修改委託價格[​](#修改委託價格 "Direct link to 修改委託價格") 由於原先的價格一直無法成交,我們調整原先的委託價格,改用66.50元的價格買入: * Python * Node.js * C# ```python orderResults = sdk.stock.get_order_results(accounts.data[0]) modified_pirce = sdk.stock.make_modify_price_obj(orderResults.data[0],"66.5") sdk.stock.modify_price(accounts.data[0], modified_pirce) ``` ```js orderResults = sdk.stock.getOrderResults(accounts.data[0]) const modified_pirce = sdk.stock.makeModifyPriceObj(orderResults.data[0],"66.5") sdk.stock.modifyPrice(accounts.data[0],modified_pirce) ``` ```cs orderResults = sdk.Stock.GetOrderResults(accounts.data[0]); var modified_pirce = sdk.Stock.MakeModifyPriceObj(orderResults.data[0],"66.5",null); //將價格調整成66.5元 sdk.Stock.ModifyPrice(accounts.data[0],modified_pirce); ``` 幾分鐘後,我們再查詢一次委託狀態,發現成交了: * Python * Node.js * C# ```python orderResults = sdk.stock.get_order_results(accounts.data[0]) print(orderResults.data[0]) ``` ```py [ { ... buy_sell: Buy, #買賣別 (BSAction) price: 66, #原始委託價格 (float) quantity: 2000, #原始委託數量 (int) after_price: 66.5, #有效委託價格 (float) after_qty: 1000, #有效委託數量 (int) filled_qty: 1000, #已成交數量 (int) filled_money: 66000, #成交價金 (int) symbol: "2881", #股票代號 (string) order_no: "bA888", #委託書號 (string) last_time: "10:13:12.123", #最後異動時間 (string) ... } ] ``` ```js orderResults = sdk.stock.getOrderResults(accounts.data[0]) console.log(orderResults.data[0]) ``` ```json { ... "buySell" : "Buy", //買賣別 (string) "price" : 66, //原始委託價格 (number) "quantity" : 2000, //原始委託數量 (number) "afterPrice" : 66.5, //有效委託價格 (number) "afterQty" : 1000, //有效委託數量 (number) "filledQty" : 1000, //已成交數量 (number) "filledMoney" : 66000, //成交價金 (number) "stockNo" : "2881", //股票代號 (string) "orderNo" : "bA888", //委託書號 (string) "lastTime" : "10:13:12.123", //最後異動時間 (string) ... } ``` ```cs orderResults = sdk.Stock.GetOrderResults(accounts.data[0]); Console.WriteLine(orderResults.data[0]); ``` ```cs { ... buySell = Buy, //買賣別 (BsAction) price = 66, //原始委託價格 (double) quantity = 2000, //原始委託數量 (int) afterPrice = 66.5, //有效委託價格 (double) afterQty = 1000, //有效委託數量 (int) filledQty = 1000, //已成交數量 (int) filledMoney = 66000, //成交價金 (int) stockNo = "2881", //股票代號 (string) orderNo = "bA888", //委託書號 (string) lastTime = "10:13:12.123", //最後異動時間 (string) ... } ``` #### 賣出股票[​](#賣出股票 "Direct link to 賣出股票") 最後決定在收盤前,賣出一張富邦金: * Python * Node.js * C# ```python #建立委託單內容 order = Order( buy_sell = BSAction.Sell, symbol = "2881", price = "67", quantity = 1000, market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force= TimeInForce.ROD, order_type = OrderType.Stock, user_def = "From_Py" # optional field ) sdk.stock.place_order(accounts.data[0], order) #下單委託 ``` ```js order = { buySell: BSAction.Sell, symbol: "2881", price: "66", quantity: 1000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" }; sdk.stock.placeOrder(accounts.data[0],order) ``` ```cs order = new Order( BsAction.Sell, "2881", "66", 1000, MarketType.Common, PriceType.Limit, TimeInForce.Rod, OrderType.Stock, null ); sdk.Stock.PlaceOrder(accounts.data[0],order); ``` --- ### 富邦新一代 API 本頁重點 * 本頁介紹富邦新一代 API 的交易與行情服務範圍。 * 支援多語言與跨平台環境,適用程式交易開發。 * 下一步建議先完成[事前準備](https://www.fbs.com.tw/TradeAPI/docs/trading/prepare.md)。 | 項目 | 說明 | | ---- | -------------------------------------------------------------------------- | | 產品 | 富邦新一代 API(Fubon Neo API) | | 服務 | 交易 / 行情 | | 平台 | Windows / macOS / Linux | | 語言 | Python / C# / JavaScript (Node.js) / C++、Go(僅支援證券交易帳務及條件單) | | 登入 | 憑證登入(可搭配 API Key) | #### 概述[​](#概述 "Direct link to 概述") 富邦新一代 API 為您的程式交易,提供了完善的交易與行情 API,滿足每一位開發者的量化與自動化交易需求。
提供用戶自由選擇主流開發語言( Python、C#、JavaScript、C++、Go),在創建程式交易的過程中,輕易地取用 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以上版本。 --- ### 銀行餘額查詢 BankRemain #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ---------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | BankRemain | 回傳餘額資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 餘額資訊 BankRemain 欄位[​](#餘額資訊-bankremain-欄位 "Direct link to 餘額資訊 BankRemain 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------ | ---------- | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | currency | string | 幣別 | | balance | int | 餘額 | | available\_balance | int | 可用餘額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto bankremain_response = sdk->accounting->bank_remain(target_account); if (bankremain_response.is_success && bankremain_response.data.has_value()) { const auto& bank_remain = bankremain_response.data.value(); // 搭配自定義 .cpp & hpp Output std::cout << bank_remain << std::endl; } else { std::cout << bankremain_response.message.value() << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { is_success = true, message = , data = BankRemain{ branch_no = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) currency = TWD, // 幣別 (string) balance = 666666, // 餘額 (int) available_balance = 123456 // 可用餘額 (int) } } ``` --- ### 庫存查詢 inventories #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳庫存資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 庫存資訊 Inventory 欄位[​](#庫存資訊-inventory-欄位 "Direct link to 庫存資訊 Inventory 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | > date | string | 交易日期 | | > account | string | 帳號 | | > branch\_no | string | 分公司代號 | | > stock\_no | string | 股票代號 | | > order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖、`SBL`借券 | | > lastday\_qty | int | 昨日庫存餘額 | | > buy\_qty | int | 今日委買股數 | | > buy\_filled\_qty | int | 今日買進成交股數 | | > buy\_value | int | 買進價金 | | > today\_qty | int | 今日庫存餘額 | | > tradable\_qty | int | 可委託股數 | | > sell\_qty | int | 今日委賣股數 | | > sell\_filled\_qty | int | 今日賣出成交股數 | | > sell\_value | int | 賣出價金 | | > odd | list | Object | | >> lastday\_qty | int | 昨日庫存餘額 | | >> buy\_qty | int | 今日委買股數 | | >> buy\_filled\_qty | int | 今日買進成交股數 | | >> buy\_value | int | 買進價金 | | >> today\_qty | int | 今日庫存餘額 | | >> tradable\_qty | int | 可委託股數 | | >> sell\_qty | int | 今日委賣股數 | | >> sell\_filled\_qty | int | 今日賣出成交股數 | | >> sell\_value | int | 賣出價金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto inventories_response = sdk->accounting->inventories(target_account); if (!inventories_response.is_success) { std::cerr << "Inventories query failed: " << (inventories_response.message.has_value() ? inventories_response.message.value() : "No message") << std::endl; } // 搭配自定義 .cpp & hpp Output else if (inventories_response.data.has_value()) { const auto& inventories = inventories_response.data.value(); for (const auto& inventory : inventories) { std::cout << inventory << std::endl; } } else { std::cout << "Inventories query succeeded but no data returned." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data = [ Inventory{ date = 2023/10/13, // 交易日期 (string) account = 26, // 帳號 (string) branchNo = 6460, // 分公司代號 (string) stockNo = 1101, // 股票代號 (string) orderType = STOCK, // 委託單類型 (OrderType) lastdayQty = 2000, // 昨日庫存餘額 (int) buyQty = 0, // 今日委買股數 (int) buyFilledQty = 0, // 今日買進成交股數 (int) buyValue = 0, // 買進價金 (int) todayQty = 2000, // 今日庫存餘額 (int) tradableQty = 2000, // 可委託股數 (int) sellQty = 0, // 今日委賣股數 (int) sellFilledQty = 0, // 今日賣出成交股數 (int) sellValue = 0, // 賣出價金 (int) odd = InventoryOdd { // 委託單狀態 (InventoryOdd 物件) lastdayQty = 0, // 昨日庫存餘額 (int) buyQty = 0, // 今日委買股數 (int) buyFilledQty = 0, // 今日買進成交股數 (int) buyValue = 0, // 買進價金 (int) todayQty = 0, // 今日庫存餘額 (int) tradableQty = 0, // 可委託股數 (int) sellQty = 0, // 今日委賣股數 (int) sellFilledQty = 0, // 今日賣出成交股數 (int) sellValue = 0 // 賣出價金 (int) } }, ... ] } ``` --- ### 維持率查詢 Maintenance #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | --------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | MaintenanceData | 回傳維持率資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 維持率 MaintenanceData 欄位[​](#維持率-maintenancedata-欄位 "Direct link to 維持率 MaintenanceData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------------------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | maintenance\_data | list | Object | | > date | string | 查詢日 | | > branch\_no | string | 分公司代號 | | > account | string | 帳號 | | > maintenance\_summary | list | Object | | >> margin\_value | int | 整戶融資市值 | | >> shortsell\_value | int | 整戶融券市值 | | >> shortsell\_margin | int | 整戶融券保證金額 | | >> collateral | int | 擔保品 | | >> margin\_loan\_amt | int | 整戶融資金額 | | >> maintenance\_ratio | double | 整戶維持率 | | > maintenance\_detail | list | Object | | >> stock\_no | string | 股票代碼 | | >> order\_no | string | 委託書號 | | >> order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、`SBL`借券 | | >> quantity | int | 持有股數 | | >> price | double | 計算價 | | >> cost\_price | double | 成本價 | | >> shortsell\_margin | int | 融券保證金 | | >> collateral | int | 擔保品 | | >> margin\_loan\_amt | int | 融資金 | | >> maintenance\_ratio | double | 維持率 | | >> collateral\_interest | double | 擔保品利息 | | >> margin\_interest | double | 融資金利息 | | >> shortsell\_interest | double | 融券保證金利息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto maintenance_response = sdk->accounting->maintenance(target_account); if (maintenance_response.is_success){ // 搭配自定義 .cpp & hpp Output std::cout << maintenance_response.data.value() << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data = MaintenanceData { date = 2024/02/27, branchNo = 6460, account = 26, maintenanceSummary = MaintenanceSummary { marginValue = 3135000, shortsellValue = 0, shortsellMargin = 0, collateral = 0, marginLoanAmt = 1494000, maintenanceRatio = 209.83 }, maintenanceDetail = [{ stockNo = 2603, orderNo = x4580, orderType = Stock, quantity = 10000, price = 152.5, costPrice = 119, shortsellMargin = 0, collateral = 0, marginLoanAmt = 0, maintenanceRatio = 213.58, collateralInterest = 0, marginInterest = 20818, shortsellInterest = 0 }, ... ], } } ``` --- ### 交割款查詢 QuerySettlement #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | -------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | range | string | 時間區間,目前有效值為"0d"(當日)、"3d" | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | -------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | SettlementData | 回傳交割款資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 交割資訊 SettlementData 欄位[​](#交割資訊-settlementdata---欄位 "Direct link to 交割資訊 SettlementData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------------------- | ----------------- | ------------------------------- | | > account | object | Object | | >> account | string | 帳號 | | >> branch\_no | string | 分公司代號 | | > details | list | Object | | >> date | string | 查詢日 | | >> settlement\_date | string (Optional) | 交割日 (若查無資料為空值) | | >> buy\_value | int (Optional) | 買進金額 (若查無資料為空值) | | >> buy\_fee | int (Optional) | 買進手續費 (若查無資料為空值) | | >> buy\_settlement | int (Optional) | 買進應收付款 (若查無資料為空值) | | >> buy\_tax | int (Optional) | 買進交易稅 (若查無資料為空值) | | >> sell\_value | int (Optional) | 賣出金額 (若查無資料為空值) | | >> sell\_fee | int (Optional) | 賣出手續費 (若查無資料為空值) | | >> sell\_settlement | int (Optional) | 賣出應收付款 (若查無資料為空值) | | >> sell\_tax | int (Optional) | 賣出交易稅 (若查無資料為空值) | | >> total\_bs\_value | int (Optional) | 合計買賣金額 (若查無資料為空值) | | >> total\_fee | int (Optional) | 合計手續費 (若查無資料為空值) | | >> total\_tax | int (Optional) | 合計交易稅 (若查無資料為空值) | | >> total\_settlement\_amount | int (Optional) | 合計交割金額 (若查無資料為空值) | | >> currency | string (Optional) | 幣別 (若查無資料為空值) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs auto settlement_response = sdk->accounting->query_settlement(target_account, "3d"); // 搭配自定義 .cpp & hpp Output if (settlement_response.is_success && settlement_response.data.has_value()) { std::cout << *settlement_response.data << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data = SettlementData{ account = AccountRes { // 帳戶資訊 account = 26, // 帳號 (string) branchNo = 6460 // 分公司代號 (string) }, details = [ Settlement{ // 交割資訊 date = 2024/03/04, // 查詢日 (string) settlementDate = 2024/03/06, // 交割日期 (string) buyValue = 735500, // 買進金額 (int) buyFee = 313, // 買進費用 (int) buySettlement = -1429513, // 買進應收付款 (int) buyTax = 0, // 買進交易稅 (int) sellValue = 770500, // 賣出金額 (int) sellFee = 320, // 賣出費用 (int) sellSettlement = 0, // 賣出應收付款 (int) sellTax = 2309, // 賣出交易稅 (int) totalBsValue = 1506000, // 合計買賣金額 (int) totalFee = 633, // 合計手續費 (int) totalSettlementAmount = -1429513, // 合計交割款金額 (int) totalTax = 2309, // 合計交易稅 (int) currency = TWD // 幣別 (string) }, Settlement{ date = 2024/03/05, // 查詢日 (string) settlementDate = 2024/03/07, // 交割日期 (string) buyValue = 2261470, // 買進金額 (int) buyFee = 1065, // 買進費用 (int) buySettlement = -3895335, // 買進應收付款 (int) buyTax = 0, // 買進交易稅 (int) sellValue = 2488170, // 賣出金額 (int) sellFee = 1137, // 賣出費用 (int) sellSettlement = 677626, // 賣出應收付款 (int) sellTax = 7412, // 賣出交易稅 (int) totalBsValue = 4749640, // 合計買賣金額 (int) totalFee = 2202, // 合計買賣手續費 (int) totalSettlementAmount = -3217709, // 合計交割款金額 (int) totalTax = 7412, // 合計交易稅 (int) currency = TWD // 幣別 (string) }, Settlement{ date = 2024/03/06, // 查詢日 (string) settlementDate = , // 交割日期 (string) buyValue = , // 買進金額 (int) buyFee = , // 買進費用 (int) buySettlement = , // 買進應收付款 (int) buyTax = , // 買進交易稅 (int) sellValue = , // 賣出金額 (int) sellFee = , // 賣出費用 (int) sellSettlement = , // 賣出應收付款 (int) sellTax = , // 賣出交易稅 (int) totalBsValue = , // 合計買賣金額 (int) totalFee = , // 合計買賣手續費 (int) totalSettlementAmount = , // 合計交割款金額 (int) totalTax = , // 合計交易稅 (int) currency = // 幣別 (string) } ] } } ``` --- ### 已實現損益查詢 realized\_gains\_and\_loses #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳已實現資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 已實現 Realized 欄位[​](#已實現-realized--欄位 "Direct link to 已實現 Realized 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | date | string | 資料日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | filled\_qty | int | 成交股數 | | filled+price | double | 成交價 | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖、`SBL`借券 | | realized\_profit | int | 已實現獲利金額 | | realized\_loss | int | 已實現損失金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto realized_response = sdk->accounting->realized_gains_and_loses(target_account); // 搭配自定義 .cpp & hpp Output if (realized_response.is_success && realized_response.data.has_value()) { for (const auto& r : *realized_response.data) { std::cout << r << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data =[ Realized{ date = 2023/08/16, // 資料日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) stockNo = 1101, // 股票代號 (string) buySell = SELL, // 買賣別 (BSAction) filledQty = 1000, // 成交股數 (int) filledPrice = 36.5, // 成交價 (double) orderType = STOCK, // 委託單類型 (OrderType) realizedProfit = 36339, // 已實現獲利金額 (int) realizedLoss = 0 // 已實現損失金額 (int) }, ... ] } ``` --- ### 已實現損益彙總 realized\_gains\_and\_loses\_summary #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳已實現彙總資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 已實現彙總 RealizedSummary 欄位[​](#已實現彙總-realizedsummary-欄位 "Direct link to 已實現彙總 RealizedSummary 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | start\_date | string | 彙總起始日 | | end\_date | string | 彙總截止日 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖、`SBL`借券 | | filled\_qty | int | 成交股數 | | filled\_avg\_price | double | 成交均價 | | realized\_profit\_and\_loss | int | 已實現損益金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto realized_summary_response = sdk->accounting->realized_gains_and_loses_summary(target_account); // 搭配自定義 .cpp & hpp Output if (realized_summary_response.is_success && realized_summary_response.data.has_value()) { const auto& realized_list = *realized_summary_response.data; for (const auto& item : realized_list) { std::cout << item << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data = [ RealizedSummary{ startDate = 20230801, // 起始日期 (string) endDate = 20230801, // 截止日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) stockNo = 1101, // 股票代號 (string) buySell = SELL, // 買賣別 (BSAction) orderType = STOCK, // 委託單類型 (OrderType) filledQty = 3000, // 成交股數 (int) filledAvgPrice = 35.7, // 成交均價 (double) realizedProfitAndLoss = 34026 // 已實現損益金額 (int) }, ... ] } ``` --- ### 未實現損益查詢 unrealized\_gains\_and\_loses #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳未實現資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 未實現 UnrealizedData 欄位[​](#未實現-unrealizeddata-欄位 "Direct link to 未實現 UnrealizedData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | date | string | 庫存建立日 | | branch\_no | string | 分公司代號 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖、`SBL`借券 | | cost\_price | double | 成本價 | | tradable\_qty | int | 可交易餘額 | | today\_qty | int | 今日餘額 | | unrealized\_profit | int | 未實現獲利 | | unrealized\_loss | int | 未實現虧損 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto unrealized_response = sdk->accounting->unrealized_gains_and_loses(target_account); // 搭配自定義 .cpp & hpp Output if (unrealized_response.is_success && unrealized_response.data.has_value()) { for (const auto& u : *unrealized_response.data) { std::cout << u << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = True, message = , data = [ UnrealizedData{ date = 2021/08/09, // 庫存建立日 (string) account = 26, // 帳號 (int) branchNo = 6460, // 分公司代號 (string) stockNo = 2303, // 股票代號 (string) buySell = BUY, // 買賣別 (BSAction) orderType = SHORT, // 委託單類型 (OrderType) costPrice = 50.0, // 成本價格 (double) tradableQty = 1000, // 可交易餘額 (int) todayQty = 1000, // 今日餘額 (int) unrealizedProfit = 45200, // 未實現獲利 (int) unrealizedLoss = 0 // 未實現虧損 (int) } ] } ``` --- ### 參數對照表 #### 類別[​](#類別 "Direct link to 類別") Class ##### OrderObject[​](#orderobject "Direct link to OrderObject") | Parameter | Type | Meaning | | -------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | buy\_sell | BSAction | [買賣別](#bsaction) 可選用參數 `BUY` 買 、 `SELL` 賣 | | symbol | string | 股票代號 | | price | string | 委託價格 (若非使用 `LIMIT` 限價,此欄代入 ***std::nullopt***) | | quantity | int | 委託數量 | | market\_type | MarketType | [盤別](#markettype) 可選用參數 `COMMON` 整股、 `FIXING` 定盤、 `INTRADAY_ODD` 盤中零股、 `ODD` 盤後零股、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | price\_type | PriceType | [價格旗標](#pricetype) 可選用參數為 `LIMIT` 限價、`LIMIT_UP` 漲停、 `LIMIT_DOWN` 跌停、 `MARKET` 市價、 `REFERENCE` 參考價 | | time\_in\_force | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD` 、 `FOK` 、 `IOC` | | order\_type | OrderType | [委託類別](#ordertype) 可選用參數為 `STOCK` 現股、 `MARGIN` 融資、 `SHORT` 融券、 `DAY_TRADE` 現股當沖(for 現沖先賣)、 `SBL` 借券 | | user\_def (optional) | string | 用戶自定義 (最長10個字元,不支援特殊字元及中文、不適用興櫃) | caution 不同 MarketType 對應的 quantity 之單位及範圍不同,請參考[盤別](#markettype)說明。 caution 當 MarketType 爲 MarketType.COMMON, MarketType.ODD, MarketType.INTRADAY\_ODD 其中之一,且 priceType 爲 PriceType.LIMIT 時,需填入 price 欄位,其餘時候 price 欄位為 std::nullopt。 caution 現沖先賣時 , order\_type = DAY\_TRADE , buy\_sell 需為 SELL , market\_type 需為COMMON ##### OrderResult[​](#orderresult "Direct link to OrderResult") 委託列表,透過 [get\_order\_result(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/trade/GetOrderResults.md) 取得。 | 參數 | 類別 | 說明 | | ------------------ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | MarketType | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | BSAction | 買賣別 : `BUY` 買 、 `SELL` 賣 | | price\_type | PriceType | 原始委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | TimeInforce | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | OrderType | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | PriceType | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間(格式請見表末說明) | | error\_message | string | 錯誤訊息 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | >> function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modified\_time | string | 修改時間(格式請見表末說明) | | >> before\_qty | int | 原始委託股數 | | >> after\_qty | int | 有效委託股數(包含已成交部分) | | >> before\_price | double | 原始委託價 | | >> after\_price | double | 有效委託價 | | >> filled\_money | double | 成交價金 | | >> status | int | 委託單狀態 | | >> err\_msg | string | 錯誤訊息 | 時間格式說明 last\_time 及 modified\_time 時間格式: **HH:MM:SS.fff** 或 **HH:MM:SS** (即當 .fff = .000 時省略此部分) ##### BatchResult[​](#batchresult "Direct link to BatchResult") 批次委託列表,透過 [BatchOrderLists(account)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/trade/batchOrder/BatchOrderList.md) 取得。 | Parameter | Type | Meaning | | -------------- | ------ | ------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單、 `10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | batch\_seq\_no | string | 批次單流水序號 | ##### ModifyPriceObj[​](#modifypriceobj "Direct link to ModifyPriceObj") 改價物件 | Parameter | Type | Meaning | | ------------- | --------- | --------------------------------------------------------------------------------------------------------- | | order\_result | Object | [委託列表](#orderresult) | | price | string | 改單後的價格 | | price\_type | PriceType | 改單後的價格類型 : `LIMIT`限價 、 `LIMIT_UP`漲停 、 `LIMIT_DOWN`跌停 、 `MARKET`市價 、 `REFERENCE`參考價 | ##### ModifyQuantityObj[​](#modifyquantityobj "Direct link to ModifyQuantityObj") 改量物件 | Parameter | Type | Meaning | | ------------- | ------ | ------------------------ | | order\_result | Object | [委託列表](#orderresult) | | quantity | int | 改單後的委託量 | ##### FilledData[​](#filleddata "Direct link to FilledData") 成交回報物件 | 參數 | 類別 | 說明 | | ------------------ | --------- | ----------------------------------------------------------------------------------------------- | | date | string | 日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | seq\_no | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | order\_no | string | 委託書號 | | stock\_no | string | 股票代號 | | buy\_sell | BSAction | 買賣別 : `BUY` 買 、 `SELL` 賣 | | order\_type | OrderType | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | filled\_no | string | 成交流水號 | | filled\_avg\_price | double | 成交均價 | | filled\_qty | int | 成交股數 | | filled\_price | double | 成交單價 | | filled\_time | string | 成交時間 | | user\_def | string | 用戶自定義 (只有主動回報才回傳此欄位) | ##### Account[​](#account "Direct link to Account") 帳號資訊 | Parameter | Type | Meaning | | ------------- | ------ | ------------------------------------------ | | name | string | 客戶姓名 | | account | string | 帳號 | | branch\_no | string | 分公司代號 | | account\_type | string | 帳號類型 ,回傳 `stock`證券 、`futopt`期貨 | #### Constants ( 欄位對應數值 )[​](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )") ##### BSAction[​](#bsaction "Direct link to BSAction") 買賣別 (BuySell) | Name | Value | Meaning | | ------------- | ----- | ------------ | | BUY | 1 | 買 | | SELL | 2 | 賣 | | UN\_SUPPORTED | 3 | 不支援此型別 | | UN\_DEFINED | 4 | 未定義此型別 | ##### MarketType[​](#markettype "Direct link to MarketType") 盤別 | Name | Value | Meaning | | ------------- | ----- | ------------ | | COMMON | 1 | 整股 | | FIXING | 2 | 定盤 | | ODD | 3 | 盤後零股 | | INTRADAY\_ODD | 4 | 盤中零股 | | EMG | 5 | 興櫃 | | EMG\_ODD | 6 | 興櫃零股 | | UN\_SUPPORTED | 7 | 不支援此型別 | | UN\_DEFINED | 8 | 未定義此型別 | 使用不同 MarketType 時,相對應的Quantity所代表的單位及範圍也會不同,詳如下表: | Name | Quantity Unit | Quantity Ranges | | ------------- | ------------- | --------------- | | COMMON | 千股 | 1000 ~ 499000 | | FIXING | 千股 | 1000 ~ 499000 | | INTRADAY\_ODD | 股 | 1 ~ 999 | | ODD | 股 | 1 ~ 999 | | EMG | 千股 | 1000 ~ 499000 | | EMG\_ODD | 股 | 1 ~ 999 | 使用不同 MarketType 時,可使用的 PriceType , TimeInForce 會不同,詳如下表: | MarketType | Available PriceType | Available TimeInForce | | ------------- | -------------------------------------------------------- | --------------------- | | COMMON | LIMIT 、 LIMIT\_UP 、 LIMIT\_DOWN 、 MARKET 、 REFERENCE | ROD 、 IOC 、 FOK | | FIXING | REFERENCE | ROD | | INTRADAY\_ODD | LIMIT 、 LIMIT\_UP 、 LIMIT\_DOWN 、 REFERENCE | ROD | | ODD | LIMIT 、 LIMIT\_UP 、 LIMIT\_DOWN 、 REFERENCE | ROD | | EMG | LIMIT | ROD | | EMG\_ODD | LIMIT | ROD | ##### PriceType[​](#pricetype "Direct link to PriceType") 價格類型 (priceType) | Name | Value | Meaning | | ------------- | ----- | ----------------------- | | LIMIT | 1 | 限價 | | LIMIT\_UP | 2 | 漲停 | | LIMIT\_DOWN | 3 | 跌停 | | MARKET | 4 | 市價 | | REFERENCE | 5 | 參考價 (定盤時為定盤價) | | UN\_SUPPORTED | 6 | 不支援此型別 | | UN\_DEFINED | 7 | 未定義此型別 | ##### 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 | 未定義此型別 | ##### OrderType[​](#ordertype "Direct link to OrderType") 委託類別 (orderType) | Name | Value | Meaning | | ------------- | ----- | ------------ | | STOCK | 1 | 現股 | | MARGIN | 2 | 融資 | | SHORT | 3 | 融券 | | SBL | 4 | 借券 | | DAY\_TRADE | 5 | 現股當沖 | | UN\_SUPPORTED | 6 | 不支援此型別 | | UN\_DEFINED | 7 | 未定義此型別 | ##### StockType[​](#stocktype "Direct link to StockType") 股票分類別 | Name | Value | Meaning | | ------------------- | ----- | -------------------- | | Stock | 0 | 股票 | | ConvertBond | 1 | 可轉債 | | Warrent | 2 | 權證 | | ETF\_and\_ETN | 3 | ETF 與 ETN | | Bond\_with\_Warrent | 4 | 存託憑證附股權公司債 | | ForeignStock | 5 | 外國股票 | | CGS | 6 | 中央登錄公債 | ##### function\_type[​](#function_type "Direct link to function_type") 功能類別 | Name | Value | | ------------------------------ | ----- | | 新單 | 0 | | 新單執行 | 10 | | 改價 | 15 | | 改量 | 20 | | 刪單 | 30 | | 完全成交(for 委託單歷程查詢) | 50 | | 失敗 | 90 | ##### market[​](#market "Direct link to market") 市場 | Name | Value | | -------- | ------- | | 上市股票 | TAIEX | | 上櫃股票 | TAISDAQ | | 興櫃股票 | TAIEMG | ##### status[​](#status "Direct link to status") 委託單狀態 | Name | Value | | ------------------ | ---------------------------------------------------------- | | 預約單 | 0 | | 系統將委託送往後台 | 4 ( 請用GetOrderResult查詢狀態 ) | | 後台傳送中 | 8 ( 請用GetOrderResult查詢狀態 ) | | 連線逾時 | 9 ( 請稍後再使用GetOrderResult查詢狀態 or 聯絡您的營業員 ) | | 委託成功 | 10 | | 未成交刪單成功 | 30 | | 部分成交,剩餘取消 | 40 | | 完全成交 | 50 | | 改價失敗 | 19 | | 改量失敗 | 29 | | 刪單失敗 | 39 | | 失敗 | 90 | --- ### API Key 登入 apikey\_login 版本資訊 v2.2.7 起新增功能 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | -------------- | | personalID | String | 登入的ID | | key | String | 申請的 API Key | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp std::shared_ptr sdk = std::make_shared(); fubon::LoginResponse res = sdk->apikey_login("PersonalID", "Key", "Cert Path", "Cert Password"); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { isSuccess = true, message = , data = [ Account{ name = 富邦Bill, // 客戶姓名 (string) account = 28, // 客戶帳號 (string) branchNo = 6460, // 分公司代號 (string) accountType = stock // 帳號類型 (string) } ] } ``` --- ### 登入 login #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | ---------- | | personalID | String | 登入的ID | | password | String | 登入的密碼 | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp std::shared_ptr sdk = std::make_shared(); fubon::LoginResponse res = sdk->login("PersonalID", "Password", "Cert Path", "Cert Password"); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { isSuccess = true, message = , data = [ Account{ name = 富邦Bill, // 客戶姓名 (string) account = 28, // 客戶帳號 (string) branchNo = 6460, // 分公司代號 (string) accountType = stock // 帳號類型 (string) } ] } ``` --- ### 刪除批次委託單 batch\_cancel\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | orderResult | [BatchList](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) | 批次取消委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | -------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs // 批次刪單(利用batch detail回傳的內容刪單) std::vector cancel; cancel.push_back(batch_list_res.data.value()[0]); cancel.push_back(batch_list_res.data.value()[1]); // 批次刪單(利用不同的單筆委託) std::vector cancel; cancel.push_back(order_res.data.value()[10]); cancel.push_back(order_res.data.value()[13]); auto batch_cancel = sdk->stock->batch_cancel_order(target_account, cancel); if (!batch_cancel.is_success) { std::cout << "batch_cancel failed reason: " << (batch_cancel.message.has_value() ? batch_cancel.message.value() : "No message") << std::endl; } else { if (batch_cancel.data.has_value()) { std::cout << batch_cancel << std::endl; } else { std::cout << "batch_cancel success but no data returned." << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data =[ OrderResult { // 批次刪單(利用batch detail回傳的內容刪單) functionType = 30, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000308998, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0028, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (float) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (string) isPreOrder = False, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.2, // 有效委託價格 (float) unit = 1000, // 單位數 (int) afterQty = 0, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 5000, // 改單前有效量 (int) beforePrice = 41.2, // 改單前有效價 (float) userDef = 12345678, // 自訂欄位 (string) lastTime = 12:53:57.536, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult { functionType = 30, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 0000030899, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0029, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (float) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (string) isPreOrder = False, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) ... } ] } ``` --- ### 批次修改委託價格 batch\_modify\_price ##### 先使用 make\_modify\_price\_obj 建立 ModifyPriceObj物件[​](#先使用-make_modify_price_obj-建立-modifypriceobj物件 "Direct link to 先使用 make_modify_price_obj 建立 ModifyPriceObj物件") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------- | ---------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 修改後的價格旗標 | caution 當 price 欄位有填入值時,priceType 需為 std::nullopt ; 當 priceType 欄位有填入值時,price 需為 std::nullopt 將回傳的物件放入 batch\_modify\_price 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | ModifyPriceObj | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#modifypriceobj)(list of object) | 批次修改委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp // 批次改價(利用batch detail回傳的內容改單) std::vector modify_orders = { sdk->stock->make_modify_price_obj(batch_list_res.data.value()[0], "41.1", std::nullopt), sdk->stock->make_modify_price_obj(batch_list_res.data.value()[1], "41.2", std::nullopt) }; // 批次改價(利用batch detail回傳的內容改單) std::vector modify_orders = { sdk->stock->make_modify_price_obj(order_res.data.value()[10], "41.1", std::nullopt), sdk->stock->make_modify_price_obj(order_res.data.value()[13], "41.2", std::nullopt) }; auto batch_price = sdk->stock->batch_modify_price(target_account, modify_orders); if (!batch_price.is_success) { std::cout << "batch_price failed reason: " << (batch_price.message.has_value() ? batch_price.message.value() : "No message") << std::endl; } else { if (batch_price.data.has_value()) { std::cout << batch_price << std::endl; } else { std::cout << "batch_price success but no data returned." << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data =[ OrderResult{ // 批次改價(利用batch detail回傳的內容改單) functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000322356, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0018, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.1, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = , // 改單前有效量 (int) beforePrice = 41.3, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 13:56:57.713, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000322355, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0017, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) ... } ] } 以下擷取data內容 [ OrderResult{ // 批次改價(利用不同的單筆委託) functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000322388, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0033, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.1, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = , // 改單前有效量 (int) beforePrice = 41.3, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 10:56:57.713, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000322386, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = "26", // 帳號 (string) orderNo = x0031, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) ... } ] ``` --- ### 批次修改委託數量 batch\_modify\_quantity ##### 先使用 make\_modify\_quantity\_obj 建立 ModifyQuantityObj物件[​](#先使用-make_modify_quantity_obj-建立-modifyquantityobj物件 "Direct link to 先使用 make_modify_quantity_obj 建立 ModifyQuantityObj物件") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 batch\_modify\_price 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | ModifyQuantityObj | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#modifyquantityobj) (list of object) | 批次改量委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | -------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ````cpp // 批次改量(利用batch detail回傳的內容改單) std::vector modify_orders = { sdk->stock->make_modify_quantity_obj(batch_list_res.data.value()[0], 1000), sdk->stock->make_modify_quantity_obj(batch_list_res.data.value()[1], 1000) }; // 批次改價(利用不同的單筆委託) std::vector modify_orders { sdk->stock->make_modify_quantity_obj(order_res.data.value()[10], 1000), sdk->stock->make_modify_quantity_obj(order_res.data.value()[13], 1000) }; auto batch_qty = sdk->stock->batch_modify_quantity(target_account, modify_qty); if (!batch_qty.is_success) { std::cout << "batch_qty failed reason: " << (batch_qty.message.has_value() ? batch_qty.message.value() : "No message") << std::endl; } else { if (batch_qty.data.has_value()) { std::cout << batch_qty << std::endl; } else { std::cout << "batch_qty success but no data returned." << std::endl; } } ## 回傳範例 ```cpp { isSuccess = true, message = , data =[ OrderResult{ // 批次改量(利用batch detail回傳的內容改單) functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000042, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0026, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2881, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (double) userDef = batch 2, // 自訂欄位 (string) lastTime = 12:21:51.023, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ // 批次改量(利用batch detail回傳的內容改單) functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000041, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0025, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2881, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (double) userDef = batch 1, // 自訂欄位 (string) lastTime = 12:21:51.023, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) } ] } 以下擷取data內容 [ OrderResult{ // 批次改量(利用不同的單筆委託) functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000043, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = "26", // 帳號 (string) orderNo = x0027, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MaeketType) stockNo = 2881, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (int) userDef = Test, // 自訂欄位 (string) lastTime = 12:21:53.023, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000044, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0028, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2881, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (string) userDef = Test, // 自訂欄位 (string) lastTime = 12:21:53.023, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) } ] ```` --- ### 取得批次委託明細 batch\_order\_detail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------- | ------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | BatchOrderList | [BatchResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#batchresult) | 批次委託列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | caution 此功能僅供查詢批次送單執行結果,欲取得委託單最新狀態請使用單筆委託單查詢功能 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto batch_list = sdk->stock->batch_order_lists(target_account); auto batch_res = batch_list.data.value()[0]; auto batch_list_res = sdk->stock->batch_order_detail(target_account, batch_res); if (!batch_list_res.is_success) { std::cout << "get order result failed reason: " << (batch_list_res.message.has_value() ? batch_list_res.message.value() : "No message") << std::endl; } else { if (batch_list_res.data.has_value()) { std::cout << batch_list_res << std::endl; } else { std::cout << "Order result success but no data returned." << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data = [ OrderResult{ functionType = , // 功能別 (int) date = 2023/10/18, // 日期 (date) seqNo = 00000000007, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA683, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 8.9, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 8.9, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 改單前有效量 (int) beforePrice = 8.9, // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 14:41:32.647, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMsg = // 錯誤訊息 (string) }, ... ] } ``` --- ### 取得批次委託列表 batch\_order\_lists #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | -------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳批次單資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 批次單 BatchResult 欄位[​](#批次單-batchresult-欄位 "Direct link to 批次單 BatchResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------ | ------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單、 `10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | batch\_seq\_no | string | 批次單流水序號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto batch_list = sdk->stock->batch_order_lists(target_account); if (!batch_list.is_success) { std::cout << "Get batch list result failed reason: " << (batch_list.message.has_value() ? batch_list.message.value() : "No message") << std::endl; } else { if (batch_list.data.has_value()) { std::cout << batch_list << std::endl; } else { std::cout << "Get batch list success but no data returned." << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data = [ BatchResult{ functionType = 0, // 功能種類 (int) date = 2023/10/04, // 交易日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) batchSeqNo = 11EE626533D072228000000C29304663 // 批次單流水序號 (string) }, ... ] } ``` --- ### 建立批次委託單 batch\_place\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------------------------ | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderobject) (list of object) | 委託內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | -------------------------------- | | is\_success | bool | 是否成功 | | message | string | 當isSuccess = False 回傳錯誤訊息 | | data | List | 回傳委託資訊 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp Order order = Order{ BsAction::BUY, "1101", std::nullopt, 1, MarketType::INTRADAY_ODD, PriceType::LIMIT_DOWN, TimeInForce::ROD, OrderType::STOCK, "c++" }; Order order2 = Order{ BsAction::BUY, "1101", std::nullopt, 1, MarketType::INTRADAY_ODD, PriceType::LIMIT_DOWN, TimeInForce::ROD, OrderType::STOCK, "c++" }; std::vector orders; orders.push_back(order); orders.push_back(order2); auto vec_order_result = sdk->stock->batch_place_order(target_account, orders); if (!vec_order_result.is_success) { std::cout << "get order result failed reason: " << (vec_order_result.message.has_value() ? vec_order_result.message.value() : "No message") << std::endl; } else { if (vec_order_result.data.has_value()) { std::cout << vec_order_result << std::endl; } else { std::cout << "Order result success but no data returned." << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data = [ OrderResult{ functionType = 0, // 功能別 (int) date = 2023/09/22, // 交易日期 (string) seqNo = 00000221431, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = , // 委託書號 (string) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stock_no = 2888, // 股票代號 (string) buy_sell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 8.9, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = true, // 是否為預約單 (bool) status = 0, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 8.9, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 異動前有效量 (int) beforePrice = 9.1, // 異動前有效價 (double) userDef = null, // 自定義欄位 (string) lastTime = null, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ functionType = 0, // 功能別 (int) date = 2023/09/22, // 交易日期 (string) seqNo = 00000221432, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = , // 委託書號 (string) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stock_no = 2888, // 股票代號 (string) buy_sell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 8.9, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = true, // 是否為預約單 (bool) status = 0, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 8.9, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 異動前有效量 (int) beforePrice = 9.1, // 異動前有效價 (double) userDef = , // 自定義欄位 (string) lastTime =, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } ] } ``` --- ### 刪除委託單 cancel\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------- | ------------------ | | account | Account | 帳號 | | orderResult | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) | 欲取消的委託單物件 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | OrderResult | 回傳修改資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto target_order = order_results_response.data.value()[0]; auto cancel_response = sdk->stock->cancel_order(target_account, target_order, std::nullopt); if (!cancel_response.is_success) { std::cout << "Cancel failed. Message: " << (cancel_response.message.has_value() ? cancel_response.message.value() : "No message") << std::endl; return 0; } // 搭配自定義 .cpp & hpp Output if (cancel_response.data.has_value()) { const fubon::OrderResult& data = cancel_response.data.value(); std::cout << "Cancel Success" << std::endl; std::cout << data << std::endl; } else { std::cout << "Order succeeded but no data returned." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = true, message = , data = OrderResult { functionType = 30, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000308948, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0023, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = COMMON, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = SELL, // 買賣別 (BSAction) priceType = LIMIT, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = ROD, // 委託條件別 (TimeInforce) orderType = STOCK, // 委託單類型 (string) isPreOrder = false, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) afterPriceType = LIMIT, // 有效委託價格別 (PriceType) afterPrice = 41.2, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 0, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 5000, // 改單前有效量 (int) beforePrice = 41.2, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 12:53:57.536, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } } ``` --- ### 現冲券配額查詢 daytrade\_and\_stock\_info #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | stockNo | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | DayTradeStockInfo | 回傳配額資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 配額資訊 DayTradeStockInfo 欄位[​](#配額資訊-daytradestockinfo-欄位 "Direct link to 配額資訊 DayTradeStockInfo 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------- | | stock\_no | string | 股票代號 | | date | string | 日期 | | daytrade\_orig\_quota | int | 原始現冲券餘額 | | daytrade\_tradable\_quota | int | 可用現冲券餘額 | | precollect\_single | int | 單筆預收股數 (若不需預收則回傳空值) | | precollect\_accumulate | int | 累積預收股數 (若不需預收則回傳空值) | | status | int | 狀態 (bitmask 加總) : `0` 全禁 、 `1` 平盤下可融券賣出、 `2` 平盤下可借券賣出、 `4` 可先買後賣當沖 、 `8`可先賣後買當沖 | info status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto daytrade_quo = sdk->stock->daytrade_and_stock_info(target_account, "2330"); // 搭配自定義 .cpp & hpp Output if (daytrade_quo.is_success && daytrade_quo.data.has_value()) { std::cout << daytrade_quo.data.value() << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ DayTradeStockInfo{ stockNo = 3264, // 股票代號 (string) date = 2023/10/04, // 日期 (string) daytradeOrigQuota = 0, // 原始現冲券餘額 (int) daytradeTradableQuota = 0, // 可用現冲券餘額 (int) precollectSingle = , // 單筆預收股數 (int) precollectAccumulate = , // 累積預收股數 (int) status = 0 // 狀態 (int) }] } ``` --- ### 查詢歷史成交 FilledHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | ----------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string (空值預設與開始日相同) | 查詢終止日 | info v2.1.1起可查詢長期歷史資料,每次查詢最大設定30日日期區間;v2.1.0之前版本可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳成交資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 成交資訊 FilledData 欄位[​](#成交資訊-filleddata-欄位 "Direct link to 成交資訊 FilledData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | date | date | 成交日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | seq\_no | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | order\_no | string | 委託書號 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | filled\_no | string | 成交流水號 | | filled\_avg\_price | double | 成交均價 | | filled\_qty | int | 成交股數 | | filled\_price | double | 成交單價 | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | filled\_time | string | 成交時間 | | user\_def | string | 自訂欄位 (只有主動回報才回傳此欄位) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto history_filled_response = sdk->stock->filled_history(target_account, "20250401", "20250501"); if (!history_filled_response.is_success) { std::cerr << "Filled data query failed: " << (history_filled_response.message ? *history_filled_response.message : "No message") << std::endl; return 1; } // 搭配自定義 .cpp & hpp Output if (history_filled_response.data.has_value()) { const auto& filled_list = history_filled_response.data.value(); for (const auto& filled : filled_list) { std::cout << filled << "\n\n"; } } else { std::cout << "No filled data returned." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = True, message = , data = [ FilledData{ date = 2025/04/29, // 成交日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) seqNo = , // 委託流水序號 (string) orderNo = bA422, // 委託書號 (string) stockNo = 1101, // 股票代號 (string) buySell = SELL, // 買賣別 (BSAction) filledNo = 00000000001, // 成交流水號 (string) filledAvgPrice = 35.2, // 成交均價 (double) filledQty = 1000, // 成交股數 (int) filledPrice = 35.2, // 成交單價 (double) orderType = STOCK, // 委託單類型 (OrderType) filledTime = 10:31:00.931 // 成交時間 (string) userDef = , // 用戶自定義 (string) }, ... ] } ``` --- ### 取得委託單結果 GetOrderResult #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto order_results_response = sdk->stock->get_order_results(target_account); // 搭配自定義 .cpp & hpp Output if (!order_results_response.is_success) { std::cout << "get order result failed reason: " << (order_results_response.message.has_value() ? order_results_response.message.value() : "No message") << std::endl; } else { if (order_results_response.data.has_value()) { for (const auto& result : order_results_response.data.value()) { std::cout << result << std::endl; } } else { std::cout << "Order result success but no data returned." << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { isSuccess = true, message = , data = [ OrderResult{ functionType = , // 功能別 (int) date = 2023/10/13, // 交易日期 (string) seqNo = 00000000002, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA614, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = COMMON, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = BUY, // 買賣別 (BSAction) priceType = LIMIT, // 原始委託價格別 (int) price = 9.0, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = ROD, // 委託條件別 (TimeInForce) orderType = STOCK, // 委託單類型 (OrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = LIMIT, // 有效委託價格別 (PriceType) afterPrice = 9.0, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 改單前有效量 (int) beforePrice = 9.0, // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 10:05:54.608, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMsg = // 錯誤訊息 (string) }, ... ] } ``` --- ### 取得委託單結果 (含歷程) GetOrderResultDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branc\_no | string | 分公司代號 | | account | string | 帳號 | | orde\_no | string | 委託書號 | | asse\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marke\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | error\_message | string | 錯誤訊息 | | details | list | 委託歷程 | | >> function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modified\_time | string | 修改時間 | | >> before\_qty | int | 原始委託股數 | | >> after\_qty | int | 有效委託股數(包含已成交部分) | | >> before\_price | double | 原始委託價 | | >> after\_price | double | 有效委託價 | | >> filled\_money | double | 成交價金 | | >> status | int | 委託單狀態 | | >> err\_msg | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto order_results_response = sdk->stock->get_order_results_detail(target_account); // 搭配自定義 .cpp & hpp Output if (!order_results_response.is_success) { std::cout << "get order result failed reason: " << (order_results_response.message.has_value() ? order_results_response.message.value() : "No message") << std::endl; } else { if (order_results_response.data.has_value()) { for (const auto& result : order_results_response.data.value()) { std::cout << result << std::endl; } } else { std::cout << "Order result success but no data returned." << std::endl; } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { isSuccess = true, message = , data = [ OrderResult{ functionType = , // 功能別 (int) date = 2023/10/13, // 交易日期 (string) seqNo = 00000000002, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA614, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = COMMON, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = BUY, // 買賣別 (BSAction) priceType = LIMIT, // 原始委託價格別 (int) price = 9.0, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = ROD, // 委託條件別 (TimeInForce) orderType = STOCK, // 委託單類型 (OrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = LIMIT, // 有效委託價格別 (PriceType) afterPrice = 9.0, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 改單前有效量 (int) beforePrice = 9.0, // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 10:05:54.608, // 最後異動時間 (string) errorMsg = // 錯誤訊息 (string) details = [ OrderDetail{ functionType = 10, modifiedTime = 10:05:54.608, beforeQty = 0, afterQty = 2000, beforePrice = 9.0, afterPrice = 9.0, status = 10, errorMsg = } ] }, ... ] } ``` --- ### 資券配額查詢 margin\_quota #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | stockNo | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ---------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | MarginShortQuota | 回傳配額資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 配額資訊 MarginShortQuota 欄位[​](#配額資訊-marginshortquota-欄位 "Direct link to 配額資訊 MarginShortQuota 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------------------- | ------ | ------------ | | stock\_no | string | 股票代號 | | date | string | 日期 | | shortsell\_orig\_quota | int | 原始融券餘額 | | shortsell\_tradable\_quota | int | 可用融券餘額 | | margin\_orig\_quota | int | 原始融資餘額 | | margin\_tradable\_quota | int | 可用融資餘額 | | margin\_ratio | int | 融資成數 | | short\_ratio | int | 融券成數 | info 額度相關說明 : 融資成數回傳空值表示停資;融券成數回傳空值表示停券,
回傳的額度說明 : 0 - 無額度 / 大於0 - 有額度 / 空值 - 無限制 / 餘額皆為 0 - 停資 or 停券 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto quota_response = sdk->stock->margin_quota(target_account, "2330"); if (!quota_response.is_success) { std::cerr << "Quota query failed: " << (quota_response.message ? *quota_response.message : "No message") << std::endl; return 1; } // 搭配自定義 .cpp & hpp Output if (quota_response.data.has_value()) { const auto& quota = quota_response.data.value(); std::cout << quota << std::endl; } else { std::cout << "No quota data available." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = True, message = , data = MarginShortQuota{ stockNo = 2330, date = 2024/01/24, shortsellOrigQuota = 894, shortsellTradableQuota = 894, marginOrigQuota = , marginTradableQuota = , marginRatio = 60, shortRatio = 90 } } ``` --- ### 修改委託價格 modify\_price ##### 先使用 make\_modify\_price\_obj 建立 ModifyPriceObj物件[​](#先使用-make_modify_price_obj-建立-modifypriceobj物件 "Direct link to 先使用 make_modify_price_obj 建立 ModifyPriceObj物件") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------- | ---------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 修改後的價格旗標 | caution 當 price 欄位有填入值時,priceType 需為 std::nullopt ; 當 priceType 欄位有填入值時,price 需為 std::nullopt 將回傳的物件放入 modifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------------- | ------------------------------------------------------------------------------------------------------- | -------------- | | account | Account | 帳號 | | modifiedPriceObj | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#modifypriceobj) | 修改價格的物件 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | OrderResult | 回傳修改資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp // 先取得欲調整的委託單 auto order_results_response = sdk->stock->get_order_results(target_account); auto target_order = order_results_response.data.value()[0]; auto modify_price_obj = sdk->stock->make_modify_price_obj(target_order, "41.1", std::nullopt); auto modify_price_response = sdk->stock->modify_price(target_account, modify_price_obj, std::nullopt); // 搭配自定義 .cpp & hpp Output if (!modify_price_response.is_success) { std::cout << "Modify Price failed. Message: " << (modify_price_response.message.has_value() ? modify_price_response.message.value() : "No message") << std::endl; return 0; } if (modify_price_response.data.has_value()) { const fubon::OrderResult& data = modify_price_response.data.value(); std::cout << "Modify Price Success" << std::endl; std::cout << data << std::endl; } else { std::cout << "Order succeeded but no data returned." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { isSuccess = True, message = , data = OrderResult { functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000308866, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0011, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = COMMON, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = SELL, // 買賣別 (BsAction) priceType = LIMIT, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = ROD, // 委託條件別 (TimeInForce) orderType = STOCK, // 委託單類型 (OrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = LIMIT, // 有效委託價格別 (PriceType) afterPrice = 41.1, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = , // 改單前有效量 (int) beforePrice = 41.3, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 10:56:57.713, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } } ``` --- ### 修改委託單數量 modify\_quantity ##### 先使用 make\_modify\_quantity\_obj 建立 ModifyQuantityObj物件[​](#先使用-make_modify_quantity_obj-建立-modifyquantityobj物件 "Direct link to 先使用 make_modify_quantity_obj 建立 ModifyQuantityObj物件") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 ModifyQuantity 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | ------------------------------------------------------------------------------------------------------------- | -------------- | | account | Account | 帳號 | | ModifyQuantityObj | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#modifyquantityobj) | 修改的委託單 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | OrderResult | 回傳修改資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp // 先取得欲調整的委託單 auto order_results_response = sdk->stock->get_order_results(target_account); auto target_order = order_results_response.data.value()[0]; auto modify_quantity_obj = sdk->stock->make_modify_quantity_obj(target_order, 1000); // 只能減量 auto modify_quantity_response = sdk->stock->modify_quantity(target_account, modify_quantity_obj, std::nullopt); // 搭配自定義 .cpp & hpp Output if (!modify_quantity_response.is_success) { std::cout << "Modify Qty failed. Message: " << (modify_quantity_response.message.has_value() ? modify_quantity_response.message.value() : "No message") << std::endl; return 0; } if (modify_quantity_response.data.has_value()) { const fubon::OrderResult& data = modify_quantity_response.data.value(); std::cout << "Modify Qty Success" << std::endl; std::cout << data << std::endl; } else { std::cout << "Order succeeded but no data returned." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { isSuccess = true, message = , data = OrderResult{ functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000308866, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0011, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = COMMON, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = SELL, // 買賣別 (string) priceType = LIMIT, // 原始委託價格別 (string) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = ROD, // 委託條件別 (TimeInForce) orderType = STOCK, // 委託單類型 (OrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = LIMIT, // 有效委託價格別 (PriceType) afterPrice = 41.3, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 3000, // 改單前有效量 (int) beforePrice = 41.2, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 12:56:28.966, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } } ``` --- ### 查詢歷史委託 order\_history #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | ----------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string (空值預設與開始日相同) | 查詢終止日 | info v2.1.1起可查詢長期歷史資料,每次查詢最大設定30日日期區間;v2.1.0之前版本可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branc\_no | string | 分公司代號 | | account | string | 帳號 | | orde\_no | string | 委託書號 | | asse\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marke\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | error\_message | string | 錯誤訊息 | | details | list | 委託歷程 | | >> function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modified\_time | string | 修改時間 | | >> before\_qty | int | 原始委託股數 | | >> after\_qty | int | 有效委託股數(包含已成交部分) | | >> before\_price | double | 原始委託價 | | >> after\_price | double | 有效委託價 | | >> filled\_money | double | 成交價金 | | >> status | int | 委託單狀態 | | >> err\_msg | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto history_order_response = sdk->stock->order_history(target_account, "20250502", "20250502"); if (!history_order_response.is_success) { std::cerr << "order_history failed: " << (history_order_response.message ? *history_order_response.message : "No message") << std::endl; return 1; } // 搭配自定義 .cpp & hpp Output if (history_order_response.data.has_value()) { for (const auto& result : *history_order_response.data) { std::cout << result << std::endl; } } else { std::cout << "No order history data." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { isSuccess = true, message = , data = [ OrderResult{ functionType = , // 功能別 (int) date = 2025/05/02, // 交易日期 (string) seqNo = 00000000001, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA598, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = COMMON, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = BUY, // 買賣別 (BSAction) priceType = LIMIT, // 原始委託價格別 (PriceType) price = 8.9, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = ROD, // 委託條件別 (TimeInForce) orderType = STOCK, // 委託單類型 (OrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 9, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = , // 改單前有效量 (int) beforePrice = , // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 14:19:41.879, // 最後異動時間 (string) details = [ OrderDetail{ functionType = 10, modifiedTime = 14:19:41.879, beforeQty = 0, afterQty = 1000, beforePrice = 9.0, afterPrice = 9.0, status = 10, errorMsg = } ] errorMsg = // 錯誤訊息 (string) }, ... ] } ``` --- ### 建立委託單 place\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | orderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#orderobject) | 委託內容 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | OrderResult | 回傳委託資訊 | | message | string | 當is\_success = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) | 盤別種類 : `COMMON` 整股 、 `FIXING` 定盤 、 `INTRADAY_ODD` 盤中零股 、 `ODD` 盤後零股 、 `EMG` 興櫃 、 `EMG_ODD` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#bsaction) | 買賣別 : `BUY` 買 、 `SELL` 賣 | | pric\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#ordertype) | 委託單類型 : `STOCK` 現股 、 `MARGIN` 融資 、 `SHORT` 融券 、 `DAY_TRADE` 現股當沖 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30`未成交刪單成功 、 `40`部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#pricetype) | 有效委託價格別 : `LIMIT` 限價 、 `LIMIT_UP` 漲停 、 `LIMIT_DOWN` 跌停 、 `MARKET` 市價 、 `REFERENCE` 參考價 | | after\_price | double | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp Order order = Order{ BsAction::BUY, "2888", "9.0", 1, MarketType::INTRADAY_ODD, PriceType::LIMIT, TimeInForce::ROD, OrderType::STOCK, "c++" }; auto order_result = sdk->stock->place_order(target_account, order, false); // 搭配自定義 .cpp & hpp Output if (!order_result.is_success) { std::cout << "Order failed. Message: " << (order_result.message.has_value() ? order_result.message.value() : "No message") << std::endl; return 0; } if (order_result.data.has_value()) { const fubon::OrderResult& data = order_result.data.value(); std::cout << data << std::endl; } else { std::cout << "Order succeeded but no data returned." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp // 搭配自定義 .cpp & hpp Output { isSuccess = true, message = , data = OrderResult{ functionType = 0, // 功能別 (int) date = 2023/10/13, // 交易日期 (string) seqNo = 00000000007, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA619, // 委託書號 (string) assetType = 0, // 資產類型 (int) market = TAIEX, // 市場類型 (string) marketType = COMMON, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = BUY, // 買賣別 (BSAction) priceType = LIMIT, // 原始委託價格別 (PriceType) price = 9.1, // 價格 (double) quantity = 3000, // 原始委託股數 (int) timeInForce = ROD, // 委託條件別 (TimeInForce) orderType = STOCK, // 委託單類型 (OrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = LIMIT, // 有效委託價格別 (PriceType) afterPrice = 9.1, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 3000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 改單前有效量 (int) beforePrice = 9.1, // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 12:10:12.546, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMsg = // 錯誤訊息 (string) } } ``` --- ### 查詢股票報價資訊 query\_symbol\_quote #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | symbol | String | 股票代碼 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回��傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolQuote | 回傳查詢資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 商品資訊 SymbolQuote 欄位[​](#商品資訊-symbolquote-欄位 "Direct link to 商品資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類型 | 說明 | | ------------------ | ------ | ---------------------- | | market | string | 市場別 | | symbol | string | 股票代碼 | | is\_tib\_or\_psb | bool | 是否為創新版或戰略新板 | | market\_type | string | 市場類型 | | status | int | 狀態 (bitmask 加總) | | reference\_price | double | 參考價格 | | unit | string | 交易單位 | | update\_time | string | 更新時間 | | limitup\_price | double | 漲停價 | | limitdown\_price | double | 跌停價 | | open\_price | double | 開盤價 | | high\_price | double | 最高價 | | low\_price | double | 最低價 | | last\_price | double | 最新成交價 | | total\_volume | int | 總成交量 | | total\_transaction | int | 總成交筆數 | | total\_value | double | 總成交金額 | | last\_size | int | 最新成交量 | | last\_transaction | int | 最新成交筆數 | | last\_value | double | 最新成交金額 | | bid\_price | double | 買1價格 | | bid\_volume | int | 買1數量 | | ask\_price | double | 賣1價格 | | ask\_volume | int | 賣1數量 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp auto query_quote = sdk->stock->query_symbol_quote(target_account,"2330"); //auto query_quote = sdk->stock->query_symbol_quote(target_account, "2330", MarketType::INTRADAY_ODD); // 搭配自定義 .cpp & hpp Output if (!query_quote.is_success) { std::cout << "get query. Message: " << (query_quote.message.has_value() ? query_quote.message.value() : "No message") << std::endl; return 0; } if (query_quote.data.has_value()) { const fubon::SymbolQuote& data = query_quote.data.value(); std::cout << data << std::endl; } else { std::cout << "Query Quote succeeded but no data returned." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = True, message = , data = SymbolQuote{ market = TAIEX, // string - 市場別 symbol = 2330, // string - 股票代碼 istibOrPsb = False, // bool - 是否為創新板或戰略新板 marketType = Common, // string - 市場類型 (現股) status = 15, // int - 狀態 (bitmask 加總: 1+2+4+8 = 可融券賣出+可借券賣出+可先買後賣當沖+可先賣後買當沖) referencePrice = 780, // double - 參考價格 (前一交易日收盤價) unit = 1000, // int - 交易單位 updateTime = , // string - 更新時間 limitupPrice = 858, // double - 漲停價 limitdownPrice = 702, // double - 跌停價 openPrice = 1155, // double - 開盤價 highPrice = 1160, // double - 最高價 lowPrice = 1145, // double - 最低價 lastPrice = 1145, // double - 最新成交價 totalVolume = 20501, // int - 總成交量 totalTransaction = 0, // int - 總成交筆數 totalValue = 23551095000, // int - 總成交金額 lastSize = 6673, // int - 最新成交量 lastTransaction = 0, // int - 最新成交筆數 lastValue = 7640585000, // int - 最新成交金額 bidPrice = 1145, // double - 買一價格 bidVolume = 1549, // int - 買一數量 askPrice = 1150, // double - 賣一價格 askVolume = 4169 // int - 賣一數量 } } ``` --- ### 查詢市場漲跌幅 query\_symbol\_snapshot #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | | stock\_type | List [StockType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#stocktype) (Optional)(default = Stock) | 股票分類別 : `Stock` 股票、`ConvertBond` 可轉債、`ETF_and_ETN` ETF 與 ETN | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolSnapshotResponse | 回傳查詢資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 商品資訊 SymbolQuote 欄位[​](#商品資訊-symbolquote-欄位 "Direct link to 商品資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類型 | 說明 | | ------------------ | ------ | ---------------------- | | market | string | 市場別 | | symbol | string | 股票代碼 | | is\_tib\_or\_psb | bool | 是否為創新版或戰略新板 | | market\_type | string | 市場類型 | | status | int | 狀態 (bitmask 加總) | | reference\_price | double | 參考價格 | | unit | int | 交易單位 | | update\_time | string | 更新時間 | | limitup\_price | double | 漲停價 | | limitdown\_price | double | 跌停價 | | open\_price | double | 開盤價 | | high\_price | double | 最高價 | | low\_price | double | 最低價 | | last\_price | double | 最新成交價 | | total\_volume | int | 總成交量 | | total\_transaction | int | 總成交筆數 | | total\_value | double | 總成交金額 | | last\_size | int | 最新成交量 | | last\_transaction | int | 最新成交筆數 | | last\_value | double | 最新成交金額 | | bid\_price | double | 買1價格 | | bid\_volume | int | 買1數量 | | ask\_price | double | 賣1價格 | | ask\_volume | int | 賣1數量 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cpp // auto query_snapshot = sdk->stock->query_symbol_snapshot(target_account, MarketType::COMMON, std::nullopt); auto query_snapshot = sdk->stock->query_symbol_snapshot(target_account, MarketType::COMMON, std::vector{ StockType::COVERT_BOND }); if (!query_snapshot.is_success) { std::cout << "get snapshot failed reason: " << (query_snapshot.message.has_value() ? query_snapshot.message.value() : "No message") << std::endl; } if (query_snapshot.data.has_value()) { // std::cout << "Data list size: " << query_snapshot.data.value().size() << std::endl << std::endl; const auto& quotes = query_snapshot.data.value(); // vector for (const auto& quote : quotes) { std::cout << quote << std::endl; } } else { std::cout << "get snapshot success but no data returned." << std::endl; } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cpp { isSuccess = True, message = , data = SymbolQuote{ market = TAIEX, // string - 市場別 symbol = 2330, // string - 股票代碼 istibOrPsb = False, // bool - 是否為創新板或戰略新板 marketType = Common, // string - 市場類型 (現股) status = 15, // int - 狀態 (bitmask 加總: 1+2+4+8 = 可融券賣出+可借券賣出+可先買後賣當沖+可先賣後買當沖) referencePrice = 780, // double - 參考價格 (前一交易日收盤價) unit = 1000, // int - 交易單位 updateTime = , // string - 更新時間 limitupPrice = 858, // double - 漲停價 limitdownPrice = 702, // double - 跌停價 openPrice = 1155, // double - 開盤價 highPrice = 1160, // double - 最高價 lowPrice = 1145, // double - 最低價 lastPrice = 1145, // double - 最新成交價 totalVolume = 20501, // int - 總成交量 totalTransaction = 0, // int - 總成交筆數 totalValue = 23551095000, // int - 總成交金額 lastSize = 6673, // int - 最新成交量 lastTransaction = 0, // int - 最新成交筆數 lastValue = 7640585000, // int - 最新成交金額 bidPrice = 1145, // double - 買一價格 bidVolume = 1549, // int - 買一數量 askPrice = 1150, // double - 賣一價格 askVolume = 4169 // int - 賣一數量 }, { market = TAIEX, // string - 市場別 symbol = 2330, // string - 股票代碼 ... } } ``` --- ### 銀行餘額查詢 BankRemain #### 輸入參數[​](#輸入參數 "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 | BankRemain | 回傳餘額資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 餘額資訊 BankRemain 欄位[​](#餘額資訊-bankremain-欄位 "Direct link to 餘額資訊 BankRemain 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------ | ---------- | | branchNo | string | 分公司代號 | | account | string | 帳號 | | currency | string | 幣別 | | balance | int | 餘額 | | availableBalance | int | 可用餘額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs sdk.Accounting.BankRemain(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = BankRemain{ branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) currency = TWD, // 幣別 (string) balance = 666666, // 餘額 (int) availableBalance = 123456 // 可用餘額 (int) } } ``` --- ### 庫存查詢 Inventories #### 輸入參數[​](#輸入參數 "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 | 當isSuccess = False 回傳錯誤訊息 | ##### 庫存資訊 Inventory 欄位[​](#庫存資訊-inventory-欄位 "Direct link to 庫存資訊 Inventory 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------- | | > date | string | 交易日期 | | > account | string | 帳號 | | > branchNo | string | 分公司代號 | | > stockNo | string | 股票代號 | | > orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣、`SBL`借券 | | > lastdayQty | int | 昨日庫存餘額 | | > buyQty | int | 今日委買股數 | | > buyFilledQty | int | 今日買進成交股數 | | > buyValue | int | 買進價金 | | > todayQty | int | 今日庫存餘額 | | > tradableQty | int | 可委託股數 | | > sellQty | int | 今日委賣股數 | | > sellFilledQty | int | 今日賣出成交股數 | | > sellValue | int | 賣出價金 | | > odd | list | Object | | >> lastdayQty | int | 昨日庫存餘額 | | >> buyQty | int | 今日委買股數 | | >> buyFilledQty | int | 今日買進成交股數 | | >> buyValue | int | 買進價金 | | >> todayQty | int | 今日庫存餘額 | | >> tradableQty | int | 可委託股數 | | >> sellQty | int | 今日委賣股數 | | >> sellFilledQty | int | 今日賣出成交股數 | | >> sellValue | int | 賣出價金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Accounting.Inventories(account)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ Inventory{ date = 2023/10/13, // 交易日期 (string) account = 26, // 帳號 (string) branchNo = 6460, // 分公司代號 (string) stockNo = 1101, // 股票代號 (string) orderType = Stock, // 委託單類型 (OrderType) lastdayQty = 2000, // 昨日庫存餘額 (int) buyQty = 0, // 今日委買股數 (int) buyFilledQty = 0, // 今日買進成交股數 (int) buyValue = 0, // 買進價金 (int) todayQty = 2000, // 今日庫存餘額 (int) tradableQty = 2000, // 可委託股數 (int) sellQty = 0, // 今日委賣股數 (int) sellFilledQty = 0, // 今日賣出成交股數 (int) sellValue = 0, // 賣出價金 (int) odd = InventoryOdd { // 委託單狀態 (InventoryOdd 物件) lastdayQty = 0, // 昨日庫存餘額 (int) buyQty = 0, // 今日委買股數 (int) buyFilledQty = 0, // 今日買進成交股數 (int) buyValue = 0, // 買進價金 (int) todayQty = 0, // 今日庫存餘額 (int) tradableQty = 0, // 可委託股數 (int) sellQty = 0, // 今日委賣股數 (int) sellFilledQty = 0, // 今日賣出成交股數 (int) sellValue = 0 // 賣出價金 (int) } }, ... ] } ``` --- ### 維持率查詢 Maintenance #### 輸入參數[​](#輸入參數 "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 | MaintenanceData | 回傳維持率資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 維持率 MaintenanceData 欄位[​](#維持率-maintenancedata-欄位 "Direct link to 維持率 MaintenanceData 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- | | MaintenanceData | list | Object | | > date | string | 查詢日 | | > branchNo | string | 分公司代號 | | > account | string | 帳號 | | > maintenanceSummary | list | Object | | >> marginValue | int | 整戶融資市值 | | >> shortsellValue | int | 整戶融券市值 | | >> shortsellMargin | int | 整戶融券保證金額 | | >> collateral | int | 擔保品 | | >> marginLoanAmt | int | 整戶融資金額 | | >> maintenanceRatio | double | 整戶維持率 | | > MaintenanceDetail | list | Object | | >> stockNo | string | 股票代碼 | | >> orderNo | string | 委託書號 | | >> orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、`SBL`借券 | | >> quantity | int | 持有股數 | | >> price | double | 計算價 | | >> costPrice | double | 成本價 | | >> shortsellMargin | int | 融券保證金 | | >> collateral | int | 擔保品 | | >> marginLoanAmt | int | 融資金 | | >> maintenanceRatio | double | 維持率 | | >> collateralInterest | double | 擔保品利息 | | >> marginInterest | double | 融資金利息 | | >> shortsellInterest | double | 融券保證金利息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Accounting.Maintenance(target_user)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = MaintenanceData { date = 2024/02/27, branchNo = 6460, account = 26, maintenanceSummary = MaintenanceSummary { marginValue = 3135000, shortsellValue = 0, shortsellMargin = 0, collateral = 0, marginLoanAmt = 1494000, maintenanceRatio = 209.83 }, maintenanceDetail = [{ stockNo = 2603, orderNo = x4580, orderType = Stock, quantity = 10000, price = 152.5, costPrice = 119, shortsellMargin = 0, collateral = 0, marginLoanAmt = 0, maintenanceRatio = 213.58, collateralInterest = 0, marginInterest = 20818, shortsellInterest = 0 }, ... ], } } ``` --- ### 交割款查詢 QuerySettlement #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | -------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | range | string | 時間區間,目前有效值為"0d"(當日)、"3d" | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | -------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SettlementData | 回傳交割資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 交割資訊 SettlementData 欄位[​](#交割資訊-settlementdata---欄位 "Direct link to 交割資訊 SettlementData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------------ | ----------------- | ------------------------------- | | > account | object | Object | | >> account | string | 帳號 | | >> branchNo | string | 分公司代號 | | > details | list | Object | | >> date | string | 查詢日 | | >> settlementDate | string (Optional) | 交割日 (若查無資料為空值) | | >> buyValue | int (Optional) | 買進金額 (若查無資料為空值) | | >> buyFee | int (Optional) | 買進手續費 (若查無資料為空值) | | >> buySettlement | int (Optional) | 買進應收付款 (若查無資料為空值) | | >> buyTax | int (Optional) | 買進交易稅 (若查無資料為空值) | | >> sellValue | int (Optional) | 賣出金額 (若查無資料為空值) | | >> sellFee | int (Optional) | 賣出手續費 (若查無資料為空值) | | >> sellSettlement | int (Optional) | 賣出應收付款 (若查無資料為空值) | | >> sellTax | int (Optional) | 賣出交易稅 (若查無資料為空值) | | >> totalBsValue | int (Optional) | 合計買賣金額 (若查無資料為空值) | | >> totalFee | int (Optional) | 合計手續費 (若查無資料為空值) | | >> totalTax | int (Optional) | 合計交易稅 (若查無資料為空值) | | >> totalSettlementAmount | int (Optional) | 合計交割金額 (若查無資料為空值) | | >> currency | string (Optional) | 幣別 (若查無資料為空值) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Accounting.QuerySettlement(target_user,"3d")); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = SettlementData{ account = AccountRes { // 帳戶資訊 account = 26, // 帳號 (string) branchNo = 6460 // 分公司代號 (string) }, details = [ Settlement{ // 交割資訊 date = 2024/03/04, // 查詢日 (string) settlementDate = 2024/03/06, // 交割日期 (string) buyValue = 735500, // 買進金額 (int) buyFee = 313, // 買進費用 (int) buySettlement = -1429513, // 買進應收付款 (int) buyTax = 0, // 買進交易稅 (int) sellValue = 770500, // 賣出金額 (int) sellFee = 320, // 賣出費用 (int) sellSettlement = 0, // 賣出應收付款 (int) sellTax = 2309, // 賣出交易稅 (int) totalBsValue = 1506000, // 合計買賣金額 (int) totalFee = 633, // 合計手續費 (int) totalSettlementAmount = -1429513, // 合計交割款金額 (int) totalTax = 2309, // 合計交易稅 (int) currency = TWD // 幣別 (string) }, Settlement{ date = 2024/03/05, // 查詢日 (string) settlementDate = 2024/03/07, // 交割日期 (string) buyValue = 2261470, // 買進金額 (int) buyFee = 1065, // 買進費用 (int) buySettlement = -3895335, // 買進應收付款 (int) buyTax = 0, // 買進交易稅 (int) sellValue = 2488170, // 賣出金額 (int) sellFee = 1137, // 賣出費用 (int) sellSettlement = 677626, // 賣出應收付款 (int) sellTax = 7412, // 賣出交易稅 (int) totalBsValue = 4749640, // 合計買賣金額 (int) totalFee = 2202, // 合計買賣手續費 (int) totalSettlementAmount = -3217709, // 合計交割款金額 (int) totalTax = 7412, // 合計交易稅 (int) currency = TWD // 幣別 (string) }, Settlement{ date = 2024/03/06, // 查詢日 (string) settlementDate = , // 交割日期 (string) buyValue = , // 買進金額 (int) buyFee = , // 買進費用 (int) buySettlement = , // 買進應收付款 (int) buyTax = , // 買進交易稅 (int) sellValue = , // 賣出金額 (int) sellFee = , // 賣出費用 (int) sellSettlement = , // 賣出應收付款 (int) sellTax = , // 賣出交易稅 (int) totalBsValue = , // 合計買賣金額 (int) totalFee = , // 合計買賣手續費 (int) totalSettlementAmount = , // 合計交割款金額 (int) totalTax = , // 合計交易稅 (int) currency = // 幣別 (string) } ] } } ``` --- ### 已實現損益查詢 RealizedGainsAndLoses #### 輸入參數[​](#輸入參數 "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 | 當isSuccess = False 回傳錯誤訊息 | ##### 已實現 Realized 欄位[​](#已實現-realized--欄位 "Direct link to 已實現 Realized 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- | | date | string | 資料日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | filledQty | int | 成交股數 | | filledPrice | double | 成交價 | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、`SBL`借券 | | realizedProfit | int | 已實現獲利金額 | | realizedLoss | int | 已實現損失金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Accounting.RealizedGainsAndLoses(account)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data =[ Realized{ date = 2023/08/16, // 資料日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) filledQty = 1000, // 成交股數 (int) filledPrice = 36.5, // 成交價 (double) orderType = Stock, // 委託單類型 (OrderType) realizedProfit = 36339, // 已實現獲利金額 (int) realizedLoss = 0 // 已實現損失金額 (int) }, ... ] } ``` --- ### 已實現損益彙總 RealizedGainsAndLosesSummary #### 輸入參數[​](#輸入參數 "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 | 當isSuccess = False 回傳錯誤訊息 | ##### 已實現彙總 RealizedSummary 欄位[​](#已實現彙總-realizedsummary-欄位 "Direct link to 已實現彙總 RealizedSummary 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- | | startDate | string | 彙總起始日 | | endDate | string | 彙總截止日 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL` 借券 | | filledQty | int | 成交股數 | | filledAvgPrice | double | 成交均價 | | realizedProfitAndLoss | int | 已實現損益金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Accounting.RealizedGainsAndLosesSummary(account)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ RealizedSummary{ startDate = 20230801, // 起始日期 (string) endDate = 20230801, // 截止日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) orderType = Stock, // 委託單類型 (OrderType) filledQty = 3000, // 成交股數 (int) filledAvgPrice = 35.7, // 成交均價 (double) realizedProfitAndLoss = 34026 // 已實現損益金額 (int) }, ... ] } ``` --- ### 未實現損益查詢 UnrealizedGainsAndLoses #### 輸入參數[​](#輸入參數 "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 | 當isSuccess = False 回傳錯誤訊息 | ##### 未實現 UnrealizedData 欄位[​](#未實現-unrealizeddata-欄位 "Direct link to 未實現 UnrealizedData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | | date | string | 查詢當天日期 | | branchNo | string | 分公司代號 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 (**註**:請見表末說明) | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | costPrice | double | 成本價 | | tradableQty | int | 可交易餘額 | | todayQty | int | 今日餘額 | | unrealizedProfit | int | 未實現獲利 | | unrealizedLoss | int | 未實現虧損 | info 現股交易 buySell 皆為 `Buy`,以餘額正負號顯示淨買賣部位;若為信用交易,則 buySell 為 `Buy` 或 `Sell`,顯示買賣類別 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Accounting.UnrealizedGainsAndLoses(account)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ UnrealizedData{ date = 2021/08/09, // 查詢當天日期 (string) account = 26, // 帳號 (int) branchNo = 6460, // 分公司代號 (string) stockNo = 2303, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) orderType = Short, // 委託單類型 (OrderType) costPrice = 50.0, // 成本價格 (double) tradableQty = 1000, // 可交易餘額 (int) todayQty = 1000, // 今日餘額 (int) unrealizedProfit = 45200, // 未實現獲利 (int) unrealizedLoss = 0 // 未實現虧損 (int) } ] } ``` --- ### 參數對照表 #### 類別[​](#類別 "Direct link to 類別") Class ##### OrderObject[​](#orderobject "Direct link to OrderObject") | Parameter | Type | Meaning | | ------------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | buySell | BsAction | [買賣別](#bsaction) 可選用參數 `Buy` 買 、 `Sell` 賣 | | symbol | string | 股票代號 | | price | string | 委託價格 (若非使用 `Limit` 限價,此欄代入 ***null***) | | quantity | int | 委託數量 | | marketType | MarketType | [盤別](#markettype) 可選用參數 `Common` 整股、 `Fixing` 定盤、 `IntradayOdd` 盤中零股、 `Odd` 盤後零股、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | priceType | PriceType | [價格旗標](#pricetype) 可選用參數為 `Limit` 限價、 `LimitUp`漲停、 `LimitDown` 跌停、 `Market` 市價、 `Reference` 參考價 | | timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `Rod` 、 `Fok` 、 `Ioc` | | orderType | OrderType | [委託類別](#ordertype) 可選用參數為 `Stock` 現股、 `Margin` 融資、 `Short` 融券、 `DayTrade` 現沖先賣、 `SBL` 借券 | | userDef (optional) | string | 用戶自定義 (最長10個字元,不支援特殊字元及中文、不適用興櫃) | caution 不同 MarketType 對應的 quantity 之單位及範圍不同,請參考[盤別](#markettype)說明。 caution 當 MarketType 爲 MarketType.Common, MarketType.Odd, MarketType.IntradayOdd 其中之一,且 priceType 爲 PriceType.Limit 時,需填入 price 欄位,其餘時候 price 欄位為 null。 現股當沖 「現沖先賣」賣出時, orderType = DayTrade , buySell 需為 Sell , marketType 需為 Common
(其餘現沖進出場操作, orderType = Stock) ##### OrderResult[​](#orderresult "Direct link to OrderResult") 委託列表,透過 [GetOrderResult(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/trade/GetOrderResults.md) 取得。 | Parameter | Type | Meaning | | --------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | MarketType | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | BsAction | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | PriceType | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | TimeInForce | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | OrderType | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | PriceType | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | lastTime | string | 最後異動時間(格式請見表末說明) | | errorMessage | string | 錯誤訊息 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | >> functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modifiedTime | string | 修改時間(格式請見表末說明) | | >> beforeQty | int | 原始委託股數 | | >> afterQty | int | 有效委託股數(包含已成交部分) | | >> beforePrice | double | 原始委託價 | | >> afterPrice | double | 有效委託價 | | >> filledMoney | double | 成交價金 | | >> status | int | 委託單狀態 | | >> errMsg | string | 錯誤訊息 | 時間格式說明 lastTime 及 modifiedTime 時間格式: **HH:MM:SS.fff** 或 **HH:MM:SS** (即當 .fff = .000 時省略此部分) ##### BatchResult[​](#batchresult "Direct link to BatchResult") 批次委託列表,透過 [BatchOrderLists(account)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/trade/batchOrder/BatchOrderList.md) 取得。 | Parameter | Type | Meaning | | ------------ | ------ | ------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單、 `10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | ##### ModifyPriceObj[​](#modifypriceobj "Direct link to ModifyPriceObj") 改價物件 | Parameter | Type | Default Value | Meaning | | ----------- | --------- | ------------- | ------------------------------------------------------------------------------------------------------------ | | OrderResult | Object | - | [委託列表](#orderresult) | | price | string | - | 改單後的價格 | | PriceType | PriceType | - | 改單後的價格類型 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | 關於價格旗標 輕量風控版**已**開放使用價格旗標 (PriceType) ##### ModifyQuantityObj[​](#modifyquantityobj "Direct link to ModifyQuantityObj") 改量物件 | Parameter | Type | Default Value | Meaning | | ----------- | ------ | ------------- | ------------------------ | | OrderResult | Object | - | [委託列表](#orderresult) | | quantity | int | - | 改單後的委託量 | ##### FilledData[​](#filleddata "Direct link to FilledData") 成交回報物件 | Parameter | Type | Meaning | | -------------- | --------- | --------------------------------------------------------------------------------- | | date | string | 日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | seqNo | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | orderNo | string | 委託書號 | | stockNo | string | 股票代號 | | buySell | BsAction | 買賣別 : `Buy` 買 、 `Sell` 賣 | | orderType | OrderType | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 | | filledNo | string | 成交流水號 | | filledAvgPrice | double | 成交均價 | | filledQty | int | 成交股數 | | filledPrice | double | 成交單價 | | filledTime | string | 成交時間 | | userDef | string | 用戶自定義 (只有主動回報才回傳此欄位) | ##### Account[​](#account "Direct link to Account") 帳號資訊 | Parameter | Type | Meaning | | ----------- | ------ | ------------------------------------- | | name | string | 客戶姓名 | | account | string | 帳號 | | branchNo | string | 分公司代號 | | accountType | string | 帳戶類型 : `stock` 證券 `futopt` 期貨 | #### Constants ( 欄位對應數值 )[​](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )") ##### BSAction[​](#bsaction "Direct link to BSAction") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Buy | 買 | | Sell | 賣 | ##### MarketType[​](#markettype "Direct link to MarketType") 盤別 | Name | Meaning | | ----------- | -------- | | Common | 整股 | | Fixing | 定盤 | | IntradayOdd | 盤中零股 | | Odd | 盤後零股 | | Emg | 興櫃 | | EmgOdd | 興櫃零股 | 使用不同MarketType時,相對應的Quantity所代表的單位及範圍也會不同,詳如下表: | Name | Quantity Unit | Quantity Ranges | | ----------- | ------------- | --------------- | | Common | 千股 | 1000 ~ 499000 | | Fixing | 千股 | 1000 ~ 499000 | | IntradayOdd | 股 | 1 ~ 999 | | Odd | 股 | 1 ~ 999 | | Emg | 千股 | 1000 ~ 499000 | | EmgOdd | 股 | 1 ~ 999 | 使用不同 MarketType 時,可使用的 PriceType , TimeInForce 會不同,詳如下表: | MarketType | Available PriceType | Available TimeInForce | | ----------- | ---------------------------------------------------- | --------------------- | | Common | Limit 、 LimitUp 、 LimitDown 、 Market 、 Reference | Rod 、 Ioc 、 Fok | | Fixing | Reference | Rod | | IntradayOdd | Limit 、 LimitUp 、 LimitDown 、 Reference | Rod | | Odd | Limit 、 LimitUp 、 LimitDown 、 Reference | Rod | | Emg | Limit | Rod | | EmgOdd | Limit | Rod | ##### PriceType[​](#pricetype "Direct link to PriceType") 價格類型 (priceType) | Name | Meaning | | --------- | ----------------------- | | Limit | 限價 | | LimitUp | 漲停 | | LimitDown | 跌停 | | Market | 市價 | | Reference | 參考價 (定盤時為定盤價) | ##### TimeInForce[​](#timeinforce "Direct link to TimeInForce") 委託條件 (TimeInForce) | Name | Meaning | | ---- | ------------------------------------- | | Rod | 當日有效(Rest of Day) | | Fok | 全部成交否則取消(Fill-or-Kill) | | Ioc | 立即成交否則取消(Immediate-or-Cancel) | ##### OrderType[​](#ordertype "Direct link to OrderType") 委託類別 (orderType) | Name | Meaning | | -------- | -------- | | Stock | 現股 | | Margin | 融資 | | Short | 融券 | | DayTrade | 現沖先賣 | | SBL | 借券 | ##### StockType[​](#stocktype "Direct link to StockType") 股票分類別 | Name | Meaning | | ------------- | ---------- | | Stock | 股票 | | ConvertBond | 可轉債 | | ETF\_and\_ETN | ETF 與 ETN | ##### functionType[​](#functiontype "Direct link to functionType") 功能類別 | Name | Value | | ------------------------------ | ----- | | 新單 | 0 | | 新單執行 | 10 | | 改價 | 15 | | 改量 | 20 | | 刪單 | 30 | | 完全成交(for 委託單歷程查詢) | 50 | | 失敗 | 90 | ##### market[​](#market "Direct link to market") 市場 | Name | Value | | -------- | ------- | | 上市股票 | TAIEX | | 上櫃股票 | TAISDAQ | | 興櫃股票 | TAIEMG | ##### status[​](#status "Direct link to status") 委託單狀態 | Name | Value | | --------------------------- | ---------------------------------------------------------- | | 預約單 | 0 | | 系統將委託送往後台 | 4 ( 請用GetOrderResult查詢狀態 ) | | 後台傳送中 | 8 ( 請用GetOrderResult查詢狀態 ) | | 連線逾時 | 9 ( 請稍後再使用GetOrderResult查詢狀態 or 聯絡您的營業員 ) | | 委託成功 | 10 | | 未成交刪單成功 | 30 | | 部分成交,剩餘取消 | 40 | | 完全成交 | 50 | | 失敗 | 90 | | 委託單歷程查詢標示 | 14 - 改價ACK、24 - 改量ACK、34 - 刪單ACK | | 改價成功 (歷史委託單查詢) | 15 | | 改量成功 (歷史委託單查詢) | 20 | | 改價失敗 (主動回報) | 19 | | 改量失敗 (主動回報) | 29 | | 刪單失敗 (主動回報) | 39 | --- ### API Key 登入 ApikeyLogin 版本資訊 v2.2.7 起新增功能 相關說明請參閱 [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.md) 頁面 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | -------------- | | personalID | String | 登入的ID | | key | String | 申請的 API Key | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var result = sdk.ApikeyLogin("Your ID", "Your Key","Your Cert Path","Your Cert Password"); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ Account{ name = 富邦Bill, // 客戶姓名 (string) account = 28, // 客戶帳號 (string) branchNo = 6460, // 分公司代號 (string) accountType = stock // 帳號類型 (string) } ] } ``` --- ### 登入 Login #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | ---------- | | personalID | String | 登入的ID | | password | String | 登入的密碼 | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var result = sdk.Login("Your ID", "Your Password","Your Cert Path","Your Cert Password"); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ Account{ name = 富邦Bill, // 客戶姓名 (string) account = 28, // 客戶帳號 (string) branchNo = 6460, // 分公司代號 (string) accountType = stock // 帳號類型 (string) } ] } ``` --- ### 登出 Logout #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---- | -------- | | isSuccess | bool | 是否成功 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var result = sdk.Logout(); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs True ``` --- ### 刪除批次委託單 BatchCancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | -------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | orderResult | [BatchList](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) | 批次取消委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs // 批次刪單(利用batch detail回傳的內容刪單) var cancel_object = new List{ batch_detail.data[0], batch_detail.data[1], }; sdk.Stock.BatchCancelOrder(account, cancel_object); // 批次刪單(利用不同的單筆委託) var cancel_object = new List{ order_res.data[0], order_res.data[1], }; sdk.Stock.BatchCancelOrder(account, cancel_object); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data =[ OrderResult { // 批次刪單(利用batch detail回傳的內容刪單) functionType = 30, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000308998, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0028, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (float) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (string) isPreOrder = False, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.2, // 有效委託價格 (float) unit = 1000, // 單位數 (int) afterQty = 0, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 5000, // 改單前有效量 (int) beforePrice = 41.2, // 改單前有效價 (float) userDef = 12345678, // 自訂欄位 (string) lastTime = 12:53:57.536, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult { functionType = 30, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 0000030899, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0029, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (float) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (string) isPreOrder = False, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) ... } ] } ``` --- ### 批次修改委託價格 BatchModifyPrice ##### 先使用 MakeModifyPriceObj 建立 ModifyPriceObj物件[​](#先使用-makemodifypriceobj-建立-modifypriceobj物件 "Direct link to 先使用 MakeModifyPriceObj 建立 ModifyPriceObj物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 修改後的價格旗標 (***註***: 輕量風控版**已**開放使用價格旗標) | caution 當 price 欄位有填入值時,priceType 需為null ; 當 priceType 欄位有填入值時,price 需為null 將回傳的物件放入 BatchModifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | -------------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | ModifyPriceObj | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#modifypriceobj)(list of object) | 批次修改委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs // 批次改價(利用batch detail回傳的內容改單) var modified_orders = new List { sdk.Stock.MakeModifyPriceObj(batch_result.data[0], "41.1", null), sdk.Stock.MakeModifyPriceObj(batch_result.data[1], "41.2", null) }; var batch_modify_price = sdk.Stock.BatchModifyPrice(account, modified_orders); Console.WriteLine(batch_modify_price); // 批次改價(利用不同的單筆委託) var modified_orders = new List { sdk.Stock.MakeModifyPriceObj(orderResults.data[37], "41.1", null), sdk.Stock.MakeModifyPriceObj(orderResults.data[35], "41.2", null) }; var batch_modify_price = sdk.Stock.BatchModifyPrice(account, modified_orders); Console.WriteLine(batch_modify_price); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data =[ OrderResult{ // 批次改價(利用batch detail回傳的內容改單) functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000322356, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0018, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.1, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = , // 改單前有效量 (int) beforePrice = 41.3, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 13:56:57.713, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000322355, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0017, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) ... } ] } 以下擷取data內容 [ OrderResult{ // 批次改價(利用不同的單筆委託) functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000322388, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0033, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.1, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = , // 改單前有效量 (int) beforePrice = 41.3, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 10:56:57.713, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000322386, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = "26", // 帳號 (string) orderNo = x0031, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) ... } ] ``` --- ### 批次修改委託數量 BatchModifyPrice ##### 先使用 MakeModifyQuantityObj 建立 ModifyQuantityObj物件[​](#先使用-makemodifyquantityobj-建立-modifyquantityobj物件 "Direct link to 先使用 MakeModifyQuantityObj 建立 ModifyQuantityObj物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 ModifyQuantity 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | ModifyQuantityObj | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#modifyquantityobj) (list of object) | 批次改量委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs // 批次改量(利用batch detail回傳的內容改單) var modified_orders = new List { sdk.Stock.MakeModifyQuantityObj(batch_result.data[0], 1000), sdk.Stock.MakeModifyQuantityObj(batch_result.data[1], 1000) }; var batch_modify_qty = sdk.Stock.BatchModifyQuantity(account, modified_orders); Console.WriteLine(batch_modify_qty); // 批次改量(利用不同的單筆委託) var modified_orders = new List { sdk.Stock.MakeModifyQuantityObj(orderResults.data[0], 1000), sdk.Stock.MakeModifyQuantityObj(orderResults.data[1], 1000) }; var batch_modify_qty = sdk.Stock.BatchModifyQuantity(account, modified_orders); Console.WriteLine(batch_modify_qty); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data =[ OrderResult{ // 批次改量(利用batch detail回傳的內容改單) functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000042, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0026, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2881, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (double) userDef = batch 2, // 自訂欄位 (string) lastTime = 12:21:51.023, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ // 批次改量(利用batch detail回傳的內容改單) functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000041, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0025, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2881, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (double) userDef = batch 1, // 自訂欄位 (string) lastTime = 12:21:51.023, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) } ] } 以下擷取data內容 [ OrderResult{ // 批次改量(利用不同的單筆委託) functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000043, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = "26", // 帳號 (string) orderNo = x0027, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MaeketType) stockNo = 2881, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (int) userDef = Test, // 自訂欄位 (string) lastTime = 12:21:53.023, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000044, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0028, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2881, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (string) userDef = Test, // 自訂欄位 (string) lastTime = 12:21:53.023, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) } ] ``` --- ### 取得批次委託明細 BatchOrderDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | BatchOrderList | [BatchResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#batchresult) | 批次委託列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | caution 此功能僅供查詢批次送單執行結果,欲取得委託單最新狀態請使用單筆委託單查詢功能 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var batch_order_list = sdk.Stock.BatchOrderLists(account); var batch_order_detail = sdk.Stock.BatchOrderDetail(account, batch_order_list.data[0]); Console.WriteLine(batch_order_detail.data[0]); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ OrderResult{ functionType = , // 功能別 (int) date = 2023/10/18, // 日期 (date) seqNo = 00000000007, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA683, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 8.9, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 8.9, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 改單前有效量 (int) beforePrice = 8.9, // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 14:41:32.647, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMsg = // 錯誤訊息 (string) }, ... ] } ``` --- ### 取得批次委託列表 BatchOrderLists #### 輸入參數[​](#輸入參數 "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 | 當isSuccess = False 回傳錯誤訊息 | ##### 批次單 BatchResult 欄位[​](#批次單-batchresult-欄位 "Direct link to 批次單 BatchResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------ | ------ | ------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單、 `10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Stock.BatchOrderLists(account)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ BatchResult{ functionType = 0, // 功能種類 (int) date = 2023/10/04, // 交易日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) batchSeqNo = 11EE626533D072228000000C29304663 // 批次單流水序號 (string) }, ... ] } ``` --- ### 建立批次委託單 BatchPlaceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | --------------------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderobject) (list of object) | 委託內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var orders = new Order[]{ new Order( BsAction.Buy, "2888", "8.90", 2000, MarketType.Common, PriceType.Limit, TimeInForce.Rod, OrderType.Stock, null ), new Order( BsAction.Buy, "2888", "8.90", 2000, MarketType.Common, PriceType.Limit, TimeInForce.Rod, OrderType.Stock, null )}; sdk.Stock.BatchPlaceOrder(account,orders.ToList()); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ OrderResult{ functionType = 0, // 功能別 (int) date = 2023/09/22, // 交易日期 (string) seqNo = 00000221431, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = , // 委託書號 (string) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stock_no = 2888, // 股票代號 (string) buy_sell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 8.9, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = true, // 是否為預約單 (bool) status = 0, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 8.9, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 異動前有效量 (int) beforePrice = 9.1, // 異動前有效價 (double) userDef = null, // 自定義欄位 (string) lastTime = null, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, OrderResult{ functionType = 0, // 功能別 (int) date = 2023/09/22, // 交易日期 (string) seqNo = 00000221432, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = , // 委託書號 (string) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stock_no = 2888, // 股票代號 (string) buy_sell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 8.9, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = true, // 是否為預約單 (bool) status = 0, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 8.9, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 異動前有效量 (int) beforePrice = 9.1, // 異動前有效價 (double) userDef = , // 自定義欄位 (string) lastTime =, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } ] } ``` --- ### 刪除委託單 CancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------ | | account | Account | 帳號 | | orderResult | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) | 欲取消的委託單物件 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | OrderResult | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Stock.CancelOrder(account, cancel_order)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = OrderResult { functionType = 30, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000308948, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0023, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Stock, // 委託單類型 (string) isPreOrder = False, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.2, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 0, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 5000, // 改單前有效量 (int) beforePrice = 41.2, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 12:53:57.536, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } } ``` --- ### 現冲券配額查詢 DaytradeAndStockInfo #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | stockNo | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | DayTradeStockInfo | 回傳配額資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 配額資訊 DayTradeStockInfo 欄位[​](#配額資訊-daytradestockinfo-欄位 "Direct link to 配額資訊 DayTradeStockInfo 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------- | | stockNo | string | 股票代號 | | date | string | 日期 | | daytradeOrigQuota | int | 原始現冲券餘額 | | daytradeTradableQuota | int | 可用現冲券餘額 | | precollectSingle | int | 單筆預收股數 (若不需預收則回傳空值) | | precollectAccumulate | int | 累積預收股數 (若不需預收則回傳空值) | | status | int | 狀態 (bitmask 加總) : `0` 全禁 、 `1` 平盤下可融券賣出、 `2` 平盤下可借券賣出、 `4` 可先買後賣當沖 、 `8`可先賣後買當沖 | | dispositionStatus | string | 警示股註記 `{ SETTYPE : 1}` : 全額交割、 `{ MARK-W : 1}` : 警示、`{ MARK-P : 1}` : 注意、`{ MARK-L : 1}` : 委託受限 【**2.2.5版本新增欄位**】 | info status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var daytrade = sdk.Stock.DaytradeAndStockInfo(account, "2330"); Console.WriteLine(daytrade.data); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ DayTradeStockInfo{ stockNo = 3264, // 股票代號 (string) date = 2023/10/04, // 日期 (string) daytradeOrigQuota = 0, // 原始現冲券餘額 (int) daytradeTradableQuota = 0, // 可用現冲券餘額 (int) precollectSingle = , // 單筆預收股數 (int) precollectAccumulate = , // 累積預收股數 (int) status = 0, // 狀態 (int) dispositionStatus = // 警示股註記【2.2.5版本新增欄位】 } } ] ``` --- ### 查詢歷史成交 FilledHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | -------------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string (空值預設與開始日相同) | 查詢終止日 | info v2.1.1起可查詢長期歷史資料,每次查詢最大設定30日日期區間;v2.1.0之前版本可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳成交資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 成交資訊 FilledData 欄位[​](#成交資訊-filleddata-欄位 "Direct link to 成交資訊 FilledData 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | | date | date | 成交日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | seqNo | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | orderNo | string | 委託書號 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | filledNo | string | 成交流水號 | | filledAvgPrice | double | 成交均價 | | filledQty | int | 成交股數 | | filledPrice | double | 成交單價 | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | filledTime | string | 成交時間 | | userDef | string | 自訂欄位 (只有主動回報才回傳此欄位) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Stock.FilledHistory(account,"20230921","20230922")); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ FilledData{ date = 2023/09/15, // 成交日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) seqNo = , // 委託流水序號 (string) orderNo = bA422, // 委託書號 (string) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) filledNo = 00000000001, // 成交流水號 (string) filledAvgPrice = 35.2, // 成交均價 (double) filledQty = 1000, // 成交股數 (int) filledPrice = 35.2, // 成交單價 (double) orderType = Stock, // 委託單類型 (OrderType) filledTime = 10:31:00.931 // 成交時間 (string) userDef = , // 用戶自定義 (string) }, ... ] } ``` --- ### 取得委託單結果 GetOrderResult #### 輸入參數[​](#輸入參數 "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 | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var orderResults = sdk.Stock.GetOrderResults(account); Console.WriteLine(orderResults); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ OrderResult{ functionType = , // 功能別 (int) date = 2023/10/13, // 交易日期 (string) seqNo = 00000000002, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA614, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (int) price = 9.0, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 9.0, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 改單前有效量 (int) beforePrice = 9.0, // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 10:05:54.608, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMsg = // 錯誤訊息 (string) }, ... ] } ``` --- ### 取得委託單結果 (含歷程) GetOrderResultDetail #### 輸入參數[​](#輸入參數 "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 | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | details | list | 委託歷程 | | >> functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeQty | int | 原始委託股數 | | >> afterQty | int | 有效委託股數(包含已成交部分) | | >> beforePrice | double | 原始委託價 | | >> afterPrice | double | 有效委託價 | | >> filledMoney | double | 成交價金 | | >> status | int | 委託單狀態 | | >> errMsg | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var orderResults = sdk.Stock.GetOrderResultsDetail(account); Console.WriteLine(orderResults); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ OrderResult{ functionType = , // 功能別 (int) date = 2023/10/13, // 交易日期 (string) seqNo = 00000000002, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA614, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (int) price = 9.0, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 9.0, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 改單前有效量 (int) beforePrice = 9.0, // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 10:05:54.608, // 最後異動時間 (string) errorMsg = // 錯誤訊息 (string) details = [ OrderDetail{ functionType = 10, modifiedTime = 10:05:54.608, beforeQty = 0, afterQty = 2000, beforePrice = 9.0, afterPrice = 9.0, status = 10, errorMsg = } ] }, ... ] } ``` --- ### 資券配額查詢 MarginQuota #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | stockNo | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | MarginShortQuota | 回傳配額資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 配額資訊 MarginShortQuota 欄位[​](#配額資訊-marginshortquota-欄位 "Direct link to 配額資訊 MarginShortQuota 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------------- | ------ | ------------ | | stock\_no | string | 股票代號 | | date | string | 日期 | | shortsellOrigQuota | int | 原始融券餘額 | | shortsellTradableQuota | int | 可用融券餘額 | | marginOrigQuota | int | 原始融資餘額 | | marginTradableQuota | int | 可用融資餘額 | | marginRatio | int | 融資成數 | | shortRatio | int | 融券成數 | info 額度相關說明 : 融資成數回傳空值表示停資;融券成數回傳空值表示停券,
回傳的額度說明 : 0 - 無額度 / 大於0 - 有額度 / 空值 - 無限制 / 餘額皆為 0 - 停資 or 停券 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Stock.MarginQuota(account, "2330")); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = MarginShortQuota{ stockNo = 2330, date = 2024/01/24, shortsellOrigQuota = 894, shortsellTradableQuota = 894, marginOrigQuota = , marginTradableQuota = , marginRatio = 60, shortRatio = 90 } } ``` --- ### 修改委託價格 ModifyPrice ##### 先使用 MakeModifyPriceObj 建立 ModifyPriceObj物件[​](#先使用-makemodifypriceobj-建立-modifypriceobj物件 "Direct link to 先使用 MakeModifyPriceObj 建立 ModifyPriceObj物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 修改後的價格旗標 (***註***: 輕量風控版**已**開放使用價格旗標) | caution 當 price 欄位有填入值時,priceType 需為 null ; 當 priceType 欄位有填入值時,price 需為 null 將回傳的物件放入 modifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------------- | ---------------------------------------------------------------------------------------------------------- | -------------- | | account | Account | 帳號 | | modifiedPriceObj | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#modifypriceobj) | 修改價格的物件 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | OrderResult | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var modify_price_obj = sdk.Stock.MakeModifyPriceObj(order_result, "41.1", null); var modify_price = sdk.Stock.ModifyPrice(account, modify_price_obj, true); Console.WriteLine(modify_price); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = OrderResult { functionType = 15, // 功能別 (int) date = 2023/11/22, // 交易日期 (string) seqNo = 00000308866, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0011, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.1, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 2000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = , // 改單前有效量 (int) beforePrice = 41.3, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 10:56:57.713, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } } ``` --- ### 修改委託單數量 ModifyQuantity ##### 先使用 MakeModifyQuantityObj 建立 ModifyQuantityObj物件[​](#先使用-makemodifyquantityobj-建立-modifyquantityobj物件 "Direct link to 先使用 MakeModifyQuantityObj 建立 ModifyQuantityObj物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 ModifyQuantity 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | ---------------------------------------------------------------------------------------------------------------- | -------------- | | account | Account | 帳號 | | ModifyQuantityObj | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#modifyquantityobj) | 修改的委託單 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | OrderResult | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var modify_qty_obj = sdk.Stock.MakeModifyQuantityObj(order_result, 1000); var modify_qty = sdk.Stock.ModifyQuantity(account, modify_qty_obj, true); Console.WriteLine(modify_qty); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = OrderResult{ functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000308866, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0011, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 1101, // 股票代號 (string) buySell = Sell, // 買賣別 (string) priceType = Limit, // 原始委託價格別 (string) price = 41.2, // 價格 (double) quantity = 5000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 41.3, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 3000, // 改單前有效量 (int) beforePrice = 41.2, // 改單前有效價 (double) userDef = 12345678, // 自訂欄位 (string) lastTime = 12:56:28.966, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } } ``` --- ### 查詢歷史委託 OrderHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | -------------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string (空值預設與開始日相同) | 查詢終止日 | info v2.1.1起可查詢長期歷史資料,每次查詢最大設定30日日期區間;v2.1.0之前版本可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int (Optioanl) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | details | list | 委託歷程 | | >> functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeQty | int | 原始委託股數 | | >> afterQty | int | 有效委託股數(包含已成交部分) | | >> beforePrice | double | 原始委託價 | | >> afterPrice | double | 有效委託價 | | >> filledMoney | double | 成交價金 | | >> status | int | 委託單狀態 | | >> errMsg | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Stock.OrderHistory(account,"20230921","20230922")); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ OrderResult{ functionType = , // 功能別 (int) date = 2023/10/12, // 交易日期 (string) seqNo = 00000000001, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA598, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 8.9, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 9, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = , // 改單前有效量 (int) beforePrice = , // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 14:19:41.879, // 最後異動時間 (string) details = [ OrderDetail{ functionType = 10, modifiedTime = 14:19:41.879, beforeQty = 0, afterQty = 1000, beforePrice = 9.0, afterPrice = 9.0, status = 10, errorMsg = } ] errorMsg = // 錯誤訊息 (string) }, ... ] } ``` --- ### 建立委託單 PlaceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | orderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#orderobject) | 委託內容 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | OrderResult | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | double | 價格 | | quantity | int | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` Rod 、 `Fok` Fok 、 `Ioc` Ioc | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | unit | int | 單位數 | | afterQty | int | 有效委託股數(包含已成交部分) | | filledQty | int | 成交股數 | | filledMoney | int | 成交價金 | | beforeQty | int | 改單前有效量 | | beforePrice | double | 改單前有效價 | | user\_def | string | 自訂欄位 (最長10個字元,不支援特殊字元及中文、不適用興櫃) | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var order = new Order( BsAction.Buy, "2881", "66", 2000, MarketType.Common, PriceType.Limit, TimeInForce.Rod, OrderType.Stock, null // User_def ); sdk.Stock.PlaceOrder(target_user,order,false); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = OrderResult{ functionType = 0, // 功能別 (int) date = 2023/10/13, // 交易日期 (string) seqNo = 00000000007, // 委託單流水序號 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA619, // 委託書號 (string) assetType = 0, // 資產類型 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MarketType) stockNo = 2888, // 股票代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 9.1, // 價格 (double) quantity = 3000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = Stock, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (PriceType) afterPrice = 9.1, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 3000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 0, // 改單前有效量 (int) beforePrice = 9.1, // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 12:10:12.546, // 最後異動時間 (string) details = , // 委託歷程 (list) errorMsg = // 錯誤訊息 (string) } } ``` --- ### 查詢商品漲跌幅報表(單筆) QuerySymbolQuote info 2.2.5 版新增 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | symbol | String | 股票代碼 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolQuote | 回傳查詢資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 配額資訊 SymbolQuote 欄位[​](#配額資訊-symbolquote-欄位 "Direct link to 配額資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------ | ---------------------------------------------------------------------------------------------------------------------- | | market | string | 市場別 | | symbol | string | 股票代碼 | | istibOrPsb | bool | 是否為創新版或戰略新板 | | marketType | string | 市場類型 | | status | int | 狀態 (bitmask 加總): `0` 全禁 、 `1` 平盤下可融券賣出、 `2` 平盤下可借券賣出、 `4` 可先買後賣當沖 、 `8`可先賣後買當沖 | | referencePrice | double | 參考價格 | | unit | int | 交易單位 | | updateTime | string | 更新時間 | | limitupPrice | double | 漲停價 | | limitdownPrice | double | 跌停價 | | openPrice | double | 開盤價 | | highPrice | double | 最高價 | | lowPrice | double | 最低價 | | lastPrice | double | 最新成交價 | | totalVolume | int | 總成交量 | | totalTransaction | int | 總成交筆數 (預留欄位,暫未使用) | | totalValue | int | 總成交金額 | | lastSize | int | 最新成交量 | | lastTransaction | int | 最新成交筆數 (預留欄位,暫未使用) | | lastValue | int | 最新成交金額 | | bidPrice | double | 買1價格 | | bidVolume | int | 買1數量 | | askPrice | double | 賣1價格 | | askVolume | int | 賣1數量 | 支援範圍 上市、上櫃標的 info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var quote = sdk.Stock.QuerySymbolQuote(result.data[0],"2330"); Console.WriteLine(quote.data) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = SymbolQuote{ market = TAIEX, // string - 市場別 symbol = 2330, // string - 股票代碼 istibOrPsb = False, // bool - 是否為創新板或戰略新板 marketType = Common, // string - 市場類型 (現股) status = 15, // int - 狀態 (bitmask 加總: 1+2+4+8 = 可融券賣出+可借券賣出+可先買後賣當沖+可先賣後買當沖) referencePrice = 780, // double - 參考價格 (前一交易日收盤價) unit = 1000, // int - 交易單位 updateTime = , // string - 更新時間 limitupPrice = 858, // double - 漲停價 limitdownPrice = 702, // double - 跌停價 openPrice = 1155, // double - 開盤價 highPrice = 1160, // double - 最高價 lowPrice = 1145, // double - 最低價 lastPrice = 1145, // double - 最新成交價 totalVolume = 20501, // int - 總成交量 totalTransaction = 0, // int - 總成交筆數 (預留欄位,暫未使用) totalValue = 23551095000, // int - 總成交金額 lastSize = 6673, // int - 最新成交量 lastTransaction = 0, // int - 最新成交筆數 (預留欄位,暫未使用) lastValue = 7640585000, // int - 最新成交金額 bidPrice = 1145, // double - 買一價格 bidVolume = 1549, // int - 買一數量 askPrice = 1150, // double - 賣一價格 askVolume = 4169 // int - 賣一數量 } } ``` --- ### 查詢商品漲跌幅報表(批次) QuerySymbolSnapshot info 2.2.5 版新增 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | --------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#account) | 帳號 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | | stock\_type | List [StockType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/EnumMatrix.md#stocktype) (Optional)(default = Stock) | 商品分類別 : `Stock` 股票、`ConvertBond` 可轉債、`ETF_and_ETN` ETF 與 ETN | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolSnapshotResponse | 回傳查詢資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 商品資訊 SymbolQuote 欄位[​](#商品資訊-symbolquote-欄位 "Direct link to 商品資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------ | ---------------------------------------------------------------------------------------------------------------------- | | market | string | 市場別 | | symbol | string | 股票代碼 | | istibOrPsb | bool | 是否為創新版或戰略新板 | | marketType | string | 市場類型 | | status | int | 狀態 (bitmask 加總): `0` 全禁 、 `1` 平盤下可融券賣出、 `2` 平盤下可借券賣出、 `4` 可先買後賣當沖 、 `8`可先賣後買當沖 | | referencePrice | double | 參考價格 | | unit | int | 交易單位 | | updateTime | string | 更新時間 | | limitupPrice | double | 漲停價 | | limitdownPrice | double | 跌停價 | | openPrice | double | 開盤價 | | highPrice | double | 最高價 | | lowPrice | double | 最低價 | | lastPrice | double | 最新成交價 | | totalVolume | int | 總成交量 | | totalTransaction | int | 總成交筆數 (預留欄位,暫未使用) | | totalValue | int | 總成交金額 | | lastSize | int | 最新成交量 | | lastTransaction | int | 最新成交筆數 (預留欄位,暫未使用) | | lastValue | int | 最新成交金額 | | bidPrice | double | 買1價格 | | bidVolume | int | 買1數量 | | askPrice | double | 賣1價格 | | askVolume | int | 賣1數量 | 支援範圍 上市、上櫃標的 info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs sdk.stock.QuerySymbolSnapshot(accounts.data[0]) // Default sdk.stock.QuerySymbolSnapshot(accounts.data[0], MarketType.Common, [StockType.Stock]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = SymbolQuote{ market = TAIEX, // string - 市場別 symbol = 2330, // string - 股票代碼 istibOrPsb = False, // bool - 是否為創新板或戰略新板 marketType = Common, // string - 市場類型 (現股) status = 15, // int - 狀態 (bitmask 加總: 1+2+4+8 = 可融券賣出+可借券賣出+可先買後賣當沖+可先賣後買當沖) referencePrice = 780, // double - 參考價格 (前一交易日收盤價) unit = 1000, // int - 交易單位 updateTime = , // string - 更新時間 limitupPrice = 858, // double - 漲停價 limitdownPrice = 702, // double - 跌停價 openPrice = 1155, // double - 開盤價 highPrice = 1160, // double - 最高價 lowPrice = 1145, // double - 最低價 lastPrice = 1145, // double - 最新成交價 totalVolume = 20501, // int - 總成交量 totalTransaction = 0, // int - 總成交筆數 (預留欄位,暫未使用) totalValue = 23551095000, // int - 總成交金額 lastSize = 6673, // int - 最新成交量 lastTransaction = 0, // int - 最新成交筆數 (預留欄位,暫未使用) lastValue = 7640585000, // int - 最新成交金額 bidPrice = 1145, // double - 買一價格 bidVolume = 1549, // int - 買一數量 askPrice = 1150, // double - 賣一價格 askVolume = 4169 // int - 賣一數量 }, SymbolQuote{ market = TAIEX, // string - 市場別 symbol = 2881, // string - 股票代碼 } } ``` --- ### 版本升級指南 本文件將引導您將現有的Fubon Neo API v1.0.4 版本升級至的 v1.3.1 以後版本。 #### 主要差異[​](#主要差異 "Direct link to 主要差異") ##### C# 主動回報訂閱[​](#c-主動回報訂閱 "Direct link to C# 主動回報訂閱") 原先v1.0.4訂閱方法 ```cs public class MyCallback : Callback { public string code =""; public string response = ""; //Callback to receive order data public void OnOrder(string code, OrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine("On Order" + response); } } //Callback to receive Modified data public void OnOrderChanged(string code, OrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Modified" + response); } } //Callback to receive Filled data public void OnFilled(string code, FilledData data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Filled" + response); } } //Callback to receive Event data public void OnEvent(String code, String data) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Event" + response); } } var callback = new MyCallback(); sdk.RegisterCallback(callback); ``` #### 新的訂閱方法[​](#新的訂閱方法 "Direct link to 新的訂閱方法") 此次改版使用新的訂閱方法,透過以下方式訂閱, 新的方法,可依照想訂閱的類別再進行訂閱即可,不需每個方法都實作 ```cs sdk.OnEvent += (code, msg) => { Console.WriteLine(code + msg ); }; // 證券 sdk.OnOrder += (code, ordeResult) => { Console.WriteLine(code + ordeResult.ToString()); }; sdk.OnOrderChanged += (code, ordeResult) => { Console.WriteLine(code + ordeResult.ToString()); }; sdk.OnFilled += (code, filledData) => { Console.WriteLine(code + filledData.ToString()); }; // 期貨 sdk.OnFutoptOrder += (code, FutOptOrderResult) => { Console.WriteLine(code + FutOptOrderResult.ToString()); }; sdk.OnFutoptOrderChanged += (code, FutOptOrderResult) => { Console.WriteLine(code + FutOptOrderResult.ToString()); }; sdk.OnFutoptFilled += (code, FutOptFilledData) => { Console.WriteLine(code + FutOptFilledData.ToString()); }; ``` --- ### 銀行餘額查詢 BankRemain #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------ | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*BankRemain | 回傳餘額資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 餘額資訊 BankRemain 欄位[​](#餘額資訊-bankremain-欄位 "Direct link to 餘額資訊 BankRemain 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | -------- | ---------- | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | Currency | \*string | 幣別 | | Balance | \*int64 | 餘額 | | AvailableBalance | \*int64 | 可用餘額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢銀行餘額 bankRemain, err := sdk.Accounting.BankRemain(account) // 錯誤處理 if err != nil { fmt.Printf("❌ Bank Remain Format Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !bankRemain.IsSuccess { message := "No message" if bankRemain.Message != nil { message = *bankRemain.Message } fmt.Printf("Bank remain failed. Message: %s\n", message) return } // 輸出銀行餘額資訊 if bankRemain.Data != nil { fmt.Println("✅ Bank Remain:") fmt.Printf("BranchNo: %s\n", *bankRemain.Data.BranchNo) fmt.Printf("Account: %s\n", *bankRemain.Data.Account) fmt.Printf("Currency: %s\n", *bankRemain.Data.Currency) fmt.Printf("Balance: %d\n", *bankRemain.Data.Balance) fmt.Printf("AvailableBalance: %d\n", *bankRemain.Data.AvailableBalance) } else { fmt.Println("Bank remain success but no data returned.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // BankRemain 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &BankRemain{ BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 Currency: "TWD", // 幣別 Balance: 666666, // 餘額 AvailableBalance: 123456, // 可用餘額 }, } ``` --- ### 庫存查詢 Inventories #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | -------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]Inventory | 回傳庫存資訊列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 庫存資訊 Inventory 欄位[​](#庫存資訊-inventory-欄位 "Direct link to 庫存資訊 Inventory 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | Date | \*string | 交易日期 | | Account | \*string | 帳號 | | BranchNo | \*string | 分公司代號 | | StockNo | \*string | 股票代號 | | OrderType | OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖、`OrderTypeSbl` 借券 | | LastdayQty | \*int64 | 昨日庫存餘額 | | BuyQty | \*int64 | 今日委買股數 | | BuyFilledQty | \*int64 | 今日買進成交股數 | | BuyValue | \*int64 | 買進價金 | | TodayQty | \*int64 | 今日庫存餘額 | | TradableQty | \*int64 | 可委託股數 | | SellQty | \*int64 | 今日委賣股數 | | SellFilledQty | \*int64 | 今日賣出成交股數 | | SellValue | \*int64 | 賣出價金 | | Odd | \*InventoryOdd | 零股庫存資訊 | | >> LastdayQty | \*int64 | 昨日庫存餘額 | | >> BuyQty | \*int64 | 今日委買股數 | | >> BuyFilledQty | \*int64 | 今日買進成交股數 | | >> BuyValue | \*int64 | 買進價金 | | >> TodayQty | \*int64 | 今日庫存餘額 | | >> TradableQty | \*int64 | 可委託股數 | | >> SellQty | \*int64 | 今日委賣股數 | | >> SellFilledQty | \*int64 | 今日賣出成交股數 | | >> SellValue | \*int64 | 賣出價金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢庫存 inventories, err := sdk.Accounting.Inventories(account) // 錯誤處理 if err != nil { fmt.Printf("❌ Inventories Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !inventories.IsSuccess { message := "No message" if inventories.Message != nil { message = *inventories.Message } fmt.Printf("Inventories query failed. Message: %s\n", message) return } // 輸出庫存列表 if inventories.Data != nil && len(*inventories.Data) > 0 { fmt.Printf("✅ Found %d inventory items\n", len(*inventories.Data)) for i, inv := range *inventories.Data { fmt.Printf("\n=== Inventory %d ===\n", i+1) fmt.Printf("StockNo: %s\n", *inv.StockNo) fmt.Printf("OrderType: %v\n", inv.OrderType) fmt.Printf("昨日庫存: %d\n", *inv.LastdayQty) fmt.Printf("今日庫存: %d\n", *inv.TodayQty) fmt.Printf("可委託量: %d\n", *inv.TradableQty) fmt.Printf("今日買進: %d (成交: %d)\n", *inv.BuyQty, *inv.BuyFilledQty) fmt.Printf("今日賣出: %d (成交: %d)\n", *inv.SellQty, *inv.SellFilledQty) // 零股資訊 if inv.Odd != nil { fmt.Printf("\n 零股庫存:\n") fmt.Printf(" 今日零股: %d\n", *inv.Odd.TodayQty) fmt.Printf(" 可委託零股: %d\n", *inv.Odd.TradableQty) } } } else { fmt.Println("Inventories query succeeded but no data returned.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // Inventories 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &[]Inventory{ { Date: "2023/10/13", // 交易日期 Account: "26", // 帳號 BranchNo: "6460", // 分公司代號 StockNo: "1101", // 股票代號 OrderType: OrderTypeStock, // 委託單類型 LastdayQty: 2000, // 昨日庫存餘額 BuyQty: 0, // 今日委買股數 BuyFilledQty: 0, // 今日買進成交股數 BuyValue: 0, // 買進價金 TodayQty: 2000, // 今日庫存餘額 TradableQty: 2000, // 可委託股數 SellQty: 0, // 今日委賣股數 SellFilledQty: 0, // 今日賣出成交股數 SellValue: 0, // 賣出價金 Odd: &InventoryOdd{ // 零股庫存 LastdayQty: 0, BuyQty: 0, BuyFilledQty: 0, BuyValue: 0, TodayQty: 0, TradableQty: 0, SellQty: 0, SellFilledQty: 0, SellValue: 0, }, }, // ... 更多庫存 }, } ``` --- ### 維持率查詢 Maintenance #### 輸入參數[​](#輸入參數 "Direct link to 輸入參��數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*MaintenanceData | 回傳維持率資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 維持率 MaintenanceData 欄位[​](#維持率-maintenancedata-欄位 "Direct link to 維持率 MaintenanceData 欄位") | 參數 | 類別 | 說明 | | --------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | Date | \*string | 查詢日 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | MaintenanceSummary | \*MaintenanceSummary | 整戶維持率彙總 | | >> MarginValue | \*int64 | 整戶融資市值 | | >> ShortsellValue | \*int64 | 整戶融券市值 | | >> ShortsellMargin | \*int64 | 整戶融券保證金額 | | >> Collateral | \*int64 | 擔保品 | | >> MarginLoanAmt | \*int64 | 整戶融資金額 | | >> MaintenanceRatio | \*string | 整戶維持率 (%) | | MaintenanceDetail | \*\[]MaintenanceDetail | 個股維持率明細 | | >> StockNo | \*string | 股票代碼 | | >> OrderNo | \*string | 委託書號 | | >> OrderType | OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、`OrderTypeSbl` 借券 | | >> Quantity | \*int64 | 持有股數 | | >> Price | \*string | 計算價 | | >> CostPrice | \*string | 成本價 | | >> ShortsellMargin | \*int64 | 融券保證金 | | >> Collateral | \*int64 | 擔保品 | | >> MarginLoanAmt | \*int64 | 融資金 | | >> MaintenanceRatio | \*string | 維持率 (%) | | >> CollateralInterest | \*string | 擔保品利息 | | >> MarginInterest | \*string | 融資金利息 | | >> ShortsellInterest | \*string | 融券保證金利息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢維持率 maintenance, err := sdk.Accounting.Maintenance(account) if err != nil { fmt.Printf("❌ Maintenance Format/Parser Error: %v\n", err) return } if maintenance.IsSuccess && maintenance.Data != nil { fmt.Println("✅ Maintenance Data:") // 整戶維持率 if maintenance.Data.MaintenanceSummary != nil { summary := maintenance.Data.MaintenanceSummary fmt.Printf("\n整戶維持率: %s%%\n", *summary.MaintenanceRatio) fmt.Printf("融資市值: %d\n", *summary.MarginValue) fmt.Printf("融資金額: %d\n", *summary.MarginLoanAmt) fmt.Printf("擔保品: %d\n", *summary.Collateral) } // 個股明細 if maintenance.Data.MaintenanceDetail != nil { fmt.Printf("\n個股明細 (%d 筆):\n", len(*maintenance.Data.MaintenanceDetail)) for i, detail := range *maintenance.Data.MaintenanceDetail { fmt.Printf("\n[%d] %s\n", i+1, *detail.StockNo) fmt.Printf(" 持有: %d 股\n", *detail.Quantity) fmt.Printf(" 成本價: %s, 計算價: %s\n", *detail.CostPrice, *detail.Price) fmt.Printf(" 維持率: %s%%\n", *detail.MaintenanceRatio) } } } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Result{ IsSuccess: true, Message: nil, Data: &MaintenanceData{ Date: "2024/02/27", BranchNo: "6460", Account: "26", MaintenanceSummary: &MaintenanceSummary{ MarginValue: 3135000, ShortsellValue: 0, ShortsellMargin: 0, Collateral: 0, MarginLoanAmt: 1494000, MaintenanceRatio: "209.83", }, MaintenanceDetail: &[]MaintenanceDetail{ { StockNo: "2603", OrderNo: "x4580", OrderType: OrderTypeStock, Quantity: 10000, Price: "152.5", CostPrice: "119", ShortsellMargin: 0, Collateral: 0, MarginLoanAmt: 0, MaintenanceRatio: "213.58", CollateralInterest: "0", MarginInterest: "20818", ShortsellInterest: "0", }, }, }, } ``` --- ### 交割款查詢 QuerySettlement #### 輸入參數[​](#輸入參數 "Direct link to 輸入�參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | range | string | 時間區間,目前有效值為 "0d" (當日)、"3d" (三日) | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*SettlementData | 回傳交割款資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 交割資訊 SettlementData 欄位[​](#交割資訊-settlementdata-欄位 "Direct link to 交割資訊 SettlementData 欄位") | 參數 | 類別 | 說明 | | ------- | --------------- | ------------ | | Account | \*AccountRes | 帳戶資訊 | | Details | \*\[]Settlement | 交割明細列表 | ##### 帳戶 AccountRes 欄位[​](#帳戶-accountres-欄位 "Direct link to 帳戶 AccountRes 欄位") | 參數 | 類別 | 說明 | | -------- | -------- | ---------- | | Account | \*string | 帳號 | | BranchNo | \*string | 分公司代號 | ##### 交割明細 Settlement 欄位[​](#交割明細-settlement-欄位 "Direct link to 交割明細 Settlement 欄位") | 參數 | 類別 | 說明 | | --------------------- | -------- | ----------------------- | | Date | \*string | 查詢日 | | SettlementDate | \*string | 交割日 (Optional) | | BuyValue | \*int64 | 買進金額 (Optional) | | BuyFee | \*int64 | 買進手續費 (Optional) | | BuySettlement | \*int64 | 買進應收付款 (Optional) | | BuyTax | \*int64 | 買進交易稅 (Optional) | | SellValue | \*int64 | 賣出金額 (Optional) | | SellFee | \*int64 | 賣出手續費 (Optional) | | SellSettlement | \*int64 | 賣出應收付款 (Optional) | | SellTax | \*int64 | 賣出交易稅 (Optional) | | TotalBsValue | \*int64 | 合計買賣金額 (Optional) | | TotalFee | \*int64 | 合計手續費 (Optional) | | TotalTax | \*int64 | 合計交易稅 (Optional) | | TotalSettlementAmount | \*int64 | 合計交割金額 (Optional) | | Currency | \*string | 幣別 (Optional) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢交割款 (查詢三日) settlement, err := sdk.Accounting.QuerySettlement(account, "3d") if err != nil { fmt.Printf("❌ Query Settlement Format/Parser Error: %v\n", err) return } if settlement.IsSuccess && settlement.Data != nil { fmt.Println("✅ Settlement Data:") fmt.Printf("Account: %s\n", *settlement.Data.Account.Account) if settlement.Data.Details != nil { for i, detail := range *settlement.Data.Details { fmt.Printf("\n=== Day %d (%s) ===\n", i+1, *detail.Date) if detail.SettlementDate != nil { fmt.Printf("交割日: %s\n", *detail.SettlementDate) fmt.Printf("買進: %d (手續費: %d, 稅: %d)\n", *detail.BuyValue, *detail.BuyFee, *detail.BuyTax) fmt.Printf("賣出: %d (手續費: %d, 稅: %d)\n", *detail.SellValue, *detail.SellFee, *detail.SellTax) fmt.Printf("合計交割款: %d\n", *detail.TotalSettlementAmount) } else { fmt.Println("尚無交割資料") } } } } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Result{ IsSuccess: true, Message: nil, Data: &SettlementData{ Account: &AccountRes{ Account: "26", BranchNo: "6460", }, Details: &[]Settlement{ { Date: "2024/03/04", SettlementDate: "2024/03/06", BuyValue: 735500, BuyFee: 313, BuySettlement: -1429513, BuyTax: 0, SellValue: 770500, SellFee: 320, SellSettlement: 0, SellTax: 2309, TotalBsValue: 1506000, TotalFee: 633, TotalSettlementAmount: -1429513, TotalTax: 2309, Currency: "TWD", }, { Date: "2024/03/06", SettlementDate: nil, // 尚未產生交割資料 // 其他欄位皆為 nil }, }, }, } ``` --- ### 已實現損益查詢 RealizedGainsAndLoses #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]Realized | 回傳已實現損益列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 已實現 Realized 欄位[​](#已實現-realized-欄位 "Direct link to 已實現 Realized 欄位") | 參數 | 類別 | 說明 | | -------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | Date | \*string | 資料日期 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | StockNo | \*string | 股票代號 | | BuySell | BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | FilledQty | \*int64 | 成交股數 | | FilledPrice | \*string | 成交價 | | OrderType | OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖、`OrderTypeSbl` 借券 | | RealizedProfit | \*int64 | 已實現獲利金額 | | RealizedLoss | \*int64 | 已實現損失金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢已實現損益明細 realized, err := sdk.Accounting.RealizedGainsAndLoses(account) if err != nil { fmt.Printf("❌ Realized P&L Format/Parser Error: %v\n", err) return } if realized.IsSuccess && realized.Data != nil { fmt.Printf("✅ Found %d realized records\n", len(*realized.Data)) } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Result{ IsSuccess: true, Message: nil, Data: &[]Realized{ { Date: "2023/08/16", // 資料日期 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 StockNo: "1101", // 股票代號 BuySell: BsActionSell, // 買賣別 FilledQty: 1000, // 成交股數 FilledPrice: "36.5", // 成交價 OrderType: OrderTypeStock,// 委託單類型 RealizedProfit: 36339, // 已實現獲利金額 RealizedLoss: 0, // 已實現損失金額 }, }, } ``` #### 注意事項[​](#注意事項 "Direct link to 注意事項") 1. **明細記錄**: 每筆成交一筆記錄 2. **獲利/虧損**: RealizedProfit 和 RealizedLoss 不會同時有值 3. **已含費用**: 損益已扣除手續費和交易稅 --- ### 已實現損益彙總 RealizedGainsAndLosesSummary #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | -------------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]RealizedSummary | 回傳已實現損益彙總列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 已實現彙總 RealizedSummary 欄位[​](#已實現彙總-realizedsummary-欄位 "Direct link to 已實現彙總 RealizedSummary 欄位") | 參數 | 類別 | 說明 | | --------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | StartDate | \*string | 彙總起始日 | | EndDate | \*string | 彙總截止日 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | StockNo | \*string | 股票代號 | | BuySell | BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | OrderType | OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖、`OrderTypeSbl` 借券 | | FilledQty | \*int64 | 成交股數 | | FilledAvgPrice | \*string | 成交均價 | | RealizedProfitAndLoss | \*int64 | 已實現損益金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢已實現損益彙總 realizedSum, err := sdk.Accounting.RealizedGainsAndLosesSummary(account) if err != nil { fmt.Printf("❌ Realized P&L Summary Format Parser error: %v\n", err) return } if realizedSum.IsSuccess && realizedSum.Data != nil { fmt.Printf("✅ Found %d realized summaries\n", len(*realizedSum.Data)) totalPnL := int64(0) for _, item := range *realizedSum.Data { fmt.Printf("\n股票: %s\n", *item.StockNo) fmt.Printf("期間: %s ~ %s\n", *item.StartDate, *item.EndDate) fmt.Printf("成交股數: %d\n", *item.FilledQty) fmt.Printf("成交均價: %s\n", *item.FilledAvgPrice) fmt.Printf("已實現損益: %d\n", *item.RealizedProfitAndLoss) totalPnL += *item.RealizedProfitAndLoss } fmt.Printf("\n總已實現損益: %d\n", totalPnL) } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Result{ IsSuccess: true, Message: nil, Data: &[]RealizedSummary{ { StartDate: "20230801", // 起始日期 EndDate: "20230801", // 截止日期 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 StockNo: "1101", // 股票代號 BuySell: BsActionSell,// 買賣別 OrderType: OrderTypeStock, // 委託單類型 FilledQty: 3000, // 成交股數 FilledAvgPrice: "35.7", // 成交均價 RealizedProfitAndLoss: 34026, // 已實現損益金額 }, }, } ``` --- ### 未實現損益查詢 UnrealizedGainsAndLoses #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]UnrealizedData | 回傳未實現損益列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 未實現 UnrealizedData 欄位[​](#未實現-unrealizeddata-欄位 "Direct link to 未實現 UnrealizedData 欄位") | 參數 | 類別 | 說明 | | ---------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | Date | \*string | 庫存建立日 | | BranchNo | \*string | 分公司代號 | | StockNo | \*string | 股票代號 | | BuySell | BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | OrderType | OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖、`OrderTypeSbl` 借券 | | CostPrice | \*string | 成本價 | | TradableQty | \*int64 | 可交易餘額 | | TodayQty | \*int64 | 今日餘額 | | UnrealizedProfit | \*int64 | 未實現獲利 | | UnrealizedLoss | \*int64 | 未實現虧損 | info 現股交易 buy\_sell 皆為 `Buy`,以餘額正負號顯示淨買賣部位;若為信用交易,則 buy\_sell 為 `Buy` 或 `Sell`,顯示買賣類別 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢未實現損益 unreal, err := sdk.Accounting.UnrealizedGainsAndLoses(account) if err != nil { fmt.Printf("❌ Unrealized P&L Format/Parser Error: %v\n", err) return } if unreal.IsSuccess && unreal.Data != nil { fmt.Printf("✅ Found %d positions\n", len(*unreal.Data)) totalProfit := int64(0) totalLoss := int64(0) for _, u := range *unreal.Data { fmt.Printf("\n股票: %s\n", *u.StockNo) fmt.Printf("成本價: %s\n", *u.CostPrice) fmt.Printf("今日餘額: %d\n", *u.TodayQty) fmt.Printf("未實現獲利: %d\n", *u.UnrealizedProfit) fmt.Printf("未實現虧損: %d\n", *u.UnrealizedLoss) totalProfit += *u.UnrealizedProfit totalLoss += *u.UnrealizedLoss } netPnL := totalProfit - totalLoss fmt.Printf("\n總未實現損益: %d\n", netPnL) } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Result{ IsSuccess: true, Message: nil, Data: &[]UnrealizedData{ { Date: "2021/08/09", // 庫存建立日 Account: "26", // 帳號 BranchNo: "6460", // 分公司代號 StockNo: "2303", // 股票代號 BuySell: Buy, // 買賣別 OrderType: Short, // 委託單類型 CostPrice: "50.0", // 成本價格 TradableQty: 1000, // 可交易餘額 TodayQty: 1000, // 今日餘額 UnrealizedProfit: 45200, // 未實現獲利 UnrealizedLoss: 0, // 未實現虧損 }, }, } ``` --- ### 參數對照表 #### 類別[​](#類別 "Direct link to 類別") Class ##### Order[​](#order "Direct link to Order") | Parameter | Type | Meaning | | ----------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | BuySell | BsAction | [買賣別](#bsaction) 可選用參數 `BsActionBuy` 買 、 `BsActionSell` 賣 | | Symbol | string | 股票代號 | | Price | \*string | 委託價格 (若非使用 `PriceTypeLimit` 限價,此欄代入 ***nil***) | | Quantity | int64 | 委託數量 | | MarketType | MarketType | [盤別](#markettype) 可選用參數 `MarketTypeCommon` 整股、 `MarketTypeFixing` 定盤、 `MarketTypeIntradayOdd` 盤中零股、 `MarketTypeOdd` 盤後零股、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | PriceType | PriceType | [價格旗標](#pricetype) 可選用參數為 `PriceTypeLimit` 限價、`PriceTypeLimitUp` 漲停、 `PriceTypeLimitDown` 跌停、 `PriceTypeMarket` 市價、 `PriceTypeReference` 參考價 | | TimeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `TimeInForceRod` 、 `TimeInForceFok` 、 `TimeInForceIoc` | | OrderType | OrderType | [委託類別](#ordertype) 可選用參數為 `OrderTypeStock` 現股、 `OrderTypeMargin` 融資、 `OrderTypeShort` 融券、 `OrderTypeDayTrade` 現股當沖(for 現沖先賣)、 `OrderTypeSbl` 借券 | | UserDef | \*string | 用戶自定義 (最長10個字元,不支援特殊字元及中文、不適用興櫃) | caution 不同 MarketType 對應的 Quantity 之單位及範圍不同,請參考[盤別](#markettype)說明。 caution 當 MarketType 為 MarketTypeCommon, MarketTypeOdd, MarketTypeIntradayOdd 其中之一,且 PriceType 為 PriceTypeLimit 時,需填入 Price 欄位,其餘時候 Price 欄位為 nil。 caution 現沖先賣時, OrderType = OrderTypeDayTrade, BuySell 需為 BsActionSell, MarketType 需為 MarketTypeCommon。(**其餘**現沖進出場操作, orderType = Stock) ##### OrderResult[​](#orderresult "Direct link to OrderResult") 委託列表,透過 [OrderResults(account)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/trade/GetOrderResults.md) 取得。 | 參數 | 類別 | 說明 | | --------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 原始委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間(格式: HH:MM:SS.fff 或 HH:MM:SS) | | ErrorMessage | \*string | 錯誤訊息 | | Details | \*\[]OrderDetail | 委託歷程(查詢 OrderResultsDetail 或 OrderHistory 才有值) | | >> FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90` 失敗 | | >> ModifiedTime | \*string | 修改時間(格式: HH:MM:SS.fff 或 HH:MM:SS) | | >> BeforeQty | \*int64 | 原始委託股數 | | >> AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | >> BeforePrice | \*string | 原始委託價 | | >> AfterPrice | \*string | 有效委託價 | | >> FilledMoney | \*string | 成交價金 | | >> Status | \*int64 | 委託單狀態 | | >> ErrMsg | \*string | 錯誤訊息 | 時間格式說明 last\_time 及 modified\_time 時間格式: **HH:MM:SS.fff** 或 **HH:MM:SS** (即當 .fff = .000 時省略此部分) ##### BatchResult[​](#batchresult "Direct link to BatchResult") 批次委託列表,透過 [BatchOrderLists(account)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/trade/batchOrder/BatchOrderList.md) 取得。 | Parameter | Type | Meaning | | ------------ | ------ | ------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單、 `10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | ##### ModifyPriceObj[​](#modifypriceobj "Direct link to ModifyPriceObj") 改價物件 | Parameter | Type | Meaning | | ----------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | OrderResult | OrderResult | [委託列表](#orderresult) | | Price | \*string | 改單後的價格 | | PriceType | \*PriceType | 改單後的價格類型 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | ##### ModifyQuantityObj[​](#modifyquantityobj "Direct link to ModifyQuantityObj") 改量物件 | Parameter | Type | Meaning | | ----------- | ----------- | ------------------------ | | OrderResult | OrderResult | [委託列表](#orderresult) | | Quantity | int64 | 改單後的委託量 | ##### FilledData[​](#filleddata "Direct link to FilledData") 成交回報物件 | 參數 | 類別 | 說明 | | -------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | Date | \*string | 日期 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | SeqNo | \*string | 委託單流水序號(只有主動回報才回傳此欄位) | | OrderNo | \*string | 委託書號 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | FilledNo | \*string | 成交流水號 | | FilledAvgPrice | \*string | 成交均價 | | FilledQty | \*int64 | 成交股數 | | FilledPrice | \*string | 成交單價 | | FilledTime | \*string | 成交時間 | | UserDef | \*string | 用戶自定義(只有主動回報才回傳此欄位) | ##### Account[​](#account "Direct link to Account") 帳號資訊 | Parameter | Type | Meaning | | ----------- | ------ | ------------------------------------------- | | Name | string | 客戶姓名 | | Account | string | 帳號 | | BranchNo | string | 分公司代號 | | AccountType | string | 帳號類型,回傳 `stock` 證券 、`futopt` 期貨 | #### Constants (欄位對應數值)[​](#constants-欄位對應數值 "Direct link to Constants (欄位對應數值)") ##### BsAction[​](#bsaction "Direct link to BsAction") 買賣別 (BuySell) | Name | Value | Meaning | | ------------ | ----- | ------- | | BsActionBuy | 1 | 買 | | BsActionSell | 2 | 賣 | ##### MarketType[​](#markettype "Direct link to MarketType") 盤別 | Name | Value | Meaning | | --------------------- | ----- | -------- | | MarketTypeCommon | 1 | 整股 | | MarketTypeFixing | 2 | 定盤 | | MarketTypeOdd | 3 | 盤後零股 | | MarketTypeIntradayOdd | 4 | 盤中零股 | | MarketTypeEmg | 5 | 興櫃 | | MarketTypeEmgOdd | 6 | 興櫃零股 | 使用不同 MarketType 時,相對應的 Quantity 所代表的單位及範圍也會不同,詳如下表: | Name | Quantity Unit | Quantity Ranges | | --------------------- | ------------- | --------------- | | MarketTypeCommon | 千股 | 1000 ~ 499000 | | MarketTypeFixing | 千股 | 1000 ~ 499000 | | MarketTypeIntradayOdd | 股 | 1 ~ 999 | | MarketTypeOdd | 股 | 1 ~ 999 | | MarketTypeEmg | 千股 | 1000 ~ 499000 | | MarketTypeEmgOdd | 股 | 1 ~ 999 | 使用不同 MarketType 時,可使用的 PriceType、TimeInForce 會不同,詳如下表: | MarketType | Available PriceType | Available TimeInForce | | --------------------- | ----------------------------------------------------------------------------------------- | ---------------------------------------------- | | MarketTypeCommon | PriceTypeLimit、PriceTypeLimitUp、PriceTypeLimitDown、PriceTypeMarket、PriceTypeReference | TimeInForceRod、TimeInForceIoc、TimeInForceFok | | MarketTypeFixing | PriceTypeReference | TimeInForceRod | | MarketTypeIntradayOdd | PriceTypeLimit、PriceTypeLimitUp、PriceTypeLimitDown、PriceTypeReference | TimeInForceRod | | MarketTypeOdd | PriceTypeLimit、PriceTypeLimitUp、PriceTypeLimitDown、PriceTypeReference | TimeInForceRod | | MarketTypeEmg | PriceTypeLimit | TimeInForceRod | | MarketTypeEmgOdd | PriceTypeLimit | TimeInForceRod | ##### PriceType[​](#pricetype "Direct link to PriceType") 價格類型 | Name | Value | Meaning | | ------------------ | ----- | ---------------------- | | PriceTypeLimit | 1 | 限價 | | PriceTypeLimitUp | 2 | 漲停 | | PriceTypeLimitDown | 3 | 跌停 | | PriceTypeMarket | 4 | 市價 | | PriceTypeReference | 5 | 參考價(定盤時為定盤價) | ##### TimeInForce[​](#timeinforce "Direct link to TimeInForce") 委託條件 | Name | Value | Meaning | | -------------- | ----- | ------------------------------------- | | TimeInForceRod | 1 | 當日有效(Rest of Day) | | TimeInForceFok | 2 | 全部成交否則取消(Fill-or-Kill) | | TimeInForceIoc | 3 | 立即成交否則取消(Immediate-or-Cancel) | ##### OrderType[​](#ordertype "Direct link to OrderType") 委託類別 | Name | Value | Meaning | | ----------------- | ----- | -------- | | OrderTypeStock | 1 | 現股 | | OrderTypeMargin | 2 | 融資 | | OrderTypeShort | 3 | 融券 | | OrderTypeSbl | 4 | 借券 | | OrderTypeDayTrade | 5 | 現股當沖 | ##### StockType[​](#stocktype "Direct link to StockType") 股票分類別 | Name | Value | Meaning | | -------------------- | ----- | ---------- | | StockTypeStock | 0 | 股票 | | StockTypeConvertBond | 1 | 可轉債 | | StockTypeEtfAndEtn | 3 | ETF 與 ETN | ##### FunctionType[​](#functiontype "Direct link to FunctionType") 功能類別 | Name | Value | | ---------------------------- | ----- | | 新單 | 0 | | 新單執行 | 10 | | 改價 | 15 | | 改量 | 20 | | 刪單 | 30 | | 完全成交(for 委託單歷程查詢) | 50 | | 失敗 | 90 | ##### Market[​](#market "Direct link to Market") 市場 | Name | Value | | -------- | ------- | | 上市股票 | TAIEX | | 上櫃股票 | TAISDAQ | | 興櫃股票 | TAIEMG | ##### Status[​](#status "Direct link to Status") 委託單狀態 | Name | Value | | --------------------------- | ------------------------------------------------------ | | 預約單 | 0 | | 系統將委託送往後台 | 4 (請用 OrderResults 查詢狀態) | | 後台傳送中 | 8 (請用 OrderResults 查詢狀態) | | 連線逾時 | 9 (請稍後再使用 OrderResults 查詢狀態或聯絡您的營業員) | | 委託成功 | 10 | | 未成交刪單成功 | 30 | | 部分成交,剩餘取消 | 40 | | 完全成交 | 50 | | 委託單歷程查詢標示 | 14 - 改價ACK、24 - 改量ACK、34 - 刪單ACK | | 改價成功 (歷史委託單查詢) | 15 | | 改量成功 (歷史委託單查詢) | 20 | | 改價失敗 (主動回報) | 19 | | 改量失敗 (主動回報) | 29 | | 刪單失敗 (主動回報) | 39 | --- ### API Key 登入 ApikeyLogin 版本限制 2.2.7版本新增功能 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | ---------- | | personalID | String | 登入的ID | | key | String | 申請的 key | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go loginResp, err := sdk.ApikeyLogin(personalId, key, certPath, &certPass) if err != nil { fmt.Printf("❌ Login Format/Parse Error: %v (Type: %T)\n", err, err) return } if loginResp.IsSuccess { fmt.Println("✓ Login successful!") } else { fmt.Printf("❌ Login failed: %s\n", *loginResp.Message) return } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go { isSuccess = true, message = , data = [ Account{ name = 富邦Bill, // 客戶姓名 (string) account = 28, // 客戶帳號 (string) branchNo = 6460, // 分公司代號 (string) accountType = stock // 帳號類型 (string) } ] } ``` --- ### 登入 login #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | ---------- | | personalID | String | 登入的ID | | password | String | 登入的密碼 | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go loginResp, err := sdk.Login(personalId, password, certPath, &certPass) if err != nil { fmt.Printf("❌ Login Format/Parse Error: %v (Type: %T)\n", err, err) return } if loginResp.IsSuccess { fmt.Println("✓ Login successful!") } else { fmt.Printf("❌ Login failed: %s\n", *loginResp.Message) return } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go { isSuccess = true, message = , data = [ Account{ name = 富邦Bill, // 客戶姓名 (string) account = 28, // 客戶帳號 (string) branchNo = 6460, // 分公司代號 (string) accountType = stock // 帳號類型 (string) } ] } ``` --- ### 登出 Logout #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---- | -------- | | isSuccess | bool | 是否成功 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) sdk := fubon.NewFubonCore() // login ... logoutResp, err := sdk.Logout() fmt.Println("Logout result: ", logoutResp) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Logout result: true ``` --- ### 刪除批次委託單 BatchCancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ---------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | orderResults | \[]OrderResult | 批次取消委託單列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]OrderResult | 回傳刪除結果列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 方法 1: 批次刪單(利用 batch detail 回傳的內容刪單) batchList, _ := sdk.Stock.BatchOrderLists(account) if batchList.Data != nil && len(*batchList.Data) > 0 { batchRes := (*batchList.Data)[0] batchDetail, _ := sdk.Stock.BatchOrderDetail(account, batchRes) if batchDetail.Data != nil && len(*batchDetail.Data) >= 2 { cancelOrders := []fubon.OrderResult{ (*batchDetail.Data)[0], (*batchDetail.Data)[1], } batchCancel, err := sdk.Stock.BatchCancelOrder(account, cancelOrders) if err != nil { fmt.Printf("❌ Batch Cancel Order Format/Parse Error: %v\n", err) return } if batchCancel.IsSuccess && batchCancel.Data != nil { fmt.Printf("✅ Cancelled %d orders\n", len(*batchCancel.Data)) for i, result := range *batchCancel.Data { fmt.Printf("Order %d: OrderNo=%s, Status=%d (30=已刪單)\n", i+1, *result.OrderNo, *result.Status) } } } } // 方法 2: 批次刪單(利用不同的單筆委託) ordResult, _ := sdk.Stock.OrderResults(account) if ordResult.Data != nil && len(*ordResult.Data) >= 2 { cancelOrders := []fubon.OrderResult{ (*ordResult.Data)[0], (*ordResult.Data)[1], } batchCancel, err := sdk.Stock.BatchCancelOrder(account, cancelOrders) if err != nil { fmt.Printf("❌ Batch Cancel Order Format/Parse Error: %v\n", err) return } if !batchCancel.IsSuccess { message := "No message" if batchCancel.Message != nil { message = *batchCancel.Message } fmt.Printf("Batch cancel failed. Message: %s\n", message) return } if batchCancel.Data != nil { fmt.Println("✅ Batch cancel succeeded!") for i, result := range *batchCancel.Data { fmt.Printf("\n--- Cancelled Order %d ---\n", i+1) fmt.Printf("FunctionType: %d (30=刪單)\n", *result.FunctionType) fmt.Printf("OrderNo: %s\n", *result.OrderNo) fmt.Printf("StockNo: %s\n", *result.StockNo) fmt.Printf("Status: %d\n", *result.Status) fmt.Printf("AfterQty: %d (刪單後為0)\n", *result.AfterQty) fmt.Printf("BeforeQty: %d\n", *result.BeforeQty) } } } else { fmt.Println("⚠️ No orders found for batch cancellation") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Result{ IsSuccess: true, Message: nil, Data: &[]OrderResult{ { FunctionType: 30, // 功能別 (30=刪單) Date: "2024/03/08", // 交易日期 SeqNo: "00000308998", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "x0028", // 委託書號 AssetType: 0, // 資產類別 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "1101", // 股票代號 BuySell: Sell, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "41.2", // 價格 Quantity: 5000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 30, // 委託單狀態 (30=未成交刪單成功) AfterPrice: "41.2", // 有效委託價格 AfterQty: 0, // 有效委託股數 (刪單後為0) BeforeQty: 5000, // 改單前有效量 BeforePrice: "41.2", // 改單前有效價 UserDef: "12345678", // 自訂欄位 LastTime: "12:53:57.536", // 最後異動時間 // ... 其他欄位 }, { FunctionType: 30, // 功能別 (30=刪單) Date: "2024/03/08", // 交易日期 SeqNo: "0000030899", // 委託單流水序號 OrderNo: "x0029", // 委託書號 StockNo: "1101", // 股票代號 Status: 30, // 委託單狀態 // ... 其他欄位 }, }, } ``` --- ### 批次修改委託價格 BatchModifyPrice ##### 先使用 MakeModifyPriceObj 建立 ModifyPriceObj 物件[​](#先使用-makemodifypriceobj-建立-modifypriceobj-物件 "Direct link to 先使用 MakeModifyPriceObj 建立 ModifyPriceObj 物件") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------ | ---------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | \*string | 修改後的價格 | | priceType | \*PriceType | 修改後的價格旗標 | caution 當 price 欄位有填入值時,priceType 需為 nil ; 當 priceType 欄位有填入值時,price 需為 nil 將回傳的物件放入 BatchModifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------- | -------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | modifyPriceObjs | \[]ModifyPriceObj | 批次修改價格物件列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]OrderResult | 回傳修改資訊列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 方法 1: 使用批次明細回傳的內容改價 batchList, _ := sdk.Stock.BatchOrderLists(account) if batchList.Data != nil && len(*batchList.Data) > 0 { batchRes := (*batchList.Data)[0] batchDetail, _ := sdk.Stock.BatchOrderDetail(account, batchRes) if batchDetail.Data != nil && len(*batchDetail.Data) >= 2 { price1 := "41.1" price2 := "41.2" modifyObjs := []fubon.ModifyPrice{ sdk.Stock.MakeModifyPriceObj((*batchDetail.Data)[0], &price1, nil), sdk.Stock.MakeModifyPriceObj((*batchDetail.Data)[1], &price2, nil), } batchPrice, err := sdk.Stock.BatchModifyPrice(account, modifyObjs) if err != nil { fmt.Printf("❌ Batch Modify Price Format/Parse Error: %v\n", err) return } if batchPrice.IsSuccess && batchPrice.Data != nil { fmt.Printf("✅ Modified %d orders\n", len(*batchPrice.Data)) } } } // 方法 2: 使用不同的單筆委託改價 ordResult, _ := sdk.Stock.OrderResults(account) if ordResult.Data != nil && len(*ordResult.Data) >= 2 { price1 := "41.1" price2 := "41.2" modifyObjs := []fubon.ModifyPrice{ sdk.Stock.MakeModifyPriceObj((*ordResult.Data)[0], &price1, nil), sdk.Stock.MakeModifyPriceObj((*ordResult.Data)[1], &price2, nil), } batchPrice, _ := sdk.Stock.BatchModifyPrice(account, modifyObjs) // ... 處理結果 } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Result{ IsSuccess: true, Message: nil, Data: &[]OrderResult{ { FunctionType: 15, // 功能別 (15=改價) Date: "2023/11/22", // 交易日期 SeqNo: "00000322356", // 委託單流水序號 OrderNo: "x0018", // 委託書號 StockNo: "1101", // 股票代號 BeforePrice: "41.3", // 改單前有效價 AfterPrice: "41.1", // 有效委託價格 (改價後) // ... 其他欄位 }, // ... 更多改價結果 }, } ``` --- ### 批次修改委託數量 BatchModifyQuantity ##### 先使用 MakeModifyQuantityObj 建立 ModifyQuantityObj 物件[​](#先使用-makemodifyquantityobj-建立-modifyquantityobj-物件 "Direct link to 先使用 MakeModifyQuantityObj 建立 ModifyQuantityObj 物件") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | int64 | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 BatchModifyQuantity 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------- | ---------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | modifyQuantityObjs | \[]ModifyQuantityObj | 批次改量物件列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]OrderResult | 回傳修改資訊列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 方法 1: 使用批次明細回傳的內容改量 batchList, _ := sdk.Stock.BatchOrderLists(account) if batchList.Data != nil && len(*batchList.Data) > 0 { batchRes := (*batchList.Data)[0] batchDetail, _ := sdk.Stock.BatchOrderDetail(account, batchRes) if batchDetail.Data != nil && len(*batchDetail.Data) >= 2 { modifyObjs := []fubon.ModifyQuantity{ sdk.Stock.MakeModifyQuantityObj((*batchDetail.Data)[0], 1000), sdk.Stock.MakeModifyQuantityObj((*batchDetail.Data)[1], 1000), } batchQty, err := sdk.Stock.BatchModifyQuantity(account, modifyObjs) if err != nil { fmt.Printf("❌ Batch Modify Quantity Format/Parse Error: %v\n", err) return } if batchQty.IsSuccess && batchQty.Data != nil { fmt.Printf("✅ Modified %d orders quantity\n", len(*batchQty.Data)) for i, result := range *batchQty.Data { fmt.Printf("Order %d: BeforeQty=%d, AfterQty=%d\n", i+1, *result.BeforeQty, *result.AfterQty) } } } } // 方法 2: 使用不同的單筆委託改量 ordResult, _ := sdk.Stock.OrderResults(account) if ordResult.Data != nil && len(*ordResult.Data) >= 2 { modifyObjs := []fubon.ModifyQuantity{ sdk.Stock.MakeModifyQuantityObj((*ordResult.Data)[0], 1000), sdk.Stock.MakeModifyQuantityObj((*ordResult.Data)[1], 1000), } batchQty, _ := sdk.Stock.BatchModifyQuantity(account, modifyObjs) // ... 處理結果 } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go Result{ IsSuccess: true, Message: nil, Data: &[]OrderResult{ { FunctionType: 20, // 功能別 (20=改量) Date: "2024/03/08", // 交易日期 SeqNo: "00000000042", // 委託單流水序號 OrderNo: "x0026", // 委託書號 StockNo: "2881", // 股票代號 BeforeQty: 2000, // 改單前有效量 AfterQty: 1000, // 有效委託股數 (改量後) UserDef: "batch 2", // 自訂欄位 // ... 其他欄位 }, // ... 更多改量結果 }, } ``` --- ### 取得批次委託明細 BatchOrderDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------ | ---------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | batchResult | [BatchResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#batchresult) | 批次委託列表項目 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]OrderResult | 回傳委託資訊列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | Details | \*string | 委託歷程 (查詢 OrderResultDetail 或 OrderHistory 才有值) | | ErrorMessage | \*string | 錯誤訊息 | caution 此功能僅供查詢批次送單執行結果,欲取得委託單最新狀態請使用單筆委託單查詢功能 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 先取得批次委託列表 batchList, err := sdk.Stock.BatchOrderLists(account) if err != nil { fmt.Printf("❌ Get Batch List Format/Parse Error: %v\n", err) return } // 選擇第一筆批次單查詢明細 if batchList.Data != nil && len(*batchList.Data) > 0 { batchRes := (*batchList.Data)[0] fmt.Printf("Querying batch detail for: %s\n", *batchRes.BatchSeqNo) // 查詢批次委託明細 batchDetail, err := sdk.Stock.BatchOrderDetail(account, batchRes) if err != nil { fmt.Printf("❌ Batch Order Detail Format/Parse Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !batchDetail.IsSuccess { message := "No message" if batchDetail.Message != nil { message = *batchDetail.Message } fmt.Printf("Get order result failed. Message: %s\n", message) return } // 輸出批次明細 if batchDetail.Data != nil && len(*batchDetail.Data) > 0 { fmt.Printf("✅ Batch contains %d orders\n", len(*batchDetail.Data)) for i, result := range *batchDetail.Data { fmt.Printf("\n--- Order %d ---\n", i+1) fmt.Printf("OrderNo: %s\n", *result.OrderNo) fmt.Printf("StockNo: %s\n", *result.StockNo) fmt.Printf("BuySell: %v\n", *result.BuySell) fmt.Printf("Price: %s\n", *result.Price) fmt.Printf("Quantity: %d\n", *result.Quantity) fmt.Printf("Status: %d\n", *result.Status) } } else { fmt.Println("Order result success but no data returned.") } } else { fmt.Println("⚠️ No batch orders found") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // BatchOrderDetail 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &[]OrderResult{ { FunctionType: nil, // 功能別 Date: "2023/10/18", // 日期 SeqNo: "00000000007", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "bA683", // 委託書號 AssetType: 0, // 資產類別 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "2888", // 股票代號 BuySell: Buy, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "8.9", // 價格 Quantity: 2000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 10, // 委託單狀態 AfterPriceType: Limit, // 有效委託價格別 AfterPrice: "8.9", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 2000, // 有效委託股數 FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: 0, // 改單前有效量 BeforePrice: "8.9", // 改單前有效價 UserDef: "", // 自訂欄位 LastTime: "14:41:32.647", // 最後異動時間 Details: nil, // 委託歷程 ErrorMessage: "", // 錯誤訊息 }, // ... 更多委託單 }, } ``` --- ### 取得批次委託列表 BatchOrderLists #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]BatchResult | 回傳批次單資訊列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 批次單 BatchResult 欄位[​](#批次單-batchresult-欄位 "Direct link to 批次單 BatchResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------ | -------- | -------------------------------------------------------------------------------- | | FunctionType | \*int64 | 功能別 : `0` 新單、 `10` 新單執行、 `15` 改價、 `20` 改量、`30` 刪單 、`90` 失敗 | | Date | \*string | 交易日期 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | BatchSeqNo | \*string | 批次單流水序號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢批次委託列表 batchList, err := sdk.Stock.BatchOrderLists(account) // 錯誤處理 if err != nil { fmt.Printf("❌ Get Batch List Format/Parse Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !batchList.IsSuccess { message := "No message" if batchList.Message != nil { message = *batchList.Message } fmt.Printf("Get batch list failed. Message: %s\n", message) return } // 輸出批次列表 if batchList.Data != nil && len(*batchList.Data) > 0 { fmt.Printf("✅ Found %d batch orders\n", len(*batchList.Data)) for i, batch := range *batchList.Data { fmt.Printf("\n--- Batch %d ---\n", i+1) fmt.Printf("Date: %s\n", *batch.Date) fmt.Printf("BatchSeqNo: %s\n", *batch.BatchSeqNo) fmt.Printf("FunctionType: %d\n", *batch.FunctionType) fmt.Printf("Account: %s\n", *batch.Account) } } else { fmt.Println("Get batch list success but no data returned.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // BatchOrderLists 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &[]BatchResult{ { FunctionType: 0, // 功能種類 (新單) Date: "2023/10/04", // 交易日期 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 BatchSeqNo: "11EE626533D072228000000C29304663", // 批次單流水序號 }, // ... 更多批次單 }, } ``` --- ### 建立批次委託單 BatchPlaceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | orders | \[]Order | 委託內容列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]OrderResult | 回傳委託資訊列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | Details | \*string | 委託歷程 (查詢 OrderResultDetail 或 OrderHistory 才有值) | | ErrorMessage | \*string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 準備批次委託單 userDef1 := "batch1" userDef2 := "batch2" orders := []fubon.Order{ { BuySell: fubon.BsActionBuy, Symbol: "2881", Price: nil, // 使用 PriceType 指定 Quantity: 2000, MarketType: fubon.MarketTypeCommon, PriceType: fubon.PriceTypeLimitDown, // 跌停價 TimeInForce: fubon.TimeInForceRod, OrderType: fubon.OrderTypeStock, UserDef: &userDef1, }, { BuySell: fubon.BsActionBuy, Symbol: "2881", Price: nil, Quantity: 2000, MarketType: fubon.MarketTypeCommon, PriceType: fubon.PriceTypeLimitDown, TimeInForce: fubon.TimeInForceRod, OrderType: fubon.OrderTypeStock, UserDef: &userDef2, }, } // 批次下單 batResult, err := sdk.Stock.BatchPlaceOrder(account, orders) // 錯誤處理 if err != nil { fmt.Printf("❌ Batch Place Order Format/Parse Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !batResult.IsSuccess { message := "No message" if batResult.Message != nil { message = *batResult.Message } fmt.Printf("Batch place order failed. Message: %s\n", message) return } // 輸出批次下單結果 if batResult.Data != nil && len(*batResult.Data) > 0 { fmt.Printf("✅ Batch placed %d orders successfully!\n", len(*batResult.Data)) for i, result := range *batResult.Data { fmt.Printf("\n--- Order %d ---\n", i+1) fmt.Printf("SeqNo: %s\n", *result.SeqNo) fmt.Printf("StockNo: %s\n", *result.StockNo) fmt.Printf("Price: %s\n", *result.Price) fmt.Printf("Quantity: %d\n", *result.Quantity) fmt.Printf("Status: %d\n", *result.Status) if result.UserDef != nil { fmt.Printf("UserDef: %s\n", *result.UserDef) } } } else { fmt.Println("Batch order succeeded but no data returned.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // BatchPlaceOrder 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &[]OrderResult{ { FunctionType: 0, // 功能別 (新單) Date: "2023/09/22", // 交易日期 SeqNo: "00000221431", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "", // 委託書號 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "2888", // 股票代號 BuySell: Buy, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "8.9", // 價格 Quantity: 2000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: true, // 是否為預約單 Status: 0, // 委託單狀態 (預約單) AfterPriceType: Limit, // 有效委託價格別 AfterPrice: "8.9", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 2000, // 有效委託股數 FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: 0, // 異動前有效量 BeforePrice: "9.1", // 異動前有效價 UserDef: nil, // 自定義欄位 LastTime: nil, // 最後異動時間 Details: nil, // 委託歷程 ErrorMessage: "", // 錯誤訊息 }, { FunctionType: 0, // 功能別 (新單) Date: "2023/09/22", // 交易日期 SeqNo: "00000221432", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "", // 委託書號 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "2888", // 股票代號 BuySell: Buy, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "8.9", // 價格 Quantity: 2000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: true, // 是否為預約單 Status: 0, // 委託單狀態 AfterPriceType: Limit, // 有效委託價格別 AfterPrice: "8.9", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 2000, // 有效委託股數 FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: 0, // 異動前有效量 BeforePrice: "9.1", // 異動前有效價 UserDef: nil, // 自定義欄位 LastTime: nil, // 最後異動時間 Details: nil, // 委託歷程 ErrorMessage: "", // 錯誤訊息 }, }, } ``` --- ### 刪除委託單 CancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------ | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#orderresult) | 欲取消的委託單物件 | | unblock | \*bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回�傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*OrderResult | 回傳委託資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 刪單資訊 OrderResult 欄位[​](#刪單資訊-orderresult-欄位 "Direct link to 刪單資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | Details | \*string | 委託歷程 (查詢 OrderResultDetail 或 OrderHistory 才有值) | | ErrorMessage | \*string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 取得委託單列表 ordResult, err := sdk.Stock.OrderResults(account) if err != nil { fmt.Printf("❌ Get Order Results Error: %v\n", err) return } // 選擇要刪除的委託單 var cancelOrder fubon.OrderResult if ordResult.Data != nil && len(*ordResult.Data) > 0 { cancelOrder = (*ordResult.Data)[0] fmt.Println("Selected order for cancellation") fmt.Printf("OrderNo: %s, StockNo: %s\n", *cancelOrder.OrderNo, *cancelOrder.StockNo) // 刪除委託單 unblock := false cancelRes, err := sdk.Stock.CancelOrder(account, cancelOrder, &unblock) if err != nil { fmt.Printf("❌ Cancel Order Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !cancelRes.IsSuccess { message := "No message" if cancelRes.Message != nil { message = *cancelRes.Message } fmt.Printf("Cancel failed. Message: %s\n", message) return } // 輸出刪單結果 if cancelRes.Data != nil { fmt.Println("✅ Order cancelled successfully!") fmt.Printf("FunctionType: %d (30=刪單)\n", *cancelRes.Data.FunctionType) fmt.Printf("Status: %d (30=未成交刪單成功)\n", *cancelRes.Data.Status) fmt.Printf("OrderNo: %s\n", *cancelRes.Data.OrderNo) fmt.Printf("AfterQty: %d\n", *cancelRes.Data.AfterQty) } else { fmt.Println("Order cancelled but no data returned.") } } else { fmt.Println("⚠️ No orders found for cancellation") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // CancelOrder 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &OrderResult{ FunctionType: 30, // 功能別 (30=刪單) Date: "2024/03/08", // 交易日期 SeqNo: "00000308948", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "x0023", // 委託書號 AssetType: 0, // 資產類別 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "1101", // 股票代號 BuySell: Sell, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "41.2", // 價格 Quantity: 5000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 30, // 委託單狀態 (30=未成交刪單成功) AfterPriceType: Limit, // 有效委託價格別 AfterPrice: "41.2", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 0, // 有效委託股數 (刪單後為0) FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: 5000, // 改單前有效量 BeforePrice: "41.2", // 改單前有效價 UserDef: "12345678", // 自訂欄位 LastTime: "12:53:57.536", // 最後異動時間 Details: nil, // 委託歷程 ErrorMessage: "", // 錯誤訊息 }, } ``` #### 注意事項[​](#注意事項 "Direct link to 注意事項") 1. **刪單條件**: 只能刪除未成交或部分成交的委託單,已完全成交的委託單無法刪除 2. **FunctionType**: 刪單成功時 `FunctionType` 為 `30` 3. **Status**: 刪單成功時 `Status` 為 `30` (未成交刪單成功) 或 `40` (部分成交,剩餘取消) 4. **AfterQty**: 刪單成功後,`AfterQty` 會變成 `0`,表示沒有有效委託量 5. **委託單物件**: 需先透過 `OrderResults()` 取得委託單列表,再從中選擇要刪除的委託單 6. **非阻塞模式**: 使用 `&unblock` 參數可設定是否採用非阻塞模式,預設為 `false` (阻塞模式) --- ### 現沖券配額查詢 DaytradeAndStockInfo #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | stockNo | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*DayTradeStockInfo | 回傳配額資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 配額資訊 DayTradeStockInfo 欄位[​](#配額資訊-daytradestockinfo-欄位 "Direct link to 配額資訊 DayTradeStockInfo 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ | | StockNo | \*string | 股票代號 | | Date | \*string | 日期 | | DaytradeOrigQuota | \*int64 | 原始現沖券餘額 | | DaytradeTradableQuota | \*int64 | 可用現沖券餘額 | | PrecollectSingle | \*int64 | 單筆預收股數 (若不需預收則回傳 nil) | | PrecollectAccumulate | \*int64 | 累積預收股數 (若不需預收則回傳 nil) | | Status | \*int64 | 狀態 (bitmask 加總) : `0` 全禁 、 `1` 平盤下可融券賣出、 `2` 平盤下可借券賣出、 `4` 可先買後賣當沖 、 `8` 可先賣後買當沖 | | DispositionStatus | \*string | 警示股註記 `{ SETTYPE : 1}` : 全額交割、 `{ MARK-W : 1}` : 警示、`{ MARK-P : 1}` : 注意、`{ MARK-L : 1}` : 委託受限 | info status 範例說明 : 若 Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若 Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢現沖券配額 stockNo := "2330" daytradeStock, err := sdk.Stock.DaytradeAndStockInfo(account, stockNo) // 錯誤處理 if err != nil { fmt.Printf("❌ DayTrade Stock Info Format/Parse Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !daytradeStock.IsSuccess { message := "No message" if daytradeStock.Message != nil { message = *daytradeStock.Message } fmt.Printf("DayTrade Stock Info failed. Message: %s\n", message) return } // 輸出配額資訊 if daytradeStock.Data != nil { fmt.Println("✅ DayTrade Stock Info:") fmt.Printf("StockNo: %s\n", *daytradeStock.Data.StockNo) fmt.Printf("Date: %s\n", *daytradeStock.Data.Date) fmt.Printf("原始現沖券餘額: %d\n", *daytradeStock.Data.DaytradeOrigQuota) fmt.Printf("可用現沖券餘額: %d\n", *daytradeStock.Data.DaytradeTradableQuota) } else { fmt.Println("No DayTrade Stock Info data returned.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // DaytradeAndStockInfo 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &DayTradeStockInfo{ StockNo: "3264", // 股票代號 Date: "2023/10/04", // 日期 DaytradeOrigQuota: 0, // 原始現沖券餘額 DaytradeTradableQuota: 0, // 可用現沖券餘額 PrecollectSingle: nil, // 單筆預收股數 (不需預收) PrecollectAccumulate: nil, // 累積預收股數 (不需預收) Status: 0, // 狀態 (全禁) DispositionStatus: "", // 警示股註記 }, } ``` --- ### 查詢歷史成交 FilledHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | ---------------------------------------------------------------------------------------- | --------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | startDate | \*string | 查詢開始日 (格式: YYYYMMDD) | | endDate | \*string (空值預設與開始日相同) | 查詢終止日 (格式: YYYYMMDD) | info 每次查詢最大設定30日日期區間 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | --------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]FilledData | 回傳成交列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 成交資訊 FilledData 欄位[​](#成交資訊-filleddata-欄位 "Direct link to 成交資訊 FilledData 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | Date | \*string | 成交日期 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | SeqNo | \*string | 委託單流水序號 (只有主動回報才回傳此欄位) | | OrderNo | \*string | 委託書號 | | StockNo | \*string | 股票代號 | | BuySell | BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | FilledNo | \*string | 成交流水號 | | FilledAvgPrice | \*string | 成交均價 | | FilledQty | \*int64 | 成交股數 | | FilledPrice | \*string | 成交單價 | | OrderType | OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | FilledTime | \*string | 成交時間 | | UserDef | \*string | 自訂欄位 (只有主動回報才回傳此欄位) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢歷史成交 startDate := "20250401" endDate := "20250501" filledHis, err := sdk.Stock.FilledHistory(account, &startDate, &endDate) // 錯誤處理 if err != nil { fmt.Printf("❌ Filled History Format/Parse Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !filledHis.IsSuccess { message := "No message" if filledHis.Message != nil { message = *filledHis.Message } fmt.Printf("Filled history failed. Message: %s\n", message) return } // 輸出歷史成交列表 if filledHis.Data != nil && len(*filledHis.Data) > 0 { fmt.Printf("✅ Found %d filled records\n", len(*filledHis.Data)) for i, filled := range *filledHis.Data { fmt.Printf("\n--- Filled %d ---\n", i+1) fmt.Printf("Date: %s\n", *filled.Date) fmt.Printf("OrderNo: %s\n", *filled.OrderNo) fmt.Printf("StockNo: %s\n", *filled.StockNo) fmt.Printf("BuySell: %v\n", filled.BuySell) fmt.Printf("FilledQty: %d\n", *filled.FilledQty) fmt.Printf("FilledPrice: %s\n", *filled.FilledPrice) fmt.Printf("FilledAvgPrice: %s\n", *filled.FilledAvgPrice) fmt.Printf("FilledTime: %s\n", *filled.FilledTime) fmt.Printf("OrderType: %v\n", filled.OrderType) if filled.UserDef != nil && *filled.UserDef != "" { fmt.Printf("UserDef: %s\n", *filled.UserDef) } } } else { fmt.Println("No filled data returned.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // FilledHistory 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &[]FilledData{ { Date: "2025/04/29", // 成交日期 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 SeqNo: nil, // 委託流水序號 OrderNo: "bA422", // 委託書號 StockNo: "1101", // 股票代號 BuySell: Sell, // 買賣別 FilledNo: "00000000001", // 成交流水號 FilledAvgPrice: "35.2", // 成交均價 FilledQty: 1000, // 成交股數 FilledPrice: "35.2", // 成交單價 OrderType: Stock, // 委託單類型 FilledTime: "10:31:00.931", // 成交時間 UserDef: nil, // 用戶自定義 }, // ... 更多成交記錄 }, } ``` --- ### 取得委託單結果 GetOrderResults #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]OrderResult | 回傳委託單列表 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | Details | \*string | 委託歷程 (查詢 OrderResultDetail 或 OrderHistory 才有值) | | ErrorMessage | \*string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 取得委託單結果 ordResult, err := sdk.Stock.GetOrderResults(account) // 錯誤處理 if err != nil { fmt.Printf("❌ Get Order Results Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !ordResult.IsSuccess { message := "No message" if ordResult.Message != nil { message = *ordResult.Message } fmt.Printf("Get order result failed. Message: %s\n", message) return } // 輸出委託單列表 if ordResult.Data != nil && len(*ordResult.Data) > 0 { fmt.Printf("✅ Found %d orders\n", len(*ordResult.Data)) for i, result := range *ordResult.Data { fmt.Printf("\n--- Order %d ---\n", i+1) fmt.Printf("OrderNo: %s\n", *result.OrderNo) fmt.Printf("StockNo: %s\n", *result.StockNo) fmt.Printf("BuySell: %v\n", *result.BuySell) fmt.Printf("Price: %s\n", *result.Price) fmt.Printf("Quantity: %d\n", *result.Quantity) fmt.Printf("Status: %d\n", *result.Status) fmt.Printf("FilledQty: %d\n", *result.FilledQty) fmt.Printf("AfterQty: %d\n", *result.AfterQty) } } else { fmt.Println("Order result success but no data returned.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // OrderResults 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &[]OrderResult{ { FunctionType: nil, // 功能別 Date: "2023/10/13", // 交易日期 SeqNo: "00000000002", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "bA614", // 委託書號 AssetType: 0, // 資產類別 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "2888", // 股票代號 BuySell: Buy, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "9.0", // 價格 Quantity: 2000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 10, // 委託單狀態 AfterPriceType: Limit, // 有效委託價格別 AfterPrice: "9.0", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 2000, // 有效委託股數 FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: 0, // 改單前有效量 BeforePrice: "9.0", // 改單前有效價 UserDef: "", // 自訂欄位 LastTime: "10:05:54.608", // 最後異動時間 Details: nil, // 委託歷程 ErrorMessage: "", // 錯誤訊息 }, // ... 更多委託單 }, } ``` --- ### 取得委託單結果 (含歷程) GetOrderResultsDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]OrderResult | 回傳委託單列表 (含歷程) | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | ErrorMessage | \*string | 錯誤訊息 | | Details | \*\[]OrderDetail | 委託歷程 | | >> FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90` 失敗 | | >> ModifiedTime | \*string | 修改時間 | | >> BeforeQty | \*int64 | 原始委託股數 | | >> AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | >> BeforePrice | \*string | 原始委託價 | | >> AfterPrice | \*string | 有效委託價 | | >> FilledMoney | \*string | 成交價金 | | >> Status | \*int64 | 委託單狀態 | | >> ErrorMessage | \*string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 取得委託單結果 (含歷程) ordResultDetail, err := sdk.Stock.GetOrderResultsDetail(account) // 錯誤處理 if err != nil { fmt.Printf("❌ Get Order Results Detail Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !ordResultDetail.IsSuccess { message := "No message" if ordResultDetail.Message != nil { message = *ordResultDetail.Message } fmt.Printf("Get order result detail failed. Message: %s\n", message) return } // 輸出委託單列表及歷程 if ordResultDetail.Data != nil && len(*ordResultDetail.Data) > 0 { fmt.Printf("✅ Found %d orders with details\n", len(*ordResultDetail.Data)) for i, result := range *ordResultDetail.Data { fmt.Printf("\n=== Order %d ===\n", i+1) fmt.Printf("OrderNo: %s\n", *result.OrderNo) fmt.Printf("StockNo: %s\n", *result.StockNo) fmt.Printf("BuySell: %v\n", *result.BuySell) fmt.Printf("Price: %s\n", *result.Price) fmt.Printf("Quantity: %d\n", *result.Quantity) fmt.Printf("Status: %d\n", *result.Status) // 顯示委託歷程 if result.Details != nil && len(*result.Details) > 0 { fmt.Printf("\n 委託歷程 (%d 筆):\n", len(*result.Details)) for j, detail := range *result.Details { fmt.Printf(" [%d] FunctionType: %d\n", j+1, *detail.FunctionType) fmt.Printf(" ModifiedTime: %s\n", *detail.ModifiedTime) fmt.Printf(" BeforeQty: %d -> AfterQty: %d\n", *detail.BeforeQty, *detail.AfterQty) fmt.Printf(" BeforePrice: %s -> AfterPrice: %s\n", *detail.BeforePrice, *detail.AfterPrice) fmt.Printf(" Status: %d\n", *detail.Status) } } else { fmt.Println(" 無委託歷程") } } } else { fmt.Println("Order result detail success but no data returned.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // OrderResultsDetail 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &[]OrderResult{ { FunctionType: nil, // 功能別 Date: "2023/10/13", // 交易日期 SeqNo: "00000000002", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "bA614", // 委託書號 AssetType: 0, // 資產類別 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "2888", // 股票代號 BuySell: Buy, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "9.0", // 價格 Quantity: 2000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 10, // 委託單狀態 AfterPriceType: Limit, // 有效委託價格別 AfterPrice: "9.0", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 2000, // 有效委託股數 FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: 0, // 改單前有效量 BeforePrice: "9.0", // 改單前有效價 UserDef: "", // 自訂欄位 LastTime: "10:05:54.608", // 最後異動時間 ErrorMessage: "", // 錯誤訊息 Details: &[]OrderDetail{ // 委託歷程 { FunctionType: 10, ModifiedTime: "10:05:54.608", BeforeQty: 0, AfterQty: 2000, BeforePrice: "9.0", AfterPrice: "9.0", Status: 10, ErrorMessage: "", }, }, }, // ... 更多委託單 }, } ``` --- ### 資券配額查詢 MarginQuota #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | stockNo | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------ | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*MarginShortQuota | 回傳配額資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 配額資訊 MarginShortQuota 欄位[​](#配額資訊-marginshortquota-欄位 "Direct link to 配額資訊 MarginShortQuota 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------------- | -------- | ------------ | | StockNo | \*string | 股票代號 | | Date | \*string | 日期 | | ShortsellOrigQuota | \*int64 | 原始融券餘額 | | ShortsellTradableQuota | \*int64 | 可用融券餘額 | | MarginOrigQuota | \*int64 | 原始融資餘額 | | MarginTradableQuota | \*int64 | 可用融資餘額 | | MarginRatio | \*int64 | 融資成數 | | ShortRatio | \*int64 | 融券成數 | info 回傳的額度說明 : 0 - 無額度 / 大於0 - 有額度 / nil - 無限制 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢資券配額 stockNo := "2330" marginQuo, err := sdk.Stock.MarginQuota(account, stockNo) // 錯誤處理 if err != nil { fmt.Printf("❌ Margin Quota Format/Parse Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !marginQuo.IsSuccess { message := "No message" if marginQuo.Message != nil { message = *marginQuo.Message } fmt.Printf("Margin Quota failed. Message: %s\n", message) return } // 輸出配額資訊 if marginQuo.Data != nil { fmt.Println("✅ Margin/Short Quota:") fmt.Printf("StockNo: %s\n", *marginQuo.Data.StockNo) fmt.Printf("Date: %s\n", *marginQuo.Data.Date) } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // MarginQuota 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &MarginShortQuota{ StockNo: "2330", // 股票代號 Date: "2024/01/24", // 日期 ShortsellOrigQuota: 894, // 原始融券餘額 ShortsellTradableQuota: 894, // 可用融券餘額 MarginOrigQuota: nil, // 原始融資餘額 (無限制) MarginTradableQuota: nil, // 可用融資餘額 (無限制) MarginRatio: 60, // 融資成數 60% ShortRatio: 90, // 融券成數 90% }, } ``` --- ### 修改委託價格 ModifyPrice ##### 先使用 MakeModifyPriceObj 建立 ModifyPriceObj 物件[​](#先使用-makemodifypriceobj-建立-modifypriceobj-物件 "Direct link to 先使用 MakeModifyPriceObj 建立 ModifyPriceObj 物件") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------ | ---------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | \*string | 修改後的價格 | | priceType | \*PriceType | 修改後的價格旗標 | caution 當 price 欄位有填入值時,priceType 需為 nil ; 當 priceType 欄位有填入值時,price 需為 nil 將回傳的物件放入 ModifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------------ | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | modifyPriceObj | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#modifypriceobj) | 修改價格的物件 | | unblock | \*bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*OrderResult | 回傳委託資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | Details | \*string | 委託歷程 (查詢 OrderResultDetail 或 OrderHistory 才有值) | | ErrorMessage | \*string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 先取得欲調整的委託單 ordResult, err := sdk.Stock.GetOrderResults(account) if err != nil { fmt.Printf("❌ Get Order Results Format/Parse Error: %v\n", err) return } var modifyOrder fubon.OrderResult if ordResult.Data != nil && len(*ordResult.Data) > 0 { modifyOrder = (*ordResult.Data)[0] fmt.Println("Selected order for price modification") fmt.Printf("OrderNo: %s, Current Price: %s\n", *modifyOrder.OrderNo, *modifyOrder.Price) // 建立改價物件 newPrice := "41.1" modifyPriceObj, err := sdk.Stock.MakeModifyPriceObj(modifyOrder, &newPrice, nil) if err != nil { fmt.Printf("❌ Make Modify Price Format/Parse Error: %v (Type: %T)\n", err, err) return } // 執行改價 unblock := false modifyPriceRes, err := sdk.Stock.ModifyPrice(account, modifyPriceObj, &unblock) if err != nil { fmt.Printf("❌ Modify Price Format/Parse Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !modifyPriceRes.IsSuccess { message := "No message" if modifyPriceRes.Message != nil { message = *modifyPriceRes.Message } fmt.Printf("Modify Price failed. Message: %s\n", message) return } // 輸出改價結果 if modifyPriceRes.Data != nil { fmt.Println("✅ Price modified successfully!") fmt.Printf("BeforePrice: %s -> AfterPrice: %s\n", *modifyPriceRes.Data.BeforePrice, *modifyPriceRes.Data.AfterPrice) } else { fmt.Println("Modify Price succeeded but no data returned.") } } else { fmt.Println("⚠️ No orders found for price modification") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // ModifyPrice 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &OrderResult{ FunctionType: 15, // 功能別 (15=改價) Date: "2023/11/22", // 交易日期 SeqNo: "00000308866", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "x0011", // 委託書號 AssetType: 0, // 資產類別 Market: "TAIEX", // 市場類型 MarketType: MarketTypeCommon, // 盤別種類 StockNo: "1101", // 股票代號 BuySell: BsActionSell, // 買賣別 PriceType: PriceTypeLimit, // 原始委託價格別 Price: "41.2", // 價格 Quantity: 5000, // 原始委託股數 TimeInForce: TimeInForceRod, // 委託條件別 OrderType: OrderTypeStock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 10, // 委託單狀態 AfterPriceType: PriceTypeLimit, // 有效委託價格別 AfterPrice: "41.1", // 有效委託價格 (改價後) Unit: 1000, // 單位數 AfterQty: 2000, // 有效委託股數 FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: nil, // 改單前有效量 BeforePrice: "41.3", // 改單前有效價 UserDef: "12345678", // 自訂欄位 LastTime: "10:56:57.713", // 最後異動時間 Details: nil, // 委託歷程 ErrorMessage: "", // 錯誤訊息 }, } ``` --- ### 修改委託單數量 ModifyQuantity ##### 先使用 MakeModifyQuantityObj 建立 ModifyQuantityObj 物件[​](#先使用-makemodifyquantityobj-建立-modifyquantityobj-物件 "Direct link to 先使用 MakeModifyQuantityObj 建立 ModifyQuantityObj 物件") | 參數 | 類別 | 說明 | | ----------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | int64 | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 ModifyQuantity 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | ------------------------------------------------------------------------------------------------------------ | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | modifyQuantityObj | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#modifyquantityobj) | 修改的委託單 | | unblock | \*bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*OrderResult | 回傳委託資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | Details | \*string | 委託歷程 (查詢 OrderResultDetail 或 OrderHistory 才有值) | | ErrorMessage | \*string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 先取得欲調整的委託單 ordResult, err := sdk.Stock.OrderResults(account) if err != nil { fmt.Printf("❌ Get Order Results Format/Parse Error: %v\n", err) return } var modifyOrder fubon.OrderResult if ordResult.Data != nil && len(*ordResult.Data) > 0 { modifyOrder = (*ordResult.Data)[0] fmt.Println("Selected order for quantity modification") fmt.Printf("OrderNo: %s, Current Quantity: %d\n", *modifyOrder.OrderNo, *modifyOrder.AfterQty) // 建立改量物件 (只能減量) newQuantity := int64(1000) modifyQtyObj, err := sdk.Stock.MakeModifyQuantityObj(modifyOrder, newQuantity) if err != nil { fmt.Printf("❌ Make Modify Quantity Format/Parse Error: %v (Type: %T)\n", err, err) return } // 執行改量 unblock := false modifyQtyRes, err := sdk.Stock.ModifyQuantity(account, modifyQtyObj, &unblock) if err != nil { fmt.Printf("❌ Modify Quantity Format/Parse Error: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !modifyQtyRes.IsSuccess { message := "No message" if modifyQtyRes.Message != nil { message = *modifyQtyRes.Message } fmt.Printf("Modify Quantity failed. Message: %s\n", message) return } // 輸出改量結果 if modifyQtyRes.Data != nil { fmt.Println("✅ Quantity modified successfully!") fmt.Printf("FunctionType: %d (20=改量)\n", *modifyQtyRes.Data.FunctionType) fmt.Printf("BeforeQty: %d -> AfterQty: %d\n", *modifyQtyRes.Data.BeforeQty, *modifyQtyRes.Data.AfterQty) } else { fmt.Println("Modify Quantity succeeded but no data returned.") } } else { fmt.Println("⚠️ No orders found for quantity modification") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // ModifyQuantity 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &OrderResult{ FunctionType: 20, // 功能別 (20=改量) Date: "2024/03/08", // 交易日期 SeqNo: "00000308866", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "x0011", // 委託書號 AssetType: 0, // 資產類別 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "1101", // 股票代號 BuySell: Sell, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "41.2", // 價格 Quantity: 5000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 10, // 委託單狀態 AfterPriceType: Limit, // 有效委託價格別 AfterPrice: "41.3", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 1000, // 有效委託股數 (改量後) FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: 3000, // 改單前有效量 BeforePrice: "41.2", // 改單前有效價 UserDef: "12345678", // 自訂欄位 LastTime: "12:56:28.966", // 最後異動時間 Details: nil, // 委託歷程 ErrorMessage: "", // 錯誤訊息 }, } ``` --- ### 查詢歷史委託 OrderHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | ---------------------------------------------------------------------------------------- | --------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 (格式: YYYYMMDD) | | endDate | \*string (空值預設與開始日相同) | 查詢終止日 (格式: YYYYMMDD) | info 每次查詢最大設定30日日期區間 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*\[]OrderResult | 回傳歷史委託列表 (含歷程) | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | ErrorMessage | \*string | 錯誤訊息 | | Details | \*\[]OrderDetail | 委託歷程 | | >> FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90` 失敗 | | >> ModifiedTime | \*string | 修改時間 | | >> BeforeQty | \*int64 | 原始委託股數 | | >> AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | >> BeforePrice | \*string | 原始委託價 | | >> AfterPrice | \*string | 有效委託價 | | >> FilledMoney | \*string | 成交價金 | | >> Status | \*int64 | 委託單狀態 | | >> ErrorMessage | \*string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK 並登入 sdk := fubon.NewSDK() // ... 登入、連線等初始化步驟 ... // 查詢歷史委託 startDate := "20250502" endDate := "20250502" orderHis, err := sdk.Stock.OrderHistory(account, startDate, &endDate) // 錯誤處理 if err != nil { fmt.Printf("❌ Order History Format/Parse Error:: %v (Type: %T)\n", err, err) return } // 檢查是否成功 if !orderHis.IsSuccess { message := "No message" if orderHis.Message != nil { message = *orderHis.Message } fmt.Printf("Order history failed. Message: %s\n", message) return } // 輸出歷史委託列表 if orderHis.Data != nil && len(*orderHis.Data) > 0 { fmt.Printf("✅ Found %d historical orders\n", len(*orderHis.Data)) for i, result := range *orderHis.Data { fmt.Printf("\n=== Historical Order %d ===\n", i+1) fmt.Printf("Date: %s\n", *result.Date) fmt.Printf("OrderNo: %s\n", *result.OrderNo) fmt.Printf("StockNo: %s\n", *result.StockNo) fmt.Printf("BuySell: %v\n", *result.BuySell) fmt.Printf("Price: %s\n", *result.Price) fmt.Printf("Quantity: %d\n", *result.Quantity) fmt.Printf("Status: %d\n", *result.Status) fmt.Printf("FilledQty: %d\n", *result.FilledQty) // 顯示委託歷程 if result.Details != nil && len(*result.Details) > 0 { fmt.Printf("\n 委託歷程 (%d 筆):\n", len(*result.Details)) for j, detail := range *result.Details { fmt.Printf(" [%d] FunctionType: %d, Time: %s\n", j+1, *detail.FunctionType, *detail.ModifiedTime) fmt.Printf(" Qty: %d -> %d, Price: %s -> %s\n", *detail.BeforeQty, *detail.AfterQty, *detail.BeforePrice, *detail.AfterPrice) } } } } else { fmt.Println("No order history data.") } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // OrderHistory 回傳結構 Result{ IsSuccess: true, Message: nil, Data: &[]OrderResult{ { FunctionType: nil, // 功能別 Date: "2025/05/02", // 交易日期 SeqNo: "00000000001", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "bA598", // 委託書號 AssetType: 0, // 資產類別 Market: "TAIEX", // 市場類型 MarketType: Common, // 盤別種類 StockNo: "2888", // 股票代號 BuySell: Buy, // 買賣別 PriceType: Limit, // 原始委託價格別 Price: "8.9", // 價格 Quantity: 2000, // 原始委託股數 TimeInForce: Rod, // 委託條件別 OrderType: Stock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 10, // 委託單狀態 AfterPriceType: nil, // 有效委託價格別 AfterPrice: "9", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 1000, // 有效委託股數 FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: nil, // 改單前有效量 BeforePrice: nil, // 改單前有效價 UserDef: "", // 自訂欄位 LastTime: "14:19:41.879", // 最後異動時間 ErrorMessage: "", // 錯誤訊息 Details: &[]OrderDetail{ // 委託歷程 { FunctionType: 10, ModifiedTime: "14:19:41.879", BeforeQty: 0, AfterQty: 1000, BeforePrice: "9.0", AfterPrice: "9.0", Status: 10, ErrorMessage: "", }, }, }, // ... 更多歷史委託單 }, } ``` --- ### 建立委託單 PlaceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ---------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#account) | 帳號 | | order | [Order](https://www.fbs.com.tw/TradeAPI/docs/trading/library/go/EnumMatrix.md#order) | 委託內容 | | unblock | \*bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------- | --------------------------------- | | IsSuccess | bool | 是否成功 | | Data | \*OrderResult | 回傳委託資訊 | | Message | \*string | 當 IsSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | FunctionType | \*int64 | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | Date | \*string | 交易日期 | | SeqNo | \*string | 委託單流水序號 | | BranchNo | \*string | 分公司代號 | | Account | \*string | 帳號 | | OrderNo | \*string | 委託書號 | | AssetType | \*int64 | 資產類別 : `0` 證券 | | Market | \*string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | MarketType | MarketType | 盤別種類 : `MarketTypeCommon` 整股 、 `MarketTypeFixing` 定盤 、 `MarketTypeIntradayOdd` 盤中零股 、 `MarketTypeOdd` 盤後零股 、 `MarketTypeEmg` 興櫃 、 `MarketTypeEmgOdd` 興櫃零股 | | StockNo | \*string | 股票代號 | | BuySell | \*BsAction | 買賣別 : `BsActionBuy` 買 、 `BsActionSell` 賣 | | PriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | Price | \*string | 價格 | | Quantity | \*int64 | 原始委託股數 | | TimeInForce | \*TimeInForce | 委託條件別 : `TimeInForceRod` ROD 、 `TimeInForceFok` FOK 、 `TimeInForceIoc` IOC | | OrderType | \*OrderType | 委託單類型 : `OrderTypeStock` 現股 、 `OrderTypeMargin` 融資 、 `OrderTypeShort` 融券 、 `OrderTypeDayTrade` 現股當沖 、 `OrderTypeSbl` 借券 | | IsPreOrder | \*bool | 是否為預約單 | | Status | \*int64 | 委託單狀態 : `0` 預約單 、 `4` 系統將委託送往後台 、 `9` 連線逾時 、`10` 委託成功 、 `30` 未成交刪單成功 、 `40` 部分成交,剩餘取消 、 `50` 完全成交 、 `90` 失敗 | | AfterPriceType | \*PriceType | 有效委託價格別 : `PriceTypeLimit` 限價 、 `PriceTypeLimitUp` 漲停 、 `PriceTypeLimitDown` 跌停 、 `PriceTypeMarket` 市價 、 `PriceTypeReference` 參考價 | | AfterPrice | \*string | 有效委託價格 | | Unit | \*int64 | 單位數 | | AfterQty | \*int64 | 有效委託股數(包含已成交部分) | | FilledQty | \*int64 | 成交股數 | | FilledMoney | \*int64 | 成交價金 | | BeforeQty | \*int64 | 改單前有效量 | | BeforePrice | \*string | 改單前有效價 | | UserDef | \*string | 自訂欄位 | | LastTime | \*string | 最後異動時間 | | Details | \*string | 委託歷程 (查詢 OrderResultDetail 或 OrderHistory 才有值) | | ErrorMessage | \*string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go package main import ( "fmt" "fubon" ) func main() { // 初始化 SDK sdk := fubon.NewSDK() orderPrice := "66.1" order := fubon.Order{ BuySell: fubon.BsActionBuy, Symbol: "2881", Price: &orderPrice, Quantity: 1000, MarketType: fubon.MarketTypeCommon, PriceType: fubon.PriceTypeLimit, TimeInForce: fubon.TimeInForceRod, OrderType: fubon.OrderTypeStock, } unblock := false result, err := sdk.Stock.PlaceOrder(account, order, &unblock) if err != nil { fmt.Printf("❌ Place Order Format/Parse Error: %v (Type: %T)\n", err, err) } else { fmt.Printf("✓ Order Placed", *result.IsSuccess) } } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go // OrderResult 結構 Result{ IsSuccess: true, Message: nil, Data: &OrderResult{ FunctionType: 0, // 功能別 Date: "2023/10/13", // 交易日期 SeqNo: "00000000007", // 委託單流水序號 BranchNo: "6460", // 分公司代號 Account: "26", // 帳號 OrderNo: "bA619", // 委託書號 AssetType: 0, // 資產類型 Market: "TAIEX", // 市場類型 MarketType: MarketTypeCommon, // 盤別種類 StockNo: "2888", // 股票代號 BuySell: BsActionBuy, // 買賣別 PriceType: PriceTypeLimit, // 原始委託價格別 Price: "9.1", // 價格 Quantity: 3000, // 原始委託股數 TimeInForce: TimeInForceRod, // 委託條件別 OrderType: OrderTypeStock, // 委託單類型 IsPreOrder: false, // 是否為預約單 Status: 10, // 委託單狀態 AfterPriceType: PriceTypeLimit, // 有效委託價格別 AfterPrice: "9.1", // 有效委託價格 Unit: 1000, // 單位數 AfterQty: 3000, // 有效委託股數 FilledQty: 0, // 成交股數 FilledMoney: 0, // 成交價金 BeforeQty: 0, // 改單前有效量 BeforePrice: "9.1", // 改單前有效價 UserDef: "", // 自訂欄位 LastTime: "12:10:12.546", // 最後異動時間 Details: nil, // 委託歷程 ErrorMessage: "", // 錯誤訊息 }, } ``` --- ### 查詢商品漲跌幅報表 ( 單筆 ) query\_symbol\_quote #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | symbol | String | 股票代碼 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolQuote | 回傳委託資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 商品資訊 SymbolQuote 欄位[​](#商品資訊-symbolquote-欄位 "Direct link to 商品資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類型 | 說明 | | ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------------- | | Market | \*string | 市場別 | | Symbol | \*string | 股票代碼 | | IsTibOrPsb | \*bool | 是否為創新板或戰略新板 | | MarketType | \*string | 市場類型 | | Status | \*int64 | 狀態 (bitmask 加總): `0` :全禁 、 `1`:平盤下可融券賣出 、 `2`:平盤下可借券賣出 、 `4`:可先買後賣當沖 、 `8`:可先賣後買當沖 | | ReferencePrice | \*string | 參考價格 | | Unit | \*int64 | 交易單位 | | UpdateTime | \*string | 更新時間 | | LimitupPrice | \*string | 漲停價 | | LimitdownPrice | \*string | 跌停價 | | OpenPrice | \*string | 開盤價 | | HighPrice | \*string | 最高價 | | LowPrice | \*string | 最低價 | | LastPrice | \*string | 最新成交價 | | TotalVolume | \*int64 | 總成交量 | | TotalTransaction | \*int64 | 總成交筆數 | | TotalValue | \*string | 總成交金額 | | LastSize | \*int64 | 最新成交量 | | LastTransaction | \*int64 | 最新成交筆數 | | LastValue | \*string | 最新成交金額 | | BidPrice | \*string | 買1價格 | | BidVolume | \*int64 | 買1數量 | | AskPrice | \*string | 賣1價格 | | AskVolume | \*int64 | 賣1數量 | 支援範圍 上市、上櫃標的 info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go quote, err := sdk.Stock.QuerySymbolQuote(account, "2330", nil) if err != nil { fmt.Printf("❌ Quote Format/Parse Error: %v (Type: %T)\n", err, err) } else { s, _ := json.MarshalIndent(quote, "", " ") fmt.Println("Quote Data ", string(s)) } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go { isSuccess : true, message : , data : SymbolQuote{ market : TAIEX, // string - 市場別 symbol : 2330, // string - 股票代碼 istibOrPsb : false, // bool - 是否為創新板或戰略新板 marketType : Common, // string - 市場類型 (現股) status : 15, // int - 狀態 (bitmask 加總: 1+2+4+8 : 可融券賣出+可借券賣出+可先買後賣當沖+可先賣後買當沖) referencePrice : 780, // double - 參考價格 (前一交易日收盤價) unit : 1000, // int - 交易單位 updateTime : , // string - 更新時間 limitupPrice : 858, // double - 漲停價 limitdownPrice : 702, // double - 跌停價 openPrice : 1155, // double - 開盤價 highPrice : 1160, // double - 最高價 lowPrice : 1145, // double - 最低價 lastPrice : 1145, // double - 最新成交價 totalVolume : 20501, // int - 總成交量 totalTransaction : 0, // int - 總成交筆數 totalValue : 23551095000, // int - 總成交金額 lastSize : 6673, // int - 最新成交量 lastTransaction : 0, // int - 最新成交筆數 lastValue : 7640585000, // int - 最新成交金額 bidPrice : 1145, // double - 買一價格 bidVolume : 1549, // int - 買一數量 askPrice : 1150, // double - 賣一價格 askVolume : 4169 // int - 賣一數量 } } ``` --- ### 查詢商品漲跌幅報表 ( 批次 ) query\_symbol\_snapshot #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#account) | 帳號 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | | stock\_type | List [StockType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/cpp/EnumMatrix.md#stocktype) (Optional)(default = Stock) | 股票分類別 : `Stock` 股票、`ConvertBond` 可轉債、`ETF_and_ETN` ETF 與 ETN | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolSnapshotResponse | 回傳委託資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 商品資訊 SymbolQuote 欄位[​](#商品資訊-symbolquote-欄位 "Direct link to 商品資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類型 | 說明 | | ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------------- | | Market | \*string | 市場別 | | Symbol | \*string | 股票代碼 | | IsTibOrPsb | \*bool | 是否為創新板或戰略新板 | | MarketType | \*string | 市場類型 | | Status | \*int64 | 狀態 (bitmask 加總): `0` :全禁 、 `1`:平盤下可融券賣出 、 `2`:平盤下可借券賣出 、 `4`:可先買後賣當沖 、 `8`:可先賣後買當沖 | | ReferencePrice | \*string | 參考價格 | | Unit | \*int64 | 交易單位 | | UpdateTime | \*string | 更新時間 | | LimitupPrice | \*string | 漲停價 | | LimitdownPrice | \*string | 跌停價 | | OpenPrice | \*string | 開盤價 | | HighPrice | \*string | 最高價 | | LowPrice | \*string | 最低價 | | LastPrice | \*string | 最新成交價 | | TotalVolume | \*int64 | 總成交量 | | TotalTransaction | \*int64 | 總成交筆數 | | TotalValue | \*string | 總成交金額 | | LastSize | \*int64 | 最新成交量 | | LastTransaction | \*int64 | 最新成交筆數 | | LastValue | \*string | 最新成交金額 | | BidPrice | \*string | 買1價格 | | BidVolume | \*int64 | 買1數量 | | AskPrice | \*string | 賣1價格 | | AskVolume | \*int64 | 賣1數量 | 支援範圍 上市、上櫃標的 info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```go snaps, err := sdk.Stock.QuerySymbolSnapshot(account, nil, nil) if err != nil { fmt.Printf("❌ Quote Format/Parse Error: %v (Type: %T)\n", err, err) } else { s, _ := json.MarshalIndent(snaps, "", " ") fmt.Println("Quote Data ", string(s)) } ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```go { isSuccess : true, message : , data : SymbolQuote{ market : TAIEX, // string - 市場別 symbol : 2330, // string - 股票代碼 istibOrPsb : false, // bool - 是否為創新板或戰略新板 marketType : Common, // string - 市場類型 (現股) status : 15, // int - 狀態 (bitmask 加總: 1+2+4+8 : 可融券賣出+可借券賣出+可先買後賣當沖+可先賣後買當沖) referencePrice : 780, // double - 參考價格 (前一交易日收盤價) unit : 1000, // int - 交易單位 updateTime : , // string - 更新時間 limitupPrice : 858, // double - 漲停價 limitdownPrice : 702, // double - 跌停價 openPrice : 1155, // double - 開盤價 highPrice : 1160, // double - 最高價 lowPrice : 1145, // double - 最低價 lastPrice : 1145, // double - 最新成交價 totalVolume : 20501, // int - 總成交量 totalTransaction : 0, // int - 總成交筆數 totalValue : 23551095000, // int - 總成交金額 lastSize : 6673, // int - 最新成交量 lastTransaction : 0, // int - 最新成交筆數 lastValue : 7640585000, // int - 最新成交金額 bidPrice : 1145, // double - 買一價格 bidVolume : 1549, // int - 買一數量 askPrice : 1150, // double - 賣一價格 askVolume : 4169 // int - 賣一數量 }, { market : TAIEX, // string - 市場別 symbol : 2330, // string - 股票代碼 ... } } ``` --- ### 銀行餘額查詢 bankRemain #### 輸入參數[​](#輸入參數 "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 | Object | 回傳餘額資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### BankRemain 欄位[​](#bankremain-欄位 "Direct link to BankRemain 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------ | ---------- | | branchNo | string | 分公司代號 | | account | string | 帳號 | | currency | string | 幣別 | | balance | int | 餘額 | | availableBalance | int | 可用餘額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.accounting.bankRemain(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:{ branchNo: "6460", // 分公司代號 (string) account: "26", // 帳號 (string) currency: "TWD", // 幣別 (string) balance: "666666", // 餘額 (int) availableBalance: "123456" // 可用餘額 (int) } } ``` --- ### 庫存查詢 inventories #### 輸入參數[​](#輸入參數 "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 | Object | 回傳庫存資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 庫存資訊 Inventory 欄位[​](#庫存資訊--inventory-欄位 "Direct link to 庫存資訊 Inventory 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | > date | string | 交易日期 | | > account | string | 帳號 | | > branchNo | string | 分公司代號 | | > stockNo | string | 股票代號 | | > orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、`SBL`借券 | | > lastdayQty | number | 昨日庫存餘額 | | > buyQty | number | 今日委買股數 | | > buyFilledQty | number | 今日買進成交股數 | | > buyValue | number | 買進價金 | | > todayQty | number | 今日庫存餘額 | | > tradableQty | number | 可委託股數 | | > sellQty | number | 今日委賣股數 | | > sellFilledQty | number | 今日賣出成交股數 | | > sellValue | number | 賣出價金 | | > odd | InventoryOdd | Object | | >> lastdayQty | nuber | 昨日庫存餘額 | | >> buyQty | number | 今日委買股數 | | >> buyFilledQty | number | 今日買進成交股數 | | >> buyValue | number | 買進價金 | | >> todayQty | number | 今日庫存餘額 | | >> tradableQty | number | 可委託股數 | | >> sellQty | number | 今日委賣股數 | | >> sellFilledQty | number | 今日賣出成交股數 | | >> sellValue | number | 賣出價金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.accounting.inventories(account); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: '2023/10/05', account: '26', branchNo: '6460', stockNo: '1101', orderType: Stock, lastdayQty: 2000, buyQty: 0, buyFilledQty: 0, buyValue: 0, todayQty: 2000, tradableQty: 2000, sellQty: 0, sellFilledQty: 0, sellValue: 0, odd: { lastdayQty: 0, buyQty: 0, buyFilledQty: 0, buyValue: 0, todayQty: 0, tradableQty: 0, sellQty: 0, sellFilledQty: 0, sellValue: 0 } }, { date: '2023/10/05', account: '26', branchNo: '6460', stockNo: '1101', orderType: Margin, lastdayQty: 8000, buyQty: 0, buyFilledQty: 0, buyValue: 0, todayQty: 8000, tradableQty: 8000, sellQty: 0, sellFilledQty: 0, sellValue: 0, odd: { lastdayQty: 0, buyQty: 0, buyFilledQty: 0, buyValue: 0, todayQty: 0, tradableQty: 0, sellQty: 0, sellFilledQty: 0, sellValue: 0 } }, ... ] } ``` --- ### 維持率查詢 maintenance #### 輸入參數[​](#輸入參數 "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 | Object | 回傳維持率資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 維持率 MaintenanceData 欄位[​](#維持率-maintenancedata-欄位 "Direct link to 維持率 MaintenanceData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | > date | string | 查詢日 | | > branchNo | string | 分公司代號 | | > account | string | 帳號 | | > maintenanceSummary | list | Object | | >> marginValue | number | 整戶融資市值 | | >> shortsellValue | number | 整戶融券市值 | | >> shortsellMargin | number | 整戶融券保證金額 | | >> collateral | number | 擔保品 | | >> marginLoanAmt | number | 整戶融資金額 | | >> maintenanceRatio | number | 整戶維持率 | | >> MaintenanceDetail | list | Object | | >>> stockNo | string | 股票代碼 | | >>> orderNo | string | 委託書號 | | >>> orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | >>> quantity | number | 持有股數 | | >>> price | number | 計算價 | | >>> costPrice | number | 成本價 | | >>> shortsellMargin | number | 融券保證金 | | >>> collateral | number | 擔保品 | | >>> marginLoanAmt | number | 融資金 | | >>> maintenanceRatio | number | 維持率 | | >>> collateralInterest | number | 擔保品利息 | | >>> marginInterest | number | 融資金利息 | | >>> shortsellInterest | number | 融券保證金利息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.accounting.maintenance(target_user); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { date: '2024/02/27', branchNo: '6460', account: '26', maintenanceSummary: { marginValue: 3135000, shortsellValue: 0, shortsellMargin: 0, collateral: 0, marginLoanAmt: 1494000, maintenanceRatio: 209.83 }, maintenanceDetail: [ { stockNo: '2603', orderNo: 'x4580', orderType: 'Stock', quantity: 10000, price: 152.5, costPrice: 119, shortsellMargin: 0, collateral: 0, marginLoanAmt: 0, maintenanceRatio: 213.58, collateralInterest: 0, marginInterest: 20818, shortsellInterest: 0 }, { stockNo: '4968', orderNo: 'x6029', orderType: 'Stock', quantity: 10000, price: 161, costPrice: 159, shortsellMargin: 0, collateral: 0, marginLoanAmt: 0, maintenanceRatio: 206.41, collateralInterest: 0, marginInterest: 23019, shortsellInterest: 0 } ] } } ``` --- ### 交割款查詢 querySettlement #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | -------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | range | string | 時間區間,目前有效值為"0d"(當日)、"3d" | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳交割款資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 交割款 SettlementData 欄位[​](#交割款-settlementdata--欄位 "Direct link to 交割款 SettlementData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------------ | ------- | ------------ | | > AccountRes | list | Object | | >> account | string | 帳號 | | >> branchNo | string | 分公司代號 | | > details | list | Object | | >> date | string | 查詢日 | | >> settlementDate | string? | 交割日 | | >> buyValue | int? | 買進金額 | | >> buyFee | int? | 買進手續費 | | >> buySettlement | int? | 買進應收付款 | | >> buyTax | int? | 買進交易稅 | | >> sellValue | int? | 賣出金額 | | >> sellFee | int? | 賣出手續費 | | >> sellSettlement | int? | 賣出應收付款 | | >> sellTax | int? | 賣出交易稅 | | >> totalBsValue | int? | 合計買賣金額 | | >> totalFee | int? | 合計手續費 | | >> totalTax | int? | 合計交易稅 | | >> totalSettlementAmount | int? | 合計交割金額 | | >> currency | string? | 幣別 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.accounting.querySettlement(target_user,"3d"); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:{ account: { branchNo: '6460', account: '26' }, details:[ { date: "2024/03/04", settlementDate: "2024/03/06", buyValue: 735500, buyFee: 313, buySettlement: -1429513, buyTax: 0, sellValue: 770500, sellFee: 320, sellSettlement: 0, sellTax: 2309, totalBsValue: 1506000, totalFee: 633, totalSettlementAmount: -1429513, totalTax: 2309, currency: "TWD" }, { date: "2024/03/05", settlementDate: "2024/03/07", buyValue: 2261470, buyFee: 1065, buySettlement: -3895335, buyTax: 0, sellValue: 2488170, sellFee: 1137, sellSettlement: 677626, sellTax: 7412, totalBsValue: 4749640, totalFee: 2202, totalSettlementAmount: -3217709, totalTax: 7412, currency: "TWD" }, { date: "2024/03/06" } ] } } ``` --- ### 已實現損益查詢 realizedGainsAndLoses #### 輸入參數[​](#輸入參數 "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 | Object | 回傳已實現資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### Realized 欄位[​](#realized-欄位 "Direct link to Realized 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | date | string | 資料日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | filledQty | number | 成交股數 | | filledPrice | number | 成交價 | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | realizedProfit | number | 已實現獲利金額 | | realizedLoss | number | 已實現損益金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.accounting.realizedGainsAndLoses(account); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: '2023/08/29', branchNo: '6460', account: '26', stockNo: '1101', buySell: Sell, filledQty: 1000, filledPrice: 35.3, orderType: 0, realizedProfit: 0, realizedLoss: 906 }, ... ] } ``` --- ### 已實現損益彙總 realizedGainsAndLosesSummary #### 輸入參數[​](#輸入參數 "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 | Object | 回傳已實現彙總資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 已實現彙總 RealizedSummary 欄位[​](#已實現彙總-realizedsummary-欄位 "Direct link to 已實現彙總 RealizedSummary 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | startDate | string | 彙總起始日 | | endDate | string | 彙總截止日 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL` 借券 | | filledQty | number | 成交股數 | | filledAvgPrice | number | 成交均價 | | realizedProfitAndLoss | number | 已實現損益金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.accounting.realizedGainsAndLosesSummary(account); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { startDate: '20230808', endDate: '20230808', branchNo: '6460', account: '26', stockNo: '1101', buySell: Sell, orderType: 0, filledQty: 3000, filledAvgPrice: 35.7, realizedProfitAndLoss: 34026 } ... ] } ``` --- ### 未實現損益查詢 unrealizedGainsAndLoses #### 輸入參數[​](#輸入參數 "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 | Object | 回傳未實現資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 未實現 UnrealizedData 欄位[​](#未實現-unrealizeddata--欄位 "Direct link to 未實現 UnrealizedData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | date | string | 查詢當天日期 | | branchNo | string | 分公司代號 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 (**註**:請見表末說明) | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | costPrice | number | 成本價 | | tradableQty | number | 可交易餘額 | | todayQty | number | 今日餘額 | | unrealizedProfit | number | 未實現獲利 | | unrealizedLoss | number | 未實現虧損 | info 現股交易 buySell 皆為 `Buy`,以餘額正負號顯示淨買賣部位;若為信用交易,則 buySell 為 `Buy` 或 `Sell`,顯示買賣類別 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.accounting.unrealizedGainsAndLoses(account); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: '2021/08/09', account: '26', branchNo: '6460', stockNo: '2303', buySell: Buy, orderType: Margin, costPrice: 50, tradableQty: 1000, todayQty: 1000, unrealizedProfit: 45200, unrealizedLoss: 0 }, ... ] } ``` --- ### 參數對照表 #### 類別[​](#類別 "Direct link to 類別") Class ##### OrderObject[​](#orderobject "Direct link to OrderObject") | Parameter | Type | Meaning | | ------------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | buySell | BSAction | [買賣別](#bsaction) 可選用參數 `Buy` 買 、 `Sell` 賣 | | symbol | string | 股票代號 | | price | string | 委託價格 (若非使用 `Limit` 限價,此欄代入 ***null***) | | quantity | int | 委託數量 | | marketType | MarketType | [盤別](#markettype) 可選用參數 `Common` 整股、 `Fixing` 定盤、 `IntradayOdd` 盤中零股、 `Odd` 盤後零股、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | priceType | PriceType | [價格旗標](#pricetype) 可選用參數為 `Limit` 限價、 `LimitUp` 漲停、 `LimitDown` 跌停、 `Market` 市價、 `Reference` 參考價 | | timeInForce | timeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD` 、 `FOK` 、 `IOC` | | orderType | OrderType | [委託類別](#ordertype) 可選用參數為 `Stock` 現股、 `Margin` 融資、 `Short` 融券、 `DayTrade` 現沖先賣、 `SBL` 借券 | | userDef (optional) | string | 用戶自定義 (最長10個字元,不支援特殊字元及中文、不適用興櫃) | caution 不同 marketType 對應的 quantity 之單位及範圍不同,請參考[盤別](#markettype)說明。 caution 當 marketType 爲 MarketType.Common, MarketType.Odd, MarketType.IntradayOdd 其中之一,且 priceType 爲 PriceType.Limit 時,需填入 price 欄位,其餘時候可不設定 price 欄位或設為 null。 現股當沖 「現沖先賣」賣出時, orderType = DayTrade , buySell 需為 Sell , marketType 需為 Common
(其餘現沖進出場操作, orderType = Stock) ##### OrderResult[​](#orderresult "Direct link to OrderResult") 委託列表,透過 [GetOrderResult(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/trade/GetOrderResults.md) 取得。 | Parameter | Type | Meaning | | --------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | MarketType | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | BSAction | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | PriceType | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | TimeInForce | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | OrderType | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | PriceType | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | lastTime | string | 最後異動時間(格式請見表末說明) | | errorMessage | string | 錯誤訊息 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | >> functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modifiedTime | string | 修改時間(格式請見表末說明) | | >> beforeQty | number | 原始委託股數 | | >> afterQty | number | 有效委託股數(包含已成交部分) | | >> beforePrice | number | 原始委託價 | | >> afterPrice | number | 有效委託價 | | >> filledMoney | number | 成交價金 | | >> status | number | 委託單狀態 | | >> errMsg | string | 錯誤訊息 | 時間格式說明 lastTime 及 modifiedTime 時間格式: **HH:MM:SS.fff** 或 **HH:MM:SS** (即當 .fff = .000 時省略此部分) ##### BatchResult[​](#batchresult "Direct link to BatchResult") 批次委託列表,透過 [BatchOrderLists(account)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/trade/batchOrder/BatchOrderList.md) 取得。 | Parameter | Type | Meaning | | ------------ | ------ | ------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單、 `10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | ##### ModifyPriceObj[​](#modifypriceobj "Direct link to ModifyPriceObj") 改價物件 | Parameter | Type | Meaning | | ----------- | --------- | ------------------------------------------------------------------------------------------------------ | | OrderResult | Object | [委託列表](#orderresult) | | price | string | 改單後的價格 | | PriceType | PriceType | 改單後的價格類型 : `Limit`限價 、`LimitUp`漲停 、 `LimitDown`跌停 、 `Market`市價 、 `Reference`參考價 | 關於價格旗標 輕量風控版**已**開放使用價格旗標 (PriceType) ##### ModifyQuantityObj[​](#modifyquantityobj "Direct link to ModifyQuantityObj") 改量物件 | Parameter | Type | Meaning | | ----------- | ------ | ------------------------ | | OrderResult | Object | [委託列表](#orderresult) | | quantity | number | 改單後的委託量 | ##### FilledData[​](#filleddata "Direct link to FilledData") 成交回報物件 | 參數 | 類別 | 說明 | | ------------------ | --------- | ---------------------------------------------------------------------------------------------- | | date | string | 日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | seqNo | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | orderNo | string | 委託書號 | | stockNo | string | 股票代號 | | buySell | BSAction | 買賣別 : `Buy` 買 、 `Sell` 賣 | | orderType | OrderType | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | filled\_no | string | 成交流水號 | | filled\_avg\_price | number | 成交均價 | | filled\_qty | number | 成交股數 | | filled\_price | number | 成交單價 | | filled\_time | string | 成交時間 | | userDef | string ? | 用戶自定義 (只有主動回報才回傳此欄位) | ##### Account[​](#account "Direct link to Account") 帳號資訊 | Parameter | Type | Meaning | | ----------- | ------ | ------------------------------------- | | name | string | 客戶姓名 | | account | string | 帳號 | | branchNo | string | 分公司代號 | | accountType | string | 帳戶類型 : `stock` 證券 `futopt` 期貨 | #### Constants ( 欄位對應數值 )[​](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )") ##### BSAction[​](#bsaction "Direct link to BSAction") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Buy | 買 | | Sell | 賣 | ##### MarketType[​](#markettype "Direct link to MarketType") 盤別 | Name | Meaning | | ----------- | -------- | | Common | 整股 | | Fixing | 定盤 | | IntradayOdd | 盤中零股 | | Odd | 盤後零股 | | Emg | 興櫃 | | EmgOdd | 興櫃零股 | 使用不同MarketType時,相對應的Quantity所代表的單位及範圍也會不同,詳如下表: | Name | Quantity Unit | Quantity Ranges | | ----------- | ------------- | --------------- | | Common | 千股 | 1000 ~ 499000 | | Fixing | 千股 | 1000 ~ 499000 | | IntradayOdd | 股 | 1 ~ 999 | | Odd | 股 | 1 ~ 999 | | Emg | 千股 | 1000 ~ 499000 | | EmgOdd | 股 | 1 ~ 999 | 使用不同 MarketType 時,可使用的 PriceType , TimeInForce 會不同,詳如下表: | MarketType | Available PriceType | Available TimeInForce | | ----------- | ---------------------------------------------------- | --------------------- | | Common | Limit 、 LimitUp 、 LimitDown 、 Market 、 Reference | ROD 、 IOC 、 FOK | | Fixing | Reference | ROD | | IntradayOdd | Limit 、 LimitUp 、 LimitDown 、 Reference | ROD | | Odd | Limit 、 LimitUp 、 LimitDown 、 Reference | ROD | | Emg | Limit | ROD | | EmgOdd | Limit | ROD | ##### PriceType[​](#pricetype "Direct link to PriceType") 價格類型 (priceType) | Name | Meaning | | --------- | ----------------------- | | Limit | 限價 | | LimitUp | 漲停 | | LimitDown | 跌停 | | Market | 市價 | | Reference | 參考價 (定盤時為定盤價) | ##### TimeInForce[​](#timeinforce "Direct link to TimeInForce") 委託條件 (TimeInForce) | Name | Meaning | | ---- | ------------------------------------- | | ROD | 當日有效(Rest of Day) | | FOK | 全部成交否則取消(Fill-or-Kill) | | IOC | 立即成交否則取消(Immediate-or-Cancel) | ##### OrderType[​](#ordertype "Direct link to OrderType") 委託類別 (orderType) | Name | Meaning | | -------- | -------- | | Stock | 現股 | | Margin | 融資 | | Short | 融券 | | DayTrade | 現沖先賣 | | SBL | 借券 | ##### StockType[​](#stocktype "Direct link to StockType") 股票分類別 | Name | Meaning | | ------------- | ---------- | | Stock | 股票 | | ConvertBond | 可轉債 | | ETF\_and\_ETN | ETF 與 ETN | ##### functionType[​](#functiontype "Direct link to functionType") 功能類別 | Name | Value | | ------------------------------ | ----- | | 新單 | 0 | | 新單執行 | 10 | | 改價 | 15 | | 改量 | 20 | | 刪單 | 30 | | 完全成交(for 委託單歷程查詢) | 50 | | 失敗 | 90 | ##### market[​](#market "Direct link to market") 市場 | Name | Value | | -------- | ------- | | 上市股票 | TAIEX | | 上櫃股票 | TAISDAQ | | 興櫃股票 | TAIEMG | ##### status[​](#status "Direct link to status") 委託單狀態 | Name | Value | | --------------------------- | ---------------------------------------------------------- | | 預約單 | 0 | | 系統將委託送往後台 | 4 ( 請用GetOrderResult查詢狀態 ) | | 後台傳送中 | 8 ( 請用GetOrderResult查詢狀態 ) | | 連線逾時 | 9 ( 請稍後再使用GetOrderResult查詢狀態 or 聯絡您的營業員 ) | | 委託成功 | 10 | | 未成交刪單成功 | 30 | | 部分成交,剩餘取消 | 40 | | 完全成交 | 50 | | 失敗 | 90 | | 委託單歷程查詢標示 | 14 - 改價ACK、24 - 改量ACK、34 - 刪單ACK | | 改價成功 (歷史委託單查詢) | 15 | | 改量成功 (歷史委託單查詢) | 20 | | 改價失敗 (主動回報) | 19 | | 改量失敗 (主動回報) | 29 | | 刪單失敗 (主動回報) | 39 | --- ### API Key 登入 apikeyLogin 版本資訊 v2.2.7 起新增功能 相關說明請參閱 [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.md) 頁面 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | -------------- | | personalID | String | 登入的ID | | key | String | 申請的 API Key | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳帳號資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); const sdk = new FubonSDK(); const accounts = sdk.apikeyLogin("Your ID", "Your Key","Your Cert Path","Your Cert Password"); Console.log(accounts); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { name: '富邦Bill', // 客戶姓名 (string) account: '28', // 客戶帳號 (string) branchNo: '6460', // 分公司代號 (string) accountType: 'stock' // 帳號類型 (string) } } ``` --- ### 登入 login #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | ---------- | | personalID | String | 登入的ID | | password | String | 登入的密碼 | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳帳號資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); const sdk = new FubonSDK(); const accounts = sdk.login("Your ID", "Your Password","Your Cert Path","Your Cert Password"); Console.log(accounts); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { name: '富邦Bill', // 客戶姓名 (string) account: '28', // 客戶帳號 (string) branchNo: '6460', // 分公司代號 (string) accountType: 'stock' // 帳號類型 (string) } } ``` --- ### 登出 logout #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---- | -------- | | isSuccess | bool | 是否成功 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); const sdk = new FubonSDK(); sdk.logout(); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js true ``` --- ### 刪除批次委託單 batchCancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | orderResult | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderresult) | 批次取消委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 批次改價(利用batch detail回傳的內容刪單) cancel_object = [ batch_results_detail.data[0], batch_results_detail.data[1], ] sdk.stock.batchCancelOrder(account, cancel_object) // 批次改量(利用不同的單筆委託) cancel_object = [ orders[37], orders[35], ] sdk.stock.batchCancelOrder(account, cancel_object) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { functionType: 30, // 功能別 (number) date: '2024/03/08', // 交易日期 (string) seqNo: '00000308998', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0028', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 30, // 委託單狀態 (number) afterPriceType: 'Limit', // 有效委託價格別 (string) afterPrice: 41.2, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 0, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforeQty: 5000, // 改單前有效量 (number) beforePrice: 41.2, // 改單前有效價 (number) userDef: '12345678', // 自訂欄位 (string) lastTime: '12:53:57.536', // 最後異動時間 (string) errorMessage: '', // 錯誤訊息 (string) }, { functionType: 30, // 功能別 (number) date: '2024/03/08', // 交易日期 (string) seqNo: '0000030899', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0029', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 30, // 委託單狀態 (number) ... } } ``` --- ### 批次修改委託價格 batchModifyPrice ##### 先使用makeModifyPriceObj 建立 ModifyPriceObj 物件[​](#先使用makemodifypriceobj-建立-modifypriceobj-物件 "Direct link to 先使用makeModifyPriceObj 建立 ModifyPriceObj 物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | string ? | 修改後的價格 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype)? | 修改後的價格旗標 (***註***: 輕量風控版**已**開放使用價格旗標) | 將回傳的物件放入 BatchModifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | -------------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | ModifyPriceObj | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#modifypriceobj)(list of object) | 批次修改委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 批次改價 ( 利用 batch detail 回傳的內容改單) modify_orders = [ sdk.stock.makeModifyPriceObj(batch_res.data[0], "41.1"), sdk.stock.makeModifyPriceObj(batch_res.data[1], "41.1") ] sdk.stock.batchModifyPrice(account, modify_orders); // 批次改價 ( 利用不同的單筆委託改單 ) modify_orders = [ sdk.stock.makeModifyPriceObj(orderResult.data[20], "41.1"), sdk.stock.makeModifyPriceObj(orderResult.data[21], "41.1"), sdk.stock.makeModifyPriceObj(orderResult.data[28], "41.1") ] sdk.stock.batchModifyPrice(account, modify_orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ // 批次改價 ( 利用 batch detail 回傳的內容改單) { functionType: 15, // 功能別 (number) date: '2023/11/22', // 交易日期 (string) seqNo: '00000322356', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0018', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (OrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: 'Limit', // 有效委託價格別 (string) afterPrice: 41.1, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 2000, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforePrice: 41.3, // 改單前有效價 (number) userDef: '12345678', // 自訂欄位 (string) lastTime: '13:56:57.713', // 最後異動時間 (string) }, { functionType: 15, // 功能別 (number) date: '2023/11/22', // 交易日期 (string) seqNo: '00000322355', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0017', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (OrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) ... } ] } 以下擷取data內容 [ // 批次改價 ( 利用不同的單筆委託改單 ) { date: '2023/11/22', // 交易日期 (string) seqNo: '00000322388', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0033', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: 'Limit', // 有效委託價格別 (string) afterPrice: 41.1, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 2000, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforePrice: 41.3, // 改單前有效價 (number) userDef: '12345678', // 自訂欄位 (string) lastTime: '10:56:57.713', // 最後異動時間 (string) }, { date: '2023/11/22', // 交易日期 (string) seqNo: '00000322386', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0031', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (OrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) ... }, ... ] ``` --- ### 批次修改委託數量 batchModifyQuantity ##### 先使用 makeModifyQuantityObj 建立一個 ModifyQuantityObj 物件[​](#先使用-makemodifyquantityobj-建立一個-modifyquantityobj-物件 "Direct link to 先使用 makeModifyQuantityObj 建立一個 ModifyQuantityObj 物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | number | 改單後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入batchModifyQuantity 方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | ModifyQuantityObj | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#modifyquantityobj) (list of object) | 批次改量委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 批次改量(利用batch detail回傳的內容改單) modify_orders = [ sdk.stock.makeModifyQuantityObj(batch_res.data[0], 1000), sdk.stock.makeModifyQuantityObj(batch_res.data[1], 1000) ] sdk.stock.batchModifyQuantity(account, modify_orders); // # 批次改量(利用不同的單筆委託) modify_orders = [ sdk.stock.makeModifyQuantityObj(orderResult.data[22], 1000), sdk.stock.makeModifyQuantityObj(orderResult.data[40], 1000) ] sdk.stock.batchModifyQuantity(account, modify_orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ // 批次改量(利用batch detail回傳的內容改單) { functionType: 20, // 功能別 (number) date: '2024/03/08', // 交易日期 (string) seqNo: '00000000042', // 委託單流水序號 (string) branchNo: '20112', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0026', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '2881', // 股票代號 (string) buySell: 'Buy', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 66, // 價格 (number) quantity: 2000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPrice: 66, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 1000, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforeQty: 2000, // 改單前有效量 (number) userDef: 'batch 2', // 自訂欄位 (string) lastTime: '12:21:51.023', // 最後異動時間 (string) }, { functionType: 20, // 功能別 (number) date: '2024/03/08', // 交易日期 (string) seqNo: '00000000041', // 委託單流水序號 (string) branchNo: '20112', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0025', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '2881', // 股票代號 (string) buySell: 'Buy', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 66, // 價格 (number) quantity: 2000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPrice: 66, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 1000, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforeQty: 2000, // 改單前有效量 (number) userDef: 'batch 1', // 自訂欄位 (string) lastTime: '12:21:51.023', // 最後異動時間 (string) } ] } 以下擷取data內容 [ // 批次改量(利用不同的單筆委託) { functionType: 20, // 功能別 (number) date: '2024/03/08', // 交易日期 (string) seqNo: '00000000043', // 委託單流水序號 (string) branchNo: '20112', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0027', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '2881', // 股票代號 (string) buySell: 'Buy', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 66, // 價格 (number) quantity: 2000, // 原始委託股數 (number) timeInForce: 'Rod', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPrice: 66, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 1000, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforeQty: 2000, // 改單前有效量 (number) userDef: 'Test', // 自訂欄位 (string) lastTime: '12:21:53.023', // 最後異動時間 (string) }, { functionType: 20, // 功能別 (number) date: '2024/03/08', // 交易日期 (string) seqNo: '00000000044', // 委託單流水序號 (string) branchNo: '20112', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0028', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '2881', // 股票代號 (string) buySell: 'Buy', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 66, // 價格 (number) quantity: 2000, // 原始委託股數 (number) timeInForce: 'Rod', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPrice: 66, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 1000, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforeQty: 2000, // 改單前有效量 (number) userDef: 'Test', // 自訂欄位 (string) lastTime: '12:21:53.023', // 最後異動時間 (string) } ] ``` --- ### 取得批次委託明細 batchOrderDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | BatchOrderList | [BatchResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#batchresult) | 批次委託列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number ? (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | PriceType | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | caution 此功能僅供查詢批次送單執行結果,欲取得委託單最新狀態請使用單筆委託單查詢功能 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const batch_order_list = sdk.stock.batchOrderLists(account) sdk.stock.batchOrderDetail(account, batch_order_list.data[0]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ { date: '2023/10/23', seqNo: '00000000023', branchNo: '6460', account: '26', assetType: 0, market: 'TAIEX', marketType: Common, stockNo: '1101', buySell: Buy, priceType: Limit, price: 35, quantity: 1000, timeInForce: ROD, orderType: Stock, isPreOrder: false, status: 90, afterPriceType: Limit, afterPrice: 35, unit: 1000, afterQty: 0, filledQty: 0, filledMoney: 0, beforeQty: 0, beforePrice: 35, userDef: 'batch 1', lastTime: '16:24:28.732' }, ... ] } ``` --- ### 取得批次委託列表 batchOrderLists #### 輸入參數[​](#輸入參數 "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 | Object | 回傳批次單資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 批次單 BatchResult 欄位[​](#批次單-batchresult-欄位 "Direct link to 批次單 BatchResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------ | ------ | ------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單、 `10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.stock.batchOrderLists(target_user) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ { functionType: 0, date: '2023/10/24', branchNo: '6460', account: '26', batchSeqNo: '11EE72270B4D79F48000000C29304663' }, ... ] } ``` --- ### 建立批次委託單 batchPlaceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | --------------------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderobject) (list of object) | 委託內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | [TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | PriceType | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const orders = [{ buySell: BSAction.Buy, symbol: "2888", price: "8.90", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" },{ buySell: BSAction.Buy, symbol: "2888", price: "9.00", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" } ]; const batch_order_results = sdk.stock.batchPlaceOrder(account,orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { functionType: 0, date: '2023/10/24', seqNo: '00000000002', branchNo: '6460', account: '26', orderNo: 'bA720', assetType: 0, market: 'TAIEX', marketType: Common, stockNo: '2888', buySell: Buy, priceType: Limit, price: 8.9, quantity: 2000, timeInForce: ROD, orderType: Stock, isPreOrder: false, status: 10, afterPriceType: Limit, afterPrice: 8.9, unit: 1000, afterQty: 2000, filledQty: 0, filledMoney: 0, beforeQty: 0, beforePrice: 9, userDef: 'from Js', lastTime: '11:02:27.599' }, { functionType: 0, date: '2023/10/24', seqNo: '00000000003', branchNo: '6460', account: '26', orderNo: 'bA720', assetType: 0, market: 'TAIEX', marketType: Common, stockNo: '2888', buySell: Buy, priceType: Limit, price: 9.0, quantity: 2000, timeInForce: ROD, orderType: Stock, isPreOrder: false, status: 10, afterPriceType: Limit, afterPrice: 9.0, unit: 1000, afterQty: 2000, filledQty: 0, filledMoney: 0, beforeQty: 0, beforePrice: 9, userDef: 'from Js', lastTime: '11:02:27.599' } ] } ``` --- ### 刪除委託單 cancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | orderResult | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderresult) | 欲取消的委託單物件 | | unblock | bool? (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.stock.cancelOrder(account, cancel_order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { functionType: 30, // 功能別 (number) date: '2024/03/08', // 交易日期 (string) seqNo: '00000308948', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0023', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 30, // 委託單狀態 (number) afterPriceType: 'Limit', // 有效委託價格別 (string) afterPrice: 41.2, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 0, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforeQty: 5000, // 改單前有效量 (number) beforePrice: 41.2, // 改單前有效價 (number) userDef: '12345678', // 自訂欄位 (string) lastTime: '12:53:57.536', // 最後異動時間 (string) } } ``` --- ### 現冲券配額查詢 daytradeAndStockInfo #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | stockNo | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳配額資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 配額資訊 DayTradeStockInfo 欄位[​](#配額資訊-daytradestockinfo-欄位 "Direct link to 配額資訊 DayTradeStockInfo 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------- | | stockNo | string | 股票代號 | | date | string | 日期 | | daytradeOrigQuota | number | 原始現冲券餘額 | | daytradeTradableQuota | number | 可用現冲券餘額 | | precollectSingle | number | 單筆預收股數 (若不需預收則不顯示) | | precollectAccumulate | number | 累積預收股數 (若不需預收則不顯示) | | status | number | 狀態 (bitmask 加總) : `0` 全禁 、 `1` 平盤下可融券賣出、 `2` 平盤下可借券賣出、 `4` 可先買後賣當沖 、 `8`可先賣後買當沖 | | dispositionStatus | string | 警示股註記 `{ SETTYPE : 1}` : 全額交割、 `{ MARK-W : 1}` : 警示、`{ MARK-P : 1}` : 注意、`{ MARK-L : 1}` : 委託受限 【**2.2.5版本新增欄位**】 | info status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.stock.daytradeAndStockInfo(account, "2330") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { stockNo: '2330', date: '2023/10/24', daytradeOrigQuota: 0, daytradeTradableQuota: 0, status: 0 } ] } ``` --- ### 查詢歷史成交 filledHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | -------------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string? (空值預設與開始日相同) | 查詢終止日 | info v2.1.1起可查詢長期歷史資料,每次查詢最大設定30日日期區間;v2.1.0之前版本可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳成交資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 成交資訊 FilledData 欄位[​](#成交資訊-filleddata-欄位 "Direct link to 成交資訊 FilledData 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | date | string | 成交日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | seqNo | string ? | 委託單流水序號 (只有主動回報才回傳此欄位) | | orderNo | string | 委託書號 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | filledNo | string | 成交流水號 | | filledAvgPrice | number | 成交均價 | | filledQty | number | 成交股數 | | filledPrice | number | 成交單價 | | filledTime | string | 成交時間 | | userDef | string ? | 用戶自定義 (只有主動回報才回傳此欄位) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const filledHistory = sdk.stock.filledHistory(account,"20230921","20230922"); console.log(filledHistory) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: '2023/08/29', branchNo: '6460', account: '26', orderNo: 'bA047', stockNo: '1101', buySell: Buy, orderType: Stock, filledNo: '00000000001', filledAvgPrice: 35.3, filledQty: 1000, filledPrice: 35.3, filledTime: '10:14:36.549' }, { date: '2023/08/29', branchNo: '6460', account: '26', orderNo: 'bA052', stockNo: '1101', buySell: Buy, orderType: Stock, filledNo: '00000000002', filledAvgPrice: 35.3, filledQty: 1000, filledPrice: 35.2, filledTime: '10:31:00.931' }, ... ] } ``` --- ### 取得委託單結果 getOrderResults #### 輸入參數[​](#輸入參數 "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 | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number ? (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js var account = accounts.data[0]; const orders = sdk.stock.getOrderResults(account); console.log(orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: '2023/10/24', seqNo: '00005000001', branchNo: '6460', account: '26', orderNo: 'bA719', assetType: 0, market: 'TAIEX', marketType: Common, stockNo: '2888', buySell: Buy, priceType: Limit, price: 9, quantity: 2000, timeInForce: ROD, orderType: Stock, isPreOrder: false, status: 10, afterPrice: 9, unit: 1000, afterQty: 2000, filledQty: 0, filledMoney: 0, userDef: 'from Js', lastTime: '10:26:22.140' }, { date: '2023/10/24', seqNo: '00005000002', branchNo: '6460', account: '26', .... unit: 1000, afterQty: 2000, filledQty: 0, filledMoney: 0, userDef: 'from Js', lastTime: '10:26:25.140' }, ... ] } ``` --- ### 取得委託單結果 (含歷程) getOrderResultsDe #### 輸入參數[​](#輸入參數 "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 | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number ? (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | useDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | details | list | 委託歷程 | | >> functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeQty | number | 原始委託股數 | | >> afterQty | number | 有效委託股數(包含已成交部分) | | >> beforePrice | number | 原始委託價 | | >> afterPrice | number | 有效委託價 | | >> filledMoney | number | 成交價金 | | >> status | int | 委託單狀態 | | >> errMsg | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js var account = accounts.data[0]; const orders = sdk.stock.getOrderResultsDetail(account); console.log(orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: '2023/10/24', seqNo: '00005000001', branchNo: '6460', account: '26', orderNo: 'bA719', assetType: 0, market: 'TAIEX', marketType: Common, stockNo: '2888', buySell: Buy, priceType: Limit, price: 9, quantity: 2000, timeInForce: ROD, orderType: Stock, isPreOrder: false, status: 10, afterPrice: 9, unit: 1000, afterQty: 2000, filledQty: 0, filledMoney: 0, userDef: 'from Js', lastTime: '10:26:22.140', details:[ functionType: 10, modifiedTime: '10:26:22.140', beforeQty: 0, afterQty: 2000, beforePrice: 9, afterPrice: 9 ] }, { date: '2023/10/24', seqNo: '00005000002', branchNo: '6460', account: '26', .... unit: 1000, afterQty: 2000, filledQty: 0, filledMoney: 0, userDef: 'from Js', lastTime: '10:26:25.140' }, ... ] } ``` --- ### 資券配額查詢 marginQuota #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | stockNo | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳配額資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 配額資訊 MarginShortQuota欄位[​](#配額資訊-marginshortquota欄位 "Direct link to 配額資訊 MarginShortQuota欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------------- | -------- | ------------ | | stock\_no | string | 股票代號 | | date | string | 日期 | | shortsellOrigQuota | number ? | 原始融券餘額 | | shortsellTradableQuota | number ? | 可用融券餘額 | | marginOrigQuota | number ? | 原始融資餘額 | | marginTradableQuota | number ? | 可用融資餘額 | | marginRatio | number ? | 融資成數 | | shortRatio | number ? | 融券成數 | info 額度相關說明 : 融資成數沒回傳表示停資;融券成數沒回傳表示停券,
回傳的額度說明 : 0 - 無額度 / 大於0 - 有額度 / 沒回傳 - 無限制 / 餘額皆為 0 - 停資 or 停券 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.stock.marginQuota(account, "2330") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ { stockNo: '2330', date: '2024/01/24', shortsellOrigQuota: 894, shortsellTradableQuota: 894, marginRatio: 60, shortRatio: 90 } ] } ``` --- ### 修改委託價格 modifyPrice ##### 先使用makeModifyPriceObj 建立 ModifyPriceObj 物件[​](#先使用makemodifypriceobj-建立-modifypriceobj-物件 "Direct link to 先使用makeModifyPriceObj 建立 ModifyPriceObj 物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | orderResult | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | string? | 修改後的價格 | | priceType | [priceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype)? | 修改後的價格旗標 (***註***: 輕量風控版**已**開放使用價格旗標) | caution 當 price 欄位有填入值時,priceType 欄位為空值或為null ; 當 priceType 欄位有填入值時,price 欄位為空值或為null 將回傳的物件放入 modifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | ModifiyPriceObj | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#modifypriceobj) | 修改價格物件 | | unblock | bool ? (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 單筆阻塞改價 const modifyPriceObj = sdk.stock.makeModifyPriceObj(target_order, "41.1"); sdk.stock.modifyPrice(accounts.data[0], modifyPriceObj, false) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:{ functionType: 15, // 功能別 (number) date: '2023/11/22', // 交易日期 (string) seqNo: '00000308866', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0011', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: 'Limit', // 有效委託價格別 (string) afterPrice: 41.1, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 2000, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforePrice: 41.3, // 改單前有效價 (number) userDef: '12345678', // 自訂欄位 (string) lastTime: '10:56:57.713', // 最後異動時間 (string) } } ``` --- ### 修改委託單數量 modifyQuantity ##### 先使用 makeModifyQuantityObj 建立一個 ModifyQuantityObj 物件[​](#先使用-makemodifyquantityobj-建立一個-modifyquantityobj-物件 "Direct link to 先使用 makeModifyQuantityObj 建立一個 ModifyQuantityObj 物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | number | 改單後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入modifyQuantity 方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | ---------------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | ModifyQuantityObj | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#modifyquantityobj) | 修改的委託單 | | unblock | bool ? (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const modifyQtyObj = sdk.stock.makeModifyQuantityObj(target_order, 1000); sdk.stock.modifyQuantity(accounts.data[0], modifyQtyObj) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { functionType: 20, // 功能別 (number) date: '2024/03/08', // 交易日期 (string) seqNo: '00000308866', // 委託單流水序號 (string) branchNo: '6460', // 分公司代號 (string) account: '26', // 帳號 (string) orderNo: 'x0011', // 委託書號 (string) assetType: 0, // 資產類別 (number) market: 'TAIEX', // 市場類型 (string) marketType: 'Common', // 盤別種類 (string) stockNo: '1101', // 股票代號 (string) buySell: 'Sell', // 買賣別 (string) priceType: 'Limit', // 原始委託價格別 (string) price: 41.2, // 價格 (number) quantity: 5000, // 原始委託股數 (number) timeInForce: 'ROD', // 委託條件別 (string) orderType: 'Stock', // 委託單類型 (string) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: 'Limit', // 有效委託價格別 (string) afterPrice: 41.3, // 有效委託價格 (number) unit: 1000, // 單位數 (number) afterQty: 1000, // 有效委託股數 (number) filledQty: 0, // 成交股數 (number) filledMoney: 0, // 成交價金 (number) beforeQty: 3000, // 改單前有效量 (number) beforePrice: 41.2, // 改單前有效價 (number) userDef: '12345678', // 自訂欄位 (string) lastTime: '12:56:28.966', // 最後異動時間 (string) } } ``` --- ### 查詢歷史委託 orderHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | -------------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string? (空值預設與開始日相同) | 查詢終止日 | info v2.1.1起可查詢長期歷史資料,每次查詢最大設定30日日期區間;v2.1.0之前版本可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number ? (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | details | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | >> functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeQty | number | 原始委託股數 | | >> afterQty | number | 有效委託股數(包含已成交部分) | | >> beforePrice | number | 原始委託價 | | >> afterPrice | number | 有效委託價 | | >> filledMoney | number | 成交價金 | | >> status | number | 委託單狀態 | | >> errMsg | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const orderHistory = sdk.stock.orderHistory(account,"20230921","20231020"); console.log(orderHistory); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: '2023/10/11', seqNo: '00005000001', branchNo: '6460', account: '26', orderNo: 'bA586', assetType: 0, market: 'TAIEX', marketType: Common, stockNo: '2888', buySell: Buy, priceType: Limit, price: 8.9, quantity: 2000, timeInForce: ROD, orderType: Stock, isPreOrder: false, status: 10, afterPrice: 8.51, unit: 1000, afterQty: 2000, filledQty: 0, filledMoney: 0, userDef: 'From Js', lastTime: '11:25:08.761', details:[ functionType: 10, modifiedTime: '11:25:08.761', beforeQty: 0, afterQty: 2000, beforePrice: 8.51, afterPrice: 8.51 ] }, ... ] } ``` --- ### 建立委託單 placeOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#orderobject) | 委託內容 | | unblock | bool ? (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | Parameter | Type | Meaning | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | marketType | js:string / ts:[MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stockNo | string | 股票代號 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | number | 價格 | | quantity | number | 原始委託股數 | | timeInForce | js:string / ts:[TimeInForce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#status) | | afterPriceType | js:string / ts:[PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | unit | number | 單位數 | | afterQty | number | 有效委託股數(包含已成交部分) | | filledQty | number | 成交股數 | | filledMoney | number | 成交價金 | | beforeQty | number | 改單前有效量 | | beforePrice | number | 改單前有效價 | | user\_def | string | 自訂欄位 (最長10個字元,不支援特殊字元及中文、不適用興櫃) | | lastTime | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const order = { buySell: BSAction.Buy, symbol: "2888", price: "8.90", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" }; sdk.stock.placeOrder(accounts.data[0],order,false); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { functionType: 0, date: '2023/10/23', seqNo: '00000000016', branchNo: '6460', account: '26', orderNo: 'bA716', assetType: 0, market: 'TAIEX', marketType: Common, stockNo: '2888', buySell: Buy, priceType: Limit, price: 9, quantity: 2000, timeInForce: ROD, orderType: 0, isPreOrder: false, status: 10, afterPriceType: Limit, afterPrice: 9, unit: 1000, afterQty: 2000, filledQty: 0, filledMoney: 0, beforeQty: 0, beforePrice: 9, userDef: 'from Js', lastTime: '13:36:38.317' } } ``` --- ### 查詢商品漲跌幅報表(單筆) querySymbolQuote info 2.2.5 版新增 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | symbol | String | 股票代碼 | | marketType | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolQuote | 回傳委託資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 配額資訊 SymbolQuote 欄位[​](#配額資訊-symbolquote-欄位 "Direct link to 配額資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------ | ---------------------------------------------------------------------------------------------------------------------- | | market | string | 市場別 | | symbol | string | 股票代碼 | | istibOrPsb | bool | 是否為創新版或戰略新板 | | marketType | string | 市場類型 | | status | number | 狀態 (bitmask 加總) `0` :全禁 、 `1`:平盤下可融券賣出、`2`:平盤下可借券賣出、 `4`:可先買後賣當沖 、 `8`:可先賣後買當沖 | | referencePrice | number | 參考價格 | | unit | number | 交易單位 | | updateTime | string | 更新時間 | | limitupPrice | number | 漲停價 | | limitdownPrice | number | 跌停價 | | openPrice | number | 開盤價 | | highPrice | number | 最高價 | | lowPrice | number | 最低價 | | lastPrice | number | 最新成交價 | | totalVolume | number | 總成交量 | | totalTransaction | number | 總成交筆數 (預留欄位,暫未使用) | | totalValue | number | 總成交金額 | | lastSize | number | 最新成交量 | | lastTransaction | number | 最新成交筆數 (預留欄位,暫未使用) | | lastValue | number | 最新成交金額 | | bidPrice | number | 買1價格 | | bidVolume | number | 買1數量 | | askPrice | number | 賣1價格 | | askVolume | number | 賣1數量 | 支援範圍 上市、上櫃標的 info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.stock.querySymbolQuote(accounts.data[0],"2330") Console.WriteLine(quote.data) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess : true, message : , data : { market : TAIEX, // string - 市場別 symbol : 2330, // string - 股票代碼 istibOrPsb : false, // bool - 是否為創新板或戰略新板 marketType : Common, // string - 市場類型 (現股) status : 15, // number - 狀態 (bitmask 加總: 1+2+4+8 : 可融券賣出+可借券賣出+可先買後賣當沖+可先賣後買當沖) referencePrice : 780, // double - 參考價格 (前一交易日收盤價) unit : 1000, // number - 交易單位 updateTime : , // string - 更新時間 limitupPrice : 858, // number - 漲停價 limitdownPrice : 702, // number - 跌停價 openPrice : 1155, // number - 開盤價 highPrice : 1160, // number - 最高價 lowPrice : 1145, // number - 最低價 lastPrice : 1145, // number - 最新成交價 totalVolume : 20501, // number - 總成交量 totalTransaction : 0, // number - 總成交筆數 (預留欄位,暫未使用) totalValue : 23551095000, // number - 總成交金額 lastSize : 6673, // number - 最新成交量 lastTransaction : 0, // number - 最新成交筆數 (預留欄位,暫未使用) lastValue : 7640585000, // number - 最新成交金額 bidPrice : 1145, // number - 買一價格 bidVolume : 1549, // number - 買一數量 askPrice : 1150, // number - 賣一價格 askVolume : 4169 // number - 賣一數量 } } ``` --- ### 查詢商品漲跌幅報表(批次) querySymbolSnapshot info 2.2.5 版新增 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | --------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#account) | 帳號 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | | stock\_type | List [StockType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/nodejs/EnumMatrix.md#stocktype) (Optional)(default = Stock) | 商品分類別 : `Stock` 股票、`ConvertBond` 可轉債、`ETF_and_ETN` ETF 與 ETN | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolSnapshotResponse | 回傳委託資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 商品資訊 SymbolQuote 欄位[​](#商品資訊-symbolquote-欄位 "Direct link to 商品資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------ | ---------------------------------------------------------------------------------------------------------------------- | | market | string | 市場別 | | symbol | string | 股票代碼 | | istibOrPsb | bool | 是否為創新版或戰略新板 | | marketType | string | 市場類型 | | status | number | 狀態 (bitmask 加總) `0` :全禁 、 `1`:平盤下可融券賣出、`2`:平盤下可借券賣出、 `4`:可先買後賣當沖 、 `8`:可先賣後買當沖 | | referencePrice | number | 參考價格 | | unit | number | 交易單位 | | updateTime | string | 更新時間 | | limitupPrice | number | 漲停價 | | limitdownPrice | number | 跌停價 | | openPrice | number | 開盤價 | | highPrice | number | 最高價 | | lowPrice | number | 最低價 | | lastPrice | number | 最新成交價 | | totalVolume | number | 總成交量 | | totalTransaction | number | 總成交筆數 (預留欄位,暫未使用) | | totalValue | number | 總成交金額 | | lastSize | number | 最新成交量 | | lastTransaction | number | 最新成交筆數 (預留欄位,暫未使用) | | lastValue | number | 最新成交金額 | | bidPrice | number | 買1價格 | | bidVolume | number | 買1數量 | | askPrice | number | 賣1價格 | | askVolume | number | 賣1數量 | 支援範圍 上市、上櫃標的 info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const { StockType } = require('fubon-neo'); sdk.stock.querySymbolSnapshot(accounts.data[0]) // Default sdk.stock.querySymbolSnapshot(accounts.data[0], MarketType.Common, [StockType.Stock]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess : true, message : , data : { market : TAIEX, // string - 市場別 symbol : 2330, // string - 股票代碼 istibOrPsb : false, // bool - 是否為創新板或戰略新板 marketType : Common, // string - 市場類型 (現股) status : 15, // number - 狀態 (bitmask 加總: 1+2+4+8 : 可融券賣出+可借券賣出+可先買後賣當沖+可先賣後買當沖) referencePrice : 780, // double - 參考價格 (前一交易日收盤價) unit : 1000, // number - 交易單位 updateTime : , // string - 更新時間 limitupPrice : 858, // number - 漲停價 limitdownPrice : 702, // number - 跌停價 openPrice : 1155, // number - 開盤價 highPrice : 1160, // number - 最高價 lowPrice : 1145, // number - 最低價 lastPrice : 1145, // number - 最新成交價 totalVolume : 20501, // number - 總成交量 totalTransaction : 0, // number - 總成交筆數 (預留欄位,暫未使用) totalValue : 23551095000, // number - 總成交金額 lastSize : 6673, // number - 最新成交量 lastTransaction : 0, // number - 最新成交筆數 (預留欄位,暫未使用) lastValue : 7640585000, // number - 最新成交金額 bidPrice : 1145, // number - 買一價格 bidVolume : 1549, // number - 買一數量 askPrice : 1150, // number - 賣一價格 askVolume : 4169 // number - 賣一數量 }, { market : TAIEX, // string - 市場別 symbol : 2881, // string - 股票代碼 ... } } ``` --- ### 銀行餘額查詢 bank\_remain #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ---------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | BankRemain | 回傳餘額資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 餘額 BankRemain 欄位[​](#餘額-bankremain-欄位 "Direct link to 餘額 BankRemain 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------ | ---------- | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | currency | string | 幣別 | | balance | int | 餘額 | | available\_balance | int | 可用餘額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.accounting.bank_remain(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : BankRemain{ branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) currency: "TWD", # 幣別 (string) balance: "666666", # 餘額 (int) available_balance: "123456" # 可用餘額 (int) }} ``` --- ### 庫存查詢 inventories #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳庫存資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 庫存 Inventory 欄位[​](#庫存-inventory-欄位 "Direct link to 庫存 Inventory 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | | > date | string | 交易日期 | | > account | string | 帳號 | | > branch\_no | string | 分公司代號 | | > stock\_no | string | 股票代號 | | > order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | > lastday\_qty | int | 昨日庫存餘額 | | > buy\_qty | int | 今日委買股數 | | > buy\_filled\_qty | int | 今日買進成交股數 | | > buy\_value | int | 買進價金 | | > today\_qty | int | 今日庫存餘額 | | > tradable\_qty | int | 可委託股數 | | > sell\_qty | int | 今日委賣股數 | | > sell\_filled\_qty | int | 今日賣出成交股數 | | > sell\_value | int | 賣出價金 | | > odd | list | Object | | >> lastday\_qty | int | 昨日庫存餘額 | | >> buy\_qty | int | 今日委買股數 | | >> buy\_filled\_qty | int | 今日買進成交股數 | | >> buy\_value | int | 買進價金 | | >> today\_qty | int | 今日庫存餘額 | | >> tradable\_qty | int | 可委託股數 | | >> sell\_qty | int | 今日委賣股數 | | >> sell\_filled\_qty | int | 今日賣出成交股數 | | >> sell\_value | int | 賣出價金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.accounting.inventories(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [Inventory{ date: "2023/10/16", # 交易日期 (string) account: "26", # 帳號 (string) branch_no: "6460", # 分公司代號 (string) stock_no: "1101", # 股票代號 (string) order_type: Stock, # 委託單類型 (OrderType) lastday_qty: 2000, # 昨日庫存餘額 (int) buy_qty: 0, # 今日委買股數 (int) buy_filled_qty: 0, # 今日買進成交股數 (int) buy_value: 0, # 買進價金 (int) today_qty: 2000, # 今日庫存餘額 (int) tradable_qty: 2000, # 可委託股數 (int) sell_qty: 0, # 今日委賣股數 (int) sell_filled_qty: 0, # 今日賣出成交股數 (int) sell_value: 0, # 賣出價金 (int) odd: InventoryOdd{ # 零股庫存 lastday_qty: 0, # 昨日庫存餘額 (int) buy_qty: 0, # 今日委買股數 (int) buy_filled_qty: 0, # 今日買進成交股數 (int) buy_value: 0, # 買進價金 (int) today_qty: 0, # 今日庫存餘額 (int) tradable_qty: 0, # 可委託股數 (int) sell_qty: 0, # 今日委賣股數 (int) sell_filled_qty: 0, # 今日賣出成交股數 (int) sell_value: 0 # 賣出價金 (int) }}, ... ] } ``` --- ### 維持率查詢 maintenance #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | --------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | MaintenanceData | 回傳維持率資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### MaintenanceData 欄位[​](#maintenancedata-欄位 "Direct link to MaintenanceData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------------ | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | | > date | string | 查詢日 | | > branch\_no | string | 分公司代號 | | > account | string | 帳號 | | > maintenance\_summary | list | Object | | >> margin\_value | int | 整戶融資市值 | | >> shortsell\_value | int | 整戶融券市值 | | >> shortsell\_margin | int | 整戶融券保證金額 | | >> collateral | int | 擔保品 | | >> margin\_loan\_amt | int | 整戶融資金額 | | >> maintenance\_ratio | float | 整戶維持率 | | >> maintenance\_detail | list | Object | | >>> stock\_no | string | 股票代號 | | >>> order\_no | string | 委託書號 | | >>> order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | >>> quantity | int | 持有股數 | | >>> price | float | 計算價 | | >>> cost\_price | float | 成本價 | | >>> shortsell\_margin | int | 融券保證金 | | >>> collateral | int | 擔保品 | | >>> margin\_loan\_amt | int | 融資金 | | >>> maintenance\_ratio | float | 維持率 | | >>> collateral\_interest | float | 擔保品利息 | | >>> margin\_interest | float | 融資金利息 | | >>> shortsell\_interest | float | 融券保證金利息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.accounting.maintenance(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data: MaintenanceData { date: "2024/02/27", # 日期 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) maintenance_summary: MaintenanceSummary { # 整戶概況 margin_value: 3135000, # 整戶融資市值 (int) shortsell_value: 0, # 整戶融券市值 (int) shortsell_margin: 0, # 整戶融券保證金額 (int) collateral: 0, # 擔保品 (int) margin_loan_amt: 1494000, # 整戶融資金額 (int) maintenance_ratio: 209.83, # 整戶維持率 (float) }, maintenance_detail: [ # 個股概況 MaintenanceSummary { stock_no: "2603", # 股票代號 (string) order_no: "x4580", # 委託書號 (string) order_type: Stock, # 委託單類型 (OrderType) quantity: 10000, # 持有股數 (int) price: 152.5, # 計算價 (float) cost_price: 119, # 成本價 (float) shortsell_margin: 0, # 融券保證金 (int) collateral: 0, # 擔保品 (int) margin_loan_amt: 0, # 融資金 (int) maintenance_ratio: 213.58, # 維持率 (float) collateral_interest: 0, # 擔保品利息 (float) margin_interest: 20818, # 融資金利息 (float) shortsell_interest: 0, # 融券保證金利息 (float) } ], } } ``` --- ### 交割款查詢 query\_settlement #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | -------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | range | string | 時間區間,目前有效值為"0d"(當日)、"3d" | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | -------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | SettlementData | 回傳交割款資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 交割款 SettlementData 欄位[​](#交割款-settlementdata-欄位 "Direct link to 交割款 SettlementData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------------------- | ----------------- | ------------------------------- | | > account | Object | Object | | >> branch\_no | string | 帳號 | | >> account | string | 分公司代號 | | > details | list | Object | | >> date | string | 查詢日 | | >> settlement\_date | string (Optional) | 交割日 (若查無資料為None) | | >> buy\_value | int (Optional) | 買進金額 (若查無資料為None) | | >> buy\_fee | int (Optional) | 買進手續費 (若查無資料為None) | | >> buy\_settlement | int (Optional) | 買進應收付款 (若查無資料為None) | | >> buy\_tax | int (Optional) | 買進交易稅 (若查無資料為None) | | >> sell\_value | int (Optional) | 賣出金額 (若查無資料為None) | | >> sell\_fee | int (Optional) | 賣出手續費 (若查無資料為None) | | >> sell\_settlement | int (Optional) | 賣出應收付款 (若查無資料為None) | | >> sell\_tax | int (Optional) | 買進交易稅 (若查無資料為None) | | >> total\_bs\_value | int (Optional) | 合計買賣金額 (若查無資料為None) | | >> total\_fee | int (Optional) | 合計手續費 (若查無資料為None) | | >> total\_tax | int (Optional) | 合計交易稅 (若查無資料為None) | | >> total\_settlement\_amount | int (Optional) | 合計交割金額 (若查無資料為None) | | >> currency | string (Optional) | 幣別 (若查無資料為None) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.accounting.query_settlement(account,"3d") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : SettlementData{ account: { branch_no: "6460", # 分公司代號 (string) account: "26" # 帳號 (string) }, details: [ Settlement{ date: "2023/10/16", # 查詢日 (string) settlement_date: "2023/10/18", # 交割日 (string) buy_value: 12, # 買進金額 (int) buy_fee: 12, # 買進手續費 (int) buy_settlement: 0, # 買進應收付款 (int) buy_tax: 0, # 買進交易稅 (int) sell_value: 4, # 賣出金額 (int) sell_fee: 4, # 賣出手續費 (int) sell_settlement: 0, # 賣出應收付款 (int) sell_tax: 4, # 賣出交易稅 (int) total_bs_value: 16, # 合計買賣金額 (int) total_fee: 16, # 合計手續費 (int) total_tax: 4, # 合計交易稅 (int) total_settlement_amount: 0, # 合計交割金額 (int) currency: TWD, # 幣別 (string) }, Settlement{ date: "2023/10/17", # 查詢日 (string) settlement_date: "2023/10/19", # 交割日 (string) buy_value: 735500, # 買進金額 (int) buy_fee: 313, # 買進手續費 (int) buy_settlement: -1429513, # 買進應收付款 (int) buy_tax: 0, # 買進交易稅 (int) sell_value: 770500, # 賣出金額 (int) sell_fee: 320, # 賣出手續費 (int) sell_settlement: 0, # 賣出應收付款 (int) sell_tax: 2309, # 賣出交易稅 (int) total_bs_value: 1506000, # 合計買賣金額 (int) total_fee: 633, # 合計手續費 (int) total_tax: 2309, # 合計交易稅 (int) total_settlement_amount: -1429513, # 合計交割金額 (int) currency: "TWD", # 幣別 (string) }, Settlement{ date: "2023/10/18", # 查詢日 (string) settlement_date: None, # 交割日 (string) buy_value: None, # 買進金額 (int) buy_fee: None, # 買進手續費 (int) buy_settlement: None, # 買進應收付款 (int) buy_tax: None, # 買進交易稅 (int) sell_value: None, # 賣出金額 (int) sell_fee: None, # 賣出手續費 (int) sell_settlement: None, # 賣出應收付款 (int) sell_tax: None, # 賣出交易稅 (int) total_bs_value: None, # 合計買賣金額 (int) total_fee: None, # 合計手續費 (int) total_tax: None, # 合計交易稅 (int) total_settlement_amount: None, # 合計交割金額 (int) currency: None, # 幣別 (string) } ] } } ``` --- ### 已實現損益查詢 realized\_gains\_and\_loses #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳已實現資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 已實現 Realized 欄位[​](#已實現-realized-欄位 "Direct link to 已實現 Realized 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | | date | string | 資料日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | filled\_qty | int | 成交股數 | | filled\_price | float | 成交價 | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | realized\_profit | int | 已實現獲利金額 | | realized\_loss | int | 已實現損失金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.accounting.realized_gains_and_loses(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ Realized { date: "2023/10/17", # 資料日期 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) filled_qty: 1000, # 成交股數 (int) filled_price: 35.0, # 成交價 (float) order_type: Stock, # 委託單類型 (OrderType) realized_profit: 0, # 已實現獲利金額 (int) realized_loss: 203 # 已實現損失金額 (int) }, ... ] } ``` --- ### 已實現損益彙總 realized\_gains\_and\_loses\_summary #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳已實現彙總資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 已實現彙總 RealizedSummary 欄位[​](#已實現彙總-realizedsummary-欄位 "Direct link to 已實現彙總 RealizedSummary 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------------------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- | | start\_date | string | 彙總起始日 | | end\_date | string | 彙總截止日 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL` 借券賣出 | | filled\_qty | int | 成交股數 | | filled\_avg\_price | float | 成交均價 | | realized\_profit\_and\_loss | int | 已實現損益金額 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.accounting.realized_gains_and_loses_summary(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [RealizedSummary{ start_date: "20231011", # 彙總起始日 (string) end_date: "20231011", # 彙總截止日 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) order_type: Stock, # 委託單類型 (OrderType) filled_qty: 1000, # 成交股數 (int) filled_avg_price: 35.0, # 成交均價 (float) realized_profit_and_loss: -203 # 已實現損益金額 (int) }, ... ] } ``` --- ### 未實現損益查詢 unrealized\_gains\_and\_loses #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳未實現資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ###### 未實現 UnrealizedData 欄位[​](#未實現-unrealizeddata-欄位 "Direct link to 未實現 UnrealizedData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | | date | string | 查詢當天日期 | | branch\_no | string | 分公司代號 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 (**註**:請見表末說明) | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | cost\_price | float | 成本價 | | tradable\_qty | int | 可交易餘額 | | today\_qty | int | 今日餘額 | | unrealized\_profit | int | 未實現獲利 | | unrealized\_loss | int | 未實現虧損 | info 現股交易 buy\_sell 皆為 `Buy`,以餘額正負號顯示淨買賣部位;若為信用交易,則 buy\_sell 為 `Buy` 或 `Sell`,顯示買賣類別 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.accounting.unrealized_gains_and_loses(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [UnrealizedData{ date: "2021/08/09", # 資料查詢日期(sting) account: "26", # 帳號(string) branch_no: "6460", # 分公司代號(string) stock_no: "2303", # 股票代號(string) buy_sell: Buy, # 買賣別(BSAction) order_type: Margin, # 委託單類型(OrderType) cost_price: 50.0, # 成本價格(double) tradable_qty: 1000, # 可交易餘額(int) today_qty: 1000, # 今日餘額(int) unrealized_profit: 48650, # 未實現獲利(int) unrealized_loss: 0 # 未實現虧損(int) }, ... ] } ``` --- ### 參數對照表 #### 類別[​](#類別 "Direct link to 類別") Class ##### OrderObject[​](#orderobject "Direct link to OrderObject") | Parameter | Type | Meaning | | -------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | buy\_sell | BSAction | [買賣別](#bsaction) 可選用參數 `Buy` 買 、 `Sell` 賣 | | symbol | string | 股票代號 | | price | string | 委託價格 (若非使用 `Limit` 限價,此欄代入 ***None***) | | quantity | int | 委託數量 | | market\_type | MarketType | [盤別](#markettype) 可選用參數 `Common` 整股、 `Fixing` 定盤、 `IntradayOdd` 盤中零股、 `Odd` 盤後零股、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | price\_type | PriceType | [價格旗標](#pricetype) 可選用參數為 `Limit` 限價、`LimitUp` 漲停、 `LimitDown` 跌停、 `Market` 市價、 `Reference` 參考價 | | time\_in\_force | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD` 、 `FOK` 、 `IOC` | | order\_type | OrderType | [委託類別](#ordertype) 可選用參數為 `Stock` 現股、 `Margin` 融資、 `Short` 融券、 `DayTrade` 現沖先賣、 `SBL` 借券 | | user\_def (optional) | string | 用戶自定義 (最長10個字元,不支援特殊字元及中文、不適用興櫃) | caution 不同 market\_type 對應的 quantity 之單位及範圍不同,請參考[盤別](#markettype)說明。 caution 當 market\_type 爲 MarketType.Common, MarketType.Odd, MarketType.IntradayOdd 其中之一,且 priceType 爲 PriceType.Limit 時,需填入 price 欄位,其餘時候可不設定 price 欄位或設為 None。 現股當沖 「現沖先賣」賣出時, orderType = DayTrade , buySell 需為 Sell , marketType 需為 Common
(其餘現沖進出場操作, orderType = Stock) ##### OrderResult[​](#orderresult "Direct link to OrderResult") 委託列表,透過 [get\_order\_result(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/trade/GetOrderResults.md) 取得。 | 參數 | 類別 | 說明 | | ------------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | MarketType | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | BSAction | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | PriceType | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | TimeInforce | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | OrderType | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | PriceType | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間(格式請見表末說明) | | error\_message | string | 錯誤訊息 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | >> function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modified\_time | string | 修改時間(格式請見表末說明) | | >> before\_qty | int | 原始委託股數 | | >> after\_qty | int | 有效委託股數(包含已成交部分) | | >> before\_price | float | 原始委託價 | | >> after\_price | float | 有效委託價 | | >> filled\_money | float | 成交價金 | | >> status | int | 委託單狀態 | | >> err\_msg | string | 錯誤訊息 | 時間格式說明 last\_time 及 modified\_time 時間格式: **HH:MM:SS.fff** 或 **HH:MM:SS** (即當 .fff = .000 時省略此部分) ##### BatchResult[​](#batchresult "Direct link to BatchResult") 批次委託列表,透過 [batch\_order\_lists(account)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/trade/batchOrder/BatchOrderList.md) 取得。 | Parameter | Type | Meaning | | -------------- | ------ | ------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | batch\_seq\_no | string | 批次單流水序號 | ##### ModifyPriceObj[​](#modifypriceobj "Direct link to ModifyPriceObj") 改價物件 | Parameter | Type | Meaning | | ------------- | --------- | ------------------------------------------------------------------------------------------------------- | | order\_result | Object | [委託列表](#orderresult) | | price | string | 改單後的價格 | | price\_type | PriceType | 改單後的價格類型 : `Limit`限價 、 `LimitUp`漲停 、 `LimitDown`跌停 、 `Market`市價 、 `Reference`參考價 | 關於價格旗標 輕量風控版**已**開放使用價格旗標 (PriceType) ##### ModifyQuantityObj[​](#modifyquantityobj "Direct link to ModifyQuantityObj") 改量物件 | Parameter | Type | Meaning | | ------------- | ------ | ------------------------ | | order\_result | Object | [委託列表](#orderresult) | | quantity | int | 改單後的委託量 | ##### FilledData[​](#filleddata "Direct link to FilledData") 成交回報物件 | 參數 | 類別 | 說明 | | ------------------ | --------- | ---------------------------------------------------------------------------------------------- | | date | string | 日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | seq\_no | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | order\_no | string | 委託書號 | | stock\_no | string | 股票代號 | | buy\_sell | BSAction | 買賣別 : `Buy` 買 、 `Sell` 賣 | | order\_type | OrderType | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | filled\_no | string | 成交流水號 | | filled\_avg\_price | float | 成交均價 | | filled\_qty | int | 成交股數 | | filled\_price | float | 成交單價 | | filled\_time | string | 成交時間 | | user\_def | string | 用戶自定義 (只有主動回報才回傳此欄位) | ##### Account[​](#account "Direct link to Account") 帳號資訊 | Parameter | Type | Meaning | | ------------- | ------ | ------------------------------------------ | | name | string | 客戶姓名 | | account | string | 帳號 | | branch\_no | string | 分公司代號 | | account\_type | string | 帳號類型 ,回傳 `stock`證券 、`futopt`期貨 | #### Constants ( 欄位對應數值 )[​](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )") ##### BSAction[​](#bsaction "Direct link to BSAction") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Buy | 買 | | Sell | 賣 | ##### MarketType[​](#markettype "Direct link to MarketType") 盤別 | Name | Meaning | | ----------- | -------- | | Common | 整股 | | Fixing | 定盤 | | IntradayOdd | 盤中零股 | | Odd | 盤後零股 | | Emg | 興櫃 | | EmgOdd | 興櫃零股 | 使用不同 MarketType 時,相對應的Quantity所代表的單位及範圍也會不同,詳如下表: | Name | Quantity Unit | Quantity Ranges | | ----------- | ------------- | --------------- | | Common | 千股 | 1000 ~ 499000 | | Fixing | 千股 | 1000 ~ 499000 | | IntradayOdd | 股 | 1 ~ 999 | | Odd | 股 | 1 ~ 999 | | Emg | 千股 | 1000 ~ 499000 | | EmgOdd | 股 | 1 ~ 999 | 使用不同 MarketType 時,可使用的 PriceType , TimeInForce 會不同,詳如下表: | MarketType | Available PriceType | Available TimeInForce | | ----------- | ---------------------------------------------------- | --------------------- | | Common | Limit 、 LimitUp 、 LimitDown 、 Market 、 Reference | ROD 、 IOC 、 FOK | | Fixing | Reference | ROD | | IntradayOdd | Limit 、 LimitUp 、 LimitDown 、 Reference | ROD | | Odd | Limit 、 LimitUp 、 LimitDown 、 Reference | ROD | | Emg | Limit | ROD | | EmgOdd | Limit | ROD | ##### PriceType[​](#pricetype "Direct link to PriceType") 價格類型 (priceType) | Name | Meaning | | --------- | ----------------------- | | Limit | 限價 | | LimitUp | 漲停 | | LimitDown | 跌停 | | Market | 市價 | | Reference | 參考價 (定盤時為定盤價) | ##### TimeInForce[​](#timeinforce "Direct link to TimeInForce") 委託條件 (TimeInForce) | Name | Meaning | | ---- | ------------------------------------- | | ROD | 當日有效(Rest of Day) | | FOK | 全部成交否則取消(Fill-or-Kill) | | IOC | 立即成交否則取消(Immediate-or-Cancel) | ##### OrderType[​](#ordertype "Direct link to OrderType") 委託類別 (orderType) | Name | Meaning | | -------- | -------- | | Stock | 現股 | | Margin | 融資 | | Short | 融券 | | DayTrade | 現沖先賣 | | SBL | 借券 | ##### StockType[​](#stocktype "Direct link to StockType") 股票分類別 | Name | Meaning | | ------------- | ---------- | | Stock | 股票 | | ConvertBond | 可轉債 | | ETF\_and\_ETN | ETF 與 ETN | ##### function\_type[​](#function_type "Direct link to function_type") 功能類別 | Name | Value | | ------------------------------ | ----- | | 新單 | 0 | | 新單執行 | 10 | | 改價 | 15 | | 改量 | 20 | | 刪單 | 30 | | 完全成交(for 委託單歷程查詢) | 50 | | 失敗 | 90 | ##### market[​](#market "Direct link to market") 市場 | Name | Value | | -------- | ------- | | 上市股票 | TAIEX | | 上櫃股票 | TAISDAQ | | 興櫃股票 | TAIEMG | ##### status[​](#status "Direct link to status") 委託單狀態 | Name | Value | | --------------------------- | ---------------------------------------------------------- | | 預約單 | 0 | | 系統將委託送往後台 | 4 ( 請用GetOrderResult查詢狀態 ) | | 後台傳送中 | 8 ( 請用GetOrderResult查詢狀態 ) | | 連線逾時 | 9 ( 請稍後再使用GetOrderResult查詢狀態 or 聯絡您的營業員 ) | | 委託成功 | 10 | | 未成交刪單成功 | 30 | | 部分成交,剩餘取消 | 40 | | 完全成交 | 50 | | 失敗 | 90 | | 委託單歷程查詢標示 | 14 - 改價ACK、24 - 改量ACK、34 - 刪單ACK | | 改價成功 (歷史委託單查詢) | 15 | | 改量成功 (歷史委託單查詢) | 20 | | 改價失敗 (主動回報) | 19 | | 改量失敗 (主動回報) | 29 | | 刪單失敗 (主動回報) | 39 | --- ### API Key 登入 apikey\_login 版本資訊 v2.2.7 起新增功能 相關說明請參閱 [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.md) 頁面 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------ | -------------- | | personal\_id | String | 登入的ID | | Key | String | 申請的 API Key | | cert\_path | String | 憑證路徑 | | cert\_pass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊--account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type: Object | 參數 | 類別 | 說明 | | ------------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branch\_no | String | 分公司代號 | | account\_type | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction sdk = FubonSDK() accounts = sdk.apikey_login("Your ID", "Your KEY","Your Cert Path","Your Cert Password") print(accounts) #若有多帳號,則回傳多個 ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : Account{ name : "富邦Bill", # 客戶姓名 (string) account : "28", # 客戶帳號 (string) branch_no : "6460", # 分公司代號 (string) account_type : "stock" # 帳號類型 (string) } } ``` --- ### 登入 login #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------ | ---------- | | personal\_id | String | 登入的ID | | password | String | 登入的密碼 | | cert\_path | String | 憑證路徑 | | cert\_pass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊--account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type: Object | 參數 | 類別 | 說明 | | ------------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branch\_no | String | 分公司代號 | | account\_type | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction sdk = FubonSDK() accounts = sdk.login("Your ID", "Your Password","Your Cert Path","Your Cert Password") print(accounts) #若有多帳號,則回傳多個 ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : Account{ name : "富邦Bill", # 客戶姓名 (string) account : "28", # 客戶帳號 (string) branch_no : "6460", # 分公司代號 (string) account_type : "stock" # 帳號類型 (string) } } ``` --- ### 登出 logout #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ---- | -------- | | is\_success | bool | 是否成功 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction sdk = FubonSDK() sdk.logout() ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py True ``` --- ### 刪除批次委託單 batch\_cancel\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ----------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | cancel\_object | [orderResults](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderresult) | 批次取消委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py # 批次刪單(利用batch detail回傳的內容刪單) cancel_object = [ batch_results_detail.data[0], batch_results_detail.data[1], ] sdk.stock.batch_cancel_order(account, cancel_object) # 批次刪單(利用不同的單筆委託) cancel_object = [ orders.data[37], orders.data[35], ] sdk.stock.batch_cancel_order(account, cancel_object) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data :[ OrderResult { # 批次刪單(利用batch detail回傳的內容刪單) function_type: 30, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000308998", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0028", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Stock, # 委託單類型 (string) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 41.2, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 0, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 5000, # 改單前有效量 (int) before_price: 41.2, # 改單前有效價 (float) user_def: "12345678", # 自訂欄位 (string) last_time: "16:53:57.536", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, OrderResult { function_type: 30, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "0000030899", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0029", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Stock, # 委託單類型 (string) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) ... } ]} 以下範例擷取data內容 [OrderResult{ # 批次刪單(利用不同的單筆委託) function_type: 30, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000307789", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0033", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: 1101, # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Stock, # 委託單類型 (string) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 41.2, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 0, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 5000, # 改單前有效量 (int) before_price: 41.2, # 改單前有效價 (float) user_def: "12345678", # 自訂欄位 (string) last_time: "16:53:58.536", # 最後異動時間 (string) error_message: None # 錯誤訊息 (string) }, OrderResult{ function_type: 30, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000307785", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0031", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: 1101, # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Stock, # 委託單類型 (string) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) ... }] ``` --- ### 批次修改委託價格 batch\_modify\_price ##### 先使用make\_modify\_price\_obj 建立 ModifyPriceObj 物件[​](#先使用make_modify_price_obj-建立-modifypriceobj-物件 "Direct link to 先使用make_modify_price_obj 建立 ModifyPriceObj 物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | order | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 修改後的價格旗標 (***註***: 輕量風控版**已**開放使用價格旗標) | caution 當 price 欄位有填入值時,priceType 欄位為空值或為None ; 當 priceType 欄位有填入值時,price 欄位為空值或為None 將回傳的物件放入 modify\_price 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | orders | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#modifypriceobj) (list) | 批次修改委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改��資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py # 批次改價(利用batch detail回傳的內容改單) modify_objects = [ sdk.stock.make_modify_price_obj(batch_results_detail.data[0], "41.1"), sdk.stock.make_modify_price_obj(batch_results_detail.data[1], "41.2"), ] sdk.stock.batch_modify_price(target_user, modify_objects) # 批次改價(利用不同的單筆委託) modify_objects = [ sdk.stock.make_modify_price_obj(orders.data[37], "41.1"), sdk.stock.make_modify_price_obj(orders.data[35], "41.2"), ] sdk.stock.batch_modify_price(target_user, modify_objects) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ OrderResult{# 批次改價(利用batch detail回傳的內容改單) function_type: 15, # 功能別 (int) date: "2023/11/22", # 交易日期 (string) seq_no: "00000322356", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0018", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 41.1, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: None, # 改單前有效量 (int) before_price: 41.3, # 改單前有效價 (float) user_def: "12345678", # 自訂欄位 (string) last_time: "13:56:57.713", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, OrderResult{ function_type: 15, # 功能別 (int) date: "2023/11/22", # 交易日期 (string) seq_no: "00000322355", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0017", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: 1101, # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) ... }] } 以下範例擷取data內容 [ OrderResult{# 批次改價(利用不同的單筆委託) function_type: 15, # 功能別 (int) date: "2023/11/22", # 交易日期 (string) seq_no: "00000322388", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0033", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: 1101, # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 41.1, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: None, # 改單前有效量 (int) before_price: 41.3, # 改單前有效價 (float) user_def: "12345678", # 自訂欄位 (string) last_time: "10:56:57.713", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, OrderResult{ function_type: 15, # 功能別 (int) date: "2023/11/22", # 交易日期 (string) seq_no: "00000322386", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0031", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) ... }] ``` --- ### 批次修改委託數量 batch\_modify\_quantity ##### 先使用make\_modify\_quantity\_obj 建立 ModifyQuantityObj 物件[​](#先使用make_modify_quantity_obj-建立-modifyquantityobj-物件 "Direct link to 先使用make_modify_quantity_obj 建立 ModifyQuantityObj 物件") | 參數 | 類別 | 說明 | | -------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | order | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入batch\_modify\_quantity 方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | orders | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#modifyquantityobj) (list) | 批次改量委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py # 批次改量(利用batch detail回傳的內容改單) modify_objects = [ sdk.stock.make_modify_quantity_obj(batch_results_detail.data[0], 1000), sdk.stock.make_modify_quantity_obj(batch_results_detail.data[1], 1000), ] sdk.stock.batch_modify_quantity(target_user, modify_objects) # 批次改量(利用不同的單筆委託) modify_objects = [ sdk.stock.make_modify_quantity_obj(orders.data[37], 1000), sdk.stock.make_modify_quantity_obj(orders.data[35], 1000), ] sdk.stock.batch_modify_quantity(target_user, modify_objects) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ OrderResult{ # 批次改量(利用batch detail回傳的內容改單) function_type: 20, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000000042", # 委託單流水序號 (string) branch_no: "20112", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0026", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2881", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 66, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 66, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 1000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 2000, # 改單前有效量 (int) before_price: None, # 改單前有效價 (string) user_def: "batch 2", # 自訂欄位 (string) last_time: "12:21:51.023", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, OrderResult{ # 批次改量(利用batch detail回傳的內容改單) function_type: 20, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000000041", # 委託單流水序號 (string) branch_no: "20112", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0025", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2881", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 66, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 66, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 1000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 2000, # 改單前有效量 (int) before_price: None, # 改單前有效價 (None) user_def: "batch 1", # 自訂欄位 (string) last_time: "12:21:51.023", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }] } 以下範例擷取data內容 [OrderResult{ # 批次改量(利用不同的單筆委託) function_type: 20, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000000043", # 委託單流水序號 (string) branch_no: "20112", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0027", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MaeketType) stock_no: 2881, # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 66, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 66, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 1000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 2000, # 改單前有效量 (int) before_price: None, # 改單前有效價 (int) user_def: "Test", # 自訂欄位 (string) last_time: "12:21:53.023", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, OrderResult{ function_type: 20, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000000044", # 委託單流水序號 (string) branch_no: "20112", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0028", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: 2881, # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 66, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 66, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 1000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 2000, # 改單前有效量 (int) before_price: None, # 改單前有效價 (None) user_def: "Test", # 自訂欄位 (string) last_time: "12:21:53.023", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (None) }] ``` --- ### 取得批次委託明細 batch\_order\_detail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | batch\_order\_list | [BatchResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#batchresult) | 批次委託列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | int | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | caution 此功能僅供查詢批次送單執行結果,欲取得委託單最新狀態請使用單筆委託單查詢功能 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py batch_results = sdk.stock.batch_order_lists(account) sdk.stock.batch_order_detail(account, batch_results.data[0]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [OrderResult{ function_type: None, # 功能別 (int) date: "2023/10/16", # 交易日期 (string) seq_no: "00000000005", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "bA632", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2888", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 8.9, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: false, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 8.9, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 0, # 改單前有效量 (int) before_price: 8.9, # 改單前有效價 (float) user_def: , # 自訂欄位 (string) last_time: "09:31:25.174", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, OrderResult{ function_type: None, # 功能別 (int) date: "2023/10/16", # 交易日期 (string) seq_no: "00000000005", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "bA631", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2888", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 8.9, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: false, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 8.9, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 0, # 改單前有效量 (int) before_price: 8.9, # 改單前有效價 (float) user_def: None, # 自訂欄位 (string) last_time: "09:31:25.101", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }]} ``` --- ### 取得批次委託列表 batch\_order\_lists #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳批次單資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 批次單 BatchResult 欄位[​](#批次單-batchresult-欄�位 "Direct link to 批次單 BatchResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------ | ------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | batch\_seq\_no | string | 批次單流水序號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.batch_order_lists(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [BatchResult{ function_type: 0, # 功能種類 (int) date: "2023/10/16", # 交易日期 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) batch_seq_no: "11EE6BC3B85670DE8000000C29304663" # 批次單流水序號 (string) }, BatchResult{ function_type: 15, # 功能種類 (int) date: "2023/10/16", # 交易日期 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) batch_seq_no: "11EE6BC3E189F02A8000000C29304663" # 批次單流水序號 (string) }, ... ] } ``` --- ### 建立批次委託單 batch\_place\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------- | --------------------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | order\_object | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderobject) (list of object) | 委託內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py orders = [ Order( buy_sell = BSAction.Buy, symbol = "2881", price = "66", quantity = 2000, market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force = TimeInForce.ROD, order_type = OrderType.Stock, user_def = "batch 1" # optional field ), Order( buy_sell = BSAction.Buy, symbol = "2881", price = "66.1", quantity = 2000, market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force = TimeInForce.ROD, order_type = OrderType.Stock, user_def = "batch 2" # optional field ) ] sdk.stock.batch_place_order(target_user, orders) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ OrderResult{ function_type: 0, # 功能別 (int) date: "2023/10/16", # 交易日期 (string) seq_no: "00000000011", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: None, # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2881", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 66, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: false, # 是否為預約單 (bool) status: 4, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 66, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 0, # 改單前有效量 (int) before_price: 8.9, # 改單前有效價 (float) user_def: "batch 1", # 自訂欄位 (string) last_time: "13:33:21.817", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, OrderResult{ function_type: 0, # 功能別 (int) date: "2023/10/16", # 交易日期 (string) seq_no: "00000000012", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (int) account: "26", # 帳號 (string) order_no: None, # 委託書號 (string) asset_type: None, # 資產類別 (int) market: None, # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2881", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 66.1, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: false, # 是否為預約單 (bool) status: 4, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 66.1, # 有效委託價格 (float) unit: None, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 0, # 改單前有效量 (int) before_price: 66.1, # 改單前有效價 (float) user_def: "batch 2", # 自訂欄位 (string) last_time: "13:33:21.817", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }]} ``` --- ### 刪除委託單 cancel\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------- | ---------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | order\_result | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderresult) | 欲取消的委託單物件 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | OrderResult | 回傳更新委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult--欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type: Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.cancel_order(account, cancel_order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : OrderResult { function_type: 30, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000308948", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0023", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Stock, # 委託單類型 (string) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 41.2, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 0, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 5000, # 改單前有效量 (int) before_price: 41.2, # 改單前有效價 (float) user_def: "12345678", # 自訂欄位 (string) last_time: "10:53:57.536", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }} ``` --- ### 現冲券配額查詢 daytrade\_and\_stock\_info #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | -------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | stock\_no | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | DayTradeStockInfo | 回傳配額資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 配額 DayTradeStockInfo 欄位[​](#配額-daytradestockinfo-欄位 "Direct link to 配額 DayTradeStockInfo 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------- | | stock\_no | string | 股票代號 | | date | string | 日期 | | daytrade\_orig\_quota | int | 原始現冲券餘額 | | daytrade\_tradable\_quota | int | 可用現冲券餘額 | | precollect\_single | int | 單筆預收股數 (若不需預收則顯示None) | | precollect\_accumulate | int | 累積預收股數 (若不需預收則顯示None) | | status | int | 狀態 (bitmask 加總) `0` :全禁 、 `1`:平盤下可融券賣出、`2`:平盤下可借券賣出、 `4`:可先買後賣當沖 、 `8`:可先賣後買當沖 | | disposition\_status | string | 警示股註記 `{ SETTYPE : 1}` : 全額交割、 `{ MARK-W : 1}` : 警示、`{ MARK-P : 1}` : 注意、`{ MARK-L : 1}` : 委託受限 【**2.2.5版本新增欄位**】 | info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.daytrade_and_stock_info(account, "2330") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ DayTradeStockInfo{ stock_no: "2330", # 股票代號 (string) date: "2023/10/16", # 日期 (string) daytrade_orig_quota: 0, # 原始現冲券餘額 (int) daytrade_tradable_quota: 0, # 可用現冲券餘額 (int) precollect_single: None, # 單筆預收股數 (int) precollect_accumulate: None, # 累積預收股數 (int) status: 0, # 狀態 (int) disposition_status: "{\"MARK-W\":1}" # 警示股註記 (string)【2.2.5版本新增欄位】 }]} ``` --- ### 查詢歷史成交 filled\_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 (optional) (不帶預設與開始日相同) | 查詢終止日 | info v2.1.1起可查詢長期歷史資料,每次查詢最大設定30日日期區間;v2.1.0之前版本可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳成交資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 成交資訊 FilledData 欄位[​](#成交資訊-filleddata-欄位 "Direct link to 成交資訊 FilledData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | | date | string | 成交日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | seq\_no | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | order\_no | string | 委託書號 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | filled\_no | string | 成交流水號 | | filled\_avg\_price | float | 成交均價 | | filled\_qty | int | 成交股數 | | filled\_price | float | 成交單價 | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | filled\_time | string | 成交時間 | | user\_def | string | 用戶自定義 (只有主動回報才回傳此欄位) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.filled_history(account,"20230921","20230922") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ FilledData{ date: "2023/09/15", # 成交日期 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "bA422", # 委託書號 (string) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) filled_no: "00000000001", # 成交流水號 (string) filled_avg_price: 35.2, # 成交均價 (float) filled_qty: 1000, # 成交股數 (int) filled_price: 35.2, # 成交單價 (float) order_type: Stock, # 委託單類型 (OrderType) filled_time: "10:31:00.931" # 成交時間 (string) user_def: None # 用戶自定義 (string) }, ... ] } ``` --- ### 取得委託單結果 get\_order\_results #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : List | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | int | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.get_order_results(accounts.data[0]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [OrderResult{ function_type: None, # 功能別 (int) date: "2023/10/16", # 交易日期 (date) seq_no: "00000000001", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "bA628", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2888", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 9.1, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: false, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 9.1, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: None, # 改單前有效量 (int) before_price: None, # 改單前有效價 (float) user_def: None, # 自訂欄位 (string) last_time: "08:30:05.157", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, ... ] } ``` --- ### 取得委託單結果 (含歷程) get\_order\_results\_detail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | -------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : List | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | int | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | error\_message | string | 錯誤訊息 | | details | list | 委託歷程 | | >> function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modified\_time | string | 修改時間 | | >> before\_qty | int | 原始委託股數 | | >> after\_qty | int | 有效委託股數(包含已成交部分) | | >> before\_price | float | 原始委託價 | | >> after\_price | float | 有效委託價 | | >> filled\_money | float | 成交價金 | | >> status | int | 委託單狀態 | | >> err\_msg | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.get_order_results_detail(accounts.data[0]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [OrderResult{ function_type: None, # 功能別 (int) date: "2023/10/16", # 交易日期 (date) seq_no: "00000000001", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "bA628", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2888", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 9.1, # 價格 (float) quantity: 2000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: false, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 9.1, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: None, # 改單前有效量 (int) before_price: None, # 改單前有效價 (float) user_def: None, # 自訂欄位 (string) last_time: "08:30:05.157", # 最後異動時間 (string) error_message: None # 錯誤訊息 (string) details:[ # 委託歷程 (list) OrderDetail { function_type: 10, # 功能別(int) modified_time: "08:30:05", # 修改時間 (string) before_qty: 0, # 改單前有效量 (int) after_qty: 2000, # 有效委託股數 (int) before_price: 9.1, # 改單前有效價 (float) after_price: 9.1 # 有效委託價 (float) status: 10, # 委託單狀態 (int) err_msg: None # 錯誤訊息 (string) } ] }, ... ] } ``` --- ### 資券配額查詢 margin\_quota #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | -------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | stock\_no | string | 股票代碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ---------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | MarginShortQuota | 回傳配額資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### MarginShortQuota欄位[​](#marginshortquota欄位 "Direct link to MarginShortQuota欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------------------- | ------ | ------------ | | stock\_no | string | 股票代號 | | date | string | 日期 | | shortsell\_orig\_quota | int | 原始融券餘額 | | shortsell\_tradable\_quota | int | 可用融券餘額 | | margin\_orig\_quota | int | 原始融資餘額 | | margin\_tradable\_quota | int | 可用融資餘額 | | margin\_ratio | int | 融資成數 | | short\_ratio | int | 融券成數 | info 額度相關說明 : 融資成數為None表示停資;融券成數為None表示停券,
回傳的額度說明 : 0 - 無額度 / 大於0 - 有額度 / None - 無限制 / 餘額皆為 0 - 停資 or 停券 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.margin_quota(account, "2330") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data: [ MarginShortQuota { stock_no: 2330, date: "2024/01/24", shortsell_orig_quota: 894, shortsell_tradable_quota: 894, margin_orig_quota: None, margin_tradable_quota: None, margin_ratio: 60, short_ratio: 90, }] } ``` --- ### 修改委託價格 modify\_price ##### 先使用make\_modify\_price\_obj 建立 ModifyPriceObj 物件[​](#先使用make_modify_price_obj-建立-modifypriceobj-物件 "Direct link to 先使用make_modify_price_obj 建立 ModifyPriceObj 物件") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | order | [OrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 修改後的價格旗標 (***註***: 輕量風控版**已**開放使用價格旗標) | caution 當 price 欄位有填入值時,priceType 欄位為空值或為None ; 當 priceType 欄位有填入值時,price 欄位為空值或為None 將回傳的物件放入 modify\_price 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ---------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | order\_res | [ModifyPriceObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#modifypriceobj) | 修改價格的物件 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | OrderResult | 回傳委託單修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py modify_price_obj = sdk.stock.make_modify_price_obj(order_result, "41.1") sdk.stock.modify_price(account, modify_price_obj) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : OrderResult { function_type: 15, # 功能別 (int) date: "2023/11/22", # 交易日期 (string) seq_no: "00000308866", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0011", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 41.1, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: None, # 改單前有效量 (int) before_price: 41.3, # 改單前有效價 (float) user_def: "12345678", # 自訂欄位 (string) last_time: "13:56:57.713", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }} ``` --- ### 修改委託單數量 modify\_quantity ##### 先使用make\_modify\_quantity\_obj 建立 ModifyQuantityObj 物件[​](#先使用make_modify_quantity_obj-建立-modifyquantityobj-物件 "Direct link to 先使用make_modify_quantity_obj 建立 ModifyQuantityObj 物件") | 參數 | 類別 | 說明 | | -------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | order | [orderResult](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderresult) | 預計修改的委託單 | | quantity | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 modify\_quantity 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ---------------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | order\_res | [ModifyQuantityObj](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#modifyquantityobj) | 修改的委託單 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | OrderResult | 回傳委託單修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 OrderResult 欄位[​](#修改資訊-orderresult-欄位 "Direct link to 修改資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py modify_qty_obj = sdk.stock.make_modify_quantity_obj(target_order, 1000) sdk.stock.modify_quantity(account, modify_qty_obj) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : OrderResult{ function_type: 20, # 功能別 (int) date: "2024/03/08", # 交易日期 (string) seq_no: "00000308866", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "x0011", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "1101", # 股票代號 (string) buy_sell: Sell, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 41.2, # 價格 (float) quantity: 5000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 41.3, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 1000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 3000, # 改單前有效量 (int) before_price: 41.2, # 改單前有效價 (float) user_def: "12345678", # 自訂欄位 (string) last_time: "13:56:28.966", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) } } ``` --- ### 查詢歷史委託 order\_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 (optional) (不帶預設與開始日相同) | 查詢終止日 | info v2.1.1起可查詢長期歷史資料,每次查詢最大設定30日日期區間;v2.1.0之前版本可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int (Optional) | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | int | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | error\_message | string | 錯誤訊息 | | >> details | list | 委託歷程 | | >> function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `50` 完全成交 、 `90`失敗 | | >> modified\_time | string | 修改時間 | | >> before\_qty | int | 原始委託股數 | | >> after\_qty | int | 有效委託股數(包含已成交部分) | | >> before\_price | float | 原始委託價 | | >> after\_price | float | 有效委託價 | | >> filled\_money | float | 成交價金 | | >> status | int | 委託單狀態 | | >> err\_msg | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.order_history(account,"20230921","20230922") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [OrderResult{ function_type: None, # 功能別 (int) date: "2023/09/21", # 交易日期 (date) seq_no: "00000221427", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "bA489", # 委託書號 (string) asset_type: 0, # 資產類別 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2888", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 9.1, # 價格 (float) quantity: 1000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: , # 有效委託價格別 (PriceType) after_price: 9.1, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 1000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: , # 改單前有效量 (int) before_price: , # 改單前有效價 (float) user_def: , # 自訂欄位 (string) last_time: "09:00:32.477", # 最後異動時間 (string) details:[ # 委託歷程 (list) OrderDetail { function_type: 10, # 功能別(int) modified_time: "09:00:32.477", # 修改時間 (string) before_qty: 0, # 改單前有效量 (int) after_qty: 1000, # 有效委託股數 (int) before_price: 9.1, # 改單前有效價 (float) after_price: 9.1 # 有效委託價 (float) } ] error_message: None # 錯誤訊息 (string) }, ... #更多的Result回傳 ]} ``` --- ### 建立委託單 place\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------- | ---------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | order\_object | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#orderobject) | 委託內容 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | OrderResult | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 OrderResult 欄位[​](#委託資訊-orderresult-欄位 "Direct link to 委託資訊 OrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、 `10` 新單執行 、 `15` 改價 、 `20` 改量 、 `30` 刪單 、 `90` 失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `0` 證券 | | market | string | 市場類型 : `TAIEX` 上市股票 、 `TAISDAQ` 上櫃股票 、 `TAIEMG` 興櫃股票 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) | 盤別種類 : `Common` 整股 、 `Fixing` 定盤 、 `IntradayOdd` 盤中零股 、 `Odd` 盤後零股 、 `Emg` 興櫃 、 `EmgOdd` 興櫃零股 | | stock\_no | string | 股票代號 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 原始委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | quantity | int | 原始委託股數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [OrderType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#ordertype) | 委託單類型 : `Stock` 現股 、 `Margin` 融資 、 `Short` 融券 、 `DayTrade` 現沖先賣 、 `SBL`借券 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | after\_price\_type | [PriceType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#pricetype) | 有效委託價格別 : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | unit | int | 單位數 | | after\_qty | int | 有效委託股數(包含已成交部分) | | filled\_qty | int | 成交股數 | | filled\_money | int | 成交價金 | | before\_qty | int | 改單前有效量 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 (最長10個字元,不支援特殊字元及中文、不適用興櫃) | | last\_time | string | 最後異動時間 | | details | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py order = Order( buy_sell = BSAction.Buy, symbol = "2881", price = "66", quantity = 1000, market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force = TimeInForce.ROD, order_type = OrderType.Stock, user_def = "From_Py" # optional field ) sdk.stock.place_order(account, order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : OrderResult { function_type: 0, # 功能別 (int) date: "2023/10/12", # 交易日期 (string) seq_no: "00000000007", # 委託單流水序號 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "bA676", # 委託書號 (string) asset_type: 0, # 資產類型 (int) market: "TAIEX", # 市場類型 (string) market_type: Common, # 盤別種類 (MarketType) stock_no: "2881", # 股票代號 (string) buy_sell: Buy, # 買賣別 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 66, # 價格 (float) quantity: 1000, # 原始委託股數 (int) time_in_force: ROD, # 委託條件別 (TimeInForce) order_type: Stock, # 委託單類型 (OrderType) is_pre_order: false, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (PriceType) after_price: 66, # 有效委託價格 (float) unit: 1000, # 單位數 (int) after_qty: 2000, # 有效委託股數 (int) filled_qty: 0, # 成交股數 (int) filled_money: 0, # 成交價金 (int) before_qty: 0, # 改單前有效量 (int) before_price: 0, # 改單前有效價 (float) user_def: "From_Py", # 自訂欄位 (string) last_time: "14:05:12.085", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }} ``` --- ### 查詢商品漲跌幅報表(單筆) query\_symbol\_quote info 2.2.5 版新增 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | symbol | String | 股票代碼 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolQuote | 回傳委託資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 商品資訊 SymbolQuote 欄位[​](#商品資訊-symbolquote-欄位 "Direct link to 商品資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類型 | 說明 | | ------------------ | ----- | ---------------------------------------------------------------------------------------------------------------------- | | market | str | 市場別 | | symbol | str | 股票代碼 | | is\_tib\_or\_psb | bool | 是否為創新版或戰略新板 | | market\_type | str | 市場類型 | | status | int | 狀態 (bitmask 加總) `0` :全禁 、 `1`:平盤下可融券賣出、`2`:平盤下可借券賣出、 `4`:可先買後賣當沖 、 `8`:可先賣後買當沖 | | reference\_price | float | 參考價格 | | unit | int | 交易單位 | | update\_time | str | 更新時間 | | limitup\_price | float | 漲停價 | | limitdown\_price | float | 跌停價 | | open\_price | float | 開盤價 | | high\_price | float | 最高價 | | low\_price | float | 最低價 | | last\_price | float | 最新成交價 | | total\_volume | int | 總成交量 | | total\_transaction | int | 總成交筆數 (預留欄位,暫未使用) | | total\_value | float | 總成交金額 | | last\_size | int | 最新成交量 | | last\_transaction | int | 最新成交筆數 (預留欄位,暫未使用) | | last\_value | float | 最新成交金額 | | bid\_price | float | 買1價格 | | bid\_volume | int | 買1數量 | | ask\_price | float | 賣1價格 | | ask\_volume | int | 賣1數量 | 支援範圍 上市、上櫃標的 info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.stock.query_symbol_quote(accounts.data[0],"2330", MarketType.IntradayOdd ) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data: SymbolQuote { market: "TAIEX", # str - 市場別 symbol: "2330", # str - 股票代碼 is_tib_or_psb: False, # bool - 是否為創新版或戰略新板 market_type: "IntradayOdd", # str - 市場類型 status: 1, # int - 狀態 (bitmask 加總) reference_price: 780, # float - 參考價格 unit: 1, # int - 交易單位 update_time: "09:09:55.741", # str - 更新時間 limitup_price: 858, # float - 漲停價 limitdown_price: 702, # float - 跌停價 open_price: None, # float | None - 開盤價 high_price: None, # float | None - 最高價 low_price: None, # float | None - 最低價 last_price: None, # float | None - 最新成交價 total_volume: None, # int | None - 總成交量 total_transaction: 0, # int - 總成交筆數 (預留欄位,暫未使用) total_value: None, # float | None - 總成交金額 last_size: None, # int | None - 最新成交量 last_transaction: 0, # int - 最新成交筆數 (預留欄位,暫未使用) last_value: 0, # float - 最新成交金額 bid_price: 1140, # float - 買1價格 bid_volume: 47975, # int - 買1數量 ask_price: 1145, # float - 賣1價格 ask_volume: 23024, # int - 賣1數量 } } ``` --- ### 查詢商品漲跌幅報表(批次) query\_symbol\_snapshot info 2.2.5 版新增 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | --------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#account) | 帳號 | | market\_type | [MarketType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#markettype) (Optional)(default = Common) | 市場別 : 支援 `Common` 整股,`IntradayOdd` 盤中零股、`Fixing` 定盤 | | stock\_type | List [StockType](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#stocktype) (Optional)(default = Stock) | 股票分類別 : `Stock` 股票、`ConvertBond` 可轉債、`ETF_and_ETN` ETF 與 ETN | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | SymbolSnapshotResponse | 回傳委託資訊 | | message | string | 當isSuccess : false 回傳錯誤訊息 | ##### 商品資訊 SymbolQuote 欄位[​](#商品資訊-symbolquote-欄位 "Direct link to 商品資訊 SymbolQuote 欄位") Return type : Object | 參數 | 類型 | 說明 | | ------------------ | ----- | ----------------------------------------------------------------------------------------------------------------------- | | market | str | 市場別 | | symbol | str | 股票代碼 | | is\_tib\_or\_psb | bool | 是否為創新版或戰略新板 | | market\_type | str | 市場類型 | | status | int | 狀態 (bitmask 加總): `0` :全禁 、 `1`:平盤下可融券賣出、`2`:平盤下可借券賣出、 `4`:可先買後賣當沖 、 `8`:可先賣後買當沖 | | reference\_price | float | 參考價格 | | unit | int | 交易單位 | | update\_time | str | 更新時間 | | limitup\_price | float | 漲停價 | | limitdown\_price | float | 跌停價 | | open\_price | float | 開盤價 | | high\_price | float | 最高價 | | low\_price | float | 最低價 | | last\_price | float | 最新成交價 | | total\_volume | int | 總成交量 | | total\_transaction | int | 總成交筆數 (預留欄位,暫未使用) | | total\_value | float | 總成交金額 | | last\_size | int | 最新成交量 | | last\_transaction | int | 最新成交筆數 (預留欄位,暫未使用) | | last\_value | float | 最新成交金額 | | bid\_price | float | 買1價格 | | bid\_volume | int | 買1數量 | | ask\_price | float | 賣1價格 | | ask\_volume | int | 賣1數量 | 支援範圍 上市、上櫃標的 info Status 範例說明 : 若Status = 15 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)+4(可先買後賣當沖)+8(可先賣後買當沖) ,的分解項目; 若Status = 3 則為,1(平盤下可融券賣出)+2(平盤下可借券賣出)的分解項目。其餘加總以此類推。 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py from fubon_neo.constant import StockType sdk.stock.query_symbol_snapshot(accounts.data[0]) #Default sdk.stock.query_symbol_snapshot(accounts.data[0], MarketType.Common, [StockType.Stock]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data: SymbolSnapshotResponse { symbols: [ SymbolQuote { market: "TAIEX", # str - 市場別 symbol: "2330", # str - 股票代碼 is_tib_or_psb: False, # bool - 是否為創新版或戰略新板 market_type: "IntradayOdd", # str - 市場類型 status: 1, # int - 狀態 (bitmask 加總) reference_price: 780, # float - 參考價格 unit: 1, # int - 交易單位 update_time: "09:09:55.741", # str - 更新時間 limitup_price: 858, # float - 漲停價 limitdown_price: 702, # float - 跌停價 open_price: None, # float | None - 開盤價 high_price: None, # float | None - 最高價 low_price: None, # float | None - 最低價 last_price: None, # float | None - 最新成交價 total_volume: None, # int | None - 總成交量 total_transaction: 0, # int - 總成交筆數 (預留欄位,暫未使用) total_value: None, # float | None - 總成交金額 last_size: None, # int | None - 最新成交量 last_transaction: 0, # int - 最新成交筆數 (預留欄位,暫未使用) last_value: 0, # float - 最新成交金額 bid_price: 1140, # float - 買1價格 bid_volume: 47975, # int - 買1數量 ask_price: 1145, # float - 賣1價格 ask_volume: 23024, # int - 賣1數量 }, SymbolQuote{ market: "TAIEX", # str - 市場別 ... }, ... ] } } ``` --- ### 事前準備 本頁重點 * 使用富邦新一代 API(Fubon Neo API)前,需完成開戶、憑證與 API 使用聲明。 * 安裝方式與版本相容性請見[安裝與版本相容性](https://www.fbs.com.tw/TradeAPI/docs/install-compatibility.md)。 * 下一步可前往[快速開始](https://www.fbs.com.tw/TradeAPI/docs/trading/quickstart.md)或[SDK 下載](https://www.fbs.com.tw/TradeAPI/docs/download/download-sdk.md)。 | 項目 | 說明 | | -------- | ----------------------------------------------- | | 產品 | 富邦新一代 API(Fubon Neo API) | | 必要條件 | 富邦證券帳戶、數位憑證、API 使用聲明 + 連線測試 | | 主要平台 | Windows(憑證工具與連線測試程式) | | 登入方式 | 憑證登入 | | 下一步 | 安裝與版本相容性 / 快速開始 | caution 在開始富邦新一代 API 前,您必須完成以下步驟 1. 準備好您的富邦證券帳戶 (若您還未擁有富邦證券帳戶,請點連結【[線上開戶](https://www.fubon.com/securities/open-now/)】) 2. 申請憑證 3. API 風險使用聲明書簽署【[線上簽署SOP](https://www.fbs.com.tw/wcm/new_web/operate_manual/operate_manual_01/API-SignSOP_guide.pdf)】+ API 連線測試【[連線測試小幫手](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/API_Sign_Test.zip)】 (Windows) #### 準備好富邦證券帳戶[​](#準備好富邦證券帳戶 "Direct link to 準備好富邦證券帳戶") 若您已有您的富邦證券帳戶請跳過此步驟,未擁有富邦證券帳戶請[立即開戶](https://www.fubon.com/securities/open-now/) ![富邦證券帳號](/TradeAPI/assets/images/prepare_account-792b5d9a17005ebde0e7d7050b37bb5c.png) #### 申請憑證[​](#申請憑證 "Direct link to 申請憑證") 至[憑證申請、展期](https://www.fbs.com.tw/Certificate/Management/)點選立即執行下載富邦證券憑證e總管(TCEM.exe)申請憑證 ![Certificate apply](/TradeAPI/assets/images/ca_navigator-8ddb522e5c70f747eb5a534d53864247.png) 登入完成並且認證後,輸入手機或電子信箱收取OTP驗證 ![OTP](/TradeAPI/assets/images/ca_cover-3de617d54b6dfac697be7cae07ea3260.png) 完成申請,憑證將存放於 C:\CAFubon\\(您的身分證字號),並以您的身份證字號為檔名 ![CertLocation](/TradeAPI/assets/images/ca_repo-829d506640c176e4a8fc1b84c13b2908.png) #### API 使用風險暨聲明書簽署及測試[​](#api-使用風險暨聲明書簽署及測試 "Direct link to API 使用風險暨聲明書簽署及測試") ###### 線上簽署[​](#線上簽署 "Direct link to 線上簽署") 依照下方說明連結分別進行API 聲明書簽署、API 連線測試 [線上簽署SOP說明書](https://www.fbs.com.tw/wcm/new_web/operate_manual/operate_manual_01/API-SignSOP_guide.pdf) [![線上簽署](/TradeAPI/assets/images/signSOP-6ed1317bfe2fb019c87930735dfc0f7d.png)](https://www.fbs.com.tw/wcm/new_web/operate_manual/operate_manual_01/API-SignSOP_guide.pdf) ###### 連線測試[​](#連線測試 "Direct link to 連線測試") 下載使用連線測試程式 (for Windows), 或直接使用新一代 API 進行連線登入 [連線測試小幫手](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/API_Sign_Test.zip) [![連線測試小幫手](/TradeAPI/assets/images/connection_test-e62eafe09e327f83f55844591ea812af.png)](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/API_Sign_Test.zip) #### 安裝與版本相容性[​](#安裝與版本相容性 "Direct link to 安裝與版本相容性") 請先閱讀[安裝與版本相容性](https://www.fbs.com.tw/TradeAPI/docs/install-compatibility.md)以確認各語言最低版本與安裝方式,並至[SDK 下載](https://www.fbs.com.tw/TradeAPI/docs/download/download-sdk.md)取得安裝檔。 #### 開始拓展程式交易之旅[​](#開始拓展程式交易之旅 "Direct link to 開始拓展程式交易之旅") * Python * Node.js * C# ```python from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction # 載入設定檔與登入 sdk = FubonSDK() accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置", "您的憑證密碼") ## accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置") # 若憑證選用"預設密碼", SDK v1.3.2與較新版本適用 acc = accounts.data[0] # 建立委託物件 order = Order( buy_sell = BSAction.Buy, symbol = "2881", quantity = 2000, price = "66", market_type = MarketType.Common, price_type = PriceType.Limit, time_in_force = TimeInForce.ROD, order_type = OrderType.Stock, user_def = "From_Py" # optional field ) # 下單 order_res = sdk.stock.place_order(acc, order) print(order_res) ``` 恭喜您🎊,完成下單,即可看到系統回覆的結果 ```python Result { is_success: True, message: None, data : OrderResult{ date: "2023/10/13", seq_no: "00000000015", branch_no: "6460", account: "26", order_no: "bA626", asset_type: 0, market: "TAIEX", market_type: Common, stock_no: "2881", buy_sell: Buy, price_type: Limit, price: 66.0, quantity: 2000, time_in_force: ROD, order_type: Stock, is_pre_order: false, status: 10, after_price_type: Limit, after_price: 66.0, unit: 1000, after_qty: 2000, filled_qty: 0, filled_money: 0, before_qty: 0, before_price: 66.0, user_def: "From_Py", last_time: "16:48:09.247", error_message: None} } ``` ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); // 載入設定檔與登入 const sdk = new FubonSDK(); const accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼"); // const accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置"); // 若憑證選用"預設密碼", SDK v1.3.2與較新版本適用 const acc = accounts.data[0]; // 建立委託物件 const order = { buySell: BSAction.Buy, symbol: 2881, price: "66", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.Limit, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" }; // 下單 sdk.stock.placeOrder(acc,order); ``` 恭喜您🎊 ,完成下單,即可看到系統回覆的結果 ```js { isSuccess: true, data:{ date : '2023/10/13', seqNo : '00000000016', branchNo : '6460', account : '26', orderNo : 'bA627', assetType : 0, market : 'TAIEX', marketType : 'Common', stockNo : '2881', buySell : 'Buy', priceType : 'Limit', price : 66, quantity : 2000, timeInForce : 'ROD', orderType : 'Stock', isPreOrder : false, status : 10, afterPriceType : 'Limit', afterPrice : 66, unit : 1000, afterQty : 2000, filledQty : 0, filledMoney : 0, beforeQty : 0, beforePrice : 66, userDef : 'From JS', lastTime : '17:19:06.048' } } ``` ```cs using FubonNeo.Sdk; //載入設定檔與登入 var sdk = new FubonSDK(); var acc_obj = sdk.Login("您的身分證號", "您的登入密碼", "您的憑證路徑" ,"您的憑證密碼"); /* // 若憑證選用"預設密碼", SDK v1.3.2 與較新版本適用 var acc_obj = sdk.Login("您的身分證號", "您的登入密碼", "您的憑證路徑"); */ var acc = acc_obj.data[0]; //建立委託物件 var order = new Order( BsAction.Buy, "2881", "66", 2000, MarketType.Common, PriceType.Limit, TimeInForce.ROD, OrderType.DayTrade, "From C#" ); // 下單 var order_res = sdk.Stock.PlaceOrder(acc, order); Console.WriteLine(order_res); ``` 恭喜您🎊,完成下單,即可看到系統回覆的結果 ```cs { isSuccess = True, message = , data = { date = 2023/10/13, seqNo = 00000000016, branchNo = 6460, account = 26, orderNo = bA627, assetType = 0, market = TAIEX, marketType = Common, stockNo = 2881, buySell = Buy, priceType = Limit , price = 66, quantity = 2000, timeInForce = ROD, orderType = DayTrade, isPreOrder = False, status = 10, afterPriceType = Limit, afterPrice = 66, unit = 1000, afterQty = 2000, filledQty = 0, filledMoney = 0, beforeQty = 0, beforePrice = 66, userDef = From C#, lastTime = 17:19:06.048, errorMessage = } } ``` --- ### 快速開始 本頁重點 * 本頁提供富邦新一代 API(Fubon Neo API)登入與下單範例。 * 開始前請先完成[事前準備](https://www.fbs.com.tw/TradeAPI/docs/trading/prepare.md)(開戶、憑證、聲明與連線測試)。 * 安裝方式與版本相容性請見[安裝與版本相容性](https://www.fbs.com.tw/TradeAPI/docs/install-compatibility.md)。 | 項目 | 說明 | | -------- | -------------------------------------------------------------------------- | | 前置條件 | 完成事前準備 | | 支援語言 | Python / C# / JavaScript (Node.js) / C++、Go(僅支援證券交易帳務及條件單) | | 下載來源 | SDK 下載頁面 | | 安裝方式 | 請見安裝與版本相容性 | | 下一步 | 依語言完成登入與下單範例 | 請先參考[事前準備](https://www.fbs.com.tw/TradeAPI/docs/trading/prepare.md)完成風險預告書申請與憑證下載。 #### 安裝與版本相容性[​](#安裝與版本相容性 "Direct link to 安裝與版本相容性") 安裝步驟與最低版本需求請見[安裝與版本相容性](https://www.fbs.com.tw/TradeAPI/docs/install-compatibility.md),下載 SDK 請至[SDK 下載頁面](https://www.fbs.com.tw/TradeAPI/docs/download/download-sdk.md)。 ##### 並將憑證放置您的資料夾結構應該像是: ```text . └── XXXXXXXXXX.pfx ``` ##### [​](#-1 "Direct link to -1") * Python * Node.js * C# 若您未曾使用 SDK 進行過登入,或更換了 SDK 執行環境,請在資料夾新增一個 `index.py` 檔案,貼上以下內容並執行: ```python from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction sdk = FubonSDK() accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證位置", "您的憑證密碼") #若有歸戶,則會回傳多筆帳號資訊 ## accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置") # 若憑證選用"預設密碼", SDK v1.3.2與較新版本適用 acc = accounts.data[0] ``` 若您未曾使用 SDK 進行過登入,或更換了 SDK 執行環境,請在資料夾新增一個 `index.js` 檔案,貼上以下內容並執行: ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); const sdk = new FubonSDK(); const accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證路徑" ,"您的憑證密碼"); // const accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置"); // 若憑證選用"預設密碼", SDK v1.3.2與較新版本適用 const acc = accounts.data[0]; ``` 若您未曾使用 SDK 進行過登入,或更換了 SDK 執行環境,請在資料夾新增一個 `index.cs` 檔案,貼上以下內容並執行: ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var accounts = sdk.Login("您的身分證字號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼"); // 若有歸戶,則會回傳多筆帳號資訊 /* // 若憑證選用"預設密碼", SDK v1.3.2 與較新版本適用 var acc_obj = sdk.Login("您的身分證號", "您的登入密碼", "您的憑證路徑"); */ var acc = accounts.data[0]; ``` #### 送出委託,買入股票[​](#送出委託買入股票 "Direct link to 送出委託,買入股票") 再將以下範例程式碼補上, 將示範如何使用富邦新一代 API 送出一張以跌停價買入 富邦金(2881)的限價委託: * Python * Node.js * C# ```py order = Order( buy_sell = BSAction.Buy, symbol = "2881", price = None, quantity = 2000, market_type = MarketType.Common, price_type = PriceType.LimitDown, time_in_force = TimeInForce.ROD, order_type = OrderType.Stock, user_def = "From_Py" # 使用者可自定義填入 , Optional field ) sdk.stock.place_order(acc, order) ``` ```js const order = { buySell: BSAction.Buy, symbol: 2881, price: "66", quantity: 2000, marketType: MarketType.Common, priceType: PriceType.LimitDown, timeInForce: TimeInForce.ROD, orderType: OrderType.Stock, userDef: "from Js" }; // sdk.stock.placeOrder(acc, order); ``` ```cs var order = new Order( BsAction.Buy, "2881", "66", 2000, MarketType.Common, PriceType.LimitDown, TimeInForce.Rod, OrderType.Stock, null ); sdk.Stock.PlaceOrder(acc ,order); // 使用阻塞委託下單 ``` --- ### 速率限制 本頁重點 * 本頁整理富邦新一代 API(Fubon Neo API)連線與下單速率限制。 * 連線數上限為 10;下單與查詢有每秒限制。 * 超過上限時,會回傳錯誤訊息(如下方範例)。 | 項目 | 上限 | | -------- | ------- | | 連線數 | 10 | | 下單 | 50 / 秒 | | 批次下單 | 10 / 秒 | | 帳務查詢 | 5 / 秒 | ##### 連線次數限制[​](#連線次數限制 "Direct link to 連線次數限制") | 行為 | 上限數 | | ------ | ------ | | 連線數 | 10 | 當連線超過上限,登入時將收到以下訊息 : ```json Result { is_success: False, message: Login Error, 超過本應用程式連線限制==>[10] data: None } ``` | 行為 | 每秒上限數 | | -------- | ---------- | | 下單 | 50 | | 批次下單 | 10 | | 帳務查詢 | 5 | 當次數超過上限,將收到以下訊息 : ```json Result { is_success: False, message: Login Error, 業務系統流量控管 data: None } ``` --- ### 帳務 *** 我們可以透過混和部位查詢及權益數來確部位等資訊。 info 查詢發送的次數為每秒5次,若超出上限,請稍後再試試! #### 部位查詢[​](#部位查詢 "Direct link to 部位查詢") * Python * Node.js * C# ```python h_position = sdk.futopt_accounting.query_hybrid_position(accounts.data[0]) print(h_position) ``` ```py Result { is_success: True, message: None, data : [HybridPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) is_spread : False, # 是否為複式部位 (bool) position_kind : 1, # 部位種類 (int) symbol : "FITX", # 商品代號 (str) expiry_date : 202404, # 履約日 (string) strike_price : None, # 履約價 (int or None) call_put : None, # 權利別 (int or None) buy_sell : Buy, # 買賣別 (BSAction) price : 20325.3333, # 成交價 (float) orig_lots : 3, # 原始口數 (int) tradable_lot : 3, # 可交易口數 (int) order_type : New, # 委託別 (FutOptOrderType) currency : "TWD", # 幣別 (str) market_price : "20351", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 0.0, # 選擇權市值 (float) opt_long_value : 0.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : 0.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) spreads : None, # 複式部位 (List[SpreadPosition]) } ... ] } ``` ```js const h_position = sdk.futoptAccounting.queryHybridPosition(accounts.data[0]) console.log(h_position) ``` ```js { isSuccess: true, data:[ { date : "2024/04/08", // 部位建立日期 (string) branchNo : "15901", // 分公司代號 (string) account : "1234567", // 帳號 (string) isSpread : false, // 是否為複式部位 (boolean) positionKind : 1, // 部位種類 (number) symbol : "FITX", // 商品代號 (string) expiryDate : '202404', // 履約日 (string) buySell : Buy, // 買賣別 (number) price : 20325.3333, // 成交價 (number) origLots : 3, // 原始口數 (number) tradableLot : 3, // 可交易口數 (number) orderType : New, // 委託別 (FutOptOrderType) currency : "TWD", // 幣別 (string) marketPrice : "20351", // 即時價 (string) initialMargin : 0.0, // 原始保證金 (number) maintenanceMargin : 0.0, // 維持保證金 (number) clearingMargin : 0.0, // 結算保證金 (number) initialMarginAllSingle : 0.0, // 原始保證金 (number) optValue : 0.0, // 選擇權市值 (number) optLongValue : 0.0, // 選擇權買進市值 (number) optShortValue : 0.0, // 選擇權賣出市值 (number) profitOrLoss : 0.0, // 部位損益 (number) premium : 0.0 // 權利金 (number) }, ] } ``` ```cs var h_position = sdk.FutOptAccounting.QueryHybridPosition(accounts.data[0]); foreach (var detail in h_position.data) { Console.WriteLine(detail); } ``` ```cs { { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) isSpread = false, // 是否為複式部位 (boolean) positionKind = 1, // 部位種類 : `1` 期貨、`2` 選擇權 (int) symbol = FITX, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = None, // 履約價 (double) callPut = None, // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 20325.3333, // 成交價 (double) origLots = 3, // 原始口數 (int) tradableLot = 3, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 20351, // 即時價 (string) initialMargin = 0.0, // 原始保證金 (double) maintenanceMargin = 0.0, // 維持保證金 (double) clearingMargin = 0.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) optValue = 0.0, // 選擇權市值 (double) optLongValue = 0.0, // 選擇權買進市值 (double) optShortValue = 0.0, // 選擇權賣出市值 (double) profitOrLoss = 0.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) spreads = None, // 複式部位 (SpreadPosition[]) }, ... } ``` * 以下範例回傳僅擷取data內容 #### 權益數查詢[​](#權益數查詢 "Direct link to 權益數查��詢") 可以查詢帳務權益數,確認我們帳戶權益的狀況。 * Python * Node.js * C# ```python equity = sdk.futopt_accounting.query_margin_equity(accounts.data[0]) print(equity.data) ``` ```js const equity = sdk.futoptAccounting.queryMarginEquity(accounts.data[0]) console.log(equity.data) ``` ```cs var equity = sdk.FutOptAccounting.QueryMarginEquity(accounts.data[0]); Console.WriteLine(equity.data); ``` * Python * Node.js * C# ```py Equity({ date: "2024/04/08", # 查詢日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) currency: "NTD", # 幣別 (string) yesterday_balance: 22435152.4, # 昨日餘額 (float) today_balance: 22434910.4, # 今日餘額 (float) initial_margin: 1114946.0, # 原始保證金 (float) maintenance_margin: 939214.0, # 維持保證金 (float) clearing_margin: 915760.0, # 結算保證金 (float) today_equity: 22694910.4, # 本日權益 (float) ... withhold: 126402.0, # 委託預扣款 (float) available_margin: 21453562.4, # 可動用保證金 (float) risk_index: 0.0, # 風險指標 (float) disgorgement: 0.0, # 追繳金額 (float) opt_pnl: -248600.0, # 未沖銷選擇權浮動損益 (float) opt_value: -193100.0, # 選擇權市值 (float) opt_long_value: 311900.0, # 未沖銷選擇權買方市值 (float) opt_short_value: 505000.0, # 未沖銷選擇權賣方市值 (float) fut_realized_pnl: 0.0, # 期貨平倉損益 (float) fut_unrealized_pnl: 60700.0, # 期貨期貨未平倉損益 (float) yesterday_equity: 22634452.4, # 昨日權益 (float) buy_lot: 22, # 買進口數 (int) sell_lot: 7 # 賣出口數 (int) }) ``` ```js { date: '2024/04/08', // 查詢日期 (string) branchNo: '15901', // 分公司代號 (string) account: '1234567', // 帳號 (string) currency: 'NTD', // 幣別 (string) yesterdayBalance: 22435152.4, // 昨日餘額 (number) todayBalance: 22434910.4, // 今日餘額 (number) initialMargin: 1114946.0, // 原始保證金 (number) maintenanceMargin: 939214.0, // 維持保證金 (number) clearingMargin: 915760.0, // 結算保證金 (number) initialMarginAllSingle: 0.0, // 原始保證金 (number) todayEquity: 22694910.4, // 本日權益 (number) ... withhold: 126402.0, // 委託預扣款 (number) availableMargin: 21453562.4, // 可動用保證金 (number) riskIndex: 0.0, // 風險指標 (number) disgorgement: 0.0, // 追繳金額 (number) optPnl: -248600.0, // 未沖銷選擇權浮動損益 (number) optValue: -193100.0, // 選擇權市值 (number) optLongValue: 311900.0, // 未沖銷選擇權買方市值 (number) optShortValue: 505000.0, // 未沖銷選擇權賣方市值 (number) futRealizedPnl: 0.0, // 期貨平倉損益 (number) futUnrealizedPnl: 60700.0, // 期貨未平倉損益 (number) yesterdayEquity: 22634452.4, // 昨日權益 (number) buyLot: 22, // 買進口數 (number) sellLot: 7, // 賣出口數 (number) } ``` ```cs { date = 2024/04/08, // 查詢日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) currency = NTD, // 幣別 (string) yesterdayBalance = 22435152.4, // 昨日餘額 (double) todayBalance = 22434910.4, // 今日餘額 (double) initialMargin = 1114946.0, // 原始保證金 (double) maintenanceMargin = 939214.0, // 維持保證金 (double) clearingMargin = 915760.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) todayEquity = 22694910.4, // 本日權益 (double) ... withhold = 126402.0, // 委託預扣款 (double) availableMargin = 21453562.4, // 可動用保證金 (double) riskIndex = 0.0, // 風險指標 (double) disgorgement = 0.0, // 追繳金額 (double) optPnl = -248600.0, // 未沖銷選擇權浮動損益 (double) optValue = -193100.0, // 選擇權市值 (double) optLongValue = 311900.0, // 未沖銷選擇權買方市值 (double) optShortValue = 505000.0, // 未沖銷選擇權賣方市值 (double) futRealizedPnl = 0.0, // 期貨平倉損益 (double) futUnrealizedPnl = 60700.0, // 期貨未平倉損益 (double) yesterdayEquity = 22634452.4, // 昨日權益 (double) buyLot = 22, // 買進口數 (int) sellLot = 7, // 賣出口數 (int) } ``` --- ### 非阻塞下單 首先,我們先理解阻塞與非阻塞的概念, 阻塞(Block)和非阻塞(Unblock)是用來描述事件、操作或通信方式的兩種不同方式,以下是它們的基本概念和區別: ##### 阻塞(Block):[​](#阻塞block "Direct link to 阻塞(Block):") 阻塞操作是指事件或操作按照預定的順序進行,並且一個操作完成後,才會回覆結果。 ![sync](/TradeAPI/assets/images/normal-24db51cb3aa3d4c74d40c79d4ab38ac8.png) ##### 非阻塞(Unblock):[​](#非阻塞unblock "Direct link to 非阻塞(Unblock):") 非阻塞操作是指事件或操作不必按照固定的順序進行,可以並行執行,且一個操作不需要等待另一個操作的完成。 當您發出Request後就直接回覆,即為非阻塞。 ![async](/TradeAPI/assets/images/async-f1632167c6d8f31259864d28445e3ffc.png) ##### 使用阻塞機制下單[​](#使用阻塞機制下單 "Direct link to 使用阻塞機制下單") 委託後,回覆的Order Response即會帶回完整的資料內容。 * Python * Node.js * C# ```py #建立委託單內容 order = FutOptOrder( buy_sell = BSAction.Buy, symbol = "TXFD4", price = "20000", lot = 1, market_type = FutOptMarketType.Future, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "From_Py" # optional field ) sdk.futopt.place_order(accounts.data[0], order) #下單委託 #或採用 #sdk.futopt.place_order(accounts.data[0], order, False) ``` ```js const order = { buySell: BSAction.Buy, symbol: "TXFD4", price: "20100", lot: 1, marketType: FutOptMarketType.Future, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutureOrderType.Auto, userDef: "from Js" }; sdk.futopt.placeOrder(accounts.data[0], order); // 或採用 //sdk.futopt.placeOrder(accounts.data[0], order, false); ``` ```cs var order = new FutOptOrder( BsAction.Buy, "TXFD4", null, null, "20000", 1, FutOptMarketType.Future, FutOptPriceType.Limit, TimeInForce.Rod, FutureOrderType.Auto, null ); sdk.FutOpt.PlaceOrder(accounts.data[0] ,order); // 使用阻塞委託下單 // 或採用 //sdk.futopt.placeOrder(accounts.data[0], order, false); ``` ##### 使用非阻塞機制下單[​](#使用非阻塞機制下單 "Direct link to 使用非阻塞機制下單") 委託後,回覆的Order Response可能會少帶出委託書號···等資訊。 * Python * Node.js * C# ```py #建立委託單內容 order = FutOptOrder( buy_sell = BSAction.Buy, symbol = "TXFD4", price = "20000", lot = 1, market_type = FutOptMarketType.Future, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "From_Py" # optional field ) sdk.futopt.place_order(accounts.data[0], order, True) #下單委託 ``` ```js const order = { buySell: BSAction.Buy, symbol: "TXFD4", price: "20100", lot: 1, marketType: FutOptMarketType.Future, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutureOrderType.Auto, userDef: "from Js" }; sdk.futopt.placeOrder(accounts.data[0], order, true); ``` ```cs var order = new FutOptOrder( BsAction.Buy, "TXFD4", null, // 複式單第二隻腳買賣別 null, // 複式單第二隻腳商品 "20000", 1, FutOptMarketType.Future, FutOptPriceType.Limit, TimeInForce.Rod, FutureOrderType.Auto, null ); sdk.FutOpt.PlaceOrder(accounts.data[0] ,order, true); // 使用非阻塞委託下單 ``` 以下為支援非阻塞委託的函數 * PlaceOrder - 下單委託 * ModifyPrice - 修改委託價格 * ModifyLot - 修改委託口數 * CancelOrder - 取消委託 --- ### Python主動回報例外處理 使用 Python 主動回報時,因為主動回報機制於獨自的 thread 中運行,因此若主動回報 callback function 內自己寫的程式碼執行產生錯誤,不會自動丟回錯誤訊息,可能造成程式 DEBUG 上的障礙。 這個時候可以在 callback function 上面加入以下 decorator,當其中程式碼發生錯誤時,錯誤將如往常一樣顯示在 console 內: ```python import os import sys import traceback import functools def handle_exceptions(func): @functools.wraps(func) def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as exp: # Extract the full traceback tb_lines = traceback.format_exc().splitlines() # Find the index of the line related to the original function func_line_index = next((i for i, line in enumerate(tb_lines) if func.__name__ in line), -1) # Highlight the specific part in the traceback where the exception occurred relevant_tb = "\n".join(tb_lines[func_line_index:]) # Include traceback from the function name error_text = f"{func.__name__} exception: {exp}\nTraceback (most recent call last):\n{relevant_tb}" print(error_text, file=sys.stderr) # 若要程式完全跳出,可加入下行 (P.S. jupyter 環境不適用) # os._exit(-1) return wrapper def on_event(code, content): print("===event=====") print(code) print(content) print("========") @handle_exceptions def on_order(code, content): print("==Order==") print(code) print(content) print("========") # Add some code that would cause exceptions test = {} print(test["key"]) # 這行會產生錯誤 ``` 以上範例程式碼中,我們故意在 on\_order 中放入一行 `print(test["key"])`,因為 `"key"` 沒有在字典 `test` 裡面,所以會產生錯誤。 這時因為我們有加入 `@handle_exceptions` decorator,所以收到新單主動回報後, console 會印出: ```python on_order exception: 'key' Traceback (most recent call last): File "xxx.py", line 47, in on_order print(test["key"]) ~~~~^^^^^^^ KeyError: 'key' ``` --- ### 斷線重連 以下將用簡單示範,利用callback偵測交易Socket,接收到斷線事件後,程式自動進行Socket重新連線: * Python * Node.js * C# ```py # A callback to receive event def on_event(code, content): print("===event=====") print(code) print(content) if code == "300": print("Reconnect") try: accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼") print("Reconnect successs") except Exception as e: print("Reconnect failed") print(e) print("========") sdk.set_on_event(on_event) ``` ```js sdk.setOnEvent(function(order, content) { console.log("===Event===\n",order, content) if(content[0] == "300"){ console.log("Reconnect") try{ accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼"); console.log("Reconnect success") }catch(e){ console.log("Reconnect Failed") } }}); ``` ```cs public class MyCallback : Callback { public string response = ""; private FubonSDK _sdk; public MyCallback(ref FubonSDK sdk) { _sdk = sdk; } public void OnEvent(string code, string data) { Console.WriteLine(code); Console.WriteLine(data); if (code == "300") { Console.WriteLine("Reconnect"); try { _sdk.Login("您的身分證字號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼"); Console.WriteLine("Reconnect success"); } catch (Exception e) { Console.WriteLine(e); Console.WriteLine("Reconnect Failed"); } } } } var callback = new MyCallback(ref sdk); sdk.RegisterCallback(callback); ``` --- ### 主動回報 *** #### 訂閱委託回報[​](#訂閱委託回報 "Direct link to 訂閱委託回報") * Python * Node.js * C# ```py # A callback to receive order data def on_order(code, content): print("==Order==") print(code) print(content) # print(content.seq_no) # 印出委託單流水號 print("========") sdk.set_on_futopt_order(on_order) ``` info 詳細回傳內容,可參照[FutOptOrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) ```js //Callback to receive order data sdk.setOnFutoptOrder(function(code, content) { console.log("====order===\n",code, content)}); ``` info 詳細回傳內容,可參照[FutOptOrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) ```cs public void OnFutoptOrder(string code, FutOptOrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine("On Order" + response); } } 或使用下方方法 sdk.OnFutoptOrder += (code, FutOptOrderResult) => { Console.WriteLine(code + FutOptOrderResult.ToString()); } ``` info 詳細回傳內容,可參照[FutOptOrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) #### 訂閱改價/改量/刪單回報[​](#訂閱改價改量刪單回報 "Direct link to 訂閱改價/改量/刪單回報") * Python * Node.js * C# ```py def on_order_changed(code, content): print("=Modified==") print(code) print(content) # print(content.seq_no) # 印出委託單流水號 print("========") sdk.set_on_order_futopt_changed(on_order_changed) ``` info 詳細回傳內容,可參照[FutOptOrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) ```js //Callback to receive Modified data sdk.setOnFutoptOrderChanged(function(order, content) { console.log("===Modified===\n", order, content)}); ``` info 詳細回傳內容,可參照[FutOptOrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) ```cs public void OnFutoptOrderChanged(string code, FutOptOrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Modified" + response); } } 或使用下方方法 sdk.OnFutoptOrderChanged += (code, FutOptOrderResult) => { Console.WriteLine(code + FutOptOrderResult.ToString()); } ``` info 詳細回傳內容,可參照[FutOptOrderResult Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) #### 訂閱成交回報[​](#訂閱成交回報 "Direct link to 訂閱成交回報") * Python * Node.js * C# ```py def on_filled(code, content): print("==Filled==") print(code) print(content) # print(content.filled_no) # 印出成交流水號 print("========") sdk.set_on_futopt_filled(on_filled) ``` info 詳細回傳內容,可參照[FutOptFilledData Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptfilleddata) ```js sdk.setOnFutoptFilled(function(code, content) { console.log("===Filled===\n",code, content)}) ``` info 詳細回傳內容,可參照[FutOptFilledData Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptfilleddata) ```cs public void OnFutoptFilled(string code, FutOptFilledData data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Filled" + response); } } 或使用下方方法 sdk.OnFutoptFilled += (code, FutOptFilledData) => { Console.WriteLine(code + FutOptFilledData.ToString()); } ``` info 詳細回傳內容,可參照[FutOptFilledData Object](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptfilleddata) #### 訂閱事件通知[​](#訂閱事件通知 "Direct link to 訂閱事件通知") * Python * Node.js * C# ```py def on_event(code, content): print("===event=====") print(code) print(content) print("========") sdk.set_on_event(on_event) ``` ```js sdk.setOnEvent(function(code, content) { console.log("===Event===\n",code, content)}) ``` ```cs public void OnEvent(String code, String data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Event" + response); } } 或使用下方方法 sdk.OnEvent += (code, msg) => { Console.WriteLine(code + msg ); }; ``` 事件包含以下情況回傳 | 回傳代碼 | 意義 | | -------- | -------------------------------------------------- | | 100 | 連線建立成功 | | 200 | 登入成功 | | 201 | 登入警示 , Ex : 90天未更換密碼 | | 300 | 斷線 | | 301 | 未收到連線pong回傳 | | 302 | 登出 , 並斷線 | | 304 | API Key 異動 (Revoked), 已強制登出 (2.2.7版本新增) | | 500 | 錯誤 | #### 訂閱範例[​](#訂閱範例 "Direct link to 訂閱範例") 使用者可訂閱不同的callback,來接收系統主動發送的委託及成交通知。 * Python * Node.js * C# ```py # A callback to receive order data def on_order(code, content): print("==Order==") print(code) print(content) print("========") sdk.set_on_futopt_order(on_order) # A callback to receive Modified data def on_order_changed(code, content): print("=Modified==") print(code) print(content) print("========") sdk.set_on_order_futopt_changed(on_order_changed) def on_filled(code, content): print("==Filled==") print(code) print(content) print("========") sdk.set_on_futopt_filled(on_filled) # A callback to receive Event data def on_event(code, content): print("===event=====") print(code) print(content) print("========") sdk.set_on_event(on_event) ``` info 詳細回傳內容,可參照[SDK Reference 參數對照表](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) ```js //Callback to receive order data sdk.setOnFutoptOrder(function(code, content) { console.log("====order===\n",code, content)}); //Callback to receive Modified data sdk.setOnFutoptOrderChanged(function(code, content) { console.log("===Modified===\n", code, content)}); //Callback to receive Filled data sdk.setOnFutoptFilled(function(code, content) { console.log("===Filled===\n",code, content)}) //Callback to receive Event data sdk.setOnEvent(function(code, content) { console.log("===Event===\n",code, content)}) ``` info 詳細回傳內容,可參照[SDK Reference 參數對照表](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) ```cs public class MyCallback : Callback { public string code =""; public string response = ""; //Callback to receive order data public void OnFutoptOrder(string code, FutOptOrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine("On Order" + response); } } //Callback to receive Modified data public void OnFutoptOrderChanged(string code, FutOptOrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Modified" + response); } } //Callback to receive Filled data public void OnFutoptFilled(string code, FutOptFilledData data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Filled" + response); } } //Callback to receive order data public void OnOrder(string code, OrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine("On Order" + response); } } //Callback to receive Modified data public void OnOrderChanged(string code, OrderResult data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Modified" + response); } } //Callback to receive Filled data public void OnFilled(string code, FilledData data) { if(data != null) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Filled" + response); } } //Callback to receive Event data public void OnEvent(String code, String data) { response = data.ToString(); Console.WriteLine(code); Console.WriteLine("Event" + response); } } var callback = new MyCallback(); sdk.RegisterCallback(callback); 或使用下方方法分別訂閱 sdk.OnEvent += (code, msg) => { Console.WriteLine(code + msg ); } sdk.OnFutoptOrder += (code, FutOptOrderResult) => { Console.WriteLine(code + FutOptOrderResult.ToString()); } sdk.OnFutoptOrderChanged += (code, FutOptOrderResult) => { Console.WriteLine(code + FutOptOrderResult.ToString()); } sdk.OnFutoptFilled += (code, FutOptFilledData) => { Console.WriteLine(code + FutOptFilledData.ToString()); } ``` info 詳細回傳內容,可參照[SDK Reference 參數對照表](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) --- ### 交易 *** 此篇教學將示範如何進行一個完整的買賣流程 #### 買入部位[​](#買入部位 "Direct link to 買入部位") 假設今天開盤後,我們想買進2口台指期20000點,我們可以這樣撰寫程式並執行: * Python * Node.js * C# ```python from fubon_neo.sdk import FubonSDK, FutOptOrder from fubon_neo.constant import TimeInForce, FutOptOrderType, FutOptPriceType, FutOptMarketType, BSAction sdk = FubonSDK() accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證位置", "您的憑證密碼") #若有歸戶,則會回傳多筆帳號資訊 #建立委託單內容 order = FutOptOrder( buy_sell = BSAction.Buy, symbol = "TXFD4", price = "20000", lot = 2, market_type = FutOptMarketType.Future, price_type = FutOptPriceType.Limit, time_in_force= TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "From_Py" # optional field ) sdk.futopt.place_order(accounts.data[0], order) #下單委託 ``` ```js const { FubonSDK, BSAction, TimeInForce, FutOptMarketType, FutOptPriceType, FutOptOrderType } = require('fubon-neo'); const sdk = new FubonSDK(); const accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證路徑" ,"您的憑證密碼"); const order = { buySell: BSAction.Buy, symbol: "TXFD4", price: "20000", lot: 2, marketType: FutOptMarketType.Future, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutOptOrderType.Auto, userDef: "from Js" }; sdk.futopt.placeOrder(accounts.data[0],order); ``` ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var accounts = sdk.Login("您的身分證字號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼"); // 若有歸戶,則會回傳多筆帳號資訊 var order = new FutOptOrder( BsAction.Buy, "TXFD4", null, // 複式單第二隻腳買賣別 null, // 複式單第二隻腳商品 "20000", 2, FutOptMarketType.Future, FutOptPriceType.Limit, TimeInForce.Rod, FutOptOrderType.Auto, null ); sdk.FutOpt.PlaceOrder(accounts.data[0],order); ``` #### 確認委託與成交回報[​](#確認委託與成交回報 "Direct link to 確認委託與成交回報") 若要確定該筆的狀態,可以依照下方範例查詢指定的委託單 ( 需指定查詢的市場別 : 期貨, 選擇權, 期貨夜盤, 選擇權夜盤 ): * Python * Node.js * C# ```python orderResults = sdk.futopt.get_order_results(accounts.data[0]) print(orderResults) ``` ```js const orderResults = sdk.futopt.getOrderResults(accounts.data[0]) console.log(orderResults) ``` ```cs var orderResults = sdk.FutOpt.GetOrderResults(accounts.data[0]); Console.WriteLine(orderResults); foreach (var results in orderResults) { Console.WriteLine(results); } ``` 根據回報的結果,我們可以判斷此筆委託是否成交,成交了多少數量: * Python * Node.js * C# ```py Result { is_success: true, message: None, data : [ FutOptOrderResult{ ... buy_sell: Buy, #買賣別 (BSAction) price: 20000, #原始委託價格 (float) lot: 2, #原始委託數量 (int) after_price: 20000, #有效委託價格 (float) after_lot: 2, #有效委託數量 (int) filled_lot: 0, #已成交數量 (int) filled_money: 0, #成交價金 (float) symbol: "FITX", #商品代號 (string) order_no: "bA888", #委託書號 (string) last_time: "10:10:10.123", #最後異動時間 (string) ... } ] } ``` ```js { isSuccess: true, data:[ { ... buySell: 'Buy', //買賣別 (string) price: 20000, //原始委託價格 (number) lot: 2, //原始委託數量 (number) afterPrice: 20000, //有效委託價格 (number) afterLot: 2, //有效委託數量 (number) filledLot: 0, //已成交數量 (number) filledMoney: 0, //成交價金 (number) symbol: 'FITX', //商品代號 (string) orderNo: 'bA888', //委託書號 (string) lastTime: '10:10:10.123', //最後異動時間 (string) ... } ] } ``` ```cs { isSuccess = True, message = , data = [ FutOptOrderResult{ ... buySell = Buy, //買賣別 (BsAction) price = 20000, //原始委託價格 (double) lot = 2, //原始委託數量 (int) afterPrice = 20000, //有效委託價格 (double) afterLot = 2, //有效委託數量 (int) filledLot = 0, //已成交數量 (int) filledMoney = 0, //成交價金 (double) symbol = FITX, //商品代號 (string) orderNo = bA888, //委託書號 (string) lastTime = 10:10:10.123, //最後異動時間 (string) ... } ] } ``` #### 修改委託價格[​](#修改委託價格 "Direct link to 修改委託價格") 由於原先的價格一直無法成交,我們調整原先的委託價格,改用20100的點數價格買入: * Python * Node.js * C# ```python orderResults = sdk.futopt.get_order_results(accounts.data[0]) modified_pirce = sdk.futopt.make_modify_price_obj(orderResults.data[0],"20100") sdk.futopt.modify_price(accounts.data[0], modified_pirce) ``` ```js orderResults = sdk.futopt.getOrderResults(accounts.data[0]) const modified_pirce = sdk.futopt.makeModifyPriceObj(orderResults.data[0],"20100") sdk.futopt.modifyPrice(accounts.data[0],modified_pirce) ``` ```cs orderResults = sdk.FutOpt.GetOrderResults(accounts.data[0]); var modified_pirce = sdk.FutOpt.MakeModifyPriceObj(orderResults.data[0],"20100",null); //將價格調整成20100點 sdk.FutOpt.ModifyPrice(accounts.data[0],modified_pirce); ``` 幾分鐘後,我們再查詢一次委託狀態,發現成交了: * Python * Node.js * C# ```python orderResults = sdk.futopt.get_order_results(accounts.data[0]) print(orderResults.data[0]) ``` ```py [ { ... buy_sell: Buy, #買賣別 (BSAction) price: 20000, #原始委託價格 (float) lot: 2, #原始委託數量 (int) after_price: 20100, #有效委託價格 (float) after_lot: 2, #有效委託數量 (int) filled_lot: 1, #已成交數量 (int) filled_money: 0, #成交價金 (float) symbol: "FITX", #商品代號 (string) order_no: "bA888", #委託書號 (string) last_time: "10:13:12.123", #最後異動時間 (string) ... } ] ``` ```js orderResults = sdk.futopt.getOrderResults(accounts.data[0]) console.log(orderResults.data[0]) ``` ```json { ... "buySell" : "Buy", //買賣別 (string) "price" : 20000, //原始委託價格 (number) "lot" : 2, //原始委託數量 (number) "afterPrice" : 20100, //有效委託價格 (number) "afterLot" : 2, //有效委託數量 (number) "filledQty" : 1, //已成交數量 (number) "filledMoney" : 20100, //成交價金 (number) "futoptNo" : "FITX ", //商品代號 (string) "orderNo" : "bA888", //委託書號 (string) "lastTime" : "10:13:12.123", //最後異動時間 (string) ... } ``` ```cs orderResults = sdk.FutOpt.GetOrderResults(accounts.data[0]); Console.WriteLine(orderResults.data[0]); ``` ```cs { ... buySell = Buy, //買賣別 (BsAction) price = 66, //原始委託價格 (double) lot = 2, //原始委託數量 (int) afterPrice = 20100, //有效委託價格 (double) afterLot = 1, //有效委託數量 (int) filledLot = 1, //已成交數量 (int) filledMoney = 20100, //成交價金 (double) symbol = "FITX", //商品代號 (string) orderNo = "bA888", //委託書號 (string) lastTime = "10:13:12.123", //最後異動時間 (string) ... } ``` #### 賣出部位[​](#賣出部位 "Direct link to 賣出部位") 最後決定在收盤前,賣出一口: * Python * Node.js * C# ```python #建立委託單內容 order = Order( buy_sell = BSAction.Sell, symbol = "TXFD4", price = "20100", lot = 1, market_type = FutOptMarketType.Future, price_type = FutOptPriceType.Limit, time_in_force= TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "From_Py" # optional field ) sdk.futopt.place_order(accounts.data[0], order) #下單委託 ``` ```js order = { buySell: BSAction.Sell, symbol: "TXFD4", price: "20100", lot: 1, marketType: FutOptMarketType.Future, priceType: FuturePriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutureOrderType.Auto, userDef: "from Js" }; sdk.futopt.placeOrder(accounts.data[0],order) ``` ```cs order = new Order( BsAction.Sell, "TXFD4", null, // 複式單第二隻腳買賣別 null, // 複式單第二隻腳商品 "20100", 1, FutOptMarketType.Future, FutOptPriceType.Limit, TimeInForce.Rod, FutOptOrderType.Auto, null ); sdk.FutOpt.PlaceOrder(accounts.data[0],order); ``` --- ### 富邦新一代 API *** 本頁重點 * 本頁介紹富邦新一代 API 期貨交易與行情服務範圍。 * 支援多語言與跨平台環境,適用期貨程式交易開發。 * 下一步建議先完成[事前準備](https://www.fbs.com.tw/TradeAPI/docs/trading-future/prepare.md)。 | 項目 | 說明 | | ---- | -------------------------------------------------------------------------- | | 產品 | 富邦新一代 API(Fubon Neo API) | | 服務 | 期貨交易 / 行情 | | 平台 | Windows / macOS / Linux | | 語言 | Python / C# / JavaScript (Node.js) / C++、Go(僅支援證券交易帳務及條件單) | | 登入 | 憑證登入(可搭配 API Key) | #### 概述[​](#概述 "Direct link to 概述") 富邦新一代 API 為您的程式交易,提供了完善的交易與行情 API,滿足每一位開發者的量化與自動化交易需求。
提供用戶自由選擇主流開發語言( Python、C#、JavaScript),在創建程式交易的過程中,輕易地取用 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以上版本。 --- ### 平倉查詢 ClosePositionRecord #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------- | --------------------------------------------------------------------------------------------------- | ---------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string (空值預設與開始日相同) | 查詢終止日 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳已實現彙總資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 平倉 CloseRecord 欄位[​](#平倉-closerecord-欄位 "Direct link to 平倉 CloseRecord 欄位") Return type = Object | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | date | string | 資料日期 | | branchNo | string | 分公司代號 | | positionKind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | account | string | 帳號 | | orderNo | string | 委託書號 | | market | string | 市場別 : `TAIMEX` 期貨、選擇權 | | symbol | string | 商品代號 | | expiryDate | string | 履約日 | | strikePrice | double | 履約價 | | callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 權利別 : `Call` Call 、`Put` Put | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | price | double | 成交價 | | origLots | int | 原始口數 | | transactionFee | double | 交易手續費 | | tax | double | 交易稅 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.FutOptAccounting.ClosePositionRecord(accounts,20240310,20240410)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ CloseRecord { date = 2024/04/10, // 資料日期(string) branchNo = 15000, // 分公司代號(string) account = 9974825, // 帳號 (string) positionKind = 1, // 部位種類 `1` 期貨, `2` 選擇權 (int) orderNo = 15001-0000, // 委託書號 (string) market = TAIMEX, // 市場別 `TAIMEX` (string) symbol = FITX, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = , // 履約價 (double) callPut = , // Call/Put Call、 Put (CallPut) buySell = Buy, // Buy/Sell Buy 、 Sell(BsAction) price = 20847.0, // 成交價 (double) origLots = 1, // 原始口數 (int) transactionFee = 40.0, // 交易手續費 (double) tax = 83.0, // 交易稅 (double) }, CloseRecord { date = 2024/04/10, // 資料日期 (string) branchNo = 15000, // 分公司代號 (string) account = 9974825, // 帳號 (string) positionKind = 1, // 部位種類 `1` 期貨, `2` 選擇權 (int) orderNo = C0005-0000, // 委託書號 (string) market = TAIMEX, // 市場別 期貨, (string) symbol = FITX, // 商品代號 (string) expiryDate = 202405, // 履約日 (string) strikePrice = , // 履約價 (double) callPut = , // Call/Put Call, Put (CallPut) buySell = Buy, // Buy/Sell Buy, Sell (BsAction) price = 20890.0, // 成交價 (double) origLots = 1, // 原始口數 (int) transactionFee = 40.0, // 交易手續費 (double) tax = 84.0, // 交易稅 (double) } ] } ``` --- ### 混合部位查詢 QueryHybridPPosition #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳部位資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 部位 HybridPosition 欄位[​](#部位-hybridposition-欄位 "Direct link to 部位 HybridPosition 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | | > date | string | 部位建立日期 | | > branchNo | string | 分公司代號 | | > account | string | 帳號 | | > isSpread | bool | 是否為複式部位 | | > positionKind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | > symbol | string | 商品代號 | | > expiryDate | string | 履約日 | | > strikePrice | double | 履約價 | | > callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 權利別 : `Call` Call 、`Put` Put | | > buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | > price | double | 成交價 | | > origLots | int | 原始口數 | | > tradableLots | int | 可交易口數 | | > orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | > currency | string | 幣別 | | > marketPrice | string | 即時價 | | > initialMargin | double | 原始保證金 | | > maintenanceMargin | double | 維持保證金 | | > clearingMargin | double | 結算保證金 | | > optValue | double | 選擇權市值 | | > optLongValue | double | 選擇權買進市值 | | > optShortValue | double | 選擇權賣出市值 | | > profitOrLoss | double | 部位損益 | | > premium | double | 權利金 | | >> spread | object | 複式部位解析 | | >> date | string | 部位建立日期 | | >> branchNo | string | 分公司代號 | | >> account | string | 帳號 | | >> isSpread | bool | 是否為複式部位 | | >> positionKind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | >> symbol | string | 商品代號 | | >> expiryDate | string | 履約日 | | >> strikePrice | double | 履約價 | | >> callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 權利別 : `Call` Call 、`Put` Put | | >> buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | >> price | double | 成交價 | | >> origLots | int | 原始口數 | | >> tradableLots | int | 可交易口數 | | >> orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | >> currency | string | 幣別 | | >> marketPrice | string | 即時價 | | >> initialMargin | double | 原始保證金 | | >> maintenanceMargin | double | 維持保證金 | | >> clearingMargin | double | 結算保證金 | | >> optValue | double | 選擇權市值 | | >> optLongValue | double | 選擇權買進市值 | | >> optShortValue | double | 選擇權賣出市值 | | >> profitOrLoss | double | 部位損益 | | >> premium | double | 權利金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.FutOptAccounting.QueryHybridPosition(account)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ HybridPosition { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) isSpread = false, // 是否為複式部位 (boolean) positionKind = 1, // 部位種類 : `1` 期貨、`2` 選擇權 (int) symbol = FITX, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = , // 履約價 (double) callPut = , // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 20325.3333, // 成交價 (double) origLots = 3, // 原始口數 (int) tradableLot = 3, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 20351, // 即時價 (string) initialMargin = 0.0, // 原始保證金 (double) maintenanceMargin = 0.0, // 維持保證金 (double) clearingMargin = 0.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) optValue = 0.0, // 選擇權市值 (double) optLongValue = 0.0, // 選擇權買進市值 (double) optShortValue = 0.0, // 選擇權賣出市值 (double) profitOrLoss = 0.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) spreads = , // 複式部位 (SpreadPosition[]) }, HybridPosition { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) isSpread = false, // 是否為複式部位 (boolean) positionKind = 2, // 部位種類 : `1` 期貨、`2` 選擇權 (int) symbol = TX1, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = 20600, // 履約價 (double) callPut = Call, // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 10, // 成交價 (double) origLots = 4, // 原始口數 (int) tradableLot = 4, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 4.6, // 即時價 (string) initialMargin = 0.0, // 原始保證金 (double) maintenanceMargin = 0.0, // 維持保證金 (double) clearingMargin = 0.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) optValue = 920.0, // 選擇權市值 (double) optLongValue = 920.0, // 選擇權買進市值 (double) optShortValue = 0.0, // 選擇權賣出市值 (double) profitOrLoss = -1080.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) spreads = , // 複式部位 (SpreadPosition[]) }, HybridPosition { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) isSpread = false, // 是否為複式部位 (boolean) positionKind = 2, // 部位種類 : `1` 期貨、`2` 選擇權 (int) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = 20000, // 履約價 (double) callPut = Call, // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 500, // 成交價 (double) origLots = 2, // 原始口數 (int) tradableLot = 2, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 430, // 即時價 (string) initialMargin = 0.0, // 原始保證金 (double) maintenanceMargin = 0.0, // 維持保證金 (double) clearingMargin = 0.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) optValue = 43000.0, // 選擇權市值 (double) optLongValue = 43000.0, // 選擇權買進市值 (double) optShortValue = 0.0, // 選擇權賣出市值 (double) profitOrLoss = -7000.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) spreads = , // 複式部位 (SpreadPosition[]) }, HybridPosition { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) isSpread = false, // 是否為複式部位 (boolean) positionKind = 2, // 部位種類 (int) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = 20000, // 履約價 (double) callPut = Put, // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 344, // 成交價 (double) origLots = 2, // 原始口數 (int) tradableLot = 2, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 82, // 即時價 (string) initialMargin = 0.0, // 原始保證金 (double) maintenanceMargin = 0.0, // 維持保證金 (double) clearingMargin = 0.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) optValue = 8200.0, // 選擇權市值 (double) optLongValue = 8200.0, // 選擇權買進市值 (double) optShortValue = 0.0, // 選擇權賣出市值 (double) profitOrLoss = -26200.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) spreads = , // 複式部位 (SpreadPosition[]) }, HybridPosition { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) isSpread = true, // 是否為複式部位 (boolean) positionKind = 2, // 部位種類 (int) symbol = TXO20100D4:20000P4, // 商品代號 (string) expiryDate = 1, // 履約日 (string) strikePrice = 1, // 履約價 (double) callPut = , // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = , // 成交價 (double) origLots = 2, // 原始口數 (int) tradableLot = 2, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 0.0, // 即時價 (string) initialMargin = 0.0, // 原始保證金 (double) maintenanceMargin = 0.0, // 維持保證金 (double) clearingMargin = 0.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) optValue = 0.0, // 選擇權市值 (double) optLongValue = 0.0, // 選擇權買進市值 (double) optShortValue = 0.0, // 選擇權賣出市值 (double) profitOrLoss = 0.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) spreads = [ // 複式部位 (SpreadPosition[]) SpreadPosition { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) positionKind = 2, // 部位種類 (int) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = 20100, // 履約價 (double) callPut = Call, // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 185, // 成交價 (double) origLots = 2, // 原始口數 (int) tradableLot = 2, // 可交易口數 (int) orderType = , // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 365, // 即時價 (string) initialMargin = 0.0, // 原始保證金 (double) maintenanceMargin = 0.0, // 維持保證金 (double) clearingMargin = 0.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) optValue = 36500.0, // 選擇權市值 (double) optLongValue = 36500.0, // 選擇權買進市值 (double) optShortValue = 0.0, // 選擇權賣出市值 (double) profitOrLoss = 18000.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) }, SpreadPosition { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) positionKind = 2, // 部位種類 (int) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = 20000, // 履約價 (double) callPut = Put, // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 354, // 成交價 (double) origLots = 2, // 原始口數 (int) tradableLot = 2, // 可交易口數 (int) orderType = , // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 82, // 即時價 (string) initialMargin = 0.0, // 原始保證金 (double) maintenanceMargin = 0.0, // 維持保證金 (double) clearingMargin = 0.0, // 結算保證金 (double) initialMarginAllSingle = 0.0, // 原始保證金 (double) optValue = 8200.0, // 選擇權市值 (double) optLongValue = 8200.0, // 選擇權買進市值 (double) optShortValue = 0.0, // 選擇權賣出市值 (double) profitOrLoss = -27200.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) }, ], } ] } ``` --- ### 權益數查詢 QueryMarginEquity #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳未實現資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ###### 權益數 Equity 欄位[​](#權益數-equity-欄位 "Direct link to 權益數 Equity 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------------- | ------ | --------------------------------------------------------------------------- | | date | string | 查詢日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | currency | string | 幣別 : `NTD` 約當台幣 、`TWD` 新台幣、`USD` 美元、`CNY` 人民幣 、`JPY` 日圓 | | yesterdayBalance | double | 昨日餘額 | | todayBalance | double | 今日餘額 | | initialMargin | double | 原始保證金 | | maintenanceMargin | double | 維持保證金 | | clearingMargin | double | 結算保證金 | | todayEquity | double | 本日權益 | | todayDeposit | double | 今日入金 | | todayWithdrawal | double | 今日出金 | | todayTradingFee | double | 今日交易手續費 | | todayTradingTax | double | 今日交易稅 | | receivablePremium | double | 收取權利金 | | payablePremium | double | 付出權利金 | | excessMargin | double | 超額保證金 | | availableMargin | double | 可動用保證金 | | disgorgement | double | 追繳金額 | | optPnl | double | 未沖銷選擇權浮動損益 | | optValue | double | 選擇權市值 | | optLongValue | double | 未沖銷選擇權買方市值 | | optShortValue | double | 未沖銷選擇權賣方市值 | | futRealizedPnl | double | 期貨平倉損益 | | futUnrealizedPnl | double | 期貨未平倉損益 | | buyLot | int | 買進口數 | | sellLot | int | 賣出口數 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.FutOptAccounting.QueryMarginEquity(account)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ Equity{ date = 2024/04/08, // 查詢日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) currency = NTD, // 幣別 (string) yesterdayBalance = 22435152.4, // 昨日餘額 (double) todayBalance = 22434910.4, // 今日餘額 (double) initialMargin = 1114946.0, // 原始保證金 (double) maintenanceMargin = 939214.0, // 維持保證金 (double) clearingMargin = 915760.0, // 結算保證金 (double) todayEquity = 22694910.4, // 本日權益 (double) todayDeposit= 0.0, // 本日入金 (double) todayWithdrawal= 2102.0, // 本日出金 (double) todayTradingFee= 16.0, // 本日交易手續費 (double) todayTradingTax= 0.0, // 本日交易稅 (double) receivablePremium= 0.0, // 收取權利金 (double) payablePremium= 9250.0, // 付出權利金 (double) excessMargin= 28744525.0, // 超額保證金 (double) availableMargin = 21453562.4, // 可動用保證金 (double) disgorgement = 0.0, // 追繳金額 (double) optPnl = -248600.0, // 未沖銷選擇權浮動損益 (double) optValue = -193100.0, // 選擇權市值 (double) optLongValue = 311900.0, // 未沖銷選擇權買方市值 (double) optShortValue = 505000.0, // 未沖銷選擇權賣方市值 (double) futRealizedPnl = 0.0, // 期貨平倉損益 (double) futUnrealizedPnl = 60700.0, // 期貨未平倉損益 (double) buyLot = 22, // 買進口數 (int) sellLot = 7, // 賣出口數 (int) }, Equity { date = 2024/04/08, // 查詢日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) currency = TWD, // 幣別 (string) yesterdayBalance = 19880310.0, // 昨日餘額 (double) todayBalance = 19880068.0, // 今日餘額 (double) initialMargin = 1114946.0, // 原始保證金 (double) maintenanceMargin = 939214.0, // 維持保證金 (double) clearingMargin = 915760.0, // 結算保證金 (double) todayEquity = 20140068.0, // 本日權益 (double) todayDeposit= 0.0, // 本日入金 (double) todayWithdrawal= 2102.0, // 本日出金 (double) todayTradingFee= 16.0, // 本日交易手續費 (double) todayTradingTax= 0.0, // 本日交易稅 (double) receivablePremium= 0.0, // 收取權利金 (double) payablePremium= 9250.0, // 付出權利金 (double) excessMargin= 28744525.0, // 超額保證金 (double) availableMargin = 18898720.0, // 可動用保證金 (double) disgorgement = 0.0, // 追繳金額 (double) optPnl = -248600.0, // 未沖銷選擇權浮動損益 (double) optValue = -193100.0, // 選擇權市值 (double) optLongValue = 311900.0, // 未沖銷選擇權買方市值 (double) optShortValue = 505000.0, // 未沖銷選擇權賣方市值 (double) futRealizedPnl = 0.0, // 期貨平倉損益 (double) futUnrealizedPnl = 60700.0, // 期貨未平倉損益 (double) buyLot = 22, // 買進口數 (int) sellLot = 7 // 賣出口數 (int) } ] } ``` --- ### 單式部位查詢 QuerySinglePosition #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳部位資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### Position 欄位[​](#position-欄位 "Direct link to Position 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | | date | string | 部位建立日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | isSpread | bool | 是否為複式部位 | | positionKind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | symbol | string | 商品代號 | | symbolName | string | 商品名稱 | | expiryDate | string | 履約日 | | strikePrice | double | 履約價 | | callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 權利別 : `1` Call 、`2` Put | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | price | double | 成交價 | | origLots | int | 原始口數 | | tradableLots | int | 可交易口數 | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | currency | string | 幣別 | | marketPrice | string | 即時價 | | initialMargin | double | 原始保證金 | | maintenanceMargin | double | 維持保證金 | | clearingMargin | double | 結算保證金 | | optValue | double | 選擇權市值 | | optLongValue | double | 選擇權買進市值 | | optShortValue | double | 選擇權賣出市值 | | profitOrLoss | double | 部位損益 | | premium | double | 權利金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs sdk.FutOptAccounting.QuerySinglePosition(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ Position { date = 2024/04/08, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = l0001-0000, // 訂單編號 (string) positionKind = 1, // 部位種類 (int) symbol = FITX, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = , // 履約價 (double) callPut = , // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 20362, // 成交價 (double) origLots = 2, // 原始口數 (int) tradableLot = 2, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 20521.0000, // 即時價 (string) initialMargin = 358000.0, // 原始保證金 (double) maintenanceMargin = 274000.0, // 維持保證金 (double) clearingMargin = 264000.0, // 結算保證金 (double) profitOrLoss = 63600.0, // 部位損益 (double) premium = 0.0, // 權利金 (double) }, Position { date = 2024/03/29, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = l0007-0000, // 訂單編號 (string) positionKind = 2, // 部位種類 (int) symbol = TX1, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = 20600, // 履約價 (double) callPut = Call, // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 10, // 成交價 (double) origLots = 2, // 原始口數 (int) tradableLot = 2, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 4.6000, // 即時價 (string) initialMargin = 52660.0, // 原始保證金 (double) maintenanceMargin = 36460.0, // 維持保證金 (double) clearingMargin = 34460.0, // 結算保證金 (double) profitOrLoss = -540.0, // 部位損益 (double) premium = -1000.0, // 權利金 (double) }, Position { date = 2024/03/29, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = l0007-0001, // 訂單編號 (string) positionKind = 2, // 部位種類 (int) symbol = TX1, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = 20600, // 履約價 (double) callPut = Call, // 權利別 (CallPut) buySell = Buy, // 買賣別 (BsAction) price = 10, // 成交價 (double) origLots = 2, // 原始口數 (int) tradableLot = 2, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 4.6000, // 即時價 (string) initialMargin = 52660.0, // 原始保證金 (double) maintenanceMargin = 36460.0, // 維持保證金 (double) clearingMargin = 34460.0, // 結算保證金 (double) profitOrLoss = -540.0, // 部位損益 (double) premium = -1000.0, // 權利金 (double) }, Position { date = 2024/03/01, // 部位建立日期 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = l0002-0000, // 訂單編號 (string) positionKind = 2, // 部位種類 (int) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = 18500, // 履約價 (double) callPut = Call, // 權利別 (CallPut) buySell = Sell, // 買賣別 (BsAction) price = 625, // 成交價 (double) origLots = 5, // 原始口數 (int) tradableLot = 4, // 可交易口數 (int) orderType = New, // 委託別 (FutOptOrderType) currency = TWD, // 幣別 (string) marketPrice = 2020.0000, // 即時價 (string) initialMargin = 584000.0, // 原始保證金 (double) maintenanceMargin = 544000.0, // 維持保證金 (double) clearingMargin = 536000.0, // 結算保證金 (double) profitOrLoss = -279000.0, // 部位損益 (double) premium = 125000.0, // 權利金 (double) } ] } ``` --- ### 參數對照表 #### 類別[​](#類別 "Direct link to 類別") Class ##### OrderObject[​](#orderobject "Direct link to OrderObject") | Parameter | Type | Meaning | | ------------------ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- | | buySell | BsAction | [買賣別](#bsaction) 可選用參數`Buy` 買 、 `Sell` 賣 | | stockNo | string | 商品代號 | | price | string | 委託價格 | | quantity | int | 委託數量 | | marketType | FutOptMarketType | [盤別](#futoptmarkettype) 可選用參數`Future` 期貨日盤 、 `Option` 選擇權日盤、 `FutureNight` 期貨夜盤、`OptionNight` 選擇權夜盤 | | priceType | FutOptPriceType | [價格旗標](#futoptpricetype) 可選用參數為 `Limit`限價 、 `Market`市價 、 `RangeMarket` 範圍市價 、 `Reference`參考價 | | timeInForce | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `Rod`、`Fok`、`Ioc` | | orderType | FutOptOrderType | [委託類別](#futoptordertype) 可選用參數為 `New` 新倉、`Close`平倉、`Auto`自動、`FdayTrade`當沖 | | userDef (optional) | string | 用戶自定義 (最長10個字元,不支援特殊字元) | ##### FutOptOrderResult[​](#futoptorderresult "Direct link to FutOptOrderResult") 委託列表,透過 [GetOrderResult(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/trade/GetOrderResults.md) 取得。 | 參數 | 類別 | 說明 | | --------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------ | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | FutOptMarketType | [盤別種類](#futoptmarkettype) : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPut | CallPut | [買賣權](#callput) : `Call` 買權、 `Put` 賣權 | | buySell | BsAction | [買賣別](#bsaction) : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | string | [買賣權](#callput) - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | BsAction | [買賣別](#bsaction) - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | FutOptPriceType | [原始委託價格別](#futoptpricetype) : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | TimeInforce | [委託條件別](#timeinforce) : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | FutOptOrderType | [委託單類型](#futoptordertype) : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態,詳細列表請參考 [STATUS](https://www.fbs.com.tw/TradeAPI/docs/trading/library/python/EnumMatrix.md#status) | | afterPriceType | FutOptPriceType | [有效委託價格別](#futoptpricetype) : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | detail | list | 委託歷程 (查詢orderResultDetail or OrderHistory才有值) | | >> functionType | int | 功能別 : `10` 新單、`15` 改價、 `20` 改量、`30`刪單、`50` 成交 、`90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeLot | int | 原始委託口數 | | >> afterLot | int | 有效委託口數 | | >> beforePrice | double | 原始委託價 | | >> afterPrice | double | 有效委託價 | | >> filledMoney | double | 成交價金 | | >> errorMessage | string | 錯誤訊息 | ##### BatchResult[​](#batchresult "Direct link to BatchResult") 批次委託列表,透過 [BatchOrderLists(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading/library/csharp/trade/batchOrder/BatchOrderList.md) 取得。 | Parameter | Type | Meaning | | ------------ | ------ | ----------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | ##### FutoptModifyPrice[​](#futoptmodifyprice "Direct link to FutoptModifyPrice") 改價物件 | Parameter | Type | Meaning | | ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------------ | | FutOptOrderResult | Object | [委託列表](#futoptorderresult) | | price | string | 改單後的價格 | | FutOptPriceType | FutOptPriceType | [改單後的價格類型](#futoptpricetype) : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | ##### FutOptModifyLot[​](#futoptmodifylot "Direct link to FutOptModifyLot") 改量物件 | Parameter | Type | Meaning | | ----------------- | ------ | ------------------------------ | | FutOptOrderResult | Object | [委託列表](#futoptorderresult) | | lot | int | 改單後的委託量 | ##### FutOptFilledData[​](#futoptfilleddata "Direct link to FutOptFilledData") 成交回報物件 | Parameter | Type | Meaning | | --------------- | --------------- | ---------------------------------------------------------------------------------------------- | | date | string | 日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | seqNo | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | orderNo | string | 委託書號 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPut | CallPut | [買賣權](#callput) : `Call` 買權、 `Put` 賣權 | | buySell | BsAction | \[買賣別] (#bsaction) : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | CallPut | [買賣權](#callput) - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | BsAction | [買賣別](#bsaction) - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | orderType | FutOptOrderType | [委託單類型](#futoptordertype) : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | filledNo | string | 成交流水號 | | filledAvgPrice | double | 成交均價 | | filledLot | int | 成交股數 | | filledPrice | double | 成交單價 | | filledTime | string | 成交時間 | | userDef | string | 用戶自定義 (只有主動回報才回傳此欄位) | ##### Account[​](#account "Direct link to Account") 帳號資訊 | Parameter | Type | Meaning | | ----------- | ------ | ------------------------------------- | | name | string | 客戶姓名 | | account | string | 帳號 | | branchNo | string | 分公司代號 | | accountType | string | 帳戶類型 : `stock` 證券 `futopt` 期貨 | #### Constants ( 欄位對應數值 )[​](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )") ##### BSAction[​](#bsaction "Direct link to BSAction") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Buy | 買 | | Sell | 賣 | ##### CallPut[​](#callput "Direct link to CallPut") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Call | Call | | Put | Put | ##### FutOptMarketType[​](#futoptmarkettype "Direct link to FutOptMarketType") 盤別 | Name | Meaning | | ----------- | ---------- | | Future | 期貨日盤 | | FutureNight | 期貨夜盤 | | Option | 選擇權日盤 | | OptionNight | 選擇權夜盤 | ##### FutOptPriceType[​](#futoptpricetype "Direct link to FutOptPriceType") 價格類型 (priceType) | Name | Meaning | | ----------- | -------- | | Limit | 限價 | | Market | 市價 | | RangeMarket | 範圍市價 | | Reference | 參考價 | ##### TimeInForce[​](#timeinforce "Direct link to TimeInForce") 委託條件 (TimeInForce) | Name | Meaning | | ---- | ------------------------------------- | | ROD | 當日有效(Rest of Day) | | FOK | 全部成交否則取消(Fill-or-Kill) | | IOC | 立即成交否則取消(Immediate-or-Cancel) | ##### FutOptOrderType[​](#futoptordertype "Direct link to FutOptOrderType") 委託類別 (orderType) | Name | Meaning | | --------- | ------- | | New | 新倉 | | Close | 平倉 | | Auto | 自動 | | FdayTrade | 當沖 | ##### function\_type[​](#function_type "Direct link to function_type") 功能類別 | Name | Value | | -------- | ----- | | 新單 | 0 | | 新單執行 | 10 | | 改價 | 15 | | 改量 | 20 | | 刪單 | 30 | | 失敗 | 90 | ##### market[​](#market "Direct link to market") 市場 | Name | Value | | ---------- | ------ | | 期貨交易所 | TAIMEX | ##### status[​](#status "Direct link to status") 委託單狀態 | Name | Value | | ------------ | ---------------------------------------------------------- | | 預約單 | 0 | | 中台收到委託 | 4 ( 請用GetOrderResult查詢狀態 ) | | 後台連線逾時 | 9 ( 請稍後再使用GetOrderResult查詢狀態 or 聯絡您的營業員 ) | | 委託成功 | 10 | | 刪單成功 | 30 | | 完全成交 | 50 | | 改價失敗 | 19 | | 改量失敗 | 29 | | 刪單失敗 | 39 | | 失敗 | 90 | #### Month[​](#month "Direct link to Month") 月份代號 ##### 期貨[​](#期貨 "Direct link to 期貨") | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | A | B | C | D | E | F | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | G | H | I | J | K | L | ##### 選擇權[​](#選擇權 "Direct link to 選擇權") Call | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | A | B | C | D | E | F | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | G | H | I | J | K | L | Put | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | M | N | O | P | Q | R | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | S | T | U | V | W | X | --- ### 登入 ApikeyLogin 版本資訊 v2.2.7 起新增功能 相關說明請參閱 [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.md) 頁面 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | -------------- | | personalID | String | 登入的ID | | key | String | 申請的 API Key | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var result = sdk.ApikeyLogin("Your ID", "Your Key","Your Cert Path","Your Cert Password"); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ Account{ name = 富邦Bill, // 客戶姓名 (string) account = 28, // 客戶帳號 (string) branchNo = 6460, // 分公司代號 (string) accountType = stock // 帳號類型 (string) } ] } ``` --- ### 登入 Login #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | ---------- | | personalID | String | 登入的ID | | password | String | 登入的密碼 | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var result = sdk.Login("Your ID", "Your Password","Your Cert Path","Your Cert Password"); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ Account{ name = 富邦Bill, // 客戶姓名 (string) account = 28, // 客戶帳號 (string) branchNo = 6460, // 分公司代號 (string) accountType = stock // 帳號類型 (string) } ] } ``` --- ### 登出 Logout #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---- | -------- | | isSuccess | bool | 是否成功 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var result = sdk.Logout(); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs True ``` --- ### 刪除批次委託單 BatchCancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | --------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | orderResult | [BatchList](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) | 批次取消委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs // 批次刪單(利用batch detail回傳的內容刪單) var cancel_object = new List{ batch_detail.data[0], batch_detail.data[1], }; sdk.Stock.BatchCancelOrder(account, cancel_object); // 批次刪單(利用不同的單筆委託) var cancel_object = new List{ order_res.data[0], order_res.data[1], }; sdk.Stock.BatchCancelOrder(account, cancel_object); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data =[ FutOptOrderResult { // 批次刪單(利用batch detail回傳的內容刪單) functionType = 30, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00110212609, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0002, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Future, // 盤別種類 (FutOptMarketType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITF, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 1822.6, // 價格 (double) lot = 2, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (FutOptPriceType) afterPrice = 1822.6, // 有效委託價格 (double) afterLot = 0, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = , // 改單前有效股口數 (int) beforePrice = , // 改單前有效價格 (double) userDef = , // 自訂欄位 (string) lastTime = 13:21:34, // 最後異動時間 (string) detail = , // 委託歷程 (list) errorMessage = , // 錯誤訊息 (string) }, OrderResult { functionType = 30, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00110212610, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0003, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Future, // 盤別種類 (FutOptMarketType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITF, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 1822.6, // 價格 (double) lot = 2, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) ... } ] } ``` --- ### 批次修改委託價格 BatchModifyPrice ##### 先使用 MakeModifyPriceObj 建立 FutOptModifyPrice物件[​](#先使用-makemodifypriceobj-建立-futoptmodifyprice物件 "Direct link to 先使用 MakeModifyPriceObj 建立 FutOptModifyPrice物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 修改後的價格旗標 | caution 當 price 欄位有填入值時,priceType 需為null ; 當 priceType 欄位有填入值時,price 需為null 將回傳的物件放入 BatchModifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | FutOptModifyPrice | [FutOptModifyPrice](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmodifyprice)(list of object) | 批次修改委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs // 批次改價(利用batch detail回傳的內容改單) var modified_orders = new List { sdk.FutOpt.MakeModifyPriceObj(batch_result.data[0], "19900", null), sdk.FutOpt.MakeModifyPriceObj(batch_result.data[1], "19900", null) }; var batch_modify_price = sdk.FutOpt.BatchModifyPrice(account, modified_orders); Console.WriteLine(batch_modify_price); // 批次改價(利用不同的單筆委託) var modified_orders = new List { sdk.FutOpt.MakeModifyPriceObj(orderResults.data[37], "19900", null), sdk.FutOpt.MakeModifyPriceObj(orderResults.data[35], "19900", null) }; var batch_modify_price = sdk.FutOpt.BatchModifyPrice(account, modified_orders); Console.WriteLine(batch_modify_price); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data =[ FutOptOrderResult{ // 批次改價(利用batch detail回傳的內容改單) function_type = 15, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seq_no = 00110212664, // 委託單流水序號 (string) branch_no = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) order_no = C0006, // 委託書號 (string) asset_type = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) market_type = Future, // 盤別種類 (FutOptMarketType) unit = , // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITX, // 商品代號 (string) expiry_date = 0, // 到期日 (string) strike_price = 0, // 履約價 (double) call_put = , // 買賣權 (string) buy_sell = Buy, // 買賣別 (BsAction) symbol_leg2 = , // 商品代號 - 複式第二隻腳 (string) expiry_date_leg2 = , // 到期日 - 複式第二隻腳 (string) strike_price_leg2 = , // 履約價 - 複式第二隻腳 (double) call_put_leg2 = , // 買賣權 - 複式第二隻腳 (string) buy_sell_leg2 = , // 買賣別 - 複式第二隻腳 (BsAction) price_type = Limit, // 原始委託價格別 (FutOptPriceType) price = 20000, // 價格 (double) lot = 1, // 原始委託股口數 (int) time_in_force = Rod, // 委託條件別 (TimeInforce) order_type = New, // 委託單類型 (FutOptOrderType) is_pre_order = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) after_price_type = Limit, // 有效委託價格別 (FutOptPriceType) after_price = 19900, // 有效委託價格 (double) after_lot = 1, // 有效委託股口數 (int) filled_lot = 0, // 成交股口數 (int) filled_money = 0, // 成交價金 (int) before_lot = 0, // 改單前有效股口數 (int) before_price = 20000, // 改單前有效價格 (double) user_def = , // 自訂欄位 (string) last_time = 13:39:05, // 最後異動時間 (string) detail = , // 委託歷程 (list) error_message = // 錯誤訊息 (string) }, FutOptOrderResult{ function_type = 15, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seq_no = 00110212665, // 委託單流水序號 (string) branch_no = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) order_no = C0007, // 委託書號 (string) asset_type = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) market_type = Future, // 盤別種類 (FutOptMarketType) unit = , // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITX, // 商品代號 (string) expiry_date = 0, // 到期日 (string) strike_price = 0, // 履約價 (double) call_put = , // 買賣權 (string) buy_sell = Buy, // 買賣別 (BsAction) symbol_leg2 = , // 商品代號 - 複式第二隻腳 (string) expiry_date_leg2 = , // 到期日 - 複式第二隻腳 (string) strike_price_leg2 = , // 履約價 - 複式第二隻腳 (double) call_put_leg2 = , // 買賣權 - 複式第二隻腳 (string) buy_sell_leg2 = , // 買賣別 - 複式第二隻腳 (BsAction) price_type = Limit, // 原始委託價格別 (FutOptPriceType) price = 20000, // 價格 (double) lot = 1, // 原始委託股口數 (int) time_in_force = Rod, // 委託條件別 (TimeInforce) order_type = New, // 委託單類型 (FutOptOrderType) is_pre_order = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) ... } ] } 以下擷取data內容 [ FutOptOrderResult{ // 批次改價(利用不同的單筆委託) function_type = 15, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seq_no = 00110212668, // 委託單流水序號 (string) branch_no = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) order_no = C0008, // 委託書號 (string) asset_type = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) market_type = Future, // 盤別種類 (FutOptMarketType) unit = , // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITX, // 商品代號 (string) expiry_date = 0, // 到期日 (string) strike_price = 0, // 履約價 (double) call_put = , // 買賣權 (string) buy_sell = Buy, // 買賣別 (BsAction) symbol_leg2 = , // 商品代號 - 複式第二隻腳 (string) expiry_date_leg2 = , // 到期日 - 複式第二隻腳 (string) strike_price_leg2 = , // 履約價 - 複式第二隻腳 (double) call_put_leg2 = , // 買賣權 - 複式第二隻腳 (string) buy_sell_leg2 = , // 買賣別 - 複式第二隻腳 (BsAction) price_type = Limit, // 原始委託價格別 (FutOptPriceType) price = 20000, // 價格 (double) lot = 1, // 原始委託股口數 (int) time_in_force = Rod, // 委託條件別 (TimeInforce) order_type = New, // 委託單類型 (FutOptOrderType) is_pre_order = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) after_price_type = Limit, // 有效委託價格別 (FutOptPriceType) after_price = 19900, // 有效委託價格 (double) after_lot = 1, // 有效委託股口數 (int) filled_lot = 0, // 成交股口數 (int) filled_money = 0, // 成交價金 (int) before_lot = 0, // 改單前有效股口數 (int) before_price = 20000, // 改單前有效價格 (double) user_def = , // 自訂欄位 (string) last_time = 13:39:05, // 最後異動時間 (string) error_message = // 錯誤訊息 (string) }, FutOptOrderResult{ function_type = 15, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seq_no = 00110212664, // 委託單流水序號 (string) branch_no = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) order_no = C0009, // 委託書號 (string) asset_type = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) market_type = Future, // 盤別種類 (FutOptMarketType) unit = , // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITX, // 商品代號 (string) expiry_date = 0, // 到期日 (string) strike_price = 0, // 履約價 (double) call_put = , // 買賣權 (string) buy_sell = Buy, // 買賣別 (BsAction) symbol_leg2 = , // 商品代號 - 複式第二隻腳 (string) expiry_date_leg2 = , // 到期日 - 複式第二隻腳 (string) strike_price_leg2 = , // 履約價 - 複式第二隻腳 (double) call_put_leg2 = , // 買賣權 - 複式第二隻腳 (string) buy_sell_leg2 = , // 買賣別 - 複式第二隻腳 (BsAction) price_type = Limit, // 原始委託價格別 (FutOptPriceType) price = 20000, // 價格 (double) lot = 1, // 原始委託股口數 (int) time_in_force = Rod, // 委託條件別 (TimeInforce) order_type = New, // 委託單類型 (FutOptOrderType) is_pre_order = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) ... } ] ``` --- ### 批次修改委託數量 BatchModifyLot ##### 先使用 MakeModifyLotObj 建立 FutOptModifyLot 物件[​](#先使用-makemodifylotobj-建立-futoptmodifylot-物件 "Direct link to 先使用 MakeModifyLotObj 建立 FutOptModifyLot 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | lots | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 ModifyLot 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | ModifyLotObj | [FutOptModifyLot](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmodifylot) (list of object) | 批次改量委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs // 批次改量(利用batch detail回傳的內容改單) var modified_orders = new List { sdk.FutOpt.MakeModifyLotObj(batch_result.data[0], 1000), sdk.FutOpt.MakeModifyLotObj(batch_result.data[1], 1000) }; var batch_modify_qty = sdk.FutOpt.BatchModifyLot(account, modified_orders); Console.WriteLine(batch_modify_qty); // 批次改量(利用不同的單筆委託) var modified_orders = new List { sdk.FutOpt.MakeModifyLotObj(orderResults.data[0], 1000), sdk.FutOpt.MakeModifyLotObj(orderResults.data[1], 1000) }; var batch_modify_qty = sdk.FutOpt.BatchModifyLot(account, modified_orders); Console.WriteLine(batch_modify_qty); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data =[ FutOptOrderResult{ // 批次改量(利用batch detail回傳的內容改單) functionType = 20, // 功能別 (int) date = 2024/04/12, // 交易日期 (string) seqNo = 03100161319, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = l001D, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = FutureNight, // 盤別種類 (FutOptMarketType) unit = , // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FIMTX, // 商品代號 (string) expiryDate = , // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (Callput) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (CallPut) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 20000, // 價格 (double) lot = 3, // 原始委託股口數 (int) timeInForce = ROD, // 委託條件別 (TimeInforce) orderType = New, // 委託單類型 (OrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (FutOptPriceType) afterPrice = 20000, // 有效委託價格 (double) afterLot = 2, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = 0, // 改單前有效股口數 (int) beforePrice = 20000, // 改單前有效價格 (double) userDef = =, // 自訂欄位 (string) lastTime = 18:24:40, // 最後異動時間 (string) detail = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, FutOptOrderResult{ // 批次改量(利用batch detail回傳的內容改單) functionType = 20, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 03100161319, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = l001D, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = FutureNight, // 盤別種類 (FutOptMarketType) unit = , // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FIMTX, // 商品代號 (string) expiryDate = , // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (Callput) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (CallPut) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 20000, // 價格 (double) lot = 3, // 原始委託股口數 (int) timeInForce = ROD, // 委託條件別 (TimeInforce) orderType = New, // 委託單類型 (OrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (FutOptPriceType) afterPrice = 20000, // 有效委託價格 (double) afterLot = 2, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = 0, // 改單前有效股口數 (int) beforePrice = 20000, // 改單前有效價格 (double) userDef = =, // 自訂欄位 (string) lastTime = 18:24:40, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) } ] } 以下擷取data內容 [ FutOptOrderResult{ // 批次改量(利用不同的單筆委託) functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000043, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = "26", // 帳號 (string) orderNo = x0027, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (MaeketType) stockNo = 2881, // 商品代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = FutOpt, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (FutOptPriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (int) userDef = Test, // 自訂欄位 (string) lastTime = 12:21:53.023, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) }, FutOptOrderResult{ functionType = 20, // 功能別 (int) date = 2024/03/08, // 交易日期 (string) seqNo = 00000000044, // 委託單流水序號 (string) branchNo = 20112, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = x0028, // 委託書號 (string) assetType = 0, // 資產類別 (int) market = TAIEX, // 市場類型 (string) marketType = Common, // 盤別種類 (FutOptMarketType) stockNo = 2881, // 商品代號 (string) buySell = Buy, // 買賣別 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 66, // 價格 (double) quantity = 2000, // 原始委託股數 (int) timeInForce = Rod, // 委託條件別 (TimeInForce) orderType = FutOpt, // 委託單類型 (OrderType) isPreOrder = False, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (FutOptPriceType) afterPrice = 66, // 有效委託價格 (double) unit = 1000, // 單位數 (int) afterQty = 1000, // 有效委託股數 (int) filledQty = 0, // 成交股數 (int) filledMoney = 0, // 成交價金 (int) beforeQty = 2000, // 改單前有效量 (int) beforePrice = , // 改單前有效價 (string) userDef = Test, // 自訂欄位 (string) lastTime = 12:21:53.023, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) } ] ``` --- ### 取得批次委託明細 BatchOrderDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ----------------------------------------------------------------------------------------------------------- | ------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | BatchOrderList | [BatchResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#batchresult) | 批次委託列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-�欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int (optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | caution 此功能僅供查詢批次送單執行結果,欲取得委託單最新狀態請使用單筆委託單查詢功能 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var batch_order_list = sdk.FutOpt.BatchOrderLists(account); Console.WriteLine(sdk.FutOpt.BatchOrderDetail(account, batch_order_list.data[0])); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ FutOptOrderResult{ functionType = , // 功能類型 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00110222608, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0101, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Future, // 盤別種類 (FutOptMarketType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITF, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 1822.6, // 價格 (double) lot = 2, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (FutOptPriceType) afterPrice = 1822.6, // 有效委託價格 (double) afterLot = 2, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = , // 改單前有效股口數 (int) beforePrice = , // 改單前有效價格 (double) userDef = , // 自訂欄位 (string) lastTime = 12:20:27, // 最後異動時間 (string) detail = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, ... ] } ``` --- ### 取得批次委託列表 BatchOrderLists #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳批次單資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 批次單 BatchResult 欄位[​](#批次單-batchresult-欄位 "Direct link to 批次單 BatchResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------ | ------ | ---------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價 、 `20` 改量 、 `30` 刪單 、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.FutOpt.BatchOrderLists(account)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ BatchResult{ functionType = 0, // 功能種類 (int) date = 2023/10/04, // 交易日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) batchSeqNo = 11EE626533D072228000000C29304663 // 批次單流水序號 (string) }, ... ] } ``` --- ### 建立批次委託單 BatchPlaceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#orderobject) (list of object) | 委託內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var orders = new FutOptOrder[]{ new FutOptOrder( BsAction.Buy, "TXO20000E4", "530", 1, FutOptMarketType.Option, FutOptPriceType.Limit, TimeInForce.Rod, FutOptOrderType.Auto, "From csharp" // optional field ), new FutOptOrder( BsAction.Buy, "TXO20000E4", "530", 1, FutOptMarketType.Option, FutOptPriceType.Limit, TimeInForce.Rod, FutOptOrderType.Auto, "From csharp" // optional field )}; sdk.Futopt.BatchPlaceOrder(account,orders.ToList()); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ FutOptOrderResult{ functionType = 0, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00230177110, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0022, // 委託書號 (string) assetType = 2, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Option, // 盤別種類 (FutOptMarketType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = 20000, // 履約價 (double) callPut = Call, // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 =, // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 =, // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 =, // 履約價 - 複式第二隻腳 (double) callPutLeg2 =, // 買賣權 - 複式第二隻腳 (string) buySellLeg2 =, // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 500, // 價格 (double) lot = 1, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (FutOptPriceType) afterPrice = 500, // 有效委託價格 (double) afterLot = 1, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = 0, // 改單前有效股口數 (int) beforePrice = 500, // 改單前有效價格 (double) userDef = From csharp, // 自訂欄位 (string) lastTime = 11:50:58, // 最後異動時間 (string) detail = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, FutOptOrderResult{ functionType = 0, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00230177111, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0023, // 委託書號 (string) assetType = 2, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Option, // 盤別種類 (FutOptMarketType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = 20000, // 履約價 (double) callPut = Call, // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 =, // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 =, // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 =, // 履約價 - 複式第二隻腳 (double) callPutLeg2 =, // 買賣權 - 複式第二隻腳 (string) buySellLeg2 =, // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 500, // 價格 (double) lot = 1, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) ... } ] } ``` --- ### 刪除委託單 CancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | Account | 帳號 | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) | 欲取消的委託單物件 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | FutOptOrderResult | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | 新單執行 | | | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.FutOpt.CancelOrder(account, cancel_order)); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = FutOptOrderResult { functionType = 30, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00110212608, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0001, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Future, // 盤別種類 (FutOptMarketType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITF, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 1822.6, // 價格 (double) lot = 2, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 30, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (FutOptPriceType) afterPrice = 1822.6, // 有效委託價格 (double) afterLot = 0, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = , // 改單前有效股口數 (int) beforePrice = , // 改單前有效價格 (double) userDef = , // 自訂欄位 (string) lastTime = 13:21:34, // 最後異動時間 (string) detail = , // 委託歷程 (list) errorMessage = , // 錯誤訊息 (string) } } ``` --- ### 商品代號轉換 ConvertSymbol #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------- | | symbol | string | 帳務商品代號 | | expiryDate | string | 履約日 | | strikePrice | double ( Optional ) | 履約價 | | callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) ( Optional ) | 買賣權 : `Call` Call 、 `Put` Put | info 月份代號可參閱[參數對照表](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#month) #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ------ | ------ | ------------------ | | symbol | string | 行情與下單商品代號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs //期貨 sdk.FutOpt.ConvertSymbol("FITX","202404",null, null) //選擇權 sdk.FutOpt.ConvertSymbol("TXO","202404",20000,CallPut.Call) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs //期貨 "TXFD4" //選擇權 "TXO20000D4" ``` --- ### 商品保證金查詢 QueryEstimateMargin #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | orderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#orderobject) | 委託內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | -------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | EstimateMargin | 回傳保證金資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### EstimateMargin 欄位[​](#estimatemargin-欄位 "Direct link to EstimateMargin 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------ | ---------- | | date | string | 查詢日期 | | currency | string | 幣別 | | estimateMargin | double | 預估保證金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs order = FutOptOrder( BsAction.Buy, "TXFE4", "20890", 1, FutOptMarketType.Future, FutOptPriceType.Limit, TimeInForce.Rod, FutOptOrderType.Auto, "From csharp" // optional field ) var estimate = sdk.Futopt.QueryEstimateMargin(account, order); Console.WriteLine(estimate.data); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = EstimateMargin{ date = 2024/04/10, // 日期 (string) currency = TWD, // 幣別 (string) estimateMargin = 179000 // 預估保證金 (double) } } ``` --- ### 查詢歷史成交 FilledHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | -------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | | startDate | string | 查詢開始日 | | endDate | string (空值預設與開始日相同) | 查詢終止日 | info 可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳成交資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 成交資訊 FilledData 欄位[​](#成交資訊-filleddata-欄位 "Direct link to 成交資訊 FilledData 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | | date | string | 成交日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | seqNo | string ? | 委託單流水序號 (只有主動回報才回傳此欄位) | | orderNo | string | 委託書號 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權- 複式第二隻腳: `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `FdayTrade` 當沖 | | filledNo | string | 成交流水號 | | filledAvgPrice | number | 成交均價 | | filledLot | number | 成交股數 | | filledPrice | number | 成交單價 | | filledTime | string | 成交時間 | | userDef | string ? | 用戶自定義 (只有主動回報才回傳此欄位) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.Futopt.FilledHistory(account,FutOptMarketType.Future,"20230921","20230922")); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ FutOptFilledData{ date = 2023/09/15, // 成交日期 (string) branchNo = 6460, // 分公司代號 (string) account = 26, // 帳號 (string) orderNo = bA422, // 委託書號 (string) seqNo = , // 委託單流水序號 (string) symbol = FITX, // 商品代號 (string) expiryDate = 202404, // 履約日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (CallPut) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 履約日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (CallPut) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) filledNo = 00000000001, // 成交流水號 (string) filledAvgPrice = 20890.0, // 成交均價 (double) filledLots = 1, // 成交股數 (int) filledPrice = 20890.0, // 成交單價 (double) orderType = New, // 委託單類型 (FutOptOrderType) filledTime = 10:31:00.931, // 成交時間 (string) userDef = // 用戶自定義 (string) }, ... ] } ``` --- ### 取得委託單結果 GetOrderResult #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) (Optional : 不帶全盤別) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int (optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var orderResults = sdk.FutOpt.GetOrderResults(account); Console.WriteLine(orderResults); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ FutOptOrderResult{ functionType = , // 功能類型 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00110212608, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0001, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Future, // 盤別種類 (FutOptOrderType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITF, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 1822.6, // 價格 (double) lot = 2, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 1822.6, // 有效委託價格 (double) afterLot = 2, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = , // 改單前有效股口數 (int) beforePrice = , // 改單前有效價格 (double) userDef = , // 自訂欄位 (string) lastTime = 10:20:27, // 最後異動時間 (string) detail = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) }, ... ] } ``` --- ### 取得委託單結果 (含歷程) GetOrderResultDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype)(Optioanl : 不帶全盤別) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | detail | list | 委託歷程 | | >> functionType | int | 功能別 : `10` 新單、`15` 改價、 `20` 改量、`30`刪單、`50` 成交 、`90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeLot | int | 原始委託口數 | | >> afterLot | int | 有效委託口數 | | >> beforePrice | double | 原始委託價 | | >> afterPrice | double | 有效委託價 | | >> filledMoney | double | 成交價金 | | >> errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var orderResults = sdk.FutOpt.GetOrderResultsDetail(account); Console.WriteLine(orderResults); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ FutOptOrderResult{ functionType = , // 功能類型 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00110212608, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0001, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Future, // 盤別種類 (FutOptOrderType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITF, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (PriceType) price = 1822.6, // 價格 (double) lot = 2, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = , // 有效委託價格別 (PriceType) afterPrice = 1822.6, // 有效委託價格 (double) afterLot = 2, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = , // 改單前有效股口數 (int) beforePrice = , // 改單前有效價格 (double) userDef = , // 自訂欄位 (string) lastTime = 10:20:27, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) detail = [ // 委託歷程 (List) OrderDetail{ functionType = 10, // 功能別 (int) modifiedTime = 10:20:27, // 修改時間 (string) beforeLot = 0, // 原始委託口數 (int) afterLot = 2, // 有效委託口數 (int) beforePrice = 1822.6, // 原始委託價格 (double) afterPrice = 1822.6, // 有效委託價格 (double) errorMessage = // 錯誤訊息 (string) } ] }, ... ] } ``` --- ### 修改委託價格 ModifyPrice ##### 先使用 MakeModifyPriceObj 建立 FutOptModifyPrice 物件[​](#先使用-makemodifypriceobj-建立-futoptmodifyprice-物件 "Direct link to 先使用 MakeModifyPriceObj 建立 FutOptModifyPrice 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 修改後的價格旗標 | caution 當 price 欄位有填入值時,priceType 需為 ; 當 priceType 欄位有填入值時,price 需為 將回傳的物件放入 modifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------------- | ----------------------------------------------------------------------------------------------------------------------- | -------------- | | account | Account | 帳號 | | modifiedPriceObj | [FutOptModifyPrice](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmodifyprice) | 修改價格的物件 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | FutOptOrderResult | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var modify_price_obj = sdk.Futopt.MakeModifyPriceObj(order_result, "19900" , null ); var modify_price = sdk.Futopt.ModifyPrice(account, modify_price_obj); Console.WriteLine(modify_price); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = FutOptOrderResult { functionType = 15, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00110212663, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0005, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Future, // 盤別種類 (FutOptMarketType) unit = , // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FITX, // 商品代號 (string) expiryDate = , // 到期日 (string) strikePrice = , // 履約價 (double) callPut = , // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 20000, // 價格 (double) lot = 1, // 原始委託股口數 (int) timeInForce = ROD, // 委託條件別 (TimeInforce) orderType = New, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (FutOptPriceType) afterPrice = 19900, // 有效委託價格 (double) afterLot = 1, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = 0, // 改單前有效股口數 (int) beforePrice = 20000, // 改單前有效價格 (double) userDef = , // 自訂欄位 (string) lastTime = 13:39:05, // 最後異動時間 (string) detail = , // 委託歷程 (list) errorMessage = // 錯誤訊息 (string) } } ``` --- ### 修改委託單數量 ModifyQuantity ##### 先使用 MakeModifyLotObj 建立 FutOptModifyLot 物件[​](#先使用-makemodifylotobj-建立-futoptmodifylot-物件 "Direct link to 先使用 MakeModifyLotObj 建立 FutOptModifyLot 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | lots | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 ModifyLot 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------------------------------------------------------------------------------------------------------------------- | -------------- | | account | Account | 帳號 | | ModifyLotObj | [FutOptModifyLot](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmodifylot) | 修改的委託單 | | unblock | bool (optional) (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | FutOptOrderResult | 回傳修改資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs var modify_qty_obj = sdk.FutOpt.MakeModifyLotObj(order_result, 2); var modify_qty = sdk.FutOpt.ModifyLot(account, modify_qty_obj, true); Console.WriteLine(modify_qty); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = FutOptOrderResult{ functionType = 20, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 03100161319, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = l001D, // 委託書號 (string) assetType = 1, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = FutureNight, // 盤別種類 (MarketType) unit = =, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = FIMTX, // 商品代號 (string) expiryDate = =, // 到期日 (string) strikePrice = =, // 履約價 (double) callPut = =, // 買賣權 (Callput) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 = =, // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = =, // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = =, // 履約價 - 複式第二隻腳 (double) callPutLeg2 = =, // 買賣權 - 複式第二隻腳 (CallPut) buySellLeg2 = =, // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 20000, // 價格 (double) lot = 3, // 原始委託股口數 (int) timeInForce = ROD, // 委託條件別 (TimeInforce) orderType = New, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (FutOptPriceType) afterPrice = 20000, // 有效委託價格 (double) afterLot = 2, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = 0, // 改單前有效股口數 (int) beforePrice = 20000, // 改單前有效價格 (double) userDef = =, // 自訂欄位 (string) lastTime = 18:24:40, // 最後異動時間 (string) detail = , // 委託歷程 (list) errorMessage = = // 錯誤訊息 (string) } } ``` --- ### 查詢歷史委託 OrderHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string | 查詢終止日 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) (Optioanl : 不帶全盤別) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | info 可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------ | -------------------------------- | | isSuccess | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當isSuccess = False 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | detail | list | 委託歷程 | | >> functionType | int | 功能別 : `10` 新單、`15` 改價、 `20` 改量、`30`刪單、`50` 成交 、`90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeLot | int | 原始委託口數 | | >> afterLot | int | 有效委託口數 | | >> beforePrice | double | 原始委託價 | | >> afterPrice | double | 有效委託價 | | >> filledMoney | double | 成交價金 | | >> errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs Console.WriteLine(sdk.FutOpt.OrderHistory(account,"20230921","20230922")); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { isSuccess = True, message = , data = [ FutOptOrderResult{ functionType = , // 功能別 (int) date = 2024/04/11, // 交易日期 (string) seqNo = 00230177314, // 委託單流水序號 (string) branchNo = 15000, // 分公司代號 (string) account = 9974825, // 帳號 (string) orderNo = C0020, // 委託書號 (string) assetType = 2, // 資產類別 : `1` 期貨 、`2` 選擇權 (int) market = TAIMEX, // 市場類型 : `TAIMEX` 期貨、選擇權 (string) marketType = Option, // 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 (FutOptMarketType) unit = , // 單位數 (int) currency = , // 幣別 (string) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = 18600, // 履約價 (double) callPut = Call, // 買賣權 : `Call` 買權、 `Put` 賣權 (string) buySell = Buy, // 買賣別 : `Buy` 買 、 `Sell` 賣 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 (BsAction) priceType = Limit, // 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 (FutOptPriceType) price = 2100, // 價格 (double) lot = 1, // 原始委託股口數 (int) timeInForce = ROD, // 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC (TimeInforce) orderType = New, // 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 50, // 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 (int) afterPriceType = , // 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 (FutOptPriceType) afterPrice = 2100, // 有效委託價格 (double) afterLot = 1, // 有效委託口數 (int) filledLot = 1, // 成交口數 (int) filledMoney = 2100, // 成交價金 (double) beforeLot = , // 改單前有效口數 (int) beforePrice = , // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 10:41:46.760, // 最後異動時間 (string) detail = [ // 委託歷程 (List) OrderDetail{ functionType = 10, // 功能別 (int) modifiedTime = 10:20:27, // 修改時間 (string) beforeLot = 0, // 原始委託口數 (int) afterLot = 2, // 有效委託口數 (int) beforePrice = 1822.6, // 原始委託價格 (double) afterPrice = 1822.6 // 有效委託價格 (double) errorMessage = // 錯誤訊息 (string) } ] errorMessage = // 錯誤訊息 (string) }, FutOptOrderResult{ functionType = , // 功能別 (int) date = 2024/04/11, // 交易日期 (string) seqNo = 00230177315, // 委託單流水序號 (string) branchNo = 15000, // 分公司代號 (string) account = 9974825, // 帳號 (string) orderNo = C0021, // 委託書號 (string) assetType = 2, // 資產類別 : `1` 期貨 、`2` 選擇權 (int) market = TAIMEX, // 市場類型 : `TAIMEX` 期貨、選擇權 (string) marketType = Option, // 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 (FutOptMarketType) unit = , // 單位數 (int) currency = , // 幣別 (string) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = 18500, // 履約價 (double) callPut = Call, // 買賣權 : `Call` 買權、 `Put` 賣權 (string) buySell = Sell, // 買賣別 : `Buy` 買 、 `Sell` 賣 (BsAction) symbolLeg2 = , // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = , // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = , // 履約價 - 複式第二隻腳 (double) callPutLeg2 = , // 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 (string) buySellLeg2 = , // 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 (BsAction) priceType = Limit, // 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 (FutOptPriceType) price = 2230, // 價格 (double) lot = 1, // 原始委託股口數 (int) timeInForce = ROD, // 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC (TimeInforce) orderType = New, // 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 50, // 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 (int) afterPriceType = , // 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 (FutOptPriceType) afterPrice = 2230, // 有效委託價格 (double) afterLot = 1, // 有效委託口數 (int) filledLot = 1, // 成交口數 (int) filledMoney = 2230, // 成交價金 (double) beforeLot = , // 改單前有效口數 (int) beforePrice = , // 改單前有效價 (double) userDef = , // 自訂欄位 (string) lastTime = 10:41:46.760, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) }, ... ] } ``` --- ### 建立委託單 PlaceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#account) | 帳號 | | orderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#orderobject) | 委託內容 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ----------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | FutOptOrderResult | 回傳委託資訊 | | message | string | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | double | 履約價 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | double | 履約價 - 複式第二隻腳 | | callPutLeg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | [BsAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | double | 價格 | | lot | int | 原始委託股口數 | | timeInForce | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#timeinforce) | 委託條件別 : `Rod` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/csharp/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | double | 有效委託價格 | | afterLot | int | 有效委託口數 | | filledLot | int | 成交口數 | | filledMoney | double | 成交價金 | | beforeLot | int | 改單前有效口數 | | beforePrice | double | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢OrderResultDetail or OrderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```cs // 單式 var order = new FutOptOrder( BsAction.Buy, "TXO20000E4", null, null, "500", 1, FutOptMarketType.Option, FutOptPriceType.Limit, TimeInForce.Rod, FutOptOrderType.Auto, "From csharp" // optional field ) sdk.FutOpt.PlaceOrder(account, order) // 複式 var order = new FutOptOrder( BsAction.Sell, "TXO20000E4", BsAction.Buy, // optional field "TXO19900E4", // optional field "90", 1, FutOptMarketType.Option, FutOptPriceType.Limit, TimeInForce.Ioc, FutOptOrderType.Auto, "From csharp" // optional field ) sdk.FutOpt.PlaceOrder(account, order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```cs { //單式回覆 isSuccess = True, message = , data = FutOptOrderResult { functionType = 0, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00230177010, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0002, // 委託書號 (string) assetType = 2, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Option, // 盤別種類 (FutOptMarketType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = TXO, // 商品代號 (string) expiryDate = 202404, // 到期日 (string) strikePrice = 20000, // 履約價 (double) callPut = Call, // 買賣權 (string) buySell = Buy, // 買賣別 (BsAction) symbolLeg2 =, // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 =, // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 =, // 履約價 - 複式第二隻腳 (double) callPutLeg2 =, // 買賣權 - 複式第二隻腳 (string) buySellLeg2 =, // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 500, // 價格 (double) lot = 1, // 原始委託股口數 (int) timeInForce = Rod, // 委託條件別 (TimeInforce) orderType = Auto, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (FutOptPriceType) afterPrice = 500, // 有效委託價格 (double) afterLot = 1, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = 0, // 改單前有效股口數 (int) beforePrice = 500, // 改單前有效價格 (double) userDef = From csharp, // 自訂欄位 (string) lastTime = 11:50:08, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) }} { //複式回覆 isSuccess = True, message =, data = OrderResult { functionType = 0, // 功能別 (int) date = 2024/03/25, // 交易日期 (string) seqNo = 00230177020, // 委託單流水序號 (string) branchNo = 15901, // 分公司代號 (string) account = 1234567, // 帳號 (string) orderNo = C0004, // 委託書號 (string) assetType = 2, // 資產類別 (int) market = TAIMEX, // 市場類型 (string) marketType = Option, // 盤別種類 (FutOptMarketType) unit = 1, // 單位數 (int) currency = TWD, // 幣別 (string) symbol = TXO, // 商品代號 (string) expiryDate = 202405, // 到期日 (string) strikePrice = 20000, // 履約價 (double) callPut = Call, // 買賣權 (string) buySell = Sell, // 買賣別 (BsAction) symbolLeg2 = TXO, // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2 = 202405, // 到期日 - 複式第二隻腳 (string) strikePriceLeg2 = 19900, // 履約價 - 複式第二隻腳 (double) callPutLeg2 = Call, // 買賣權 - 複式第二隻腳 (string) buySellLeg2 = Buy, // 買賣別 - 複式第二隻腳 (BsAction) priceType = Limit, // 原始委託價格別 (FutOptPriceType) price = 90, // 價格 (double) lot = 1, // 原始委託股口數 (int) timeInForce = IOC, // 委託條件別 (TimeInforce) orderType = New, // 委託單類型 (FutOptOrderType) isPreOrder = false, // 是否為預約單 (bool) status = 10, // 委託單狀態 (int) afterPriceType = Limit, // 有效委託價格別 (FutOptPriceType) afterPrice = 90, // 有效委託價格 (double) afterLot = 1, // 有效委託股口數 (int) filledLot = 0, // 成交股口數 (int) filledMoney = 0, // 成交價金 (int) beforeLot = 0, // 改單前有效股口數 (int) beforePrice = 90, // 改單前有效價格 (double) userDef = From csharp, // 自訂欄位 (string) lastTime = 11:57:41, // 最後異動時間 (string) errorMessage = // 錯誤訊息 (string) }} ``` --- ### 平倉查詢 closePositionRecord #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | --------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | start\_date | string | 查詢起日 | | end\_date | string | 查詢迄日 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳交割款資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 平倉 CloseRecord 欄位[​](#平倉-closerecord--欄位 "Direct link to 平倉 CloseRecord 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | date | string | 資料日期 | | branchNo | string | 分公司代號 | | positionKind | number | 部位種類 : `1` 期貨 、`2` 選擇權 | | account | string | 帳號 | | orderNo | string | 委託書號 | | market | string | 市場別 : `TAIMEX` 期貨、選擇權 | | symbol | string | 商品代號 | | expiryDate | string | 履約日 | | strikePrice | number | 履約價 | | callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 權利別 : `Call` Call 、`Put` Put | | buySell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | price | number | 成交價 | | origLots | number | 原始口數 | | transactionFee | number | 交易手續費 | | tax | number | 交易稅 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.futoptAccounting.closePositionRecord(target_user,"20240410"); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: "2024/04/10", // 資料日期 (string) branchNo: "15000", // 分公司代號 (string) account: "9974825", // 帳號 (string) positionKind: 1, // 部位種類: `1` 期貨, `2` 選擇權 (number) orderNo: "15001-0000", // 委託書號 (string) market: "TAIMEX", // 市場別 : `TAIMEX` (string) symbol: "FITX", // 商品代號 (string) expiryDate: '202404', // 履約日 (string) buySell: Buy, // Buy/Sell Type : `Buy`, `Sell` (BSAction) price: 20847.0, // 成交價 (number) origLots: 1, // 原始口數 (number) transactionFee: 40.0, // 交易手續費 (number) tax: 83.0, // 交易稅 (number) }, { date: "2024/04/10", // 資料日期 (string) branchNo: "15000", // 分公司代號 (string) account: "9974825", // 帳號 (string) positionKind: 1, // 部位種類d : `1` 期貨, `2` 選擇權 (number) orderNo: "C0005-0000", // 委託書號 (string) market: "TAIMEX", // 市場別 : `TAIMEX` 期貨, 選擇權 (string) symbol: "FITX", // 商品代號 (string) expiryDate: '202405', // 履約日 (string) buySell: Buy, // Buy/Sell Type : `Buy`, `Sell` (BSAction) price: 20890.0, // 成交價 (number) origLots: 1, // 原始口數 (number) transactionFee: 40.0, // 交易手續費 (number) tax: 84.0, // 交易稅 (number) } ] } ``` --- ### 混合部位查詢 queryHybridPosition #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳部位資訊 | | message | string ? (optional) | 當isSuccess : false 回傳錯誤訊息 | ##### 部位資訊 HybridPosition 欄位[​](#部位資訊--hybridposition-欄位 "Direct link to 部位資訊 HybridPosition 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | | > date | string | 部位建立日期 | | > branchNo | string | 分公司代號 | | > account | string | 帳號 | | > isSpread | bool | 是否為複式部位 | | > positionKind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | > symbol | string | 商品代號 | | > expiryDate | string | 履約日 | | > strikePrice | double | 履約價 | | > callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 權利別 : `1` Call 、`2` Put | | > buySell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | > price | double | 成交價 | | > origLots | int | 原始口數 | | > tradableLots | int | 可交易口數 | | > orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | > currency | string | 幣別 | | > marketPrice | string | 即時價 | | > initialMargin | double | 原始保證金 | | > maintenanceMargin | double | 維持保證金 | | > clearingMargin | double | 結算保證金 | | > optValue | double | 選擇權市值 | | > optLongValue | double | 選擇權買進市值 | | > optShortValue | double | 選擇權賣出市值 | | > profitOrLoss | double | 部位損益 | | > premium | double | 權利金 | | >> spread | object | 複式部位解析 | | >> date | string | 部位建立日期 | | >> branchNo | string | 分公司代號 | | >> account | string | 帳號 | | >> isSpread | bool | 是否為複式部位 | | >> positionKind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | >> symbol | string | 商品代號 | | >> expiryDate | string | 履約日 | | >> strikePrice | double | 履約價 | | >> callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 權利別 : `1` Call 、`2` Put | | >> buySell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | >> price | double | 成交價 | | >> origLots | int | 原始口數 | | >> tradableLots | int | 可交易口數 | | >> orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | >> currency | string | 幣別 | | >> marketPrice | string | 即時價 | | >> initialMargin | double | 原始保證金 | | >> maintenanceMargin | double | 維持保證金 | | >> clearingMargin | double | 結算保證金 | | >> optValue | double | 選擇權市值 | | >> optLongValue | double | 選擇權買進市值 | | >> optShortValue | double | 選擇權賣出市值 | | >> profitOrLoss | double | 部位損益 | | >> premium | double | 權利金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.futoptAccounting.queryHybridPosition(account); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date : "2024/04/08", // 部位建立日期 (string) branchNo : "15901", // 分公司代號 (string) account : "1234567", // 帳號 (string) isSpread : false, // 是否為複式部位 (boolean) positionKind : 1, // 部位種類 (number) symbol : "FITX", // 商品代號 (string) expiryDate : '202404', // 履約日 (string) buySell : Buy, // 買賣別 (number) price : 20325.3333, // 成交價 (number) origLots : 3, // 原始口數 (number) tradableLot : 3, // 可交易口數 (number) orderType : New, // 委託別 (FutOptOrderType) currency : "TWD", // 幣別 (string) marketPrice : "20351", // 即時價 (string) initialMargin : 0.0, // 原始保證金 (number) maintenanceMargin : 0.0, // 維持保證金 (number) clearingMargin : 0.0, // 結算保證金 (number) initialMarginAllSingle : 0.0, // 原始保證金 (number) optValue : 0.0, // 選擇權市值 (number) optLongValue : 0.0, // 選擇權買進市值 (number) optShortValue : 0.0, // 選擇權賣出市值 (number) profitOrLoss : 0.0, // 部位損益 (number) premium : 0.0 // 權利金 (number) }, { date : "2024/04/08", // 部位建立日期 (string) branchNo : "15901", // 分公司代號 (string) account : "1234567", // 帳號 (string) isSpread : false, // 是否為複式部位 (boolean) positionKind : 2, // 部位種類 (number) symbol : "TX1", // 商品代號 (string) expiryDate : '202404', // 履約日 (string) strikePrice : 206000, // 履約價 (number) callPut : Call, // 權利別 (number) buySell : Buy, // 買賣別 (number) price : 10, // 成交價 (number) origLots : 4, // 原始口數 (number) tradableLot : 4, // 可交易口數 (number) orderType : New, // 委託別(FutOptOrderType) currency : "TWD", // 幣別 (string) marketPrice : "4.6", // 即時價 (string) initialMargin : 0.0, // 原始保證金 (number) maintenanceMargin : 0.0, // 維持保證金 (number) clearingMargin : 0.0, // 結算保證金 (number) initialMarginAllSingle : 0.0, // 原始保證金 (number) optValue : 920.0, // 選擇權市值 (number) optLongValue : 920.0, // 選擇權買進市值 (number) optShortValue : 0.0, // 選擇權賣出市值 (number) profitOrLoss : -1080.0, // 部位損益 (number) premium : 0.0 // 權利金 (number) }, { date : "2024/04/08", // 部位建立日期 (string) branchNo : "15901", // 分公司代號 (string) account : "1234567", // 帳號 (string) isSpread : false, // 是否為複式部位 (boolean) positionKind : 2, // 部位種類 (number) symbol : "TXO", // 商品代號 (string) expiryDate : '202404', // 履約日 (string) strikePrice : 198000, // 履約價 (number) callPut : Call, // 權利別 (number) buySell : Buy, // 買賣別 (number) price : 243, // 成交價 (number) origLots : 2, // 原始口數 (number) tradableLot : 2, // 可交易口數 (number) orderType : New, // 委託別 (FutOptOrderType) currency : "TWD", // 幣別 (string) marketPrice : "46", // 即時價 (string) initialMargin : 0.0, // 原始保證金 (number) maintenanceMargin : 0.0, // 維持保證金 (number) clearingMargin : 0.0, // 結算保證金 (number) initialMarginAllSingle : 0.0, // 原始保證金 (number) optValue : 4600.0, // 選擇權市值 (number) optLongValue : 4600.0, // 選擇權買進市值 (number) optShortValue : 0.0, // 選擇權賣出市值 (number) profitOrLoss : -19700.0, // 部位損益 (number) premium : 0.0 // 權利金 (number) }, { date : "2024/04/08", // 部位建立日期 (string) branchNo : "15901", // 分公司代號 (string) account : "1234567", // 帳號 (string) isSpread : false, // 是否為複式部位 (boolean) positionKind : 2, // 部位種類 (number) symbol : "TXO", // 商品代號 (string) expiryDate : '202404', // 履約日 (string) strikePrice : 200000, // 履約價 (number) callPut : Put, // 權利別 (number) buySell : Buy, // 買賣別 (number) price : 344, // 成交價 (number) origLots : 2, // 原始口數 (number) tradableLot : 2, // 可交易口數 (number) orderType : New, // 委託別 (FutOptOrderType) currency : "TWD", // 幣別 (string) marketPrice : "82", // 即時價 (string) initialMargin : 0.0, // 原始保證金 (number) maintenanceMargin : 0.0, // 維持保證金 (number) clearingMargin : 0.0, // 結算保證金 (number) initialMarginAllSingle : 0.0, // 原始保證金 (number) optValue : 8200.0, // 選擇權市值 (number) optLongValue : 8200.0, // 選擇權買進市值 (number) optShortValue : 0.0, // 選擇權賣出市值 (number) profitOrLoss : -26200.0, // 部位損益 (number) premium : 0.0 // 權利金 (number) }, { date : "2024/04/08", // 部位建立日期 (string) branchNo : "15901", // 分公司代號 (string) account : "1234567", // 帳號 (string) isSpread : true, // 是否為複式部位 (boolean) positionKind : 2, // 部位種類(number) symbol : "TXO20100D4:20000P4", // 商品代號 (string) expiryDate : 1, // 履約日 (string) strikePrice : 1, // 履約價 (number) buySell : Buy, // 買賣別 (number) origLots : 2, // 原始口數 (number) tradableLot : 2, // 可交易口數 (number) orderType : New, // 委託別(FutOptOrderType) currency : "TWD", // 幣別 (string) marketPrice : "0.0", // 即時價 (string) initialMargin : 0.0, // 原始保證金 (number) maintenanceMargin : 0.0, // 維持保證金 (number) clearingMargin : 0.0, // 結算保證金 (number) initialMarginAllSingle : 0.0, // 原始保證金 (number) optValue : 0.0, // 選擇權市值 (number) optLongValue : 0.0, // 選擇權買進市值 (number) optShortValue : 0.0, // 選擇權賣出市值 (number) profitOrLoss : 0.0, // 部位損益 (number) premium : 0.0, // 權利金 (number) spreads : [ // 複式部位 (SpreadPosition[]) { date : "2024/04/08", // 部位建立日期 (string) branchNo : "15901", // 分公司代號 (string) account : "1234567", // 帳號 (string) positionKind : 2, // 部位種類 (number) symbol : "TXO", // 商品代號 (string) symbolName : "臺指選擇權", // 商品名稱 (string) strikePrice : 201000, // 履約價 (number) callPut : Call, // 權利別 (number) buySell : Buy, // 買賣別 (number) price : 185, // 成交價 (number) origLots : 2, // 原始口數 (number) tradableLot : 2, // 可交易口數 (number) currency : "TWD", // 幣別 (string) marketPrice : "365", // 即時價 (string) initialMargin : 0.0, // 原始保證金 (number) maintenanceMargin : 0.0, // 維持保證金 (number) clearingMargin : 0.0, // 結算保證金 (number) initialMarginAllSingle : 0.0, // 原始保證金 (number) optValue : 36500.0, // 選擇權市值 (number) optLongValue : 36500.0, // 選擇權買進市值 (number) optShortValue : 0.0, // 選擇權賣出市值 (number) profitOrLoss : 18000.0, // 部位損益 (number) premium : 0.0, // 權利金 (number) }, { date : "2024/04/08", // 部位建立日期 (string) branchNo : "15901", // 分公司代號 (string) account : "1234567", // 帳號 (string) positionKind : 2, // 部位種類 (number) symbol : "TXO", // 商品代號 (string) expiryDate : '202404', // 履約日 (string) strikePrice : 200000, // 履約價 (number) callPut : Put, // 權利別 (number) buySell : Buy, // 買賣別 (number) price : 354, // 成交價 (number) origLots : 2, // 原始口數 (number) tradableLot : 2, // 可交易口數 (number) currency : "TWD", // 幣別 (string) marketPrice : "82", // 即時價 (string) initialMargin : 0.0, // 原始保證金 (number) maintenanceMargin : 0.0, // 維持保證金 (number) clearingMargin : 0.0, // 結算保證金 (number) initialMarginAllSingle : 0.0, // 原始保證金 (number) optValue : 8200.0, // 選擇權市值 (number) optLongValue : 8200.0, // 選擇權買進市值 (number) optShortValue : 0.0, // 選擇權賣出市值 (number) profitOrLoss : -27200.0, // 部位損益 (number) premium : 0.0, // 權利金 (number) }, ], } ] } ``` --- ### 權益數查詢 queryMarginEquity #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ###### 權益數 Equity 欄位[​](#權益數-equity-欄位 "Direct link to 權益數 Equity 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------------- | ------ | --------------------------------------------------------------------------- | | date | string | 查詢日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | currency | string | 幣別 : `NTD` 約當台幣 、`TWD` 新台幣、`USD` 美元、`CNY` 人民幣 、`JPY` 日圓 | | yesterdayBalance | number | 昨日餘額 | | todayBalance | number | 今日餘額 | | initialMargin | number | 原始保證金 | | maintenanceMargin | number | 維持保證金 | | clearingMargin | number | 結算保證金 | | todayEquity | number | 本日權益 | | todayDeposit | number | 今日入金 | | todayWithdrawal | number | 今日出金 | | todayTradingFee | number | 今日交易手續費 | | todayTradingTax | number | 今日交易稅 | | receivablePremium | number | 收取權利金 | | payablePremium | number | 付出權利金 | | excessMargin | number | 超額保證金 | | availableMargin | number | 可動用保證金 | | disgorgement | number | 追繳金額 | | optPnl | number | 未沖銷選擇權浮動損益 | | optValue | number | 選擇權市值 | | optLongValue | number | 未沖銷選擇權買方市值 | | optShortValue | number | 未沖銷選擇權賣方市值 | | futRealizedPnl | number | 期貨平倉損益 | | futUnrealizedPnl | number | 期貨未平倉損益 | | buyLot | number | 買進口數 | | sellLot | number | 賣出口數 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.futoptAccounting.queryMarginEquity(account); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: '2024/04/08', // 查詢日期 (string) branchNo: '15901', // 分公司代號 (string) account: '1234567', // 帳號 (string) currency: 'NTD', // 幣別 (string) yesterdayBalance: 22435152.4, // 昨日餘額 (number) todayBalance: 22434910.4, // 今日餘額 (number) initialMargin: 1114946.0, // 原始保證金 (number) maintenanceMargin: 939214.0, // 維持保證金 (number) clearingMargin: 915760.0, // 結算保證金 (number) todayEquity: 22694910.4, // 本日權益 (number) todayDeposit: 0.0, // 本日入金 (number) todayWithdrawal: 2102.0, // 本日出金 (number) todayTradingFee: 16.0, // 本日交易手續費 (number) todayTradingTax: 0.0, // 本日交易稅 (number) receivablePremium: 0.0, // 收取權利金 (number) payablePremium: 9250.0, // 付出權利金 (number) excessMargin: 28744525.0, // 超額保證金 (number) availableMargin: 21453562.4, // 可動用保證金 (number) disgorgement: 0.0, // 追繳金額 (number) optPnl: -248600.0, // 未沖銷選擇權浮動損益 (number) optValue: -193100.0, // 選擇權市值 (number) optLongValue: 311900.0, // 未沖銷選擇權買方市值 (number) optShortValue: 505000.0, // 未沖銷選擇權賣方市值 (number) futRealizedPnl: 0.0, // 期貨平倉損益 (number) futUnrealizedPnl: 60700.0, // 期貨未平倉損益 (number) buyLot: 22, // 買進口數 (number) sellLot: 7, // 賣出口數 (number) }, { date: '2024/04/08', // 查詢日期 (string) branchNo: '15901', // 分公司代號 (string) account: '1234567', // 帳號 (string) currency: 'TWD', // 幣別 (string) yesterdayBalance: 19880310.0, // 昨日餘額 (number) todayBalance: 19880068.0, // 今日餘額 (number) initialMargin: 1114946.0, // 原始保證金 (number) maintenanceMargin: 939214.0, // 維持保證金 (number) clearingMargin: 915760.0, // 結算保證金 (number) todayEquity: 20140068.0, // 本日權益 (number) todayDeposit: 0.0, // 本日入金 (number) todayWithdrawal: 2102.0, // 本日出金 (number) todayTradingFee: 16.0, // 本日交易手續費 (number) todayTradingTax: 0.0, // 本日交易稅 (number) receivablePremium: 0.0, // 收取權利金 (number) payablePremium: 9250.0, // 付出權利金 (number) excessMargin: 28744525.0, // 超額保證金 (number) availableMargin: 18898720.0, // 可動用保證金 (number) disgorgement: 0.0, // 追繳金額 (number) optPnl: -248600.0, // 未沖銷選擇權浮動損益 (number) optValue: -193100.0, // 選擇權市值 (number) optLongValue: 311900.0, // 未沖銷選擇權買方市值 (number) optShortValue: 505000.0, // 未沖銷選擇權賣方市值 (number) futRealizedPnl: 0.0, // 期貨平倉損益 (number) futUnrealizedPnl: 60700.0, // 期貨未平倉損益 (number) buyLot: 22, // 買進口數 (number) sellLot: 7, // 賣出口數 (number) }, ... ] } ``` --- ### 單式部位查詢 querySinglePosition #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳未實現資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 部位 Position 欄位[​](#部位-position--欄位 "Direct link to 部位 Position 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | | date | string | 部位建立日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | isSpread | bool | 是否為複式部位 | | positionKind | number | 部位種類 : `1` 期貨 、`2` 選擇權 | | symbol | string | 商品代號 | | symbolName | string | 商品名稱 | | expiryDate | string | 履約日 | | strikePrice | number | 履約價 | | callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 權利別 : `1` Call 、`2` Put | | buySell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | price | number | 成交價 | | origLots | number | 原始口數 | | tradableLots | number | 可交易口數 | | orderType | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | currency | string | 幣別 | | marketPrice | string | 即時價 | | initialMargin | number | 原始保證金 | | maintenanceMargin | number | 維持保證金 | | clearingMargin | number | 結算保證金 | | optValue | number | 選擇權市值 | | optLongValue | number | 選擇權買進市值 | | optShortValue | number | 選擇權賣出市值 | | profitOrLoss | number | 部位損益 | | premium | number | 權利金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.futoptAccounting.querySinglePosition(account); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: "2024/04/08", // 部位建立日期 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l0001-0000", // 訂單編號 (string) positionKind: 1, // 部位種類 (number) spreadKind: 0, // 是否為複式部位 (number) symbol: "FITX", // 商品代號 (string) expiryDate: '202404', // 履約日 (string) buySell: Buy, // 買賣別 (BSAction) price: 20362, // 成交價 (number) origLots: 2, // 原始口數 (number) tradableLot: 2, // 可交易口數 (number) orderType: "NEW", // 委託別 (FutOptOrderType) currency: "TWD", // 幣別 (string) marketPrice: "20521.0000", // 即時價 (string) initialMargin: 358000.0, // 原始保證金 (number) maintenanceMargin: 274000.0, // 維持保證金 (number) clearingMargin: 264000.0, // 結算保證金 (number) profitOrLoss: 63600.0, // 部位損益 (number) premium: 0.0, // 權利金 (number) }, { date: "2024/03/29", // 部位建立日期 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l0007-0000", // 訂單編號 (string) positionKind: 2, // 部位種類 (number) spreadKind: 1, // 是否為複式部位 (number) symbol: "TX1", // 商品代號 (string) expiryDate: '202404', // 履約日 (string) strikePrice: 20600, // 履約價 (number) callPut: Call, // 權利別 (CallPut) buySell: Buy, // 買賣別 (BSAction) price: 10, // 成交價 (number) origLots: 2, // 原始口數 (number) tradableLot: 2, // 可交易口數 (number) orderType: 0, // 委託別 (FutOptOrderType) currency: "TWD", // 幣別 (string) marketPrice: "4.6000", // 即時價 (string) initialMargin: 52660.0, // 原始保證金 (number) maintenanceMargin: 36460.0, // 維持保證金 (number) clearingMargin: 34460.0, // 結算保證金 (number) profitOrLoss: -540.0, // 部位損益 (number) premium: -1000.0, // 權利金 (number) }, { date: "2024/03/29", // 部位建立日期 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l0007-0001", // 訂單編號 (string) positionKind: 2, // 部位種類 (number) spreadKind: 1, // 是否為複式部位 (number) symbol: "TX1", // 商品代號 (string) expiryDate: 202404, // 履約日 (string) strikePrice: 20600, // 履約價 (number) callPut: Call, // 權利別 (CallPut) buySell: Buy, // 買賣別 (BSAction) price: 10, // 成交價 (number) origLots: 2, // 原始口數 (number) tradableLot: 2, // 可交易口數 (number) orderType: 0, // 委託別 (FutOptOrderType) currency: "TWD", // 幣別 (string) marketPrice: "4.6000", // 即時價 (string) initialMargin: 52660.0, // 原始保證金 (number) maintenanceMargin: 36460.0, // 維持保證金 (number) clearingMargin: 34460.0, // 結算保證金 (number) profitOrLoss: -540.0, // 部位損益 (number) premium: -1000.0, // 權利金 (number) }, { date: "2024/03/01", // 部位建立日期 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l0002-0000", // 訂單編號 (string) positionKind: 2, // 部位種類 (number) spreadKind: 1, // 是否為複式部位 (number) symbol: "TXO", // 商品代號 (string) expiryDate: 202404, // 履約日 (string) strikePrice: 18500, // 履約價 (number) callPut: Call, // 權利別 (CallPut) buySell: Sell, // 買賣別 (BSAction) price: 625, // 成交價 (number) origLots: 5, // 原始口數 (number) tradableLot: 4, // 可交易口數 (number) orderType: 0, // 委託別 (FutOptOrderType) currency: "TWD", // 幣別 (string) marketPrice: "2020.0000", // 即時價 (string) initialMargin: 584000.0, // 原始保證金 (number) maintenanceMargin: 544000.0, // 維持保證金 (number) clearingMargin: 536000.0, // 結算保證金 (number) profitOrLoss: -279000.0, // 部位損益 (number) premium: 125000.0, // 權利金 (number) } ] } ``` --- ### 參數對照表 #### 類別[​](#類別 "Direct link to 類別") Class ##### OrderObject[​](#orderobject "Direct link to OrderObject") | Parameter | Type | Meaning | | ------------------ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- | | buySell | BSAction | [買賣別](#bsaction) 可選用參數`Buy` 買 、 `Sell` 賣 | | symbol | string | 商品代號 | | buySell2 | BSAction | [買賣別](#bsaction) - 複式單 | | symbol2 | string | 商品代號 - 複式單 | | price | string | 委託價格 | | lot | int | 委託數量 | | marketType | FutOptMarketType | [盤別](#futoptmarkettype) 可選用參數`Future` 期貨日盤 、 `Option` 選擇權日盤、 `FutureNight` 期貨夜盤、`OptionNight` 選擇權夜盤 | | priceType | FutOptPriceType | [價格旗標](#futoptpricetype) 可選用參數為 `Limit`限價 、 `Market`市價 、 `RangeMarket` 範圍市價 、 `Reference`參考價 | | timeInForce | timeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` | | orderType | FutOptOrderType | [委託類別](#futoptordertype) 可選用參數為 `New` 新倉、`Close`平倉、`Auto`自動、`FdayTrade`當沖 | | userDef (optional) | string | 用戶自定義 (最長10個字元,不支援特殊字元) | caution priceType 爲 FutOptPriceType.Limit 時,需填入 price 欄位,其餘時候 price 欄位為空值或為null。 ##### FutOptOrderResult[​](#futoptorderresult "Direct link to FutOptOrderResult") 委託列表,透過 [GetOrderResult(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/trade/GetOrderResults.md) 取得。 | 參數 | 類別 | 說明 | | --------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行、`15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | FutOptMarketType | [盤別種類](#futoptmarkettype) : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | string | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | BSAction | [買賣別](#bsaction) : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | string | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | BSAction | [買賣別](#bsaction) - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | FutOptPriceType | [原始委託價格別](#futoptpricetype) : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | TimeInforce | [委託條件別](#timeinforce) : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | FutOptOrderType | [委託單類型](#futoptordertype) : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | FutOptPriceType | [有效委託價格別](#futoptpricetype) : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | >> functionType | number | 功能別 : `10` 新單、`15` 改價、 `20` 改量、`30`刪單、`50` 成交 、`90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeLot | number | 原始委託口數 | | >> afterLot | number | 有效委託口數 | | >> beforePrice | number | 原始委託價 | | >> filledMoney | number | 成交價金 | | >> afterPrice | number | 有效委託價 | | >> errorMessage | string | 錯誤訊息 | ##### BatchResult[​](#batchresult "Direct link to BatchResult") 批次委託列表,透過 [BatchOrderLists(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/trade/batchOrder/BatchOrderList.md) 取得。 | Parameter | Type | Meaning | | ------------ | ------ | ------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、 `10` 新單執行、`15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | ##### FutoptModifyPrice[​](#futoptmodifyprice "Direct link to FutoptModifyPrice") 改價物件 | Parameter | Type | Meaning | | ----------------- | --------------- | ---------------------------------------------------------------------------------------------- | | FutOptOrderResult | Object | [委託列表](#futoptorderresult) | | price | string | 改單後的價格 | | FutOptPriceType | FutOptPriceType | 改單後的價格類型 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | ##### FutOptModifyLot[​](#futoptmodifylot "Direct link to FutOptModifyLot") 改量物件 | Parameter | Type | Meaning | | ----------------- | ------ | ------------------------------ | | FutOptOrderResult | Object | [委託列表](#futoptorderresult) | | lot | number | 改單後的委託量 | ##### FutOptFilledData[​](#futoptfilleddata "Direct link to FutOptFilledData") 成交回報物件 | 參數 | 類別 | 說明 | | --------------- | --------------- | ---------------------------------------------------------------------------------------------- | | date | string | 日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | seqNo | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | orderNo | string | 委託書號 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | float | 履約價 | | callPut | CallPut | [買賣權](#callput) : `Call` 買權、 `Put` 賣權 | | buySell | BSAction | \[買賣別] (#bsaction) : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | float | 履約價 - 複式第二隻腳 | | callPutLeg2 | CallPut | [買賣權](#callput) - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | BSAction | [買賣別](#bsaction) - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | orderType | FutOptOrderType | [委託單類型](#futoptordertype) : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | filledNo | string | 成交流水號 | | filledAvgPrice | float | 成交均價 | | filledLot | int | 成交股數 | | filledPrice | float | 成交單價 | | filledTime | string | 成交時間 | | userDef | string | 用戶自定義 (只有主動回報才回傳此欄位) | ##### Account[​](#account "Direct link to Account") 帳號資訊 | Parameter | Type | Meaning | | ----------- | ------ | ------------------------------------- | | name | string | 客戶姓名 | | account | string | 帳號 | | branchNo | string | 分公司代號 | | accountType | string | 帳戶類型 : `stock` 證券 `futopt` 期貨 | #### Constants ( 欄位對應數值 )[​](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )") ##### BSAction[​](#bsaction "Direct link to BSAction") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Buy | 買 | | Sell | 賣 | ##### CallPut[​](#callput "Direct link to CallPut") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Call | Call | | Put | Put | ##### FutOptMarketType[​](#futoptmarkettype "Direct link to FutOptMarketType") 盤別 | Name | Meaning | | ----------- | ---------- | | Future | 期貨日盤 | | FutureNight | 期貨夜盤 | | Option | 選擇權日盤 | | OptionNight | 選擇權夜盤 | ##### FutOptPriceType[​](#futoptpricetype "Direct link to FutOptPriceType") 價格類型 (priceType) | Name | Meaning | | ----------- | -------- | | Limit | 限價 | | Market | 市價 | | RangeMarket | 範圍市價 | | Reference | 參考價 | ##### TimeInForce[​](#timeinforce "Direct link to TimeInForce") 委託條件 (TimeInForce) | Name | Meaning | | ---- | ------------------------------------- | | ROD | 當日有效(Rest of Day) | | FOK | 全部成交否則取消(Fill-or-Kill) | | IOC | 立即成交否則取消(Immediate-or-Cancel) | ##### FutOptOrderType[​](#futoptordertype "Direct link to FutOptOrderType") 委託類別 (orderType) | Name | Meaning | | --------- | ------- | | New | 新倉 | | Close | 平倉 | | Auto | 自動 | | FdayTrade | 當沖 | ##### function\_type[​](#function_type "Direct link to function_type") 功能類別 | Name | Value | | -------- | ----- | | 新單 | 0 | | 新單執行 | 10 | | 改價 | 15 | | 改量 | 20 | | 刪單 | 30 | | 失敗 | 90 | ##### market[​](#market "Direct link to market") 市場 | Name | Value | | ---------- | ------ | | 期貨交易所 | TAIMEX | ##### status[​](#status "Direct link to status") 委託單狀態 | Name | Value | | ------------ | ---------------------------------------------------------- | | 預約單 | 0 | | 中台收到委託 | 4 ( 請用GetOrderResult查詢狀態 ) | | 後台連線逾時 | 9 ( 請稍後再使用GetOrderResult查詢狀態 or 聯絡您的營業員 ) | | 委託成功 | 10 | | 刪單成功 | 30 | | 完全成交 | 50 | | 改價失敗 | 19 | | 改量失敗 | 29 | | 刪單失敗 | 39 | | 失敗 | 90 | #### Month[​](#month "Direct link to Month") 月份代號 ##### 期貨[​](#期貨 "Direct link to 期貨") | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | A | B | C | D | E | F | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | G | H | I | J | K | L | ##### 選擇權[​](#選擇權 "Direct link to 選擇權") Call | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | A | B | C | D | E | F | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | G | H | I | J | K | L | Put | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | M | N | O | P | Q | R | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | S | T | U | V | W | X | --- ### 登入 apikeyLogin 版本資訊 v2.2.7 起新增功能 相關說明請參閱 [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.md) 頁面 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | -------------- | | personalID | String | 登入的ID | | key | String | 申請的 API Key | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳帳號資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); const sdk = new FubonSDK(); const accounts = sdk.login("Your ID", "Your Key","Your Cert Path","Your Cert Password"); Console.log(accounts); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { name: '富邦Bill', // 客戶姓名 (string) account: '28', // 客戶帳號 (string) branchNo: '6460', // 分公司代號 (string) accountType: 'futopt' // 帳號類型 (string) } } ``` --- ### 登入 login #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | ------ | ---------- | | personalID | String | 登入的ID | | password | String | 登入的密碼 | | certPath | String | 憑證路徑 | | certPass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳帳號資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊-account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type : Object | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branchNo | String | 分公司代號 | | accountType | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); const sdk = new FubonSDK(); const accounts = sdk.login("Your ID", "Your Password","Your Cert Path","Your Cert Password"); Console.log(accounts); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { name: '富邦Bill', // 客戶姓名 (string) account: '28', // 客戶帳號 (string) branchNo: '6460', // 分公司代號 (string) accountType: 'futopt' // 帳號類型 (string) } } ``` --- ### 登出 logout #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ---- | -------- | | isSuccess | bool | 是否成功 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const { FubonSDK, BSAction, TimeInForce, OrderType, PriceType, MarketType } = require('fubon-neo'); const sdk = new FubonSDK(); sdk.logout(); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js true ``` --- ### 刪除批次委託單 batchCancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) | 批次取消委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 批次改價(利用batch detail回傳的內容刪單) cancel_object = [ batch_results_detail.data[0], batch_results_detail.data[1], ] sdk.futopt.batchCancelOrder(account, cancel_object) // 批次改量(利用不同的單筆委託) cancel_object = [ orders[37], orders[35], ] sdk.futopt.batchCancelOrder(account, cancel_object) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { functionType: 30, // 功能別 (number) date: "2024/03/25", // 交易日期 (string) seqNo: "00110212608", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0001", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "FITF", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 1822.6, // 價格 (number) lot: 2, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "Auto", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 30, // 委託單狀態 (number) afterPrice: 1822.6, // 有效委託價格 (number) afterLot: 0, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) lastTime: "13:21:34", // 最後異動時間 (string) }, { functionType: 30, // 功能別 (number) date: "2024/03/25", // 交易日期 (string) seqNo: "00110212608", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0001", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "FITF", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 1822.6, // 價格 (number) lot: 2, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "Auto", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 30, // 委託單狀態 (number) ... } } ``` --- ### 批次修改委託價格 batchModifyPrice ##### 先使用makeModifyPriceObj 建立 FutOptModifyPrice 物件[​](#先使用makemodifypriceobj-建立-futoptmodifyprice-物件 "Direct link to 先使用makeModifyPriceObj 建立 FutOptModifyPrice 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | price | string ? | 修改後的價格 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype)? | 修改後的價格旗標 | 將回傳的物件放入 BatchModifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | ModifyPriceObj | [FutOptModifyPrice](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmodifyprice)(list of object) | 批次修改委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 批次改價 ( 利用 batch detail 回傳的內容改單) modify_orders = [ sdk.futopt.makeModifyPriceObj(batch_res.data[0], "19900"), sdk.futopt.makeModifyPriceObj(batch_res.data[1], "19900") ] sdk.futopt.batchModifyPrice(account, modify_orders); // 批次改價 ( 利用不同的單筆委託改單 ) modify_orders = [ sdk.futopt.makeModifyPriceObj(orderResult.data[20], "19900"), sdk.futopt.makeModifyPriceObj(orderResult.data[21], "19900"), sdk.futopt.makeModifyPriceObj(orderResult.data[28], "19900") ] sdk.futopt.batchModifyPrice(account, modify_orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ // 批次改價 ( 利用 batch detail 回傳的內容改單) { functionType: 15, // 功能別 (int) date: "2024/03/25", // 交易日期 (string) seqNo: "00110212663", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0005", // 委託書號 (string) assetType: 1, // 資產類別 (int) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptPriceType) currency: "TWD", // 幣別 (string) symbol: "FITX", // 商品代號 (string) expiryDate: "0", // 到期日 (string) strikePrice: 0, // 履約價 (float) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (float) lot: 1, // 原始委託股口數 (int) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (int) afterPriceType: "Limit", // 有效委託價格別 (FutOptPriceType) afterPrice: 19900, // 有效委託價格 (float) afterLot: 1, // 有效委託股口數 (int) filledLot: 0, // 成交股口數 (int) filledMoney: 0, // 成交價金 (int) beforeLot: 0, // 改單前有效股口數 (int) beforePrice: 20000, // 改單前有效價格 (float) lastTime: "13:39:05", // 最後異動時間 (string) }, { functionType: 15, // 功能別 (int) date: "2024/03/25", // 交易日期 (string) seqNo: "00110212664", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0006", // 委託書號 (string) assetType: 1, // 資產類別 (int) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptPriceType) currency: "TWD", // 幣別 (string) symbol: "FITX", // 商品代號 (string) expiryDate: "0", // 到期日 (string) strikePrice: 0, // 履約價 (float) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (float) lot: 1, // 原始委託股口數 (int) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (int) ... } ] } 以下擷取data內容 [ // 批次改價 ( 利用不同的單筆委託改單 ) { functionType: 15, // 功能別 (int) date: "2024/03/25", // 交易日期 (string) seqNo: "00110212763", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0015", // 委託書號 (string) assetType: 1, // 資產類別 (int) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptPriceType) currency: "TWD", // 幣別 (string) symbol: "FITX", // 商品代號 (string) expiryDate: "0", // 到期日 (string) strikePrice: 0, // 履約價 (float) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (float) lot: 1, // 原始委託股口數 (int) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (int) afterPriceType: "Limit", // 有效委託價格別 (FutOptPriceType) afterPrice: 19900, // 有效委託價格 (float) afterLot: 1, // 有效委託股口數 (int) filledLot: 0, // 成交股口數 (int) filledMoney: 0, // 成交價金 (int) beforeLot: 0, // 改單前有效股口數 (int) beforePrice: 20000, // 改單前有效價格 (float) lastTime: "13:39:35", // 最後異動時間 (string) }, { functionType: 15, // 功能別 (int) date: "2024/03/25", // 交易日期 (string) seqNo: "00110212764", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0016", // 委託書號 (string) assetType: 1, // 資產類別 (int) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptPriceType) currency: "TWD", // 幣別 (string) symbol: "FITX", // 商品代號 (string) expiryDate: "0", // 到期日 (string) strikePrice: 0, // 履約價 (float) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (float) lot: 1, // 原始委託股口數 (int) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (int) ... }, ... ] ``` --- ### 批次修改委託數量 batchModifyQuantity ##### 先使用 makeModifyLotObj 建立一個 FutoptModifyLot 物件[​](#先使用-makemodifylotobj-建立一個-futoptmodifylot-物件 "Direct link to 先使用 makeModifyLotObj 建立一個 FutoptModifyLot 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | lot | number | 改單後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入batchModifyLot 方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | ModifiedLotObj | [FutoptModifyLot](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmodifylot) (list of object) | 批次改量委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 批次改量(利用batch detail回傳的內容改單) modify_orders = [ sdk.futopt.makeModifyLotObj(batch_res.data[0], 2), sdk.futopt.makeModifyLotObj(batch_res.data[1], 2) ] sdk.futopt.batchModifyLot(account, modify_orders); // # 批次改量(利用不同的單筆委託) modify_orders = [ sdk.futopt.makeModifyLotObj(orderResult.data[22], 2), sdk.futopt.makeModifyLotObj(orderResult.data[40], 2) ] sdk.futopt.batchModifyLot(account, modify_orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ // 批次改量(利用batch detail回傳的內容改單) { functionType: 20, // 功能別 (number) date: "2024/03/05", // 交易日期 (string) seqNo: "03100151319", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l001A", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "FutureNight", // 盤別種類 (FutOptMarketType) currency: "TWD", // 幣別 (string) symbol: "FIMTX", // 商品代號 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (number) lot: 3, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: "Limit", // 有效委託價格別 (FutOptPriceType) afterPrice: 20000, // 有效委託價格 (number) afterLot: 2, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 20000, // 改單前有效價格 (number) lastTime: "18:24:40", // 最後異動時間 (string) }, { functionType: 20, // 功能別 (number) date: "2024/03/05", // 交易日期 (string) seqNo: "03100151320", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l001B", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "FutureNight", // 盤別種類 (FutOptMarketType) currency: "TWD", // 幣別 (string) symbol: "FIMTX", // 商品代號 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (number) lot: 3, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: "Limit", // 有效委託價格別 (FutOptPriceType) afterPrice: 20000, // 有效委託價格 (number) afterLot: 2, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 20000, // 改單前有效價格 (number) lastTime: "18:24:40", // 最後異動時間 (string) } ] } 以下擷取data內容 [ // 批次改量(利用不同的單筆委託) { functionType: 20, // 功能別 (number) date: "2024/03/05", // 交易日期 (string) seqNo: "03100151419", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l001Q", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "FutureNight", // 盤別種類 (FutOptMarketType) currency: "TWD", // 幣別 (string) symbol: "FIMTX", // 商品代號 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (number) lot: 3, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: "Limit", // 有效委託價格別 (FutOptPriceType) afterPrice: 20000, // 有效委託價格 (number) afterLot: 2, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 20000, // 改單前有效價格 (number) lastTime: "18:44:40", // 最後異動時間 (string) }, { functionType: 20, // 功能別 (number) date: "2024/03/05", // 交易日期 (string) seqNo: "0310015142", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l001R", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "FutureNight", // 盤別種類 (FutOptMarketType) currency: "TWD", // 幣別 (string) symbol: "FIMTX", // 商品代號 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (number) lot: 3, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: "Limit", // 有效委託價格別 (FutOptPriceType) afterPrice: 20000, // 有效委託價格 (number) afterLot: 2, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 20000, // 改單前有效價格 (number) lastTime: "18:44:40", // 最後異動時間 (string) } ] ``` --- ### 取得批次委託明細 batchOrderDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ----------------------------------------------------------------------------------------------------------- | ------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | BatchOrderList | [BatchResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#batchresult) | 批次委託列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | caution 此功能僅供查詢批次送單執行結果,欲取得委託單最新狀態請使用單筆委託單查詢功能 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const batch_order_list = sdk.futopt.batchOrderLists(account) sdk.futopt.batchOrderDetail(account, batch_order_list.data[0]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ { date: "2024/03/25", // 交易日期 (string) seqNo: "00110212608", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0001", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "FITF", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 1822.6, // 價格 (number) lot: 2, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "Auto", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPrice: 1822.6, // 有效委託價格 (number) afterLot: 2, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) lastTime: "10:20:27", // 最後異動時間 (string) }, ... ] } ``` --- ### 取得批次委託列表 batchOrderLists #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳批次單資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 批次單 BatchResult 欄位[​](#批次單-batchresult-欄位 "Direct link to 批次單 BatchResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------ | ------ | ------------------------------------------------------------------------------ | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | batchSeqNo | string | 批次單流水序號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.futopt.batchOrderLists(target_user) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: [ { functionType: 0, date: '2023/10/24', branchNo: '6460', account: '26', batchSeqNo: '11EE72270B4D79F48000000C29304663' }, ... ] } ``` --- ### 建立批次委託單 batchPlaceOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#orderobject) (list of object) | 委託內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資��訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const orders = [{ buySell: BSAction.Buy, symbol: "TXO20000E4", price: "530", lot: 1, marketType: FutOptMarketType.Option, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutOptOrderType.Auto, userDef: "nodejs" // optional field },{ buySell: BSAction.Buy, symbol: "TXO20000E4", price: "530", lot: 1, marketType: FutOptMarketType.Option, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutOptOrderType.Auto, userDef: "nodejs" // optional field } ]; const batch_order_results = sdk.futopt.batchPlaceOrder(account,orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { functionType: 0, // 功能別 (number) date: "2024/03/15", // 交易日期 (string) seqNo: "00230177010", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0002", // 委託書號 (string) assetType: 2, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: Option, // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "TXO", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) strikePrice: 20000, // 履約價 (number) callPut: "Call", // 買賣權 (string) buySell: Buy, // 買賣別 (BSAction) priceType: Limit, // 原始委託價格別 (FutOptPriceType) price: 500, // 價格 (number) lot: 1, // 原始委託股口數 (number) timeInForce: ROD, // 委託條件別 (TimeInforce) orderType: Auto, // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: Limit, // 有效委託價格別 (FutOptPriceType) afterPrice: 500, // 有效委託價格 (number) afterLot: 1, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 500, // 改單前有效價格 (number) userDef: "nodejs", // 自訂欄位 (string) lastTime: "11:50:08", // 最後異動時間 (string) }, { functionType: 0, // 功能別 (number) date: "2024/03/15", // 交易日期 (string) seqNo: "00230177011", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0003", // 委託書號 (string) assetType: 2, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: Option, // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "TXO", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) strikePrice: 20000, // 履約價 (number) callPut: "Call", // 買賣權 (string) buySell: Buy, // 買賣別 (BSAction) priceType: Limit, // 原始委託價格別 (FutOptPriceType) price: 500, // 價格 (number) lot: 1, // 原始委託股口數 (number) timeInForce: ROD, // 委託條件別 (TimeInforce) orderType: Auto, // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: Limit, // 有效委託價格別 (FutOptPriceType) afterPrice: 500, // 有效委託價格 (number) afterLot: 1, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 500, // 改單前有效價格 (number) userDef: "nodejs", // 自訂欄位 (string) lastTime: "11:50:08", // 最後異動時間 (string) } ] } ``` --- ### 刪除委託單 cancelOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | orderResult | [FutOprOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) | 欲取消的委託單物件 | | unblock | bool? (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js sdk.futopt.cancelOrder(account, cancel_order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { functionType: 30, // 功能別 (number) date: "2024/03/25", // 交易日期 (string) seqNo: "00110212608", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0001", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "FITF", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 1822.6, // 價格 (number) lot: 2, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "Auto", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 30, // 委託單狀態 (number) afterPrice: 1822.6, // 有效委託價格 (number) afterLot: 0, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) lastTime: "13:21:34", // 最後異動時間 (string) } } ``` --- ### 商品代號轉換 convertSymbol #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------- | | symbol | string | 帳務商品代號 | | expiryDate | string | 履約日 | | strikePrice | number ( Optional ) | 履約價 | | callPut | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) ( Optional ) | 買賣權 : `Call` Call 、 `Put` Put | info 月份代號可參閱[參數對照表](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#month) #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ------ | ------ | ------------------ | | symbol | string | 行情與下單商品代號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js //期貨 sdk.futopt.convertSymbol("FITX","202404") //選擇權 sdk.futopt.convertSymbol("TXO","202404",20000,CallPut.Call) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js //期貨 "TXFD4" //選擇權 "TXO20000D4" ``` --- ### 商品保證金查詢 queryEstimateMargin #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | orderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#orderobject) | 委託物件 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳配額資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### EstimateMargin 欄位[​](#estimatemargin-欄位 "Direct link to EstimateMargin 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------ | ---------- | | date | string | 查詢日期 | | currency | string | 幣別 | | estimateMargin | number | 預估保證金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js order = FutOptOrder( BSAction.Buy, "TXFE4", "20900", 1, FutOptMarketType.Future, FutOptPriceType.Limit, TimeInForce.ROD, FutOptOrderType.Auto, "From nodejs" // optional field ) sdk.futopt.queryEstimateMargin(account, order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { date: "2024/04/10", // 日期 (string) currency: "TWD", // 幣別 (string) estimateMargin: 179000 // 預估保證金 (number) } } ``` --- ### 查詢歷史成交 filledHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | | startDate | string | 查詢開始日 | | endDate | string? (空值預設與開始日相同) | 查詢終止日 | info 可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳成交資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 成交資訊 FutOptFilledData 欄位[​](#成交資訊-futoptfilleddata-欄位 "Direct link to 成交資訊 FutOptFilledData 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | | date | string | 成交日期 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | seqNo | string ? | 委託單流水序號 (只有主動回報才回傳此欄位) | | orderNo | string | 委託書號 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權- 複式第二隻腳: `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `FdayTrade` 當沖 | | filledNo | string | 成交流水號 | | filledAvgPrice | number | 成交均價 | | filledLot | number | 成交股數 | | filledPrice | number | 成交單價 | | filledTime | string | 成交時間 | | userDef | string ? | 用戶自定義 (只有主動回報才回傳此欄位) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const filledHistory = sdk.futopt.filledHistory(account,FutOptMarketType.Future,"20230921","20230922"); console.log(filledHistory) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: "2023/09/15", // 成交日期 (string) branchNo: "6460", // 分公司代號 (string) account: "26", // 帳號 (string) orderNo: "bA422", // 委託書號 (string) symbol: "FITX", // 商品代號 (string) expiryDate: "202404", // 履約日 (string) buySell: "Buy", // 買賣別 (BSAction) filledNo: "00000000001", // 成交流水號 (string) filledAvgPrice: 20890.0, // 成交均價 (float) filledLots: 1, // 成交股數 (int) filledPrice: 20890.0, // 成交單價 (float) orderType: "New", // 委託單類型 (FutOptOrderType) filledTime: "10:31:00.931", // 成交時間 (string) }, ... ] } ``` --- ### 取得委託單結果 getOrderResults #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) (Optional : 不帶全盤別) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const orders = sdk.futopt.getOrderResults(accounts,FutOptMarketType.Future); console.log(orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: "2024/03/25", // 交易日期 (string) seqNo: "00110212608", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0001", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "FITF", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 1822.6, // 價格 (number) lot: 2, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "Auto", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPrice: 1822.6, // 有效委託價格 (number) afterLot: 2, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) lastTime: "10:20:27", // 最後異動時間 (string) }, ... ] } ``` --- ### 取得委託單結果 (含歷程) getOrderResultsDetail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | marketType | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) (Optioanl : 不帶全盤別) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | errorMessage | string | 錯誤訊息 | | detail | list | 委託歷程 | | >> functionType | number | 功能別 : `10` 新單、`15` 改價、 `20` 改量、`30`刪單、`50` 成交 、 `90` 失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeLot | number | 原始委託口數 | | >> afterLot | number | 有效委託口數 | | >> beforePrice | number | 原始委託價 | | >> afterPrice | number | 有效委託價 | | >> errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js var account = accounts.data[0]; const orders = sdk.futopt.getOrderResultsDetail(account); console.log(orders); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: "2024/03/25", // 交易日期 (string) seqNo: "00110212608", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0001", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "FITF", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 1822.6, // 價格 (number) lot: 2, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "Auto", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPrice: 1822.6, // 有效委託價格 (number) afterLot: 2, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) lastTime: "10:20:27", // 最後異動時間 (string) details:[ functionType: 10, // 功能別 (number) modifiedTime: "10:20:27", // 修改時間 (string) beforeLot: 0, // 原始委託口數 (number) afterLot: 2, // 有效委託口數 (number) beforePrice: 1822.6, // 原始委託價格 (number) afterPrice: 1822.6, // 有效委託價格 (number) status: 10 // 委託單狀態 (number) ] }, ... ] } ``` --- ### 修改委託價格 modifyPrice ##### 先使用makeModifyPriceObj 建立 FutOptModifyPrice 物件[​](#先使用makemodifypriceobj-建立-futoptmodifyprice-物件 "Direct link to 先使用makeModifyPriceObj 建立 FutOptModifyPrice 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | price | string? | 新的委託價格 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype)? | 新的價格旗標 | caution 當 price 欄位有填入值時,priceType 欄位為空值或為null ; 當 priceType 欄位有填入值時,price 欄位為空值或為null 將回傳的物件放入 modifyPrice 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------------- | ----------------------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | FutOptModifyPrice | [FutOptModifyPrice](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmodifyprice) | 修改價格物件 | | unblock | bool ? (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 單筆阻塞改價 const modifyPriceObj = sdk.futopt.makeModifyPriceObj(target_order, "19900"); sdk.futopt.modifyPrice(accounts.data[0], modifyPriceObj, false) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:{ functionType: 15, // 功能別 (int) date: "2024/03/25", // 交易日期 (string) seqNo: "00110212663", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0005", // 委託書號 (string) assetType: 1, // 資產類別 (int) market: "TAIMEX", // 市場類型 (string) marketType: "Future", // 盤別種類 (FutOptMarketType) currency: "TWD", // 幣別 (string) symbol: "FITX", // 商品代號 (string) expiryDate: "0", // 到期日 (string) strikePrice: 0, // 履約價 (float) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (float) lot: 1, // 原始委託股口數 (int) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (int) afterPriceType: "Limit", // 有效委託價格別 (FutOptPriceType) afterPrice: 19900, // 有效委託價格 (float) afterLot: 1, // 有效委託股口數 (int) filledLot: 0, // 成交股口數 (int) filledMoney: 0, // 成交價金 (int) beforeLot: 0, // 改單前有效股口數 (int) beforePrice: 20000, // 改單前有效價格 (float) lastTime: "13:39:05", // 最後異動時間 (string) } } ``` --- ### 修改委託單數量 modifyLot ##### 先使用 makeModifyLotObj 建立一個 FutoptModifyLot 物件[​](#先使用-makemodifylotobj-建立一個-futoptmodifylot-物件 "Direct link to 先使用 makeModifyLotObj 建立一個 FutoptModifyLot 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | quantity | number | 改單後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入modifyLot 方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------------- | ------------------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | FutoptModifyLot | [FutoptModifyLot](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmodifylot) | 修改的委託單 | | unblock | bool ? (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳修改資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const modifyLotObj = sdk.futopt.makeModifyLotObj(target_order, 2); sdk.futopt.modifyLot(accounts.data[0], modifyLotObj) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data: { functionType: 20, // 功能別 (number) date: "2024/03/25", // 交易日期 (string) seqNo: "03100161319", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "l001D", // 委託書號 (string) assetType: 1, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: "FutureNight", // 盤別種類 (FutOptMarketType) currency: "TWD", // 幣別 (string) symbol: "FIMTX", // 商品代號 (string) buySell: "Buy", // 買賣別 (BSAction) priceType: "Limit", // 原始委託價格別 (FutOptPriceType) price: 20000, // 價格 (number) lot: 3, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 (TimeInforce) orderType: "New", // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: "Limit", // 有效委託價格別 (FutOptPriceType) afterPrice: 20000, // 有效委託價格 (number) afterLot: 2, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 20000, // 改單前有效價格 (number) lastTime: "18:24:40", // 最後異動時間 (string) } } ``` --- ### 查詢歷史委託 orderHistory #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | startDate | string | 查詢開始日 | | endDate | string | 查詢終止日 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) (Optional : 不帶全盤別) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | info 可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 | | >> functionType | number | 功能別 : `10` 新單、`15` 改價、 `20` 改量、`30`刪單、`50` 成交、`90`失敗 | | >> modifiedTime | string | 修改時間 | | >> beforeLot | number | 原始委託口數 | | >> afterLot | number | 有效委託口數 | | >> beforePrice | number | 原始委託價 | | >> afterPrice | number | 有效委託價 | | >> errorMessage | string | 錯誤訊息 | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js const orderHistory = sdk.stock.orderHistory(account,"20230921","20231020"); console.log(orderHistory); ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { isSuccess: true, data:[ { date: "2024/04/11", // 交易日期 (string) seqNo: "00230177314", // 委託單流水序號 (string) branchNo: "15000", // 分公司代號 (string) account: "9974825", // 帳號 (string) orderNo: "C0020", // 委託書號 (string) assetType: 2, // 資產類別 : `1` 期貨 、`2` 選擇權 (number) market: "TAIMEX", // 市場類型 : `TAIMEX` 期貨、選擇權 (string) marketType: "Option", // 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 (FutOptMarketType) symbol: "TXO", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) strikePrice: 18600, // 履約價 (number) callPut: "Call", // 買賣權 : `Call` 買權、 `Put` 賣權 (string) buySell: "Buy", // 買賣別 : `Buy` 買 、 `Sell` 賣 (BSAction) priceType: "Limit", // 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 (PriceType) price: 2100, // 價格 (number) lot: 1, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC (TimeInforce) orderType: "New", // 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 50, // 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 (number) afterPrice: 2100, // 有效委託價格 (number) afterLot: 1, // 有效委託口數 (number) filledLot: 1, // 成交口數 (number) filledMoney: 2100, // 成交價金 (number) lastTime: "10:41:46.760", // 最後異動時間 (string) details:[ functionType: 10, // 功能別 (number) modifiedTime: "10:20:27", // 修改時間 (string) beforeLot: 0, // 原始委託口數 (number) afterLot: 1, // 有效委託口數 (number) beforePrice: 2100, // 原始委託價格 (number) afterPrice: 2100, // 有效委託價格 (number) ] .... }, { date: "2024/04/11", // 交易日期 (string) seqNo: "00230177315", // 委託單流水序號 (string) branchNo: "15000", // 分公司代號 (string) account: "9974825", // 帳號 (string) orderNo: "C0021", // 委託書號 (string) assetType: 2, // 資產類別 : `1` 期貨 、`2` 選擇權 (number) market: "TAIMEX", // 市場類型 : `TAIMEX` 期貨、選擇權 (string) marketType: "Option", // 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 (FutOptMarketType) symbol: "TXO", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) strikePrice: 18500, // 履約價 (number) callPut: "Call", // 買賣權 : `Call` 買權、 `Put` 賣權 (string) buySell: "Sell", // 買賣別 : `Buy` 買 、 `Sell` 賣 (BSAction) priceType: "Limit", // 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 (PriceType) price: 2230, // 價格 (number) lot: 1, // 原始委託股口數 (number) timeInForce: "ROD", // 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC (TimeInforce) orderType: "New", // 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 50, // 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 (number) afterPrice: 2230, // 有效委託價格 (number) afterLot: 1, // 有效委託口數 (number) filledLot: 1, // 成交口數 (number) filledMoney: 2230, // 成交價金 (number) lastTime: "10:41:46.760", // 最後異動時間 (string) } ] } ``` --- ### 建立委託單 placeOrder #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#account) | 帳號 | | OrderObject | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#orderobject) | 委託內容 | | unblock | bool ? (default = false) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | --------- | ------------------- | -------------------------------- | | isSuccess | bool | 是否成功 | | data | Object | 回傳委託資訊 | | message | string ? (optional) | 當isSuccess = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | functionType | number | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seqNo | string | 委託單流水序號 | | branchNo | string | 分公司代號 | | account | string | 帳號 | | orderNo | string | 委託書號 | | assetType | number | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | marketType | js:string / ts:[FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | number | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiryDate | string | 到期日 | | strikePrice | number | 履約價 | | callPut | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySell | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbolLeg2 | string | 商品代號 - 複式第二隻腳 | | expiryDateLeg2 | string | 到期日 - 複式第二隻腳 | | strikePriceLeg2 | number | 履約價 - 複式第二隻腳 | | callPutLeg2 | js:string / ts:[CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buySellLeg2 | js:string / ts:[BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | priceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | number | 價格 | | lot | number | 原始委託股口數 | | timeInForce | js:string / ts:[TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | orderType | js:string / ts:[FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | isPreOrder | bool | 是否為預約單 | | status | number | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | afterPriceType | js:string / ts:[FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/nodejs/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | afterPrice | number | 有效委託價格 | | afterLot | number | 有效委託口數 | | filledLot | number | 成交口數 | | filledMoney | number | 成交價金 | | beforeLot | number | 改單前有效口數 | | beforePrice | number | 改單前有效價 | | userDef | string | 自訂欄位 | | lastTime | string | 最後異動時間 | | detail | list | 委託歷程 (查詢orderResultDetail or orderHistory才有值) | | errorMessage | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```js // 單式 futoptorder = { buySell: BSAction.Buy, symbol: "TXO20000E4", price: "530", lot: 1, marketType: FutOptMarketType.Option, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutOptOrderType.Auto, userDef: "nodejs" // optional field } sdk.futopt.placeOrder(account, futoptorder) // 複式 futoptorder = { buySell: BSAction.Sell, symbol: "TXO20000E4", buySell2: BSAction.Buy, // optional field symbol2: "TXO19900E4", // optional field price: "90", lot: 1, marketType: FutOptMarketType.Option, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.IOC, orderType: FutOptOrderType.Auto, userDef: "nodejs" // optional field } sdk.futopt.placeOrder(account, futoptorder) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```js { //單式回覆 isSuccess : true, data = { functionType: 0, // 功能別 (number) date: "2024/03/25", // 交易日期 (string) seqNo: "00230177010", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0002", // 委託書號 (string) assetType: 2, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: Option, // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "TXO", // 商品代號 (string) expiryDate: "202404", // 到期日 (string) strikePrice: 20000, // 履約價 (number) callPut: "Call", // 買賣權 (string) buySell: Buy, // 買賣別 (BSAction) priceType: Limit, // 原始委託價格別 (FutOptPriceType) price: 500, // 價格 (number) lot: 1, // 原始委託股口數 (number) timeInForce: ROD, // 委託條件別 (TimeInforce) orderType: Auto, // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: Limit, // 有效委託價格別 (FutOptPriceType) afterPrice: 500, // 有效委託價格 (number) afterLot: 1, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 500, // 改單前有效價格 (number) userDef: "nodejs", // 自訂欄位 (string) lastTime: "11:50:08", // 最後異動時間 (string) }} { //複式回覆 isSuccess : true, data : { functionType: 0, // 功能別 (number) date: "2024/03/25", // 交易日期 (string) seqNo: "00230177020", // 委託單流水序號 (string) branchNo: "15901", // 分公司代號 (string) account: "1234567", // 帳號 (string) orderNo: "C0004", // 委託書號 (string) assetType: 2, // 資產類別 (number) market: "TAIMEX", // 市場類型 (string) marketType: Option, // 盤別種類 (FutOptMarketType) unit: 1, // 單位數 (number) currency: "TWD", // 幣別 (string) symbol: "TXO", // 商品代號 (string) expiryDate: "202405", // 到期日 (string) strikePrice: 20000, // 履約價 (number) callPut: Call, // 買賣權 (string) buySell: Sell, // 買賣別 (BSAction) symbolLeg2: "TXO", // 商品代號 - 複式第二隻腳 (string) expiryDateLeg2: "202405", // 到期日 - 複式第二隻腳 (string) strikePriceLeg2: 199000, // 履約價 - 複式第二隻腳 (number) callPutLeg2: Call, // 買賣權 - 複式第二隻腳 (string) buySellLeg2: Buy, // 買賣別 - 複式第二隻腳 (BSAction) priceType: Limit, // 原始委託價格別 (FutOptPriceType) price: 90, // 價格 (number) lot: 1, // 原始委託股口數 (number) timeInForce: IOC, // 委託條件別 (TimeInforce) orderType: Auto, // 委託單類型 (FutOptOrderType) isPreOrder: false, // 是否為預約單 (bool) status: 10, // 委託單狀態 (number) afterPriceType: Limit, // 有效委託價格別 (FutOptPriceType) afterPrice: 90, // 有效委託價格 (number) afterLot: 1, // 有效委託股口數 (number) filledLot: 0, // 成交股口數 (number) filledMoney: 0, // 成交價金 (number) beforeLot: 0, // 改單前有效股口數 (number) beforePrice: 90, // 改單前有效價格 (number) userDef: "nodejs", // 自訂欄位 (string) lastTime: "11:57:41", // 最後異動時間 (string) } } ``` --- ### 平倉查詢 close\_position\_record #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ----------- | --------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | start\_date | string | 查詢起日 | | end\_date | string | 查詢迄日 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳平倉資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 已實現彙總 CloseRecord 欄位[​](#已實現彙總-closerecord-欄位 "Direct link to 已實現彙總 CloseRecord 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | date | string | 資料日期 | | branch\_no | string | 分公司代號 | | position\_kind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | account | string | 帳號 | | order\_no | string | 委託書號 | | market | string | 市場別 : `TAIMEX` 期貨、選擇權 | | symbol | string | 商品代號 | | expiry\_date | string | 履約日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 權利別 : `Call` Call 、`Put` Put | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | price | float | 成交價 | | orig\_lots | int | 原始口數 | | transaction\_fee | float | 交易手續費 | | tax | float | 交易稅 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt_accounting.close_position_record(accounts,"20240310","20240410") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ CloseRecord { date: "2024/04/10", # 資料日期(string) branch_no: "15000", # 分公司代號(string) account: "9974825", # 帳號 (string) position_kind: 1, # 部位種類: `1` 期貨, `2` 選擇權 (int) order_no: "15001-0000", # 委託書號 (string) market: "TAIMEX", # 市場別 : `TAIMEX` (string) symbol: "FITX", # 商品代號 (string) expiry_date: "202404", # 履約日 (string) strike_price: None, # 履約價 (float) call_put: None, # Call/Put Type : `Call` Call, `Put` Put (CallPut) buy_sell: Buy, # Buy/Sell Type : `Buy`, `Sell` (BSAction) price: 20847.0, # 成交價 (float) orig_lots: 1, # 原始口數 (int) transaction_fee: 40.0, # 交易手續費 (float) tax: 83.0, # 交易稅 (float) }, CloseRecord { date: "2024/04/10", # 資料日期 (string) branch_no: "15000", # 分公司代號 (string) account: "9974825", # 帳號 (string) position_kind: 1, # 部位種類d : `1` 期貨, `2` 選擇權 (int) order_no: "C0005-0000", # 委託書號 (string) market: "TAIMEX", # 市場別 : `TAIMEX` 期貨, 選擇權 (string) symbol: "FITX", # 商品代號 (string) expiry_date: "202405", # 履約日 (string) strike_price: None, # 履約價 (float) call_put: None, # Call/Put Type : `Call` Call, `Put` Put (CallPut) buy_sell: Buy, # Buy/Sell Type : `Buy`, `Sell` (BSAction) price: 20890.0, # 成交價 (float) orig_lots: 1, # 原始口數 (int) transaction_fee: 40.0, # 交易手續費 (float) tax: 84.0, # 交易稅 (float) } ] } ``` --- ### 混合部位查詢 query\_hybrid\_position #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳混和部位資訊 | | message | string | 當is\_success : false 回傳錯誤訊息 | ##### 部位 HybridPosition 欄位[​](#部位-hybridposition-欄位 "Direct link to 部位 HybridPosition 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | | > date | string | 部位建立日期 | | > branch\_no | string | 分公司代號 | | > account | string | 帳號 | | > is\_spread | bool | 是否為複式部位 | | > position\_kind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | > symbol | string | 商品代號 | | > expiry\_date | string | 履約日 | | > strike\_price | float | 履約價 | | > call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 權利別 : `Call` 、`Put` | | > buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | > price | float | 成交價 | | > orig\_lots | int | 原始口數 | | > tradable\_lots | int | 可交易口數 | | > order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | > currency | string | 幣別 | | > market\_price | string | 即時價 | | > initial\_margin | float | 原始保證金 | | > maintenance\_margin | float | 維持保證金 | | > clearing\_margin | float | 結算保證金 | | > opt\_value | float | 選擇權市值 | | > opt\_long\_value | float | 選擇權買進市值 | | > opt\_short\_value | float | 選擇權賣出市值 | | > profit\_or\_loss | float | 部位損益 | | > premium | float | 權利金 | | >> spread | object | 複式部位解析 | | >> date | string | 部位建立日期 | | >> branch\_no | string | 分公司代號 | | >> account | string | 帳號 | | >> is\_spread | bool | 是否為複式部位 | | >> position\_kind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | >> symbol | string | 商品代號 | | >> expiry\_date | string | 履約日 | | >> strike\_price | float | 履約價 | | >> call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 權利別 : `Call` 、`Put` | | >> buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | >> price | float | 成交價 | | >> orig\_lots | int | 原始口數 | | >> tradable\_lots | int | 可交易口數 | | >> order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | >> currency | string | 幣別 | | >> market\_price | string | 即時價 | | >> initial\_margin | float | 原始保證金 | | >> maintenance\_margin | float | 維持保證金 | | >> clearing\_margin | float | 結算保證金 | | >> opt\_value | float | 選擇權市值 | | >> opt\_long\_value | float | 選擇權買進市值 | | >> opt\_short\_value | float | 選擇權賣出市值 | | >> profit\_or\_loss | float | 部位損益 | | >> premium | float | 權利金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt_accounting.query_hybrid_position(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [HybridPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) is_spread : False, # 是否為複式部位 (bool) position_kind : 1, # 部位種類 (int) symbol : "FITX", # 商品代號 (str) expiry_date : 202404, # 履約日 (string) strike_price : None, # 履約價 (int or None) call_put : None, # 權利別 (int or None) buy_sell : Buy, # 買賣別 (BSAction) price : 20325.3333, # 成交價 (float) orig_lots : 3, # 原始口數 (int) tradable_lot : 3, # 可交易口數 (int) order_type : New, # 委託別 (FutOptOrderType) currency : "TWD", # 幣別 (str) market_price : "20351", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 0.0, # 選擇權市值 (float) opt_long_value : 0.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : 0.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) spreads : None, # 複式部位 (List[SpreadPosition]) }, HybridPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) is_spread : False, # 是否為複式部位 (bool) position_kind : 2, # 部位種類 (int)) symbol : "TX1", # 商品代號 (str) expiry_date : 202404, # 履約日 (string) strike_price : 206000, # 履約價 (float) call_put : Call, # 權利別 (CallPut) buy_sell : Buy, # 買賣別 (BSAction) price : 10, # 成交價 (int) orig_lots : 4, # 原始口數 (int) tradable_lot : 4, # 可交易口數 (int) order_type : New, # 委託別 (FutOptOrderType) currency : "TWD", # 幣別 (str) market_price : "4.6", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 920.0, # 選擇權市值 (float) opt_long_value : 920.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : -1080.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) spreads : None, # 複式部位 (List[SpreadPosition]) }, HybridPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) is_spread : False, # 是否為複式部位 (bool) position_kind : 2, # 部位種類 (int) symbol : "TXO", # 商品代號 (str) expiry_date : 202404, # 履約日 (string) strike_price : 198000, # 履約價 (float) call_put : Call, # 權利別 (CallPut) buy_sell : Sell, # 買賣別 (BSAction) price : 243, # 成交價 (int) orig_lots : 2, # 原始口數 (int) tradable_lot : 2, # 可交易口數 (int) order_type : New, # 委託別 (int) currency : "TWD", # 幣別 (str) market_price : "46", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 4600.0, # 選擇權市值 (float) opt_long_value : 4600.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : -19700.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) spreads : None, # 複式部位 (List[SpreadPosition]) }, HybridPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) is_spread : False, # 是否為複式部位 (bool) position_kind : 2, # 部位種類 (int) symbol : "TXO", # 商品代號 (str) expiry_date : 202404, # 履約日 (string) strike_price : 200000, # 履約價 (float) call_put : Call, # 權利別 (CallPut) buy_sell : Buy, # 買賣別 (BSAction) price : 500, # 成交價 (int) orig_lots : 2, # 原始口數 (int) tradable_lot : 2, # 可交易口數 (int) order_type : New, # 委託別 (FutOptOrderType) currency : "TWD", # 幣別 (str) market_price : "430", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 43000.0, # 選擇權市值 (float) opt_long_value : 43000.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : -7000.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) spreads : None, # 複式部位 (List[SpreadPosition]) }, HybridPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) is_spread : False, # 是否為複式部位 (bool) position_kind : 2, # 部位種類 (int) symbol : "TXO", # 商品代號 (str) expiry_date : 202404, # 履約日 (string) strike_price : 200000, # 履約價 (float) call_put : Put, # 權利別 (CallPut) buy_sell : Buy, # 買賣別 (BSAction) price : 344, # 成交價 (int) orig_lots : 2, # 原始口數 (int) tradable_lot : 2, # 可交易口數 (int) order_type : New, # 委託別 (FutOptOrderType) currency : "TWD", # 幣別 (str) market_price : "82", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 8200.0, # 選擇權市值 (float) opt_long_value : 8200.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : -26200.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) spreads : None, # 複式部位 (List[SpreadPosition]) }, HybridPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) is_spread : False, # 是否為複式部位 (bool) position_kind : 2, # 部位種類 (int) symbol : "TXO", # 商品代號 (str) expiry_date : 202405, # 履約日 (string) strike_price : 199000, # 履約價 (float) call_put : Call, # 權利別 (CallPut) buy_sell : Buy, # 買賣別 (BSAction) price : 610, # 成交價 (int) orig_lots : 1, # 原始口數 (int) tradable_lot : 1, # 可交易口數 (int) order_type : New, # 委託別 (FutOptOrderType) currency : "TWD", # 幣別 (str) market_price : "670", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 33500.0, # 選擇權市值 (float) opt_long_value : 33500.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : 3000.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) spreads : None, # 複式部位 (List[SpreadPosition]) }, HybridPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) is_spread : True, # 是否為複式部位 (bool) position_kind : 2, # 部位種類 (int) symbol : "TXO20100D4:20000P4", # 商品代號 (str) expiry_date : 1, # 履約日 (string) strike_price : 1, # 履約價 (float) call_put : None, # 權利別 (int or None) buy_sell : Buy, # 買賣別 (BSAction) price : None, # 成交價 (int or None) orig_lots : 2, # 原始口數 (int) tradable_lot : 2, # 可交易口數 (int) order_type : New, # 委託別 (FutOptOrderType) currency : "TWD", # 幣別 (str) market_price : "0.0", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 0.0, # 選擇權市值 (float) opt_long_value : 0.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : 0.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) spreads : [ # 複式部位 (List[SpreadPosition]) SpreadPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) position_kind : 2, # 部位種類 (int) symbol : "TXO", # 商品代號 (str) expiry_date : 202404, # 履約日 (string) strike_price : 201000, # 履約價 (float) call_put : Call, # 權利別 (CallPut) buy_sell : Buy, # 買賣別 (BSAction) price : 185, # 成交價 (int) orig_lots : 2, # 原始口數 (int) tradable_lot : 2, # 可交易口數 (int) order_type : None, # 委託別 (int or None) currency : "TWD", # 幣別 (str) market_price : "365", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 36500.0, # 選擇權市值 (float) opt_long_value : 36500.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : 18000.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) }, SpreadPosition { date : "2024/04/08", # 部位建立日期 (str) branch_no : "15901", # 分公司代號 (str) account : "1234567", # 帳號 (str) position_kind : 2, # 部位種類 (int) symbol : "TXO", # 商品代號 (str) expiry_date : 202404, # 履約日 (string) strike_price : 200000, # 履約價 (float) call_put : Put, # 權利別 (CallPut) buy_sell : Buy, # 買賣別 (BSAction) price : 354, # 成交價 (int) orig_lots : 2, # 原始口數 (int) tradable_lot : 2, # 可交易口數 (int) order_type : None, # 委託別 (int or None) currency : "TWD", # 幣別 (str) market_price : "82", # 即時價 (str) initial_margin : 0.0, # 原始保證金 (float) maintenance_margin : 0.0, # 維持保證金 (float) clearing_margin : 0.0, # 結算保證金 (float) initial_margin_all_single : 0.0, # 原始保證金 (float) opt_value : 8200.0, # 選擇權市值 (float) opt_long_value : 8200.0, # 選擇權買進市值 (float) opt_short_value : 0.0, # 選擇權賣出市值 (float) profit_or_loss : -27200.0, # 部位損益 (float) premium : 0.0, # 權利金 (float) }, ], } ] } ``` --- ### 權益數查詢 query\_margin\_equity #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳權益數資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ###### 權益數 Equity 欄位[​](#權益數-equity-欄位 "Direct link to 權益數 Equity 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------------- | ------ | --------------------------------------------------------------------------- | | date | string | 查詢日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | currency | string | 幣別 : `NTD` 約當台幣 、`TWD` 新台幣、`USD` 美元、`CNY` 人民幣 、`JPY` 日圓 | | yesterday\_balance | float | 昨日餘額 | | today\_balance | float | 今日餘額 | | initial\_margin | float | 原始保證金 | | maintenance\_margin | float | 維持保證金 | | clearing\_margin | float | 結算保證金 | | today\_equity | float | 本日權益 | | today\_deposit | float | 今日入金 | | today\_withdrawal | float | 今日出金 | | today\_trading\_fee | float | 今日交易手續費 | | today\_trading\_tax | float | 今日交易稅 | | receivable\_premium | float | 收取權利金 | | payable\_premium | float | 付出權利金 | | excess\_margin | float | 超額保證金 | | available\_margin | float | 可動用保證金 | | disgorgement | float | 追繳金額 | | opt\_pnl | float | 未沖銷選擇權浮動損益 | | opt\_value | float | 選擇權市值 | | opt\_long\_value | float | 未沖銷選擇權買方市值 | | opt\_short\_value | float | 未沖銷選擇權賣方市值 | | fut\_realized\_pnl | float | 期貨平倉損益 | | fut\_unrealized\_pnl | float | 期貨期貨未平倉損益 | | buy\_lot | int | 買進口數 | | sell\_lot | int | 賣出口數 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt_accounting.query_margin_equity(accounts) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [Equity({ date: "2024/04/08", # 查詢日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) currency: "NTD", # 幣別 (string) yesterday_balance: 22435152.4, # 昨日餘額 (float) today_balance: 22434910.4, # 今日餘額 (float) initial_margin: 1114946.0, # 原始保證金 (float) maintenance_margin: 939214.0, # 維持保證金 (float) clearing_margin: 915760.0, # 結算保證金 (float) today_equity: 22694910.4, # 本日權益 (float) today_deposit : 0.0, # 本日入金 (float) today_withdrawal: 2102.0, # 本日出金 (float) today_trading_fee: 16.0, # 本日交易手續費 (float) today_trading_tax: 0.0, # 本日交易稅 (float) receivable_premium: 0.0, # 收取權利金 (float) payable_premium: 9250.0, # 付出權利金 (float) excess_margin: 28744525.0, # 超額保證金 (float) available_margin: 21453562.4, # 可動用保證金 (float) disgorgement: 0.0, # 追繳金額 (float) opt_pnl: -248600.0, # 未沖銷選擇權浮動損益 (float) opt_value: -193100.0, # 選擇權市值 (float) opt_long_value: 311900.0, # 未沖銷選擇權買方市值 (float) opt_short_value: 505000.0, # 未沖銷選擇權賣方市值 (float) fut_realized_pnl: 0.0, # 期貨平倉損益 (float) fut_unrealized_pnl: 60700.0, # 期貨期貨未平倉損益 (float) buy_lot: 22, # 買進口數 (int) sell_lot: 7 # 賣出口數 (int) }), Equity({ date: "2024/04/08", # 查詢日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) currency: "TWD", # 幣別 (string) yesterday_balance: 19880310.0, # 昨日餘額 (float) today_balance: 19880068.0, # 今日餘額 (float) initial_margin: 1114946.0, # 原始保證金 (float) maintenance_margin: 939214.0, # 維持保證金 (float) clearing_margin: 915760.0, # 結算保證金 (float) today_equity: 20140068.0, # 本日權益 (float) today_deposit : 0.0, # 本日入金 (float) today_withdrawal: 2102.0, # 本日出金 (float) today_trading_fee: 16.0, # 本日交易手續費 (float) today_trading_tax: 0.0, # 本日交易稅 (float) receivable_premium: 0.0, # 收取權利金 (float) payable_premium: 9250.0, # 付出權利金 (float) excess_margin: 28744525.0, # 超額保證金 (float) available_margin: 18898720.0, # 可動用保證金 (float) disgorgement: 0.0, # 追繳金額 (float) opt_pnl: -248600.0, # 未沖銷選擇權浮動損益 (float) opt_value: -193100.0, # 選擇權市值 (float) opt_long_value: 311900.0, # 未沖銷選擇權買方市值 (float) opt_short_value: 505000.0, # 未沖銷選擇權賣方市值 (float) fut_realized_pnl: 0.0, # 期貨平倉損益 (float) fut_unrealized_pnl: 60700.0, # 期貨期貨未平倉損益 (float) buy_lot: 22, # 買進口數 (int) sell_lot: 7, # 賣出口數 (int) }), ... ] } ``` --- ### 單式部位查詢 query\_single\_position #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳部位資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### Position 欄位[​](#position-欄位 "Direct link to Position 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | | date | string | 部位建立日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | is\_spread | bool | 是否為複式部位 | | position\_kind | int | 部位種類 : `1` 期貨 、`2` 選擇權 | | symbol | string | 商品代號 | | expiry\_date | string | 履約日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 權利別 : `Call` 、 `Put` | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買、`Sell` 賣 | | price | float | 成交價 | | orig\_lots | int | 原始口數 | | tradable\_lots | int | 可交易口數 | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託別 : `New` 新倉、`Close`平倉、`FdayTrade`當沖 | | currency | string | 幣別 | | market\_price | string | 即時價 | | initial\_margin | float | 原始保證金 | | maintenance\_margin | float | 維持保證金 | | clearing\_margin | float | 結算保證金 | | opt\_value | float | 選擇權市值 | | opt\_long\_value | float | 選擇權買進市值 | | opt\_short\_value | float | 選擇權賣出市值 | | profit\_or\_loss | float | 部位損益 | | premium | float | 權利金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt_accounting.query_single_position(accounts) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data: [ Position { date: "2024/04/08", # 部位建立日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l0001-0000", # 訂單編號 (string) position_kind: 1, # 部位種類 (int) symbol: "FITX", # 商品代號 (string) expiry_date: 202404, # 履約日 (string) strike_price: None, # 履約價 (float) call_put: None, # 權利別 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) price: 20362, # 成交價 (float) orig_lots: 2, # 原始口數 (int) tradable_lot: 2, # 可交易口數 (int) order_type: New, # 委託別 (FutOptOrderType) currency: "TWD", # 幣別 (string) market_price: "20521.0000", # 即時價 (string) initial_margin: 358000.0, # 原始保證金 (float) maintenance_margin: 274000.0, # 維持保證金 (float) clearing_margin: 264000.0, # 結算保證金 (float) profit_or_loss: 63600.0, # 部位損益 (float) premium: 0.0, # 權利金 (float) }, Position { date: "2024/03/29", # 部位建立日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l0007-0000", # 訂單編號 (string) position_kind: 2, # 部位種類 (int) symbol: "TX1", # 商品代號 (string) expiry_date: 202404, # 履約日 (string) strike_price: 20600, # 履約價 (float) call_put: Call, # 權利別 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) price: 10, # 成交價 (float) orig_lots: 2, # 原始口數 (int) tradable_lot: 2, # 可交易口數 (int) order_type: NEW, # 委託別 (FutOptOrderType) currency: "TWD", # 幣別 (string) market_price: "4.6000", # 即時價 (string) initial_margin: 52660.0, # 原始保證金 (float) maintenance_margin: 36460.0, # 維持保證金 (float) clearing_margin: 34460.0, # 結算保證金 (float) profit_or_loss: -540.0, # 部位損益 (float) premium: -1000.0, # 權利金 (float) }, Position { date: "2024/03/29", # 部位建立日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l0007-0001", # 訂單編號 (string) position_kind: 2, # 部位種類 (int) symbol: "TX1", # 商品代號 (string) expiry_date: 202404, # 履約日 (string) strike_price: 20600, # 履約價 (float) call_put: Call, # 權利別 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) price: 10, # 成交價 (float) orig_lots: 2, # 原始口數 (int) tradable_lot: 2, # 可交易口數 (int) order_type: NEW, # 委託別 (FutOptOrderType) currency: "TWD", # 幣別 (string) market_price: "4.6000", # 即時價 (string) initial_margin: 52660.0, # 原始保證金 (float) maintenance_margin: 36460.0, # 維持保證金 (float) clearing_margin: 34460.0, # 結算保證金 (float) profit_or_loss: -540.0, # 部位損益 (float) premium: -1000.0, # 權利金 (float) }, Position { date: "2024/03/01", # 部位建立日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l0002-0000", # 訂單編號 (string) position_kind: 2, # 部位種類 (int) symbol: "TXO", # 商品代號 (string) expiry_date: 202404, # 履約日 (string) strike_price: 18500, # 履約價 (float) call_put: Call, # 權利別 (CallPut) buy_sell: Sell, # 買賣別 (BSAction) price: 625, # 成交價 (float) orig_lots: 5, # 原始口數 (int) tradable_lot: 4, # 可交易口數 (int) order_type: NEW, # 委託別 (FutOptOrderType) currency: "TWD", # 幣別 (string) market_price: "2020.0000", # 即時價 (string) initial_margin: 584000.0, # 原始保證金 (float) maintenance_margin: 544000.0, # 維持保證金 (float) clearing_margin: 536000.0, # 結算保證金 (float) profit_or_loss: -279000.0, # 部位損益 (float) premium: 125000.0, # 權利金 (float) } ] } ``` --- ### 參數對照表 #### 類別[​](#類別 "Direct link to 類別") Class ##### OrderObject[​](#orderobject "Direct link to OrderObject") | Parameter | Type | Meaning | | --------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------- | | buy\_sell | BSAction | [買賣別](#bsaction) 可選用參數`Buy` 買 、 `Sell` 賣 | | symbol | string | 商品代號 | | buy\_sell2 (optional) | BSAction | [買賣別](#bsaction) - 複式第二隻腳 | | symbol2 (optional) | string | 商品代號 - 複式第二隻腳 | | price | string | 委託價格 | | lot | int | 委託口數 | | market\_type | FutOptMarketType | [盤別](#futoptmarkettype) 可選用參數`Future` 期貨日盤、`Option`選擇權日盤、`FutureNight` 期貨夜盤、`OptionNight` 選擇權夜盤 | | price\_type | FutOptPriceType | [價格旗標](#futoptpricetype) 可選用參數為 `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | time\_in\_force | TimeInForce | [委託條件](#timeinforce) 可選用參數為 `ROD`、`FOK`、`IOC` | | order\_type | FutOptOrderType | [委託類別](#futoptordertype) 可選用參數為 `New` 新倉、`Close`平倉、`Auto`自動、`FdayTrade`當沖 | | user\_def (optional) | string | 用戶自定義 (最長10個字元,不支援特殊字元) | caution priceType 爲 FutOptPriceType.Limit 時,需填入 price 欄位,其餘時候 price 欄位為空值或為None。 ##### FutOptOrderResult[​](#futoptorderresult "Direct link to FutOptOrderResult") 委託列表,透過 [get\_order\_result(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/trade/GetOrderResults.md) 取得。 | 參數 | 類別 | 說明 | | ------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | FutOptMarketType | [盤別種類](#futoptmarkettype) : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | string | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | BSAction | [買賣別](#bsaction) : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | string | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | BSAction | [買賣別](#bsaction) - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | FutOptPriceType | [原始委託價格別](#futoptpricetype) : `Limit` 限價 、 `LimitUp` 漲停 、 `LimitDown` 跌停 、 `Market` 市價 、 `Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | TimeInforce | [委託條件別](#timeinforce) : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | FutOptOrderType | [委託單類型](#futoptordertype) : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | FutOptPriceType | [有效委託價格別](#futoptpricetype) : `Limit`限價 、 `Market`市價 、`RangeMarket` 範圍市價 、 `Reference`參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | error\_message | string | 錯誤訊息 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | >> function\_type | int | 功能別 : `10` 新單、 `15` 改價、 `20` 改量、`30`刪單、`50`成交 | | >> modified\_time | string | 修改時間 | | >> before\_lot | int | 原始委託口數 | | >> after\_lot | int | 有效委託口數 | | >> before\_price | float | 原始委託價 | | >> after\_price | float | 有效委託價 | | >> filled\_money | float | 成交價金 | | >> error\_message | string | 錯誤訊息 | ##### BatchResult[​](#batchresult "Direct link to BatchResult") 批次委託列表,透過 [batch\_order\_lists(accounts)](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/trade/batchOrder/BatchOrderList.md) 取得。 | Parameter | Type | Meaning | | -------------- | ------ | ------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | batch\_seq\_no | string | 批次單流水序號 | ##### FutoptModifyPrice[​](#futoptmodifyprice "Direct link to FutoptModifyPrice") 改價物件 | Parameter | Type | Meaning | | ------------- | --------------- | ---------------------------------------------------------------------------------------------------------------- | | order\_result | Object | [委託列表](#futoptorderresult) | | price | string | 改單後的價格 | | price\_type | FutOptPriceType | [改單後的價格類型](#futoptpricetype) : `Limit`限價 、 `Market`市價 、`RangeMarket` 範圍市價 、 `Reference`參考價 | ##### FutOptModifyLot[​](#futoptmodifylot "Direct link to FutOptModifyLot") 改量物件 | Parameter | Type | Meaning | | ------------- | ------ | ------------------------------ | | order\_result | Object | [委託列表](#futoptorderresult) | | lot | int | 改單後的委託量 | ##### FutOptFilledData[​](#futoptfilleddata "Direct link to FutOptFilledData") 成交回報物件 | 參數 | 類別 | 說明 | | ------------------- | --------------- | ---------------------------------------------------------------------------------------------- | | date | string | 日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | seq\_no | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | order\_no | string | 委託書號 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | CallPut | [買賣權](#callput) : `Call` 買權、 `Put` 賣權 | | buy\_sell | BSAction | \[買賣別] (#bsaction) : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | CallPut | [買賣權](#callput) - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | BSAction | [買賣別](#bsaction) - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | order\_type | FutOptOrderType | [委託單類型](#futoptordertype) : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | filled\_no | string | 成交流水號 | | filled\_avg\_price | float | 成交均價 | | filled\_lot | int | 成交股數 | | filled\_price | float | 成交單價 | | filled\_time | string | 成交時間 | | user\_def | string | 用戶自定義 (只有主動回報才回傳此欄位) | ##### Account[​](#account "Direct link to Account") 帳號資訊 | Parameter | Type | Meaning | | ------------- | ------ | ------------------------------------------ | | name | string | 客戶姓名 | | account | string | 帳號 | | branch\_no | string | 分公司代號 | | account\_type | string | 帳號類型 ,回傳 `stock`證券 、`futopt`期貨 | #### Constants ( 欄位對應數值 )[​](#constants--欄位對應數值- "Direct link to Constants ( 欄位對應數值 )") ##### BSAction[​](#bsaction "Direct link to BSAction") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Buy | 買 | | Sell | 賣 | ##### CallPut[​](#callput "Direct link to CallPut") 買賣別 (buySell) | Name | Meaning | | ---- | ------- | | Call | Call | | Put | Put | ##### FutOptMarketType[​](#futoptmarkettype "Direct link to FutOptMarketType") 盤別 | Name | Meaning | | ----------- | ---------- | | Future | 期貨日盤 | | FutureNight | 期貨夜盤 | | Option | 選擇權日盤 | | OptionNight | 選擇權夜盤 | ##### FutOptPriceType[​](#futoptpricetype "Direct link to FutOptPriceType") 價格類型 (priceType) | Name | Meaning | | ----------- | -------- | | Limit | 限價 | | Market | 市價 | | RangeMarket | 範圍市價 | | Reference | 參考價 | ##### TimeInForce[​](#timeinforce "Direct link to TimeInForce") 委託條件 (TimeInForce) | Name | Meaning | | ---- | ------------------------------------- | | ROD | 當日有效(Rest of Day) | | FOK | 全部成交否則取消(Fill-or-Kill) | | IOC | 立即成交否則取消(Immediate-or-Cancel) | ##### FutOptOrderType[​](#futoptordertype "Direct link to FutOptOrderType") 委託類別 (orderType) | Name | Meaning | | --------- | ------- | | New | 新倉 | | Close | 平倉 | | Auto | 自動 | | FdayTrade | 當沖 | ##### function\_type[​](#function_type "Direct link to function_type") 功能類別 | Name | Value | | -------- | ----- | | 新單 | 0 | | 新單執行 | 10 | | 改價 | 15 | | 改量 | 20 | | 刪單 | 30 | | 失敗 | 90 | ##### market[​](#market "Direct link to market") 市場 | Name | Value | | ---------- | ------ | | 期貨交易所 | TAIMEX | ##### status[​](#status "Direct link to status") 委託單狀態 | Name | Value | | ------------ | ---------------------------------------------------------- | | 預約單 | 0 | | 中台收到委託 | 4 ( 請用GetOrderResult查詢狀態 ) | | 後台連線逾時 | 9 ( 請稍後再使用GetOrderResult查詢狀態 or 聯絡您的營業員 ) | | 委託成功 | 10 | | 刪單成功 | 30 | | 完全成交 | 50 | | 改價失敗 | 19 | | 改量失敗 | 29 | | 刪單失敗 | 39 | | 失敗 | 90 | #### Month[​](#month "Direct link to Month") 月份代號 ##### 期貨[​](#期貨 "Direct link to 期貨") | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | A | B | C | D | E | F | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | G | H | I | J | K | L | ##### 選擇權[​](#選擇權 "Direct link to 選擇權") Call | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | A | B | C | D | E | F | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | G | H | I | J | K | L | Put | 一月 | 二月 | 三月 | 四月 | 五月 | 六月 | | ---- | ---- | ---- | ---- | ------ | ------ | | M | N | O | P | Q | R | | 七月 | 八月 | 九月 | 十月 | 十一月 | 十二月 | | S | T | U | V | W | X | --- ### 登入 apikey\_login 版本資訊 v2.2.7 起新增功能 相關說明請參閱 [API Key 說明](https://www.fbs.com.tw/TradeAPI/docs/trading/api-key-apply.md) 頁面 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------ | -------------- | | personal\_id | String | 登入的ID | | Key | String | 申請的 API Key | | cert\_path | String | 憑證路徑 | | cert\_pass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊--account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type: Object | 參數 | 類別 | 說明 | | ------------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branch\_no | String | 分公司代號 | | account\_type | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction sdk = FubonSDK() accounts = sdk.apikey_login("Your ID", "Your KEY","Your Cert Path","Your Cert Password") print(accounts) #若有多帳號,則回傳多個 ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : Account{ name : "富邦Bill", # 客戶姓名 (string) account : "28", # 客戶帳號 (string) branch_no : "6460", # 分公司代號 (string) account_type : "futopt" # 帳號類型 (string) } } ``` --- ### 登入 login #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ------ | ---------- | | personal\_id | String | 登入的ID | | password | String | 登入的密碼 | | cert\_path | String | 憑證路徑 | | cert\_pass | String | 憑證密碼 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳帳號資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 帳號資訊 Account 欄位[​](#帳號資訊--account-欄位 "Direct link to 帳號資訊 Account 欄位") Return type: Object | 參數 | 類別 | 說明 | | ------------- | ------ | ---------------------------------------- | | name | String | 客戶姓名 | | account | String | 客戶帳號 | | branch\_no | String | 分公司代號 | | account\_type | string | 帳號類型 回傳 `stock` 證券 `futopt` 期貨 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction sdk = FubonSDK() accounts = sdk.login("Your ID", "Your Password","Your Cert Path","Your Cert Password") print(accounts) #若有多帳號,則回傳多個 ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : Account{ name : "富邦Bill", # 客戶姓名 (string) account : "28", # 客戶帳號 (string) branch_no : "6460", # 分公司代號 (string) account_type : "futopt" # 帳號類型 (string) } } ``` --- ### 登出 logout #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ---- | -------- | | is\_success | bool | 是否成功 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py from fubon_neo.sdk import FubonSDK, Order from fubon_neo.constant import TimeInForce, OrderType, PriceType, MarketType, BSAction sdk = FubonSDK() sdk.logout() ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py True ``` --- ### 刪除批次委託單 batch\_cancel\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | cancel\_object | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) | 批次取消委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資��訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py # 批次刪單(利用batch detail回傳的內容刪單) cancel_object = [ batch_results_detail.data[0], batch_results_detail.data[1], ] sdk.futopt.batch_cancel_order(account, cancel_object) # 批次刪單(利用不同的單筆委託) cancel_object = [ orders.data[37], orders.data[35], ] sdk.futopt.batch_cancel_order(account, cancel_object) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data :[ FutOptOrderResult { # 利用batchDetail 回傳內容 function_type: 30, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212608", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0001", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITF", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 1822.6, # 價格 (float) lot: 2, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (FutOptPriceType) after_price: 1822.6, # 有效委託價格 (float) after_lot: 0, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: None, # 改單前有效股口數 (int) before_price: None, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "13:21:34", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None, # 錯誤訊息 (string) }, FutOptOrderResult { function_type: 30, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212609", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0002", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITF", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) ... } ]} 以下範例擷取data內容 [FutOptOrderResult{ # 批次刪單(利用不同的單筆委託) function_type: 30, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212610", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0003", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITF", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 1822.6, # 價格 (float) lot: 2, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (FutOptPriceType) after_price: 1822.6, # 有效委託價格 (float) after_lot: 0, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: None, # 改單前有效股口數 (int) before_price: None, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "13:21:28", # 最後異動時間 (string) error_message: None, # 錯誤訊息 (string) }, FutOptOrderResult{ function_type: 30, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212611", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0004", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITF", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 1822.6, # 價格 (float) lot: 2, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) }] ``` --- ### 批次修改委託價格 batch\_modify\_price ##### 先使用make\_modify\_price\_obj 建立 FutOptModifyPrice 物件[​](#先使用make_modify_price_obj-建立-futoptmodifyprice-物件 "Direct link to 先使用make_modify_price_obj 建立 FutOptModifyPrice 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 修改後的價格旗標 | caution 當 price 欄位有填入值時,priceType 欄位為空值或為None ; 當 priceType 欄位有填入值時,price 欄位為空值或為None 將回傳的物件放入 modify\_price 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | ModifyPriceObj | [FutOptModifyPrice](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmodifyprice) (list) | 批次修改委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py # 批次改價(利用batch detail回傳的內容改單) modify_objects = [ sdk.futopt.make_modify_price_obj(batch_results_detail.data[0], "19900"), sdk.futopt.make_modify_price_obj(batch_results_detail.data[1], "19900"), ] sdk.futopt.batch_modify_price(target_user, modify_objects) # 批次改價(利用不同的單筆委託) modify_objects = [ sdk.futopt.make_modify_price_obj(orders.data[37], "19900"), sdk.futopt.make_modify_price_obj(orders.data[35], "19900"), ] sdk.futopt.batch_modify_price(target_user, modify_objects) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ FutOptOrderResult{# 批次改價(利用batch detail回傳的內容改單) function_type: 15, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212663", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0005", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITX", # 商品代號 (string) expiry_date: "0", # 到期日 (string) strike_price: 0, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 19900, # 有效委託價格 (float) after_lot: 1, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 0, # 改單前有效股口數 (int) before_price: 20000, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "13:39:05", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None, # 錯誤訊息 (string) }, FutOptOrderResult{ function_type: 15, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212664", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0006", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITX", # 商品代號 (string) expiry_date: "0", # 到期日 (string) strike_price: 0, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) ... }] } 以下範例擷取data內容 [ FutOptOrderResult{# 批次改價(利用不同的單筆委託) function_type: 15, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212665", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0006", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITX", # 商品代號 (string) expiry_date: "0", # 到期日 (string) strike_price: 0, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 19900, # 有效委託價格 (float) after_lot: 1, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 0, # 改單前有效股口數 (int) before_price: 20000, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "13:39:10", # 最後異動時間 (string) error_message: None, # 錯誤訊息 (string) }, FutOptOrderResult{ function_type: 15, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212665", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0007", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITX", # 商品代號 (string) expiry_date: "0", # 到期日 (string) strike_price: 0, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) ... }] ``` --- ### 批次修改委託數量 batch\_modify\_lot ##### 先使用make\_modify\_lot\_obj 建立 FutOptModifyLot 物件[​](#先使用make_modify_lot_obj-建立-futoptmodifylot-物件 "Direct link to 先使用make_modify_lot_obj 建立 FutOptModifyLot 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | lots | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入batch\_modify\_lot 方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | ModifyLotObj | [FutOptModifyLot](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmodifylot) (list) | 批次改量委託單內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py # 批次改量(利用batch detail回傳的內容改單) modify_objects = [ sdk.futopt.make_modify_lot_obj(batch_results_detail.data[0], 2), sdk.futopt.make_modify_lot_obj(batch_results_detail.data[1], 2), ] sdk.futopt.batch_modify_lot(target_user, modify_objects) # 批次改量(利用不同的單筆委託) modify_objects = [ sdk.futopt.make_modify_lot_obj(orders.data[37], 2), sdk.futopt.make_modify_lot_obj(orders.data[35], 2), ] sdk.futopt.batch_modify_lot(target_user, modify_objects) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ FutOptOrderResult{ # 批次改量(利用batch detail回傳的內容改單) function_type: 20, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "03100161319", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l001D", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: FutureNight, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FIMTX", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 3, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 20000, # 有效委託價格 (float) after_lot: 2, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 3, # 改單前有效股口數 (int) before_price: None, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "18:24:40", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None, # 錯誤訊息 (string) }, FutOptOrderResult{ # 批次改量(利用batch detail回傳的內容改單) function_type: 20, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "03100161320", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l001E", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: FutureNight, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FIMTX", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 3, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) ... }] } 以下範例擷取data內容 [FutOptOrderResult{ # 批次改量(利用不同的單筆委託) function_type: 20, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "03100161321", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l001F", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: FutureNight, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FIMTX", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 3, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 20000, # 有效委託價格 (float) after_lot: 2, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 3, # 改單前有效股口數 (int) before_price: None, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "18:24:40", # 最後異動時間 (string) error_message: None, # 錯誤訊息 (string) }, FutOptOrderResult{ function_type: 20, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "03100161322", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l001G", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: FutureNight, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FIMTX", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 3, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) ... }] ``` --- ### 取得批次委託明細 batch\_order\_detail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------------ | ----------------------------------------------------------------------------------------------------------- | ------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | batch\_order\_list | [BatchResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#batchresult) | 批次委託列表 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | caution 此功能僅供查詢批次送單執行結果,欲取得委託單最新狀態請使用單筆委託單查詢功能 #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py batch_results = sdk.futopt.batch_order_lists(account) sdk.futopt.batch_order_detail(account, batch_results.data[0]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [FutOptOrderResult { date: "2024/04/11", # 交易日期 (string) seq_no: "00230177314", # 委託單流水序號 (string) branch_no: "15000", # 分公司代號 (string) account: "9974825", # 帳號 (string) order_no: "C0020", # 委託書號 (string) asset_type: 2, # 資產類別 : `1` 期貨 、`2` 選擇權 (int) market: "TAIMEX", # 市場類型 : `TAIMEX` 期貨、選擇權 (string) market_type: Option, # 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 (MarketType) unit: None, # 單位數 (int) currency: None, # 幣別 (string) symbol: "TXO", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: 18600, # 履約價 (float) call_put: Call, # 買賣權 : `Call` 買權、 `Put` 賣權 (string) buy_sell: Buy, # 買賣別 : `Buy` 買 、 `Sell` 賣 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 (string) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 (BSAction) price_type: Limit, # 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 (PriceType) price: 2100, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC (TimeInforce) order_type: New, # 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 50, # 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 (int) after_price_type: None, # 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 (PriceType) after_price: 2100, # 有效委託價格 (float) after_lot: 1, # 有效委託口數 (int) filled_lot: 1, # 成交口數 (int) filled_money: 2100, # 成交價金 (float) before_lot: None, # 改單前有效口數 (int) before_price: None, # 改單前有效價 (float) user_def: None, # 自訂欄位 (string) last_time: "10:41:46.760", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, FutOptOrderResult { date: "2024/04/11", # 交易日期 (string) seq_no: "00230177315", # 委託單流水序號 (string) branch_no: "15000", # 分公司代號 (string) account: "9974825", # 帳號 (string) order_no: "C0021", # 委託書號 (string) asset_type: 2, # 資產類別 : `1` 期貨 、`2` 選擇權 (int) market: "TAIMEX", # 市場類型 : `TAIMEX` 期貨、選擇權 (string) market_type: Option, # 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 (MarketType) unit: None, # 單位數 (int) currency: None, # 幣別 (string) symbol: "TXO", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: 18500, # 履約價 (float) call_put: Call, # 買賣權 : `Call` 買權、 `Put` 賣權 (string) buy_sell: Sell, # 買賣別 : `Buy` 買 、 `Sell` 賣 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 (string) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 (BSAction) price_type: Limit, # 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 (PriceType) price: 2230, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC (TimeInforce) order_type: New, # 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 (OrderType) is_pre_order: False, # 是否為預約單 (bool) status: 50, # 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 (int) after_price_type: None, # 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 (PriceType) after_price: 2230, # 有效委託價格 (float) after_lot: 1, # 有效委託口數 (int) filled_lot: 1, # 成交口數 (int) filled_money: 2230, # 成交價金 (float) before_lot: None, # 改單前有效口數 (int) before_price: None, # 改單前有效價 (float) user_def: None, # 自訂欄位 (string) last_time: "10:41:46.760", # 最後異動時間 (string) error_message: None # 錯誤訊息 (string) }]} ``` --- ### 取得批次委託列表 batch\_order\_lists #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------- | --------------------------------------------------------------------------------------------------- | ---- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳批次單資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 批次單 BatchResult 欄位[​](#批次單-batchresult-欄位 "Direct link to 批次單 BatchResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | -------------- | ------ | ------------------------------------------------------------------------------ | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | batch\_seq\_no | string | 批次單流水序號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt.batch_order_lists(account) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [BatchResult{ function_type: 0, # 功能種類 (int) date: "2023/10/16", # 交易日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) batch_seq_no: "11EE6BC3B85670DE8000000C29304663" # 批次單流水序號 (string) }, BatchResult{ function_type: 15, # 功能種類 (int) date: "2023/10/16", # 交易日期 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) batch_seq_no: "11EE6BC3E189F02A8000000C29304663" # 批次單流水序號 (string) }, ... ] } ``` --- ### 建立批次委託單 batch\_place\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------- | ---------------------------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | order\_object | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#orderobject) (list of object) | 委託內容 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py orders = [ FutOptOrder( buy_sell = BSAction.Buy, symbol = "TXO20000E4", price = "530", lot = 1, market_type = FutOptMarketType.Option, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "From_Py" # optional field ), FutOptOrder( buy_sell = BSAction.Buy, symbol = "TXO20000E4", price = "530", lot = 1, market_type = FutOptMarketType.Option, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "From_Py" # optional field ) ] sdk.futopt.batch_place_order(target_user, orders) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ FutOptOrderResult{ function_type: 0, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00230177010", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0002", # 委託書號 (string) asset_type: 2, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Option, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "TXO", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: 20000, # 履約價 (float) call_put: Call, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 530, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 530, # 有效委託價格 (float) after_lot: 1, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 0, # 改單前有效股口數 (int) before_price: 530, # 改單前有效價格 (float) user_def: "From_Py", # 自訂欄位 (string) last_time: "11:50:08", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }, FutOptOrderResult{ function_type: 0, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00230177010", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0002", # 委託書號 (string) asset_type: 2, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Option, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "TXO", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: 20000, # 履約價 (float) call_put: Call, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 530, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 530, # 有效委託價格 (float) after_lot: 1, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 0, # 改單前有效股口數 (int) before_price: 530, # 改單前有效價格 (float) user_def: "From_Py", # 自訂欄位 (string) last_time: "11:50:08", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }]} ``` --- ### 刪除委託單 cancel\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------ | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | order\_result | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) | 欲取消的委託單物件 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | FutOptOrderResult | 回傳更新委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult--欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type: Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt.cancel_order(account, cancel_order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : FutOptOrderResult { function_type: 30, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212608", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0001", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITF", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 1822.6, # 價格 (float) lot: 2, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 30, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 1822.6, # 有效委託價格 (float) after_lot: 0, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: None, # 改單前有效股口數 (int) before_price: None, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "13:21:34", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None, # 錯誤訊息 (string) } } ``` --- ### 商品代號轉換 convert\_symbol #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------- | | symbol | string | 帳務商品代號 | | expiry\_date | string | 履約日 | | strike\_price | float ( Optional ) | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) ( Optional ) | 買賣權 : `Call` Call 、 `Put` Put | info 月份代號可參閱[參數對照表](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#month) #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ------ | ------ | ------------------ | | symbol | string | 行情與下單商品代號 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py #期貨 sdk.futopt.convert_symbol("FITX","202404") #選擇權 sdk.futopt.convert_symbol("TXO","202404",20000,CallPut.Call) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py #期貨 "TXFD4" #選擇權 "TXO20000D4" ``` --- ### 商品保證金查詢 query\_estimate\_margin #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------- | ----------------------------------------------------------------------------------------------------------- | -------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | order\_object | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#orderobject) | 委託物件 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | -------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | EstimateMargin | 回傳保證金資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### EstimateMargin 欄位[​](#estimatemargin-欄位 "Direct link to EstimateMargin 欄位") Return type : Object | 參數 | 類別 | 說明 | | ---------------- | ------ | ---------- | | date | string | 查詢日期 | | currency | string | 幣別 | | estimate\_margin | float | 預估保證金 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py order = FutOptOrder( buy_sell = BSAction.Buy, symbol = "TXFE4", price = "20890", lot = 1, market_type = FutOptMarketType.Future, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptOrderType.New, user_def = "From_Py" # optional field ); sdk.futopt.query_estimate_margin(accounts.data[0], order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data: EstimateMargin { date: "2024/04/10", # 查詢日期 (string) currency: "TWD", # 幣別 (string) estimate_margin: 179000 # 預估保證金 (float) } } ``` --- ### 查詢歷史成交 filled\_history #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 市場別 : `Future` 期貨日盤、 `Option` 選擇權 、`FutureNight` 期貨夜盤、`OptionNight` 選擇權夜盤 | | start\_date | string | 查詢開始日 | | end\_date | string (optional) (不帶預設與開始日相同) | 查詢終止日 | info 可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳成交資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 成交資訊 FutOptFilledData 欄位[​](#成交資訊-futoptfilleddata-欄位 "Direct link to 成交資訊 FutOptFilledData 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | | date | string | 成交日期 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | seq\_no | string | 委託單流水序號 (只有主動回報才回傳此欄位) | | order\_no | string | 委託書號 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | filled\_no | string | 成交流水號 | | filled\_avg\_price | float | 成交均價 | | filled\_lots | int | 成交口數 | | filled\_price | float | 成交單價 | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新單 、 `Close` 平倉 、 `FdayTrade` 當沖 | | filled\_time | string | 成交時間 | | user\_def | string | 用戶自定義 (只有主動回報才回傳此欄位) | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt.filled_history(account,FutOptMarketType.Future,"20230921","20230922") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [ FutOptFilledData{ date: "2023/09/15", # 成交日期 (string) branch_no: "6460", # 分公司代號 (string) account: "26", # 帳號 (string) order_no: "bA422", # 委託書號 (string) seq_no: None, # 委託單流水序號 (string) symbol: "FITX", # 商品代號 (string) expiry_date: "202404", # 履約日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳(string) expiry_date_leg2: None, # 履約日 - 複式第二隻腳(string) strike_price_leg2: None, # 履約價 - 複式第二隻腳(float) call_put_leg2: None, # 買賣權 - 複式第二隻腳(CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳(BSAction) filled_no: "00000000001", # 成交流水號 (string) filled_avg_price: 20890.0, # 成交均價 (float) filled_lots: 1, # 成交股數 (int) filled_price: 20890.0, # 成交單價 (float) order_type: New, # 委託單類型 (FutOptOrderType) filled_time: "10:31:00.931" # 成交時間 (string) user_def: None # 用戶自定義 (string) }, ... ] } ``` --- ### 取得委託單結果 get\_order\_results #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) (Optional : 不帶為) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : List | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt.get_order_results(accounts.data[0]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [FutOptOrderResult{ function_type: None, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212608", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0001", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITF", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 1822.6, # 價格 (float) lot: 2, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 1822.6, # 有效委託價格 (float) after_lot: 2, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: None, # 改單前有效股口數 (int) before_price: None, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "10:20:27", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None, # 錯誤訊息 (string) }, ... ] } ``` --- ### 取得委託單結果 (含歷程) get\_order\_results\_detail #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------ | -------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) (Optional) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : List | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | error\_message | string | 錯誤訊息 | | detail | list | 委託歷程 | | >> function\_type | int | 功能別 : `10` 新單、`15` 改價、 `20` 改量、`30`刪單、`50` 成交 、`90 `失敗 | | >> modified\_time | string | 修改時間 | | >> before\_lot | int | 原始委託口數 | | >> after\_lot | int | 有效委託口數 | | >> before\_price | float | 原始委託價 | | >> after\_price | float | 有效委託價 | | >> error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt.get_order_results_detail(accounts.data[0]) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [FutOptOrderResult{ function_type: None, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212608", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0001", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITF", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (PriceType) price: 1822.6, # 價格 (float) lot: 2, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: None, # 有效委託價格別 (PriceType) after_price: 1822.6, # 有效委託價格 (float) after_lot: 2, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: None, # 改單前有效股口數 (int) before_price: None, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "10:20:27", # 最後異動時間 (string) error_message: None, # 錯誤訊息 (string) details:[ # 委託歷程 (list) OrderDetail{ function_type: 10, # 功能別 (int) modified_time: "10:20:27", # 修改時間 (string) before_lot: 0, # 原始委託口數 (int) after_lot: 2, # 有效委託口數 (int) before_price: 1822.6, # 原始委託價格 (float) after_price: 1822.6, # 有效委託價格 (float) error_message: None # 錯誤訊息 (string) } ] }, ... ] } ``` --- ### 修改委託價格 modify\_price ##### 先使用make\_modify\_price\_obj 建立 FutOptModifyPrice 物件[​](#先使用make_modify_price_obj-建立-futoptmodifyprice-物件 "Direct link to 先使用make_modify_price_obj 建立 FutOptModifyPrice 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | price | string | 修改後的價格 | | priceType | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 修改後的價格旗標 | caution 當 price 欄位有填入值時,priceType 欄位為空值或為None ; 當 priceType 欄位有填入值時,price 欄位為空值或為None 將回傳的物件放入 modify\_price 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | -------------- | ----------------------------------------------------------------------------------------------------------------------- | -------------- | | accounts | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | ModifyPriceObj | [FutOptModifyPrice](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmodifyprice) | 修改價格的物件 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | FutOptOrderResult | 回傳委託單修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py modify_price_obj = sdk.futopt.make_modify_price_obj(order_result, "19900") sdk.futopt.modify_price(account, modify_price_obj) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : FutOptOrderResult { function_type: 15, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00110212663", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0005", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Future, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FITX", # 商品代號 (string) expiry_date: "0", # 到期日 (string) strike_price: 0, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 19900, # 有效委託價格 (float) after_lot: 1, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 0, # 改單前有效股口數 (int) before_price: 20000, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "13:39:05", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None, # 錯誤訊息 (string) }} ``` --- ### 修改委託單數量 modify\_lot ##### 先使用make\_modify\_lot\_obj 建立 FutOptModifyLot 物件[​](#先使用make_modify_lot_obj-建立-futoptmodifylot-物件 "Direct link to 先使用make_modify_lot_obj 建立 FutOptModifyLot 物件") | 參數 | 類別 | 說明 | | ----------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | orderResult | [FutOptOrderResult](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptorderresult) | 預計修改的委託單 | | lot | int | 修改後的委託量 ( 修改後數量包含此委託單已成交部份 ) | 將回傳的物件放入 modify\_lot 的方法中 #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | --------------- | ------------------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | futOptModifyLot | [FutOptModifyLot](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmodifylot) | 修改的委託單 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | FutOptOrderResult | 回傳委託單修改資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 修改資訊 FutOptOrderResult 欄位[​](#修改資訊-futoptorderresult-欄位 "Direct link to 修改資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py modify_lot_obj = sdk.futopt.make_modify_lot_obj(target_order, 2) sdk.futopt.modify_lot(account, modify_lot_obj) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : FutOptOrderResult{ function_type: 20, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "03100161319", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "l001D", # 委託書號 (string) asset_type: 1, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: FutureNight, # 盤別種類 (FutOptMarketType) unit: None, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "FIMTX", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: None, # 履約價 (float) call_put: None, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 20000, # 價格 (float) lot: 3, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 20000, # 有效委託價格 (float) after_lot: 2, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 0, # 改單前有效股口數 (int) before_price: 20000, # 改單前有效價格 (float) user_def: None, # 自訂欄位 (string) last_time: "18:24:40", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None, # 錯誤訊息 (string) } } ``` --- ### 查詢歷史委託 order\_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 | 查詢終止日 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) (Optional : 不帶全盤別) | 盤別種類 : `Future` 期貨日盤 、 `FutureNight` 期貨夜盤 、 `Option` 選擇權日盤 、 `OptionNight` 選擇權夜盤 | info 可查詢最近兩日之歷史資料 #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ------ | ---------------------------------- | | is\_success | bool | 是否成功 | | data | List | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int (Optional) | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 | | >> function\_type | int | 功能別 : `10` 新單、`15` 改價、 `20` 改量、`30`刪單、`50` 成交 、`90 `失敗 | | >> modified\_time | string | 修改時間 | | >> before\_lot | int | 原始委託口數 | | >> after\_lot | int | 有效委託口數 | | >> before\_price | float | 原始委託價 | | >> after\_price | float | 有效委託價 | | >> error\_message | string | 錯誤訊息 | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py sdk.futopt.order_history(accounts,"20240410","20240411") ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { is_success: True, message: None, data : [FutOptOrderResult { function_type: None, # 功能別 (int) date: "2024/04/11", # 交易日期 (string) seq_no: "00230177314", # 委託單流水序號 (string) branch_no: "15000", # 分公司代號 (string) account: "9974825", # 帳號 (string) order_no: "C0020", # 委託書號 (string) asset_type: 2, # 資產類別 : `1` 期貨 、`2` 選擇權 (int) market: "TAIMEX", # 市場類型 : `TAIMEX` 期貨、選擇權 (string) market_type: Option, # 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 (FutOptMarketType) unit: None, # 單位數 (int) currency: None, # 幣別 (string) symbol: "TXO", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: 18600, # 履約價 (float) call_put: Call, # 買賣權 : `Call` 買權、 `Put` 賣權 (string) buy_sell: Buy, # 買賣別 : `Buy` 買 、 `Sell` 賣 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 (string) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 (BSAction) price_type: Limit, # 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 (FutOptPriceType) price: 2100, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC (TimeInforce) order_type: New, # 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 50, # 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 (int) after_price_type: None, # 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 (FutOptPriceType) after_price: 2100, # 有效委託價格 (float) after_lot: 1, # 有效委託口數 (int) filled_lot: 1, # 成交口數 (int) filled_money: 2100, # 成交價金 (float) before_lot: None, # 改單前有效口數 (int) before_price: None, # 改單前有效價 (float) user_def: None, # 自訂欄位 (string) last_time: "10:41:46.760", # 最後異動時間 (string) details:[ # 委託歷程 (list) OrderDetail{ function_type: 10, # 功能別 (int) modified_time: "10:20:27", # 修改時間 (string) before_lot: 0, # 原始委託口數 (int) after_lot: 1, # 有效委託口數 (int) before_price: 2100, # 原始委託價格 (float) after_price: 2100 # 有效委託價格 (float) error_message: None # 錯誤訊息 (string) } ... ] error_message: None # 錯誤訊息 (string) }, FutOptOrderResult { date: "2024/04/11", # 交易日期 (string) seq_no: "00230177315", # 委託單流水序號 (string) branch_no: "15000", # 分公司代號 (string) account: "9974825", # 帳號 (string) order_no: "C0021", # 委託書號 (string) asset_type: 2, # 資產類別 : `1` 期貨 、`2` 選擇權 (int) market: "TAIMEX", # 市場類型 : `TAIMEX` 期貨、選擇權 (string) market_type: Option, # 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 (FutOptMarketType) unit: None, # 單位數 (int) currency: None, # 幣別 (string) symbol: "TXO", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: 18500, # 履約價 (float) call_put: Call, # 買賣權 : `Call` 買權、 `Put` 賣權 (string) buy_sell: Sell, # 買賣別 : `Buy` 買 、 `Sell` 賣 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 (string) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 (BSAction) price_type: Limit, # 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 (FutOptPriceType) price: 2230, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC (TimeInforce) order_type: New, # 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 50, # 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、`9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 (int) after_price_type: None, # 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 (FutOptPriceType) after_price: 2230, # 有效委託價格 (float) after_lot: 1, # 有效委託口數 (int) filled_lot: 1, # 成交口數 (int) filled_money: 2230, # 成交價金 (float) before_lot: None, # 改單前有效口數 (int) before_price: None, # 改單前有效價 (float) user_def: None, # 自訂欄位 (string) last_time: "10:41:46.760", # 最後異動時間 (string) error_message: None # 錯誤訊息 (string) }, ... #更多的Result回傳 ]} ``` --- ### 建立委託單 place\_order #### 輸入參數[​](#輸入參數 "Direct link to 輸入參數") | 參數 | 類別 | 說明 | | ------------- | ----------------------------------------------------------------------------------------------------------- | -------------- | | account | [Account](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#account) | 帳號 | | order\_object | [OrderObject](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#orderobject) | 委託內容 | | unblock | bool (optional) (default = False) | 是否採用非阻塞 | #### Result 回傳[​](#result-回傳 "Direct link to Result 回傳") | 參數 | 類別 | 說明 | | ----------- | ----------------- | ---------------------------------- | | is\_success | bool | 是否成功 | | data | FutOptOrderResult | 回傳委託資訊 | | message | string | 當is\_success = false 回傳錯誤訊息 | ##### 委託資訊 FutOptOrderResult 欄位[​](#委託資訊-futoptorderresult-欄位 "Direct link to 委託資訊 FutOptOrderResult 欄位") Return type : Object | 參數 | 類別 | 說明 | | ------------------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | function\_type | int | 功能別 : `0` 新單 、`10` 新單執行、 `15` 改價、 `20` 改量、`30`刪單 、`90`失敗 | | date | string | 交易日期 | | seq\_no | string | 委託單流水序號 | | branch\_no | string | 分公司代號 | | account | string | 帳號 | | order\_no | string | 委託書號 | | asset\_type | int | 資產類別 : `1` 期貨 、`2` 選擇權 | | market | string | 市場類型 : `TAIMEX` 期貨、選擇權 | | market\_type | [FutOptMarketType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptmarkettype) | 盤別種類 : `Future` 期貨日盤 、 `Option` 選擇權日盤 、 `FutureNight` 期貨夜盤 、 `OptionNight` 選擇權夜盤 | | unit | int | 單位數 | | currency | string | 幣別 | | symbol | string | 商品代號 | | expiry\_date | string | 到期日 | | strike\_price | float | 履約價 | | call\_put | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 : `Call` 買權、 `Put` 賣權 | | buy\_sell | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 : `Buy` 買 、 `Sell` 賣 | | symbol\_leg2 | string | 商品代號 - 複式第二隻腳 | | expiry\_date\_leg2 | string | 到期日 - 複式第二隻腳 | | strike\_price\_leg2 | float | 履約價 - 複式第二隻腳 | | call\_put\_leg2 | [CallPut](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#callput) | 買賣權 - 複式第二隻腳 : `Call` 買權、 `Put` 賣權 | | buy\_sell\_leg2 | [BSAction](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#bsaction) | 買賣別 - 複式第二隻腳: `Buy` 買 、 `Sell` 賣 | | price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 原始委託價格別 : `Limit` 限價 、 `Market` 市價 、 `RangeMarket` 範圍市價、`Reference` 參考價 | | price | float | 價格 | | lot | int | 原始委託股口數 | | time\_in\_force | [TimeInforce](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#timeinforce) | 委託條件別 : `ROD` ROD 、 `FOK` FOK 、 `IOC` IOC | | order\_type | [FutOptOrderType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptordertype) | 委託單類型 : `New` 新倉 、 `Close` 平倉 、 `Auto` 自動 、 `FdayTrade` 當沖 | | is\_pre\_order | bool | 是否為預約單 | | status | int | 委託單狀態 : `0` 預約單 、 `4` 中台收到委託 、 `8` 後台傳送中 、 `9` 後台連線逾時 、`10` 委託成功 、 `30`刪單成功 、 `50` 完全成交 、 `90` 失敗 | | after\_price\_type | [FutOptPriceType](https://www.fbs.com.tw/TradeAPI/docs/trading-future/library/python/EnumMatrix.md#futoptpricetype) | 有效委託價格別 : `Limit` 限價 、 `Market` 市價 、`RangeMarket` 範圍市價、 `Reference` 參考價 | | after\_price | float | 有效委託價格 | | after\_lot | int | 有效委託口數 | | filled\_lot | int | 成交口數 | | filled\_money | float | 成交價金 | | before\_lot | int | 改單前有效口數 | | before\_price | float | 改單前有效價 | | user\_def | string | 自訂欄位 | | last\_time | string | 最後異動時間 | | detail | list | 委託歷程 (查詢order\_result\_detail or order\_history才有值) | | error\_message | string | 錯誤訊息 | #### 請求範例[​](#請求範例 "Direct link to 請求範例") ```py # 單式 order = FutOptOrder( buy_sell = BSAction.Buy, symbol = "TXO20000E4", price = "530", lot = 1, market_type = FutOptMarketType.Option, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "From_Py" # optional field ) sdk.futopt.place_order(account, order) # 複式單 order = FutOptOrder( buy_sell = BSAction.Sell, symbol = "TXO20000E4", buy_sell2 = BSAction.Buy, symbol2 = "TXO19900E4", price = "90", lot = 1, market_type = FutOptMarketType.Option, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.IOC, order_type = FutOptOrderType.Auto, user_def = "From_Py" # optional field ) sdk.futopt.place_order(account, order) ``` #### 回傳範例[​](#回傳範例 "Direct link to 回傳範例") ```py Result { #單式回覆 is_success: True, message: None, data : FutOptOrderResult { function_type: 0, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00230177010", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0002", # 委託書號 (string) asset_type: 2, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Option, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "TXO", # 商品代號 (string) expiry_date: "202404", # 到期日 (string) strike_price: 20000, # 履約價 (float) call_put: Call, # 買賣權 (CallPut) buy_sell: Buy, # 買賣別 (BSAction) symbol_leg2: None, # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: None, # 到期日 - 複式第二隻腳 (string) strike_price_leg2: None, # 履約價 - 複式第二隻腳 (float) call_put_leg2: None, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: None, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 530, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: ROD, # 委託條件別 (TimeInforce) order_type: Auto, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 530, # 有效委託價格 (float) after_lot: 1, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 0, # 改單前有效股口數 (int) before_price: 530, # 改單前有效價格 (float) user_def: "From_Py", # 自訂欄位 (string) last_time: "11:50:08", # 最後異動時間 (string) details: None, # 委託歷程 (list) error_message: None # 錯誤訊息 (string) }} Result { #複式回覆 is_success: True, message: None, data : FutOptOrderResult { function_type: 0, # 功能別 (int) date: "2024/03/25", # 交易日期 (string) seq_no: "00230177020", # 委託單流水序號 (string) branch_no: "15901", # 分公司代號 (string) account: "1234567", # 帳號 (string) order_no: "C0004", # 委託書號 (string) asset_type: 2, # 資產類別 (int) market: "TAIMEX", # 市場類型 (string) market_type: Option, # 盤別種類 (FutOptMarketType) unit: 1, # 單位數 (int) currency: "TWD", # 幣別 (string) symbol: "TXO", # 商品代號 (string) expiry_date: "202405", # 到期日 (string) strike_price: 20000, # 履約價 (float) call_put: Call, # 買賣權 (CallPut) buy_sell: Sell, # 買賣別 (BSAction) symbol_leg2: "TXO", # 商品代號 - 複式第二隻腳 (string) expiry_date_leg2: "202405", # 到期日 - 複式第二隻腳 (string) strike_price_leg2: 19900, # 履約價 - 複式第二隻腳 (float) call_put_leg2: Call, # 買賣權 - 複式第二隻腳 (CallPut) buy_sell_leg2: Buy, # 買賣別 - 複式第二隻腳 (BSAction) price_type: Limit, # 原始委託價格別 (FutOptPriceType) price: 90, # 價格 (float) lot: 1, # 原始委託股口數 (int) time_in_force: IOC, # 委託條件別 (TimeInforce) order_type: New, # 委託單類型 (FutOptOrderType) is_pre_order: False, # 是否為預約單 (bool) status: 10, # 委託單狀態 (int) after_price_type: Limit, # 有效委託價格別 (FutOptPriceType) after_price: 90, # 有效委託價格 (float) after_lot: 1, # 有效委託股口數 (int) filled_lot: 0, # 成交股口數 (int) filled_money: 0, # 成交價金 (int) before_lot: 0, # 改單前有效股口數 (int) before_price: 90, # 改單前有效價格 (float) user_def: "From_Py", # 自訂欄位 (string) last_time: "11:57:41", # 最後異動時間 (string) error_message: None # 錯誤訊息 (string) }} ``` --- ### 事前準備 caution 在開始富邦新一代 API 前,您必須完成以下步驟 1. 準備好您的富邦期貨帳戶 (若您還未擁有富邦期貨帳戶,請點連結[線上開戶](https://www.fubon.com/futures/home/account/e_open/e_open.html)) 2. 簽署 API 風險使用聲明書 3. 申請憑證 #### 準備好富邦期貨帳戶[​](#準備好富邦期貨帳戶 "Direct link to 準備好富邦期貨帳戶") 使用您的富邦期貨帳戶 ![富邦期貨帳號](/TradeAPI/assets/images/prepare_account-792b5d9a17005ebde0e7d7050b37bb5c.png) #### 簽署 API 使用風險暨聲明書[​](#簽署-api-使用風險暨聲明書 "Direct link to 簽署 API 使用風險暨聲明書") 請使用手機`富邦e點通` 或 使用電腦版 `E+`進行API 線上簽署 ###### 完成簽署[​](#完成簽署 "Direct link to 完成簽署") 恭喜您,已簽署完成使用風險暨聲明書 #### 申請憑證[​](#申請憑證 "Direct link to 申請憑證") 至[憑證申請、展期](https://www.fbs.com.tw/Certificate/Management/)點選立即執行下載富邦證券憑證e總管(TCEM.exe)申請憑證 ![Certificate apply](/TradeAPI/assets/images/ca_navigator-8ddb522e5c70f747eb5a534d53864247.png) 登入完成並且認證後,輸入手機或電子信箱收取OTP驗證 ![OTP](/TradeAPI/assets/images/ca_cover-3de617d54b6dfac697be7cae07ea3260.png) 完成申請,憑證將存放於 C:\CAFubon\\(您的身分證字號),並以您的身份證字號為檔名 ![CertLocation](/TradeAPI/assets/images/ca_repo-829d506640c176e4a8fc1b84c13b2908.png) #### 安裝與版本相容性[​](#安裝與版本相容性 "Direct link to 安裝與版本相容性") 安裝步驟與最低版本需求請見[安裝與版本相容性](https://www.fbs.com.tw/TradeAPI/docs/install-compatibility.md),下載 SDK 請至[SDK 下載頁面](https://www.fbs.com.tw/TradeAPI/docs/download/download-sdk.md)。 #### 開始拓展程式交易之旅[​](#開始拓展程式交易之旅 "Direct link to 開始拓展程式交易之旅") * Python * Node.js * C# ```python from fubon_neo.sdk import FubonSDK, FutOptOrder from fubon_neo.constant import TimeInForce, FutOptOrderType, FutOptPriceType, FutOptMarketType, CallPut, BSAction #載入設定檔與登入 sdk = FubonSDK() accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置" , "您的憑證密碼") ## accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置") # 若憑證選用"預設密碼", SDK v1.3.2與較新版本適用 acc = accounts.data[0] #建立委託物件 order = FutOptOrder( buy_sell = BSAction.Sell, symbol = "TXFD4", price = "20800", lot = 3, market_type = FutOptMarketType.Future, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "Python" # optional field ) # 下單 order_res = sdk.futopt.place_order(acc, order) print(order_res) ``` 恭喜您🎊,完成下單,即可看到系統回覆的結果 ```python Result { is_success: True, message: None, data : FutOptOrderResult{ function_type: 0, date : "2023/10/13", seq_no : "00000000016", branch_no : "6460", account : "26", order_no : "bA627", asset_type : 1, market : "TAIMEX", market_type : Future, symbol : "FITX", unit : 1 , currency : "TWD", expiry_date : "202404", strike_price : , call_put : , buy_sell : Buy , price_type : Limit, price : 20800, lot : 3, time_in_force : ROD, order_type : Auto, is_pre_order : False, status : 10, after_price_type : Limit, afterPrice : 20800, after_lot : 2000, filled_lot : 0, filled_money : 0, ... , user_def : "From Pyhton", last_time : "12:19:06.048", error_message : } } ``` ```js const { FubonSDK, TimeInForce, FutOptOrderType, FutOptPriceType, FutOptMarketType, CallPut, BSAction } = require('fubon-neo'); // 載入設定檔與登入 const sdk = new FubonSDK(); const accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼"); // const accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置"); // 若憑證選用"預設密碼", SDK v1.3.2與較新版本適用 const acc = accounts.data[0]; // 建立委託物件 const order = { buySell: BSAction.Buy, symbol: TXFD4, price: "20800", lot: 3, marketType: FutOptMarketType.Future, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutOptOrderType.Auto, userDef: "from Js" }; // 下單 sdk.futopt.placeOrder(acc,order); ``` 恭喜您🎊 ,完成下單,即可看到系統回覆的結果 ```js { isSuccess: true, data:{ functionType : 0, date : '2023/10/13', seqNo : '00000000016', branchNo : '6460', account : '26', orderNo : 'bA627', assetType : 1, market : 'TAIMEX', marketType : Future, symbol : 'FITX', unit : 1 , currency : 'TWD', expiryDate : '202404' , buySell : Buy , priceType : Limit, price : 20800, lot : 3, timeInForce : ROD, orderType : Auto, isPreOrder : False, status : 10, afterPriceType : Limit, afterPrice : 20800, afterLot : 3, filledLot : 0, filledMoney : 0, ... , userDef : 'From JS', lastTime : '12:19:06.048', errorMessage : } } ``` ```cs using FubonNeo.Sdk; //載入設定檔與登入 var sdk = new FubonSDK(); var acc_obj = sdk.Login("您的身分證號", "您的登入密碼", "您的憑證路徑" ,"您的憑證密碼"); /* // 若憑證選用"預設密碼", SDK v1.3.2 與較新版本適用 var acc_obj = sdk.Login("您的身分證號", "您的登入密碼", "您的憑證路徑"); */ var acc = acc_obj.data[0]; //建立委託物件 var order = new FutOptOrder( BsAction.Buy, "TXFD4", "20800", 3, FutOptMarketType.Future, FutOptPriceType.Limit, TimeInForce.Rod, FutOptOrderType.Auto, "From C#" ); // 下單 var order_res = sdk.FutOpt.PlaceOrder(acc, order); Console.WriteLine(order_res); ``` 恭喜您🎊,完成下單,即可看到系統回覆的結果 ```cs { isSuccess = True, message = , data = FutOptOrderResult{functionType: 0, date = 2023/10/13, seqNo = 00000000016, branchNo = 6460, account = 26, orderNo = bA627, assetType = 1, market = TAIMEX, marketType = Future, symbol = FITX, unit = 1 , currency = TWD, expiryDate = 202404, strikePrice = , callPut = , buySell = Buy , priceType = Limit, price = 20800, lot = 3, timeInForce = ROD, orderType = Auto, isPreOrder = False, status = 10, afterPriceType = Limit, afterPrice = 66, afterLot = 2000, filledLot = 0, filledMoney = 0, ... , userDef = From C#, lastTime = 12:19:06.048, errorMessage = } } ``` --- ### 快速開始 請先參考[事前準備](https://www.fbs.com.tw/TradeAPI/docs/trading-future/prepare.md)完成風險預告書申請與憑證下載。 #### 安裝與版本相容性[​](#安裝與版本相容性 "Direct link to 安裝與版本相容性") 安裝步驟與最低版本需求請見[安裝與版本相容性](https://www.fbs.com.tw/TradeAPI/docs/install-compatibility.md),下載 SDK 請至[SDK 下載頁面](https://www.fbs.com.tw/TradeAPI/docs/download/download-sdk.md)。 ##### 並將憑證放置您的資料夾結構應該像是: ```text . └── XXXXXXXXXX.pfx ``` ##### [​](#-1 "Direct link to -1") * Python * Node.js * C# 若您未曾使用 SDK 進行過登入,或更換了 SDK 執行環境,請在資料夾新增一個 `index.py` 檔案,貼上以下內容並執行: ```python from fubon_neo.sdk import FubonSDK, FutOptOrder from fubon_neo.constant import TimeInForce, FutOptOrderType, FutOptPriceType, FutOptMarketType, CallPut, BSAction sdk = FubonSDK() accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證位置", "您的憑證密碼") #若有歸戶,則會回傳多筆帳號資訊 ## accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置") # 若憑證選用"預設密碼", SDK v1.3.2與較新版本適用 acc = accounts.data[0] ``` 若您未曾使用 SDK 進行過登入,或更換了 SDK 執行環境,請在資料夾新增一個 `index.js` 檔案,貼上以下內容並執行: ```js const { FubonSDK, TimeInForce, FutOptOrderType, FutOptPriceType, FutOptMarketType, CallPut, BSAction } = require('fubon-neo'); const sdk = new FubonSDK(); const accounts = sdk.login("您的身分證字號", "您的登入密碼", "您的憑證路徑" ,"您的憑證密碼"); // const accounts = sdk.login("您的身分證號", "您的登入密碼", "您的憑證路徑位置"); // 若憑證選用"預設密碼", SDK v1.3.2與較新版本適用 const acc = accounts.data[0]; ``` 若您未曾使用 SDK 進行過登入,或更換了 SDK 執行環境,請在資料夾新增一個 `index.cs` 檔案,貼上以下內容並執行: ```cs using FubonNeo.Sdk; var sdk = new FubonSDK(); var accounts = sdk.Login("您的身分證字號", "您的登入密碼", "您的憑證路徑", "您的憑證密碼"); // 若有歸戶,則會回傳多筆帳號資訊 /* // 若憑證選用"預設密碼", SDK v1.3.2 與較新版本適用 var acc_obj = sdk.Login("您的身分證號", "您的登入密碼", "您的憑證路徑"); */ var acc = accounts.data[0]; ``` #### 送出委託,買入股票[​](#送出委託買入股票 "Direct link to 送出委託,買入股票") 再將以下範例程式碼補上, 將示範如何使用富邦新一代 API 送出一張以跌停價買入 富邦金(2881)的限價委託: * Python * Node.js * C# ```py order = FutOptOrder( buy_sell = BSAction.Sell, symbol = "TXFD4", price = "20800", lot = 3, market_type = FutOptMarketType.Future, price_type = FutOptPriceType.Limit, time_in_force = TimeInForce.ROD, order_type = FutOptOrderType.Auto, user_def = "Python" # optional field ) sdk.futopt.place_order(acc, order) ``` ```js const order = { buySell: BSAction.Buy, symbol: "TXFD4", price: "20800", lot: 3, marketType: FutOptMarketType.Future, priceType: FutOptPriceType.Limit, timeInForce: TimeInForce.ROD, orderType: FutOptOrderType.Auto, userDef: "from Js" }; sdk.futopt.placeOrder(acc,order); ``` ```cs var order = new FutOptOrder( BsAction.Buy, "TXFD4", null, // 複式單第二隻腳 買賣別 null, // 複式單第二隻腳 商品 "20800", 3, FutOptMarketType.Future, FutOptPriceType.Limit, TimeInForce.Rod, FutOptOrderType.Auto, "From C#" ); sdk.FutOpt.PlaceOrder(acc, order); ``` --- ### 速率限制 ##### 連線次數限制[​](#連線次數限制 "Direct link to 連線次數限制") | 行為 | 上限數 | | ------ | ------ | | 連線數 | 10 | 當連線超過上限,登入時將收到以下訊息 : ```json Result { is_success: False, message: Login Error, 超過本應用程式連線限制==>[10] data: None } ``` | 行為 | 每秒上限數 | | -------- | ---------- | | 下單 | 50 | | 批次下單 | 10 | | 帳務查詢 | 5 | 當次數超過上限,將收到以下訊息 : ```json Result { is_success: False, message: Login Error, 業務系統流量控管 data: None } ``` --- ### 富邦新一代 API 快速上手 *** 本頁重點 * 本頁提供富邦新一代 API(Fubon Neo API)快速上手流程與資源入口。 * 開始前需完成:開戶、憑證申請、API 使用聲明與連線測試。 * 提供 Python / C# / JavaScript 範例程式下載與社群資源。 * 下一步請先完成[事前準備](https://www.fbs.com.tw/TradeAPI/docs/trading/prepare.md)。 | 項目 | 說明 | | -------- | -------------------------------------------------------------------------- | | 產品 | 富邦新一代 API(Fubon Neo API) | | 主要受眾 | 程式交易開發者 | | 必要前置 | 開戶、憑證申請、API 使用聲明 + 連線測試 | | 支援語言 | Python / C# / JavaScript (Node.js) / C++、Go(僅支援證券交易帳務及條件單) | | 相關資源 | 範例程式、測試環境、社群 | 行前小提醒 在開始新一代 API 的旅程之前,您必須完成以下步驟 1. 至【[事前準備](https://www.fbs.com.tw/TradeAPI/docs/trading/prepare.md)】完成三步驟 **a. 開戶 b.電子交易憑證申請 c. 簽署 API 使用聲明+連線測試** 2. 選定欲使用的程式語言,並參考本頁對應之【[範例程式](#code_sample)】 3. 加入【[Discord群組](https://discord.com/invite/M8Gv9yKfza)】獲取更多程式交易資源,解決您的疑難雜症 #### 環境建置與範例程式[​](#環境建置與範例程式 "Direct link to 環境建置與範例程式") 環境建置僅為建議並無強制,若已有熟悉之開發環境可以直接開始執行範例程式 ##### 環境建置[​](#環境建置 "Direct link to 環境建置") [Python安裝與使用教學](https://www.youtube.com/embed/XQo8d4-WsIg?si=Aq7l1Br0S5nqPE_m) ##### 範例程式[​](#code_sample "Direct link to 範例程式") 行前小提醒 以下僅為範例程式原始碼,SDK需另行下載安裝 PYTHON 範例程式碼 * **API 功能使用範例:** * [Python 範例程式碼](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/python_sample_code.zip) (.ipynb, Jupyter 互動開發格式) * **情境式範例:** * [盤中搶漲停](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/win_for_limitup.zip) * [盤前搶券](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/win_for_short_sell.zip) * [盤前限價單開盤轉市價](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/limit_to_market.zip) * [庫存停損停利](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/inventory_stop_loss.zip) C# 範例程式碼 * **API 功能使用範例:** * [C# 範例程式碼](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/fubondotnetsdkgui.zip) (WPF 專案) * [C# 行情及帳務範例程式碼](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/marketdata_n_accounting.zip) (Windows Forms 專案) * **情境式範例:** * [盤前限價單開盤轉市價 ](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/limit_to_market.zip)(Windows Forms 專案) JAVASCRIPT 範例程式碼 * **API 功能使用範例:** * [JS 範例程式碼](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/js_sample_code.zip) (.ipynb, Jupyter 互動開發格式) #### 測試環境[​](#測試環境 "Direct link to 測試環境") 新一代 API 開放使用測試環境,請下載測試環境說明包: [下載測試環境說明包](https://www.fbs.com.tw/TradeAPI_SDK/sample_code/test_environment.zip)

註1. 目前暫僅提供證券測試帳號
註2. 若有任何使用上的疑問,可來信至富邦證券程式交易PM信箱 ****** 洽詢 #### 更多資源[​](#更多資源 "Direct link to 更多資源") 富邦證券程式交易線上講座 【[不定期線上講座報名](https://www.fbs.com.tw/Course/Main;areaID=F)】每月都會有不定期的程式交易線上講座,內容涵蓋選股到API 交易程式開發 GITHUB教學範例 包含多種由新一代 API Python開發的常見交易圖形化介面應用程式範例,歡迎參考【[GitHub教學範例](https://github.com/Tradepm/-API)】 YOUTUBE程式交易頻道 新一代 API 的大小事及教學留影都在【[富邦證券YouTube](https://youtube.com/playlist?list=PLm7R8dzlvMHd6LonqpQHoIS6ga0d5fdpp\&si=NrJt2fEl0kgXS_NG)】程式交易頻道,幫您快速入門程式交易 DISCORD程式交易討論 開發程式交易工具卡住了嗎?快到【[Discord](https://discord.com/invite/M8Gv9yKfza)】留言您的疑難雜症,從入門到進階都有專人幫忙 --- ### 以 LLM 輔助開發 你可以使用大型語言模型(LLMs)來協助建置富邦新一代 API 的整合。
我們提供了以下應用,協助你在開發過程中使用 LLM。 #### 純文字文件(Plain text docs)[​](#純文字文件plain-text-docs "Direct link to 純文字文件(Plain text docs)") 我們提供 [llms.txt](https://www.fbs.com.tw/TradeAPI/llms.txt) 檔案,用於指引 AI 工具與代理如何取得我們頁面的純文字版本。 `/llms.txt` 是一項新興標準,旨在讓網站與內容更容易被 LLM 存取與使用。 * [llms.txt](https://www.fbs.com.tw/TradeAPI/llms.txt) * [llms-full.txt](https://www.fbs.com.tw/TradeAPI/llms-full.txt) ---