iT邦幫忙

2021 iThome 鐵人賽

DAY 11
0

shioaji 股票下單

contract = api.Contracts.Stocks.TSE.TSE2890

掛買單


order = api.Order(
    price=12, 
    quantity=1, 
    action=sj.constant.Action.Buy, 
    price_type=sj.constant.StockPriceType.LMT, # {LMT, MKT, MKP} (限價、市價、範圍市價)
    order_type=sj.constant.TFTOrderType.ROD, # {ROD, IOC, FOK}
    order_lot=sj.constant.TFTStockOrderLot.Common, # {Common, Fixing, Odd, IntradayOdd} (整股、定盤、盤後零股、盤中零股)
    account=api.stock_account
)

掛賣單


order = api.Order(
            price=12, 
            quantity=1, 
            action="Sell", 
            price_type="LMT", 
            order_type="ROD", 
            order_lot="Common", 
            account=api.stock_account
        )


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="Person of this Ca",
)

contract = api.Contracts.Stocks.TSE.TSE2890
order = api.Order(
    price=12,
    quantity=10,
    action=sj.constant.Action.Buy,
    price_type=sj.constant.StockPriceType.LMT,
    order_type=sj.constant.TFTOrderType.ROD,
    account=api.stock_account
)
trade = api.place_order(contract, order)
trade


Trade(
    contract=Stock(
        exchange=<Exchange.TSE: 'TSE'>, 
        code='2890', 
        symbol='TSE2890', 
        name='永豐金', 
        category='17'
    ), 
    order=Order(
        action=<Action.Buy: 'Buy'>, 
        price=12.0, 
        quantity=10, 
        id='004d9bed', 
        seqno='427793', 
        ordno='WA345', 
        account=Account(
            account_type=<AccountType.Stock: 'S'>, 
            person_id='RBCCJCBIGB', 
            broker_id='9A95', 
            account_id='9809975', 
            signed=True
        ), 
        price_type=<StockPriceType.LMT: 'LMT'>, 
        order_type=<FuturesOrderType.ROD: 'ROD'>
    ), 
    status=OrderStatus(
        id='004d9bed', 
        status=<Status.PendingSubmit: 'PendingSubmit'>, 
        status_code='0', 
        order_datetime=datetime.datetime(2020, 3, 3, 15, 16, 40), 
        deals=[]
    )
)


上一篇
海棠小姐借我一根頭髮, 輕輕的拉~拉~拉~ - 盤中 call 訊
下一篇
買菸賠菸 - 零股買賣
系列文
在賭場尋求財富是否搞錯了什麼22
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言