Skip to content

期貨選擇權

提醒

下單前必須先登入及啟用憑證

期貨委託單

期貨委託單

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
    };