主動回報範例(輕量風控版)
輕量風控為大戶下單服務,需另外申請開通,詳情請洽所屬營業員
以下列舉主動回報範例,包含阻塞式 (non-async, unblock=False) 及 非阻塞式 (async, unblock=True) 功能
( 關於阻塞式與非阻塞式功能,請參考 非阻塞下單 )
此文件僅提供常見使用場景對應範例,不保證包含所有例外情況
單筆下單
單筆新單
阻塞式 (non-async, unblock=False)
-
下單成功
-
主動回報(兩筆):
第一筆 status 顯示為 8,表示後台準備送出委託單;第二筆 status 顯示為 10,下單成功
==下單主動回報==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,}==========下單主動回報==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):
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,}}
-
-
下單失敗
-
主動回報(兩筆):
第一筆 status 顯示為 8,表示後 台準備送出委託單;第二筆 status 顯示為 90,下單異常
==下單主動回報==內容 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,}==========下單主動回報==內容 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):
下單失敗,無委託單資料回傳
Result {is_success: False,message: 超過跌停價,data: None}
-
非阻塞 (async, unblock=True)
-
下單成功
-
主動回報(三筆):
第一筆為ACK,表示系統將執行請求(status 4),第二筆表示後台準備送單(status 8),此時皆無 order_no(尚未確認下單成功),可用 seq_no 進行後續比對;最後確認下單狀態(成功為 status 10)
==下單主動回報==內容 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,}==========下單主動回報==內容 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,}==========下單主動回報==內容 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)
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,}}
-
-
下單失敗
-
主動回報(三筆):
第一筆為ACK,表示系統將執行請求(status 4),第二筆表示後台準備送單(status 8),此時皆無 order_no(尚未確認下單成功),可用 seq_no 進行後續比對;最後確認下單狀態(失敗為 status 90)
==下單主動回報==內容 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,}==========下單主動回報==內容 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,}==========下單主動回報==內容 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)
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,}}
-
修改委託單價格
改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報
阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到該筆回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳
阻塞
-
改價成功
-
主動回報(兩筆):
改價 function_type 15,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10
==改單主動回報==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,}==========改單主動回報==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):
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,}}
-
-
改價失敗
-
主動回報(兩筆):
第一筆系統將執行請求 status 4;第二筆改價失敗回報 status 19
info此範例由後台 擋回請求,因此有 status 4
==改單主動回報==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,}==========改單主動回報==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):
改價失敗,無委託單資料回傳
Result {is_success: False,message: 超過漲停價,data: None}
-
非阻塞
-
改價成功
-
主動回報(兩筆):
改價 function_type 15,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10
==改單主動回報==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,}==========改單主動回報==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)即回傳
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,}}
-
-
改價失敗
-
主動回報(一筆):
改價失敗 status 19
info此範例由系統直接擋回請求,因此無 status 4
==改單主動回報==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):
改價失敗,無委託單資料回傳
Result {is_success: False,message: 證券改價限價格格和原價格相同==>[00098000025],data: None}
-
修改委託單數量
改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報
阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到該筆回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳
阻塞
-
改量成功
-
主動回報(兩筆):
改量 function_type 20,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10
==改單主動回報==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,}==========改單主動回報==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):
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,}}
-
-
改量失敗
-
主動回報(一筆):
改量 function_type 20,回報失敗 status 29 (由系統直接擋回請求,因此無 status 4)
==改單主動回報==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):
改量失敗,無委託單資料回傳
Result {is_success: False,message: 證券減量使用剩餘數量大於有效單位數量==>[00098000025],data: None}
-
非阻塞
-
改量成功
-
主動回報(兩筆):
改量 function_type 20,回報第一筆為系統將執行請求(status 4);第二筆改價成功 status 10
==改單主動回報==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,}==========改單主動回報==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) 即回傳
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,}}
-
-
改量失敗
-
主動回報(一筆):
改量 function_type 20,回報失敗 status 29 (由系統直接擋回請求,因此無 status 4)
==改單主動回報==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):
改量失敗,無委託單資料回傳
response: Result {is_success: False,message: 證券減量使用剩餘數量大於有效單位數量==>[00098000025],data: None}
-
刪除委託單
若委託單已部分成交, 刪單成功狀態代碼為 40, 其餘為 30
改單無論使用阻塞模式或非阻塞模式,若由系統擋單(例如改價同原委託價),無 status 4 回報(表示系統將執行請求);若由後台擋單(例如超過漲跌停價),則有 status 4 回報
阻塞模式與非阻塞模式差異為,若有 status 4 回報時(系統向後送單),非阻塞模式之函式收到該筆回報即回傳,而阻塞模式之函式將等到最終成功或失敗確認才回傳
阻塞
-
刪單成功
-
主動回報(兩筆):
刪單 function_type 30,回報第一筆為系統將執行請求(status 4);第二筆刪單成功 status 30 (若已有部分成交 status 40)
==改單主動回報==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,}==========改單主動回報==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):
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,}}
-
-
刪單失敗
-
主動回報(一筆):
刪單 function_type 30,回報刪單失敗 status 39 (由系統直接擋回請求,因此無 status 4)
==改單主動回報==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):
刪單失敗,無委託單資料回傳
Result {is_success: False,message: 證券委託目前狀態部分成交單已不允許取消交易,data: None}
-
非阻塞
-
刪單成功
-
主動回報(兩筆):
刪單 function_type 30,回報第一筆為系統將執行請求(status 4);第二筆刪單成功 status 30 (若已有部分成交 status 40)
==改單主動回報==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,}==========改單主動回報==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)
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,}}
-
-
刪單失敗
-
主動回報(一筆):
刪單 function_type 30,回報刪 單失敗 status 39 (由系統直接擋回請求,因此無 status 4)
==改單主動回報==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):
刪單失敗,無委託單資料回傳
Result {is_success: False,message: 證券委託目前狀態取消單已不允許取消交易,data: None}
-
批次下單
批次功能由系統收到請求後以多線程 (threads) 方式運作
後續批次範例以下委託單列表為例:
[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",
}]
新委託單下單
-
主動回報(六筆):
包含三筆後台準備送出委託單回報(status 8);三筆下單成功確認(status 10)
==下單主動回報==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,}==========下單主動回報==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,}==========下單主動回報==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,}==========下單主動回報==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,}==========下單主動回報==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,}==========下單主動回報==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) 進行比對
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,}]}
修改委託單價格
委託單列表中不可含市價單,若含市價單則整批請求不執行,並回傳錯誤訊息
-
主動回報(四筆,此處無納入市價委託單):
兩筆 ACK (status 4);兩筆確認 status 10
==改單主動回報==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,}==========改單主動回報==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,}==========改單主動回報==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,}==========改單主動回報==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)
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,}]}