主動回報範例(輕量風控版)
輕量風控為大戶下單服務,需另外申請開通,詳情請洽所屬營業員
以下列舉主動回報範例,包含阻塞式 (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,
}
}
-
-
改量失敗