简体   繁体   中英

Interactive brokers API Client /Python setting LMT price as current price

Using Python and IB API how do you set lmt price to current market price. Below is an example where when you call make_order and you pass price with action and quantity. How to define price as 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

You need to access the current price by calling a function like reqTickByTickData or reqMktData . Then you can set the lmtPrice field to the current price.

If you want to place an order at the current price, wouldn't you be better off creating a market order?

I would suggest a different order type such as Snap-To-Market or Snap-To-Midpoint if you want to do it in one step:

Snap to Market Orders

order = Order()
order.action = action
order.orderType = "SNAP MKT"
order.totalQuantity = quantity
order.auxPrice = offset

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