In [3]:
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="The Ca belong to which person_id",
)

contract = api.Contracts.Stocks.TSE.TSE2890
order = api.Order(price=11.5,
                  quantity=2,
                  action="Buy",
                  price_type="LMT",
                  order_type="ROD",
                  account=api.stock_account
                  )
trade = api.place_order(contract, order)
Response Code: 0 | Event Code: 0 | Info: host '203.66.91.161:80', IP 203.66.91.161:80 (host 1 of 1) (host connection attempt 1 of 1) (total connection attempt 1 of 1) | Event: Session up
Ca Initial Done.
OrderState.Order {'operation': {'op_type': 'NEW', 'op_code': '00', 'op_msg': ''}, 'order': {'id': '28ed0a7a', 'seqno': '270229', 'ordno': 'I2006', 'action': 'Buy', 'price': 11.5, 'quantity': 2, 'order_cond': 'Cash'}, 'status': {'id': '28ed0a7a', 'exchange_ts': 1583893802, 'modified_price': 0, 'cancel_quantity': 0}, 'contract': {'security_type': 'STK', 'exchange': 'TSE', 'code': '2890', 'symbol': '', 'name': '', 'currency': 'TWD'}}
In [ ]:
contract = api.Contracts.Stocks.TSE.TSE2890
order = api.Order(price=11.5,
                  quantity=2,
                  action="Buy",
                  price_type="LMT",
                  order_type="ROD",
                  account=api.stock_account
                  )
trade = api.place_order(contract, order)
In [6]:
api.update_status(api.stock_account)
trade = api.cancel_order(trade)
OrderState.Order {'operation': {'op_type': 'CANCEL', 'op_code': '00', 'op_msg': ''}, 'order': {'id': '28ed0a7a', 'seqno': '270229', 'ordno': 'I2006', 'action': 'Buy', 'price': 11.5, 'quantity': 2, 'order_cond': 'Cash'}, 'status': {'id': '28ed0a7a', 'exchange_ts': 1583893809, 'modified_price': 0, 'cancel_quantity': 1}, 'contract': {'security_type': 'STK', 'exchange': 'TSE', 'code': '2890', 'symbol': '', 'name': '', 'currency': 'TWD'}}
In [7]:
trade
Out[7]:
Trade(contract=Stock(exchange=<Exchange.TSE: 'TSE'>, code='2890', symbol='TSE2890', name='永豐金', category='17', limit_up=13.75, limit_down=11.25, update_date='2020/03/11', day_trade=<DayTrade.OnlyBuy: 'OnlyBuy'>), order=Order(action=<Action.Buy: 'Buy'>, price=11.5, quantity=2, id='28ed0a7a', seqno='270229', ordno='I2006', account=Account(account_type=<AccountType.Stock: 'S'>, person_id=SecretStr('**********'), broker_id=SecretStr('**********'), account_id=SecretStr('**********'), signed=True, username=SecretStr('')), price_type=<StockPriceType.LMT: 'LMT'>, order_type=<FuturesOrderType.ROD: 'ROD'>), status=OrderStatus(id='28ed0a7a', status=<Status.Submitted: 'Submitted'>, status_code='00', order_datetime=datetime.datetime(2020, 3, 11, 10, 30, 2), modified_price=11.5, cancel_quantity=1, deals=[]))
In [4]:
api.update_status(api.stock_account)
trade = api.update_order(trade, price=11.5, qty=1)
OrderState.Order {'operation': {'op_type': 'UPDATE', 'op_code': '00', 'op_msg': ''}, 'order': {'id': '28ed0a7a', 'seqno': '270229', 'ordno': 'I2006', 'action': 'Buy', 'price': 11.5, 'quantity': 2, 'order_cond': 'Cash'}, 'status': {'id': '28ed0a7a', 'exchange_ts': 1583893806, 'modified_price': 0, 'cancel_quantity': 1}, 'contract': {'security_type': 'STK', 'exchange': 'TSE', 'code': '2890', 'symbol': '', 'name': '', 'currency': 'TWD'}}
In [5]:
trade
Out[5]:
Trade(contract=Stock(exchange=<Exchange.TSE: 'TSE'>, code='2890', symbol='TSE2890', name='永豐金', category='17', limit_up=13.75, limit_down=11.25, update_date='2020/03/11', day_trade=<DayTrade.OnlyBuy: 'OnlyBuy'>), order=Order(action=<Action.Buy: 'Buy'>, price=11.5, quantity=2, id='28ed0a7a', seqno='270229', ordno='I2006', account=Account(account_type=<AccountType.Stock: 'S'>, person_id=SecretStr('**********'), broker_id=SecretStr('**********'), account_id=SecretStr('**********'), signed=True, username=SecretStr('')), price_type=<StockPriceType.LMT: 'LMT'>, order_type=<FuturesOrderType.ROD: 'ROD'>), status=OrderStatus(id='28ed0a7a', status=<Status.Submitted: 'Submitted'>, status_code='00', order_datetime=datetime.datetime(2020, 3, 11, 10, 30, 2), modified_price=11.5, deals=[]))