Skip to content

QA

下單

如何下市價單(MKT)、範圍市價單(MKP)

order = api.Order(
    action=sj.constant.Action.Buy,
    price=0, # MKT, MKP will not use price parameter
    quantity=1,
    price_type='MKP', # change to MKT or MKP
    order_type='IOC', # MKT, MKP only accecpt IOC order
    octype=sj.constant.FuturesOCType.Auto,
    account=api.futopt_account
)

如何掛漲(跌)停限價ROD單

First, we need to know the limit up(limit down) price of the security. Just take a look at the api.Contracts, you will find the information you want.

In

api.Contracts.Stocks.TSE['TSE2330']

Out

Stock(
    exchange=<Exchange.TSE: 'TSE'>, 
    code='2330', 
    symbol='TSE2330', 
    name='台積電', 
    category='24', 
    unit=1000, 
    limit_up=653.0, 
    limit_down=535.0, 
    reference=594.0, 
    update_date='2021/08/27', 
    margin_trading_balance=6565, 
    short_selling_balance=365, 
    day_trade=<DayTrade.Yes: 'Yes'>
)

Example place LMT and ROD order at limit up price.

In

contract = api.Contracts.Stocks.TSE['TSE2330']
price = contract.limit_up
order = api.Order(
    action=sj.constant.Action.Buy,
    price=price,
    quantity=1,
    price_type='LMT',
    order_type='ROD', 
    order_lot=sj.constant.StockOrderLot.Common,
    account=api.stock_account
)

行情

為什麼行情只能收幾行就斷掉了

If your code something like this, and possibly run code on cmd/terminal with python stream.py. Then you definitely won't get any additional ticks, since the python program has already terminated.

import shioaji as sj

api = sj.Shioaji(simulation=True)
api.login('YOUR_API_KEY', 'YOUR_SECRET_KEY')
api.quote.subscribe(
    api.Contracts.Stocks["2330"], 
    quote_type = sj.constant.QuoteType.Tick
)
# stream.py
import shioaji as sj

api = sj.Shioaji(simulation=True)
api.login('YOUR_PERSON_ID', '2222')
api.quote.subscribe(
    api.Contracts.Stocks["2330"], 
    quote_type = sj.constant.QuoteType.Tick
)

If you wish your python program to survive, please modify you python script as below.

# stream.py
import shioaji as sj
from threading import Event

api = sj.Shioaji(simulation=True)
api.login('YOUR_API_KEY', 'YOUR_SECRET_KEY')
api.quote.subscribe(
    api.Contracts.Stocks["2330"], 
    quote_type = sj.constant.QuoteType.Tick
)

Event().wait()
# stream.py
import shioaji as sj
from threading import Event

api = sj.Shioaji(simulation=True)
api.login('YOUR_PERSON_ID', '2222')
api.quote.subscribe(
    api.Contracts.Stocks["2330"], 
    quote_type = sj.constant.QuoteType.Tick
)

Event().wait()

其他

出現 Account not acceptable,可能原因如下

  • 未完成簽署API測試
  • update_status預設查詢為名下所有帳號,若想使用預設查詢方式,請確認所有帳號皆有完成簽署及測試。

如何更改shioaji.log

Please add environment variable before import shioaji. (version >= 0.3.3.dev0)

linux or Mac OS:

export SJ_LOG_PATH=/path/to/shioaji.log

windows:

set SJ_LOG_PATH=C:\path\to\shioaji.log

如何更改contracts下載路徑

Please add environment variable before import shioaji. (version >= 0.3.4.dev2)

linux or Mac OS:

export SJ_CONTRACTS_PATH=MY_PATH

windows:

set SJ_CONTRACTS_PATH=MY_PATH

python:

os.environ["SJ_CONTRACTS_PATH"]=MY_PATH

輸入密碼錯誤3次怎麼辦

線上解鎖

Note that you only have 2 chances to unlock your account online in a day.

We've migrate QA site to Shioaji Forum