Futures期貨下單範例:
import shioaji as sj
from shioaji.constant import Action, StockPriceType, FuturesOrderType, FuturesOCType #匯入期貨下單常數
api = sj.Shioaji(simulation=True)
api.login(
person_id='PAPIUSER06',
passwd='2222'
)
contract = api.Contracts.Futures.TXF['TXF202110'] #期貨Contract
order = api.Order(action=Action.Buy,
price=10200, #價格(點)
quantity=2, #口數
price_type=StockPriceType.LMT,
order_type=FuturesOrderType.ROD,
octype=FuturesOCType.Auto, #倉別,使用自動
account=api.futopt_account #下單帳戶指定期貨帳戶
)
trade = api.place_order(contract, order)
print(trade)
期貨Order參數會多一個octype倉別,可以直接使用FuturesOCType.Auto讓系統自動判斷所要建立的倉別
Options選擇權下單範例:
import shioaji as sj
from shioaji.constant import Action, OptionRight, StockPriceType, FuturesOrderType, FuturesOCType #選擇權下單,多匯入一個OptionRight常數
api = sj.Shioaji(simulation=True)
api.login(
person_id='PAPIUSER06',
passwd='2222'
)
contract = api.Contracts.Options.TXO.TXO202110017500C #選擇權Contract
order = api.Order(action=Action.Buy,
price=170, #價格
quantity=2, #口數
price_type=StockPriceType.LMT,
order_type=FuturesOrderType.ROD,
octype=FuturesOCType.Auto, #倉別,使用自動
OptionRight=OptionRight.Call, #選擇權類型
account=api.futopt_account #下單帳戶指定期貨帳戶
)
trade = api.place_order(contract, order)
print(trade)
選擇權Order參數,基本上跟期貨一樣,只再多一個OptionRight選擇權類型 - Call或Put。