Skip to content

證券

提醒

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

證券委託單

證券委託單

price (float or int): 價格
quantity (int): 委託數量
action (Action): {Buy: , Sell: }
price_type (StockPriceType): {LMT: 限價, MKT: 市價, MKP: 範圍市價}
order_type (OrderType): 委託類別 {ROD, IOC, FOK}
order_cond (StockOrderCond): {Cash:現股, MarginTrading:融資, ShortSelling:融券}
order_lot (StockOrderLot): {Common:整股, Fixing:定盤, Odd:盤後零股, IntradayOdd:盤中零股}
daytrade_short (DayTradeShort): 先賣後買 {Yes, No}
account (:obj:Account): 下單帳號  
custom_field (string): 備註
ca (binary): the ca of this order
price (float or int): 價格
quantity (int): 委託數量
action (Action): {Buy: , Sell: }
price_type (StockPriceType): {LMT: 限價, MKT: 市價, MKP: 範圍市價}
order_type (StockOrderType): 委託類別 {ROD, IOC, FOK}
order_cond (StockOrderCond): {Cash:現股, MarginTrading:融資, ShortSelling:融券}
order_lot (StockOrderLot): {Common:整股, Fixing:定盤, Odd:盤後零股, IntradayOdd:盤中零股}
first_sell (StockFirstSell): 先賣後買 {Yes, No}
account (:obj:Account): 下單帳號  
custom_field (string): 備註
ca (binary): the ca of this order

下單

下單時必須提供商品資訊contract及下單資訊order

商品檔

var contract = _api.Contracts.Stocks["TSE"]["2890"];

下單資訊

var order = new StockOrder()
    {
        price = 15.55,
        quantity = 3,
        action = Action.Buy,
        price_type = StockPriceType.LMT,
        order_type = OrderType.ROD,
        order_lot = StockOrderLot.Common,
        daytrade_short = DayTradeShort.No,
        custom_field = "Test"
    };
  var order = new StockOrder()
    {
        price = 15.55,
        quantity = 3,
        action = Action.Buy,
        price_type = StockPriceType.LMT,
        order_type = StockOrderType.ROD,
        order_lot = StockOrderLot.Common,
        daytrade_short = StockFirstSell.No,
        custom_field = "Test"
    };

下單

_trade = _api.PlaceOrder(contract, order)
Console.WriteLine(_trade)

Out

{
    contract={
        security_type=STK, 
        code=2890, 
        symbol=TSE2890, 
        exchange=TSE, 
        limit_up=19.1, 
        limit_down=15.7, 
        reference=17.4, 
        margin_trading_balance=0, 
        short_selling_balance=0, 
        update_date=2023/02/20, 
        category=17, 
        day_trade=Yes,
    }, 
    order={
        action=Buy, 
        price=15.55, 
        quantity=3, 
        price_type=LMT, 
        order_type=ROD, 
        order_lot=Common, 
        order_cond=Cash, 
        daytrade_short =false,
        id=c9854d9d, 
        seqno=024592, 
        ordno=WA036,
        custom_field=test, 
        account={
            account_type=S, 
            person_id=, 
            broker_id=9A95, 
            account_id=, 
            signed=True, 
            username=,
        },
    }, 
    status={
        id=c9854d9d, 
        status=PendingSubmit, 
        status_code=0, 
        order_ts=1608863715, 
        modified_ts=0, 
        modified_price=0, 
        deal_quantity=0, 
        cancel_quantity=0,
    },
}

下單完同時也會收到從交易所傳回來的資料,詳情內容可詳見下單回報

您需要執行UpdateStatus來更新trade物件的狀態。

更新委託狀態

_api.UpdateStatus(_api.StockAccount)
Console.WriteLine(_trade)

Out

{
    contract={
        security_type=STK, 
        code=2890, 
        symbol=TSE2890, 
        exchange=TSE, 
        limit_up=19.1, 
        limit_down=15.7, 
        reference=17.4, 
        margin_trading_balance=0, 
        short_selling_balance=0, 
        update_date=2023/02/20, 
        category=17, 
        day_trade=Yes,
    }, 
    order={
        action=Buy, 
        price=15.55, 
        quantity=3, 
        price_type=LMT, 
        order_type=ROD, 
        order_lot=Common, 
        order_cond=Cash, 
        daytrade_short =false,
        id=c9854d9d, 
        seqno=024592, 
        ordno=WA036,
        custom_field=test, 
        account={
            account_type=S, 
            person_id=, 
            broker_id=9A95, 
            account_id=, 
            signed=True, 
            username=,
        },
    }, 
    status={
        id=c9854d9d, 
        status=Submitted, 
        status_code=0, 
        order_ts=1608863715, 
        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:17.5);
_api.UpdateStatus();
Console.WriteLine(_trade);

Out

{
    contract={
        security_type=STK, 
        code=2890, 
        symbol=TSE2890, 
        exchange=TSE, 
        limit_up=19.1, 
        limit_down=15.7, 
        reference=17.4, 
        margin_trading_balance=0, 
        short_selling_balance=0, 
        update_date=2023/02/20, 
        category=17, 
        day_trade=Yes,
    }, 
    order={
        action=Buy, 
        price=17.5, 
        quantity=1, 
        price_type=LMT, 
        order_type=ROD, 
        order_lot=Common, 
        order_cond=Cash, 
        daytrade_short =false,
        id=c9854d9d, 
        seqno=024592, 
        ordno=WA036,
        custom_field=test, 
        account={
            account_type=S, 
            person_id=, 
            broker_id=9A95, 
            account_id=, 
            signed=True, 
            username=,
        },
    }, 
    status={
        id=c9854d9d, 
        status=Submitted, 
        status_code=0, 
        order_ts=1608863715, 
        modified_ts=0, 
        modified_price=17.5, 
        deal_quantity=0, 
        cancel_quantity=0,
    },
}

改量(減量)

UpdateOrder 只能用來減少原委託單的委託數量。

In

_trade = _api.UpdateOrder(_trade, quantity:1);
_api.UpdateStatus();
Console.WriteLine(_trade);

Out

{
    contract={
        security_type=STK, 
        code=2890, 
        symbol=TSE2890, 
        exchange=TSE, 
        limit_up=19.1, 
        limit_down=15.7, 
        reference=17.4, 
        margin_trading_balance=0, 
        short_selling_balance=0, 
        update_date=2023/02/20, 
        category=17, 
        day_trade=Yes,
    }, 
    order={
        action=Buy, 
        price=17.5, 
        quantity=3, 
        price_type=LMT, 
        order_type=ROD, 
        order_lot=Common, 
        order_cond=Cash, 
        daytrade_short =false,
        id=c9854d9d, 
        seqno=024592, 
        ordno=WA036,
        custom_field=test, 
        account={
            account_type=S, 
            person_id=, 
            broker_id=9A95, 
            account_id=, 
            signed=True, 
            username=,
        },
    }, 
    status={
        id=c9854d9d, 
        status=Submitted, 
        status_code=0, 
        order_ts=1608863715, 
        modified_ts=0, 
        modified_price=0, 
        deal_quantity=0, 
        cancel_quantity=1,
    },
}

刪單

In

_trade = _api.CancelOrder(_trade);
_api.UpdateStatus();
Console.WriteLine(_trade);

Out

{
    contract={
        security_type=STK, 
        code=2890, 
        symbol=TSE2890, 
        exchange=TSE, 
        limit_up=19.1, 
        limit_down=15.7, 
        reference=17.4, 
        margin_trading_balance=0, 
        short_selling_balance=0, 
        update_date=2023/02/20, 
        category=17, 
        day_trade=Yes,
    }, 
    order={
        action=Buy, 
        price=17.5, 
        quantity=3, 
        price_type=LMT, 
        order_type=ROD, 
        order_lot=Common, 
        order_cond=Cash, 
        daytrade_short =false,
        id=c9854d9d, 
        seqno=024592, 
        ordno=WA036,
        custom_field=test, 
        account={
            account_type=S, 
            person_id=,  
            broker_id=9A95, 
            account_id=, 
            signed=True, 
            username=,
        },
    }, 
    status={
        id=c9854d9d, 0
        status=Cancelled, 
        status_code=0, 
        order_ts=1608863715, 
        modified_ts=0, 
        modified_price=0, 
        deal_quantity=0, 
        cancel_quantity=3,
    },
}

成交

更新委託狀態

_api.UpdateStatus(_api.StockAccount);
Console.WriteLine(_trade);

Out

{
    contract={
        security_type=STK, 
        code=2890, 
        symbol=TSE2890, 
        exchange=TSE, 
        limit_up=19.1, 
        limit_down=15.7, 
        reference=17.4, 
        margin_trading_balance=0, 
        short_selling_balance=0, 
        update_date=2023/02/20, 
        category=17, 
        day_trade=Yes,
    }, 
    order={
        action=Buy, 
        price=17.5, 
        quantity=3, 
        price_type=LMT, 
        order_type=ROD, 
        order_lot=Common, 
        order_cond=Cash, 
        daytrade_short =false,
        id=c9854d9d, 
        seqno=024592, 
        ordno=WA036,
        custom_field=test, 
        account={
            account_type=S, 
            person_id=, 
            broker_id=9A95, 
            account_id=, 
            signed=True, 
            username=,
        },
    }, 
    status={
        id=c9854d9d, 
        status=Filled, 
        status_code=0, 
        order_ts=1608863715, 
        modified_ts=0, 
        modified_price=0, 
        deal_quantity=0, 
        cancel_quantity=0,
        deals=System.Collections.Generic.List`1[Sinopac.Shioaji.Deal],
    },
}

範例

買賣別

var order = new StockOrder()
    {
        price = 15.55,
        quantity = 1,
        action = Action.Buy,
        price_type = StockPriceType.LMT,
        order_type = OrderType.ROD,
        order_lot = StockOrderLot.Common,
        daytrade_short = DayTradeShort.No,
        custom_field = "Test"
    };

var order = new StockOrder()
{
    price = 15.55,
    quantity = 1,
    action = Action.Sell,
    price_type = StockPriceType.LMT,
    order_type = OrderType.ROD,
    order_lot = StockOrderLot.Common,
    daytrade_short = DayTradeShort.No,
    custom_field = "Test"
};

Daytrade Short

var order = new StockOrder()
{
    price = 15.55,
    quantity = 1,
    action = Action.Sell,
    price_type = StockPriceType.LMT,
    order_type = OrderType.ROD,
    order_lot = StockOrderLot.Common,
    daytrade_short = DayTradeShort.Yes,
    custom_field = "Test"
};
var order = new StockOrder()
{
    price = 15.55,
    quantity = 1,
    action = Action.Sell,
    price_type = StockPriceType.LMT,
    order_type = StockOrderType.ROD,
    order_lot = StockOrderLot.Common,
    first_sell = StockFirstSell.Yes,
    custom_field = "Test"
};

ROD + LMT

ROD + LMT

order = new StockOrder()
{
    price = 15.55,
    quantity = 1,
    action = Action.Sell,
    price_type = StockPriceType.LMT,
    order_type = OrderType.ROD,
    order_lot = StockOrderLot.Common,
    custom_field = "Test"
};
order = new StockOrder()
{
    price = 15.55,
    quantity = 1,
    action = Action.Sell,
    price_type = StockPriceType.LMT,
    order_type = StockOrderType.ROD,
    order_lot = StockOrderLot.Common,
    custom_field = "Test"
};