通过 ibpy 向盈透证券提交 LOO 或 MOO 订单

Submitting LOO or MOO orders to Interactive Brokers via ibpy

使用下面的标准代码,我已经能够使用免费模拟账户提交市价单 (MKT) 和限价单 (LMT)

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()

有没有人有提交 LOO 或 MOO 订单的经验?当我改变时:

    order.m_orderType = 'LOO'

我没有得到异常,但是,IB TWS(演示)中没有显示挂单。

根据文档,您像往常一样输入 LMT 或 MKT,但将 tif 更改为 OPG(我猜是为了打开)。

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

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

请注意,字段名称使用的是 IB 的新 python API,您可能需要查看。