简体   繁体   中英

Submitting LOO or MOO orders to Interactive Brokers via ibpy

With the standard code below, I have been able to submit market (MKT) and limit orders(LMT) using a free demo account

from ib.opt import Connection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order


def make_contract(symbol, sec_type, exch, prim_exch, curr):
    Contract.m_symbol = symbol
    Contract.m_secType = sec_type
    Contract.m_exchange = exch
    Contract.m_primaryExch = prim_exch
    Contract.m_currency = curr
    return Contract


def make_order(action, quantity, price=None):
    if price is not None:
        order = Order()
        order.m_orderType = 'LMT'
        order.m_totalQuantity = quantity
        order.m_action = action
        order.m_lmtPrice = price
    else:
        order = Order()
        order.m_orderType = 'MKT'
        order.m_totalQuantity = quantity
        order.m_action = action

    return order


def main():
    conn = Connection.create(port=7496, clientId=999)
    conn.connect()

    oid = 100001
    cont = make_contract('TSLA', 'STK', 'SMART', 'SMART', 'USD')
    offer = make_order('BUY', 100, 315)

    conn.placeOrder(oid, cont, offer)
    conn.disconnect()


main()

does anyone have experience submitting LOO or MOO orders? When I change:

    order.m_orderType = 'LOO'

I do not get an exception, however, no pending order is show in IB TWS (demo).

According to the docs you make the type LMT or MKT as usual but change tif to OPG (for opening I guess).

order.tif = "OPG"
order.orderType = "LMT"

http://interactivebrokers.github.io/tws-api/basic_orders.html#limitonopen

note, the field names are using IB's new python API that you may want to look at.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM