Order & Deal Event
Order & Deal Event is a report of order action. When you place order, cancel order and update order, it will return an OrderState. OrderState is order info.
For Example¶
Stock¶
Place Order¶
In
import shioaji as sj
api = sj.Shioaji()
accounts = api.login("YOUR_PERSON_ID", "YOUR_PASSWORD", contracts_timeout=10000)
api.activate_ca(
ca_path="/c/your/ca/path/Sinopac.pfx",
ca_passwd="YOUR_CA_PASSWORD",
person_id="Person of this Ca",
)
contract = api.Contracts.Stocks.TSE.TSE2890
order = api.Order(price=12,
quantity=10,
action=sj.constant.Action.Buy,
price_type=sj.constant.StockPriceType.LMT,
order_type=sj.constant.TFTOrderType.ROD,
account=api.stock_account
)
trade = api.place_order(contract, order)
Out
OrderState.TFTOrder {
'operation': {
'op_type': 'New',
'op_code': '00',
'op_msg': ''
},
'order': {
'id': 'c21b876d',
'seqno': '429832',
'ordno': 'W2892',
'action': 'Buy',
'price': 12.0,
'quantity': 10,
'order_cond': 'Cash',
'order_type': 'ROD',
'price_type': 'LMT'
},
'status': {
'id': 'c21b876d',
'exchange_ts': 1583828972,
'modified_price': 0,
'cancel_quantity': 0
},
'contract': {
'security_type': 'STK',
'exchange': 'TSE',
'code': '2890',
'symbol': '',
'name': '',
'currency': 'TWD'
}
}
Success Deal
OrderState.TFTDeal {
'trade_id': '12ab3456',
'exchange_seq': '123456',
'broker_id': 'your_broker_id',
'account_id': 'your_account_id',
'action': <Action.Buy: 'Buy'>,
'code': '2890',
'order_cond': <StockOrderCond.Cash: 'Cash'>,
'price': 12,
'quantity': 10,
'ts': 1583828972
}
Set order callback¶
In
def place_cb(stat, msg):
print('my_place_callback')
print(stat, msg)
api.set_order_callback(place_cb)
contract = api.Contracts.Stocks.TSE.TSE2890
order = api.Order(price=12,
quantity=10,
action=sj.constant.Action.Buy,
price_type=sj.constant.StockPriceType.LMT,
order_type=sj.constant.TFTOrderType.ROD,
account=api.stock_account
)
trade = api.place_order(contract, order)
Out
my_place_callback
OrderState.TFTOrder {
'operation': {
'op_type': 'New',
'op_code': '00',
'op_msg': ''
},
'order': {
'id': 'c21b876d',
'seqno': '429832',
'ordno': 'W2892',
'action': 'Buy',
'price': 12.0,
'quantity': 10,
'order_cond': 'Cash',
'order_type': 'ROD',
'price_type': 'LMT'
},
'status': {
'id': 'c21b876d',
'exchange_ts': 1583828972,
'modified_price': 0,
'cancel_quantity': 0
},
'contract': {
'security_type': 'STK',
'exchange': 'TSE',
'code': '2890',
'symbol': '',
'name': '',
'currency': 'TWD'
}
}
Success Deal
my_place_callback
OrderState.TFTDeal {
'trade_id': '12ab3456',
'exchange_seq': '123456',
'broker_id': 'your_broker_id',
'account_id': 'your_account_id',
'action': <Action.Buy: 'Buy'>,
'code': '2890',
'order_cond': <StockOrderCond.Cash: 'Cash'>,
'price': 12,
'quantity': 10,
'ts': 1583828972
}
Cancel Order¶
In
api.update_status(api.stock_account)
api.cancel_order(trade)
Out
OrderState.TFTOrder {
'operation': {
'op_type': 'Cancel',
'op_code': '00',
'op_msg': ''
},
'order': {
'id': 'c21b876d',
'seqno': '429832',
'ordno': 'W2892',
'action': 'Buy',
'price': 12.0,
'quantity': 10,
'order_cond': 'Cash',
'order_type': 'ROD',
'price_type': 'LMT'
},
'status': {
'id': 'c21b876d',
'exchange_ts': 1583829131,
'modified_price': 0,
'cancel_quantity': 10
},
'contract': {
'security_type': 'STK',
'exchange': 'TSE',
'code': '2890',
'symbol': '',
'name': '',
'currency': 'TWD'
}
}
Update Price¶
In
api.update_status(api.stock_account)
api.update_order(trade=trade, price=12.5, quantity=10)
Out
OrderState.TFTOrder {
'operation': {
'op_type': 'UpdatePrice',
'op_code': '00',
'op_msg': ''
},
'order': {
'id': 'a5cff9b6',
'seqno': '429833',
'ordno': 'W2893',
'action': 'Buy',
'price': 12.5,
'quantity': 10,
'order_cond': 'Cash',
'order_type': 'ROD',
'price_type': 'LMT'
},
'status': {
'id': 'a5cff9b6',
'exchange_ts': 1583829166,
'modified_price': 0,
'cancel_quantity': 0
},
'contract': {
'security_type': 'STK',
'exchange': 'TSE',
'code': '2890',
'symbol': '',
'name': '',
'currency': 'TWD'
}
}
Update Quantity¶
In
api.update_status(api.stock_account)
api.update_order(trade=trade, price=12, quantity=2)
Out
OrderState.TFTOrder {
'operation': {
'op_type': 'UpdateQty',
'op_code': '00',
'op_msg': ''
},
'order': {
'id': 'a5cff9b6',
'seqno': '429833',
'ordno': 'W2893',
'action': 'Buy',
'price': 12.0,
'quantity': 10,
'order_cond': 'Cash',
'order_type': 'ROD',
'price_type': 'LMT'
},
'status': {
'id': 'a5cff9b6',
'exchange_ts': 1583829187,
'modified_price': 0,
'cancel_quantity': 2
},
'contract': {
'security_type': 'STK',
'exchange': 'TSE',
'code': '2890',
'symbol': '',
'name': '',
'currency': 'TWD'
}
}