0

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

2 Answers2

0

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?

MatthewScarpino
  • 5,672
  • 5
  • 33
  • 47
  • Thank you, I think you are correct. What I am trying to do is open at market and define a $4 trail and a $8 target. Currently I can place a market order and put on a trail on. I am not sure how to put the take profit to be 8 dollars. Do I have to check the fill price then do something like. Fill+8 as a var for price? – Nikolaos Trader Aug 08 '19 at 16:40
0

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
Josh
  • 706
  • 3
  • 8
  • You mean to use SNAP MKT for the Target? ```python – Nikolaos Trader Aug 08 '19 at 17:24
  • Is SNAP MKT available in Python API I don't see it .https://interactivebrokers.github.io/tws-api/available_orders.html – Nikolaos Trader Aug 08 '19 at 17:39
  • Oh that was only in regards to the original question. Yes, snap to market orders are available, there just doesn't happen to be an example provided. If you try the above it should go through fine. – Josh Aug 08 '19 at 21:09
  • I really like the SNAP MKT order. Looks like it will work great as a target. https://www.interactivebrokers.com/en/index.php?f=5933 – Nikolaos Trader Aug 10 '19 at 00:37