主動回報範例(標準版)
以下列舉主動回報範例,包含阻塞式 (non-async, unblock=False) 及 非阻塞式 (async, unblock=True) 功能
( 關於阻塞式與非阻塞式功能,請參考 非阻塞 下單 )
caution
此文件僅提供常見使用場景對應範例,不保證包含所有例外情況
單筆下單
單筆新單
阻塞式 (non-async, unblock=False)
-
下單成功
-
主動回報(一筆):
下單成功,status 顯示為 10
==下單主動回報==
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):
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,
}
}
-
-
下單失敗
-
主動回報(一筆):
下單異常,status 顯示為 90
==下單主動回報==
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):
下單失敗,無委託單資料回傳
Result {
is_success: False,
message: 單價輸入錯誤[4385715],
data: None
}
-
非阻塞 (async, unblock=True)
-
下單成功
-
主動回報( 三筆):
第一筆為ACK,表示系統將執行請求(status 4),第二筆表示後台準備送單(status 8),此時皆無 order_no(尚未確認下單成功),可用 seq_no 進行後續比對;最後確認下單狀態(成功為 status 10)
==下單主動回報==
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,
}
==========下單主動回報==
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,
}
==========下單主動回報==
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)
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,
}
}
-
-
下單失敗
-
主動回報(三筆):
第一筆為ACK,表示系統將執行請求(status 4),第二筆表示後台準備送單(status 8),此時皆無 order_no(尚未確認下單成功),可用 seq_no 進行後續比對;最後確 認下單狀態(異常為 status 90)
==下單主動回報==
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,
}
==========下單主動回報==
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,
}
==========下單主動回報==
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)
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,
}
}
-