委託回報
每次使用 PlaceOrder
、UpdateOrder
或者 CancelOrder
時,皆會收到來自交易所的委託或成交回報。
處理委託及成交回報¶
您可以使用 SetOrderCallback
來處理委託及成交回報。以下範例顯示,自製的委託回報函數(order_cb
)會先印 my_order_callback
然後才印委託及成交回報。
設定委託回報函式
private static void order_cb(OrderState orderState, dynamic msg)
{
Console.WriteLine("my_order_callback");
Console.WriteLine($"OrderState.{orderState} {msg}");
}
_api.SetOrderCallback(order_cb);
下單
IContract contract = _api.Contracts.Stocks["TSE"]["2890"];
var orderr = 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 trade = _api.PlaceOrder(contract, order)
IContract contract = _api.Contracts.Stocks["TSE"]["2890"];
var orderr = 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 trade = _api.PlaceOrder(contract, order)
委託回報¶
委託回報
my_order_callback
OrderState.StockOrder {
'operation': {
'op_type': 'New',
'op_code': '00',
'op_msg': ''
},
'order': {
'id': '97b63e2f',
'seqno': '267677',
'ordno': 'IM394',
'account': {
'account_type': 'S',
'person_id': '',
'broker_id': '9A95',
'account_id': '1234567',
'signed': True
},
'action': 'Buy',
'price': 15.55,
'quantity': 1,
'order_type': 'ROD',
'price_type': 'LMT',
'order_cond': 'Cash',
'order_lot': 'Common',
'custom_field': 'test'
},
'status': {
'id': '97b63e2f',
'exchange_ts': 1673576134.038,
'modified_price': 0.0,
'cancel_quantity': 0,
'order_quantity': 1,
'web_id': '137'
},
'contract': {
'security_type': 'STK',
'exchange': 'TSE',
'code': '2890',
'symbol': '',
'name': '',
'currency': 'TWD'
}
}
my_order_callback
OrderState.TFTOrder {
'operation': {
'op_type': 'New',
'op_code': '00',
'op_msg': ''
},
'order': {
'id': '97b63e2f',
'seqno': '267677',
'ordno': 'IM394',
'account': {
'account_type': 'S',
'person_id': '',
'broker_id': '9A95',
'account_id': '1234567',
'signed': True
},
'action': 'Buy',
'price': 15.55,
'quantity': 1,
'order_type': 'ROD',
'price_type': 'LMT',
'order_cond': 'Cash',
'order_lot': 'Common',
'custom_field': 'test'
},
'status': {
'id': '97b63e2f',
'exchange_ts': 1673576134.038,
'modified_price': 0.0,
'cancel_quantity': 0,
'order_quantity': 1,
'web_id': '137'
},
'contract': {
'security_type': 'STK',
'exchange': 'TSE',
'code': '2890',
'symbol': '',
'name': '',
'currency': 'TWD'
}
}
成交回報¶
成交回報
my_order_callback
OrderState.StockDeal {
'trade_id': '97b63e2f',
'seqno': '267677',
'ordno': 'IM394',
'exchange_seq': '669915',
'broker_id': '9A95',
'account_id': '1234567',
'action': 'Buy',
'code': '2890',
'order_cond': 'Cash',
'order_lot': 'Common',
'price': 15.55,
'quantity': 1,
'web_id': '137',
'custom_field': 'test',
'ts': 1673577256.354
}
my_order_callback
OrderState.TFTDeal {
'trade_id': '97b63e2f',
'seqno': '267677',
'ordno': 'IM394',
'exchange_seq': '669915',
'broker_id': '9A95',
'account_id': '1234567',
'action': 'Buy',
'code': '2890',
'order_cond': 'Cash',
'order_lot': 'Common',
'price': 15.55,
'quantity': 1,
'web_id': '137',
'custom_field': 'test',
'ts': 1673577256.354
}