期貨選擇權
期貨委託單¶
期貨委託單
price (float or int): 價格
quantity (int): 委託數量
action (str): {Buy: 買, Sell: 賣}
price_type (str): {LMT: 限價, MKT: 市價, MKP: 範圍市價}
order_type (str): 委託類別 {ROD, IOC, FOK}
octype (str): {Auto: 自動, New: 新倉, Cover: 平倉, DayTrade: 當沖}
account (:obj:Account): 下單帳號
ca (binary): 憑證
下單¶
下單時必須提供商品資訊contract
及下單資訊order
。
商品檔
var contract = _api.Contracts.Futures["TXO"]["TXO20230310600P"];
委託單
var order = new FutOptOrder()
{
action=Action.Buy,
price=0.1,
quantity=3,
price_type=FuturesPriceType.LMT,
order_type=OrderType.ROD,
octype=OCType.Auto,
}
var order = new FutOptOrder()
{
action=Action.Buy,
price=0.1,
quantity=3,
price_type=FuturesPriceType.LMT,
order_type=FuturesOrderType.ROD,
octype=OCType.Auto,
}
下單
_trade = _api.PlaceOrder(contract, order)
Console.WriteLine(_trade)
Out
{
contract={
security_type=OPT,
code=TXO10600O3,
category=TXO,
symbol=TXO20230310600P,
exchange=TAIFEX,
delivery_month=202303,
strike_price=10600,
option_right=P,
underlying_kind=I,
limit_up=1550,
limit_down=0.1,
reference=0.3,
update_date=2023/02/21,
name=臺指選擇權03月 10600P
},
order={
action=Buy,
price=0.1,
quantity=3,
price_type=LMT,
order_type=ROD,
order_lot=Common,
order_cond=Cash,
daytrade_short=false,
id=a0df16d5,
seqno=564801,
account={
account_type=F,
person_id=,
broker_id=F002000,
account_id=,
signed=True,
username=
}, ca=
},
status={
id=a0df16d5,
status=PendingSubmit,
status_code= ,
order_ts=1676946129.0,
modified_ts=0,
modified_price=0,
deal_quantity=0,
cancel_quantity=0
}
}
下單完同時也會收到從交易所傳回來的資料,詳情內容可詳見下單回報。
您需要執行UpdateStatus
已更新trade
物件的狀態。
更新委託狀態
_api.UpdateStatus(_api.FutureAccount)
Console.WriteLine(_trade)
Out
{
contract={
security_type=OPT,
code=TXO10600O3,
category=TXO,
symbol=TXO20230310600P,
exchange=TAIFEX,
delivery_month=202303,
strike_price=10600,
option_right=P,
underlying_kind=I,
limit_up=1550,
limit_down=0.1,
reference=0.3,
update_date=2023/02/21,
name=臺指選擇權03月 10600P
},
order={
action=Buy,
price=0.1,
quantity=3,
price_type=LMT,
order_type=ROD,
order_lot=Common,
order_cond=Cash,
daytrade_short=false,
id=a0df16d5,
seqno=564801,
account={
account_type=F,
person_id=,
broker_id=F002000,
account_id=,
signed=True,
username=
}, ca=
},
status={
id=a0df16d5,
status=Submitted,
status_code= ,
order_ts=1676946129.0,
modified_ts=0,
modified_price=0,
deal_quantity=0,
cancel_quantity=0
}
}
委託單狀態
PendingSubmit
: 傳送中PreSubmitted
: 預約單Submitted
: 傳送成功Failed
: 失敗Cancelled
: 已刪除Filled
: 完全成交Filling
: 部分成交
改單¶
改價¶
In
_trade = _api.UpdateOrder(_trade, price:0.2);
_api.UpdateStatus();
Console.WriteLine(_trade);
Out
{
contract={
security_type=OPT,
code=TXO10600O3,
category=TXO,
symbol=TXO20230310600P,
exchange=TAIFEX,
delivery_month=202303,
strike_price=10600,
option_right=P,
underlying_kind=I,
limit_up=1550,
limit_down=0.1,
reference=0.3,
update_date=2023/02/21,
name=臺指選擇權03月 10600P
},
order={
action=Buy,
price=0.2,
quantity=3,
price_type=LMT,
order_type=ROD,
order_lot=Common,
order_cond=Cash,
daytrade_short=false,
id=a0df16d5,
seqno=564801,
account={
account_type=F,
person_id=,
broker_id=F002000,
account_id=,
signed=True,
username=
}, ca=
},
status={
id=a0df16d5,
status=Submitted,
status_code= ,
order_ts=1676946129.0,
modified_ts=0,
modified_price=0.2,
deal_quantity=0,
cancel_quantity=0
}
}
改量(減量)¶
UpdateOrder
只能用來減少原委託單的委託數量。
In
_trade = _api.UpdateOrder(_trade, quantity:1);
_api.UpdateStatus();
Console.WriteLine(_trade);
Out
{
contract={
security_type=OPT,
code=TXO10600O3,
category=TXO,
symbol=TXO20230310600P,
exchange=TAIFEX,
delivery_month=202303,
strike_price=10600,
option_right=P,
underlying_kind=I,
limit_up=1550,
limit_down=0.1,
reference=0.3,
update_date=2023/02/21,
name=臺指選擇權03月 10600P
},
order={
action=Buy,
price=0.1,
quantity=3,
price_type=LMT,
order_type=ROD,
order_lot=Common,
order_cond=Cash,
daytrade_short=false,
id=a0df16d5,
seqno=564801,
account={
account_type=F,
person_id=,
broker_id=F002000,
account_id=,
signed=True,
username=
}, ca=
},
status={
id=a0df16d5,
status=Submitted,
status_code= ,
order_ts=1676946129.0,
modified_ts=0,
modified_price=0,
deal_quantity=0,
cancel_quantity=1
}
}
刪單¶
In
_api.UpdateStatus();
_trade = _api.CancelOrder(_trade);
_api.UpdateStatus();
Console.WriteLine(_trade.ToString());
Out
{
contract={
security_type=OPT,
code=TXO10600O3,
category=TXO,
symbol=TXO20230310600P,
exchange=TAIFEX,
limit_up=1550,
limit_down=0.1,
reference=0.3,
update_date=2023/02/21,
},
order={
action=Buy,
price=0.1,
quantity=3,
price_type=LMT,
order_type=ROD,
order_lot=Common,
order_cond=Cash,
daytrade_short=false,
id=a0df16d5,
seqno=564801,
account={
account_type=F,
person_id=,
broker_id=F002000,
account_id=,
signed=True,
username=,
},
},
status={
id=a0df16d5,
status=Cancelled,
status_code= ,
order_ts=1689120488,
modified_ts=0,
modified_price=0,
deal_quantity=0,
cancel_quantity=3,
},
}
成交¶
更新委託狀態
_api.UpdateStatus(_api.FuturesAccount);
Console.WriteLine(_trade);
Out
{
contract={
security_type=OPT,
code=TXO10600O3,
category=TXO,
symbol=TXO20230310600P,
exchange=TAIFEX,
limit_up=1550,
limit_down=0.1,
reference=0.3,
update_date=2023/02/21,
},
order={
action=Buy,
price=0.1,
quantity=3,
price_type=LMT,
order_type=ROD,
order_lot=Common,
order_cond=Cash,
daytrade_short=false,
id=a0df16d5,
seqno=564801,
account={
account_type=F,
person_id=,
broker_id=F002000,
account_id=,
signed=True,
username=,
},
},
status={
id=a0df16d5,
status=Filled,
status_code=00 ,
order_ts=1609120488,
modified_ts=0,
modified_price=0,
deal_quantity=0,
cancel_quantity=0,
deals=System.Collections.Generic.List`1[Sinopac.Shioaji.Deal],
},
}
範例¶
買賣別¶
買
var order = new FutOptOrder()
{
price = 0.1,
quantity = 3,
action = Action.Buy,
price_type = FuturePriceType.LMT,
order_type = OrderType.ROD,
octype = OCType.Auto
};
賣
var order = new FutOptOrder()
{
price = 0.1,
quantity = 3,
action = Action.Sell,
price_type = FuturePriceType.LMT,
order_type = OrderType.ROD,
octype = OCType.Auto
};
ROD + LMT¶
ROD + LMT
var order = new FutOptOrder()
{
price = 0.1,
quantity = 3,
action = Action.Sell,
price_type = FuturePriceType.LMT,
order_type = OrderType.ROD,
octype = OCType.Auto
};