首页 > 解决方案 > 交互式经纪商 API 客户端 /Python 将 LMT 价格设置为当前价格

问题描述

使用 Python 和 IB API 如何将 lmt 价格设置为当前市场价格。下面是一个示例,当您调用 make_order 并通过操作和数量传递价格时。如何将价格定义为 MarketPrice?

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

标签: python-3.xinteractive-brokers

解决方案


您需要通过调用类似reqTickByTickDataor的函数来访问当前价格reqMktData。然后您可以将该lmtPrice字段设置为当前价格。

如果你想以当前价格下单,你创建一个市价单不是更好吗?


推荐阅读