Shioaji is a trading API provided by Sinopac that offers a comprehensive and user-friendly platform for accessing the Taiwan financial markets. With Shioaji, you can trade a variety of financial instruments including stocks, futures, and options using your favorite Python packages such as numpy, scipy, pandas, pytorch, or tensorflow to build your own custom trading models. The platform is easy to use and intuitive, with advanced charting tools, real-time market data, and a customizable interface that allows you to tailor your trading experience to your specific needs. Shioaji is fast and efficient, with a high-performance core implemented in C++ and using FPGA event broker technology, and it is the first Python trading API in Taiwan that is compatible with Linux and Mac, making it a truly cross-platform solution. Whether you are a beginner looking to get started in the world of trading or an experienced trader looking for a more powerful platform, Shioaji has something to offer. Sign up for a free account today and start trading with confidence.
!pip install shioaji
import shioaji as sj
from shioaji import constant
api = sj.Shioaji(simulation=True)
api_key = "your api key"
secret_key ="your secret key"
api.login(api_key=api_key, secret_key=secret_key)
api.list_accounts()
❗❗❗ activate_ca is not necessary when using the simulation environment.
# api.activate_ca(ca_path='../ca/Sinopac.pfx', ca_passwd='SCCEIEFAJA', person_id=person_id)
# For example, to obtain contract of TSMC (symbol 2330)
api.Contracts.Stocks.TSE.TSE2330
api.Contracts.Stocks['2330']
# For example, to obtain contract of TXF (symbol TXF)
api.Contracts.Futures.TXF.TXF202301
api.Contracts.Futures['TXFA3']
⚠️Currently only supports historical quotes query ⚠️
api.Contracts.Futures.TXF.TXFR1
api.Contracts.Futures.TXF['TXFR1']
official document
# For example, subscribe to the tick for TSMC (symbol 2330)
from shioaji import Exchange, TickSTKv1, TickFOPv1
from shioaji import constant
@api.on_tick_stk_v1()
def quote_callback(exchange: Exchange, tick:TickSTKv1):
print(f"Exchange: {exchange}, Tick: {tick}")
api.quote.subscribe(
api.Contracts.Stocks["2330"],
quote_type = constant.QuoteType.Tick,
version = constant.QuoteVersion.v1
)
# For example, subscribe to the tick for Taiwan Stock Exchange Capitalization Weighted Stock Index (TAIEX) (symbol TXF)
from shioaji import Exchange, TickSTKv1, TickFOPv1
from shioaji import constant
from shioaji import TickFOPv1, Exchange
@api.on_tick_fop_v1()
def quote_callback(exchange:Exchange, tick:TickFOPv1):
print(f"Exchange: {exchange}, Tick: {tick}")
api.quote.subscribe(
api.Contracts.Futures.TXF['TXF202301'],
quote_type = constant.QuoteType.Tick, # or 'tick'
version = constant.QuoteVersion.v1, # or 'v1'
)
from shioaji import constant
TSE2890 = api.Contracts.Stocks['2890']
sample_order = api.Order(price=15.1,
quantity=2,
action=constant.Action.Buy,
price_type=constant.StockPriceType.LMT,
order_type=constant.OrderType.ROD,
daytrade=True,
account=api.futopt_account,
)
# just pass Order object to place_order fuction to place order then will get the Trade object return
trade = api.place_order(TSE2890, sample_order)
trade
sample_order = api.Order(price=14000,
quantity=5,
action=constant.Action.Buy,
price_type=constant.FuturesPriceType.LMT,
order_type=constant.OrderType.ROD,
octype=constant.FuturesOCType.Auto,
account=api.futopt_account,
)
# just pass Order object to place_order fuction to place order then will get the Trade object return
trade = api.place_order(TXFA3, sample_order)
trade
api.update_status()
api.list_trades()
trade = api.cancel_order(trade)
trade
Shioaji current state is Pre-Alpha, we expect no obvious bugs. Please let us know if you encounter a bug by filing an issue.
We appreciate all suggestions. If you have any idea want us to implement, please discuss with us in telegram.
Shioaji is currently maintained by ec666 team with major contributions.