0

使用下面的标准代码,我可以使用免费的模拟账户提交市价单(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(演示)中没有显示挂单。

4

1 回答 1

1

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

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

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

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

于 2017-12-27T16:53:40.863 回答