import json
import shioaji as sj
api = sj.Shioaji()
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
api.tft = True
with open('login.json', 'rb') as f:
login_kwargs = json.loads(f.read())
login_kwargs = dict(person_id="YOUR_PERSONID", passwd="YOUR_PASSWORD")
accounts = api.login(**login_kwargs, contracts_cb=lambda security_type: print(f"{repr(security_type)} fetch complete."))
<SecurityType.Index: 'IND'> fetch complete. <SecurityType.Future: 'FUT'> fetch complete. <SecurityType.Option: 'OPT'> fetch complete. <SecurityType.Stock: 'STK'> fetch complete.
with open('ca.json', 'rb') as f:
ca_kwargs = json.loads(f.read())
ca_kwargs = dict(ca_path="YOUR_CA_PATH",
ca_passwd="CA_PASSWORD",
person_id="CA_BELONGS_TO_PERSON_ID")
api.activate_ca(**ca_kwargs)
Ca Initial Done.
0
c2330 = api.Contracts.Stocks["2890"]
c2330
Stock(exchange=<Exchange.TSE: 'TSE'>, code='2890', symbol='TSE2890', name='永豐金', category='17')
order = api.Order(price=12.5,
quantity=2,
action=sj.constant.Action.Buy,
price_type=sj.constant.TFTStockPriceType.LMT,
order_type=sj.constant.OrderType.ROD)
order
Order(action=<Action.Buy: 'Buy'>, price=12.5, quantity=2, price_type=<StockPriceType.LMT: 'LMT'>, order_type=<FuturesOrderType.ROD: 'ROD'>)
trade = api.place_order(c2330, order, timeout=0, cb=lambda trade: print(trade))
trade
Trade(contract=Stock(exchange=<Exchange.TSE: 'TSE'>, code='2890', symbol='TSE2890', name='永豐金', category='17'), order=Order(action=<Action.Buy: 'Buy'>, price=12.5, quantity=2, account=StockAccount(person_id='P124081046', broker_id='9A95', account_id='9816502', signed=True, username='楊之帆'), price_type=<StockPriceType.LMT: 'LMT'>, order_type=<FuturesOrderType.ROD: 'ROD'>), status=OrderStatus(status=<Status.Inactive: 'Inactive'>))
contract=Stock(exchange=<Exchange.TSE: 'TSE'>, code='2890', symbol='TSE2890', name='永豐金', category='17') order=Order(action=<Action.Buy: 'Buy'>, price=12.5, quantity=2, id='64bb488a', seqno='602143', ordno='00000', account=Account(account_type=<AccountType.Stock: 'S'>, person_id='P124081046', broker_id='9A95', account_id='9816502', signed=True), price_type=<StockPriceType.LMT: 'LMT'>, order_type=<FuturesOrderType.ROD: 'ROD'>) status=OrderStatus(id='64bb488a', status=<Status.PendingSubmit: 'PendingSubmit'>, status_code='0', order_datetime=datetime.datetime(2020, 2, 20, 19, 7, 55), deals=[])
api.update_status()
trade
Trade(contract=Stock(exchange=<Exchange.TSE: 'TSE'>, code='2890', symbol='TSE2890', name='永豐金', category='17'), order=Order(action=<Action.Buy: 'Buy'>, price=12.5, quantity=2, id='64bb488a', seqno='602143', ordno=' ', account=Account(account_type=<AccountType.Stock: 'S'>, person_id='P124081046', broker_id='9A95', account_id='9816502', signed=True), price_type=<StockPriceType.LMT: 'LMT'>, order_type=<FuturesOrderType.ROD: 'ROD'>), status=OrderStatus(id='64bb488a', status=<Status.PreSubmitted: 'PreSubmitted'>, status_code='R', order_datetime=datetime.datetime(2020, 2, 20, 19, 7, 55), deals=[]))