¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

buy order at open if market open between a minimum and maximum


 

I would like to place a buy order that will fill at the open if the open price (or open ask) is between a certain minimum and maximum.

The maximum is easy enough (I think) using a limit on open order.? Can this be successfully used with a price condition for the minimum?? Something like:

o = Order()
o.action = 'BUY'
o.lmtPrice = maximum_entry_price
o.totalQuantity = qty
o.tif = 'OPG'


price_condition = Create(OrderCondition.Price)
price_condition.conId = contract.conId
price_condition.exchange =
'SMART'
price_condition.isMore = True
price_condition.triggerMethod = 4
price_condition.price = minimum_entry_price

I have used trigger method 4 (bid/ask) on the price condition so that I don't have to wait for a trade to complete before the conditioned logic is evaluated - does that provide any advantage?

Can anyone provide comment on whether the above approach will work, issues to consider, or other options?

Thanks!


 

For an opening auction, it cannot be done due to market mechanics. The exchange has to introduce a new order type or amend the current.


 

Try to find a library for scheduling in your programming language and send an order when you'd like.?


 

On Wed, Jul 12, 2023 at 06:14 AM, Gaether wrote:
Try to find a library for scheduling in your programming language and send an order when you'd like.?
Does not work for exchange auctions, they don't care what parameters IB supplies.


 

Why care about a minimum? Your limit-on-open will fill if the current price is below the limit.It's effectively a market order with a maximum.


 

¿ªÔÆÌåÓý

A minimum indicates a sufficiently strong follow on move (from previous day), a maximum prohibits excessively outsized moves. The trading system does significantly better with both a minimum and a maximum price limit when entering at the open.? Though of course, yes, one option is to take the hit, use only a maximum, and just work with a more reliable LOO order.

?

I¡¯ve come up with three workarounds, which approximate the required order behaviour.? Each of them is fine, even with their inherent faults, for an EOD trading system (which shouldn¡¯t be so fragile as to require trade entry prices to be at exactly the open price); but they compromise/approximate in different ways, and the differences are just techncially interesting (how does IB really handle price/time conditions in these scenarios).

?

The three options I see are:

?

  1. Stream tick data and place a LOO buy order (at the required maximum) if the first trade price is above the required minimum.? Slowest of the three options (I would guess) as it involves my client code on a non IB server; has the advantage of making a decision based on the opening price, but the order will reach the market at some interval (likely just milliseconds) after the open.? I think this is the most robust, but I¡¯m trying to avoid adding streaming architecture to this trading client if I can.

?

  1. Place a limit order (for the required maximum), and add price and time conditioning to cancel the order if the open price is less than the required minimum.? [theoretically, if our order was somehow first in the queue, it could be filled first, before the cancel conditions can trigger; or it may be filled prior to IB¡¯s order handling has time to register another opening trade below the minimum and send the cancel order]

?

order = Order()

order.action = "BUY"
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = limit_price
order.outsideRth = False
# PRICE CONDITION to cancel order if opening trade is below the minimum price
price_condition = Create(OrderCondition.Price)
price_condition.conId = t.contract.conId
price_condition.exchange =
'SMART'
price_condition.isMore = False
price_condition.triggerMethod = 2
price_condition.price = minimum_required_open

price_condition.isConjunctionConnection = False
order.conditions.append(price_condition)
# TIME CONDITION ¨C cancel after n seconds so the order is only active at the ¡°open¡±

time_condition = Create(OrderCondition.Time)
time_condition.time = datetime.strftime(end_datetime,
'%Y%m%d %H:%M:%S ')? # end_datetime = n seconds after the 9:30

time_condition.isMore = True
time_condition.isConjunctionConnection = False

order.conditions.append(time_condition)

# Conditions do not apply outside RTH, and any condition being met will cancel the order
order.conditionsIgnoreRth = False
order.conditionsCancelOrder = True

?

  1. Place a limit order (for the required maximum) and add price conditioning to activate the order if the opening price is above the required minimum? [this will activate the order if there is any trade above the required minimum during the GTD period (n seconds), which is not the same as activating on the open price alone]

?

# [Indicative code, untested]

order = Order()

order.action = "BUY"
order.orderType = "LMT"

order.tif = "GTD"

order.goodTillDate = datetime.strftime(end_datetime, '%Y%m%d %H:%M:%S ')? # end_datetime = n seconds after the 9:30

order.totalQuantity = quantity
order.lmtPrice = limit_price
order.outsideRth = False
# PRICE CONDITION to activate the order if a minimum price trade is observed

price_condition = Create(OrderCondition.Price)
price_condition.conId = t.contract.conId
price_condition.exchange =
'SMART'
price_condition.isMore = True
price_condition.triggerMethod = 2
price_condition.price = minimum_required_open

order.conditions.append(price_condition)

# Conditions do not apply outside RTH
order.conditionsIgnoreRth = False

?

Unfortunately IB won¡¯t allow conditions to be added to LOO type orders ¨C otherwise that would be a great way to remove the timing aspect of it.

?

?

The three options are all a bit rough, and each may be trying too hard! ?I am testing #2 at the moment. ??The system trades infrequently (once or twice a week), so it takes a while to build up a dataset.

?

But are there better ways of doing it?? Would love to get others thoughts.

?

?

Dave

?

?

From: [email protected] <[email protected]> On Behalf Of Hilmar via groups.io
Sent: Friday, July 14, 2023 7:59 AM
To: [email protected]
Subject: Re: [TWS API] buy order at open if market open between a minimum and maximum

?

Why care about a minimum? Your limit-on-open will fill if the current price is below the limit.It's effectively a market order with a maximum.


 

What you wish to implement is effectively a stop-limit order to be placed into the market center official opening auction. That is not possible.

LOO/MOO orders are totally special exchange orders, as well as MOC/LOC.?

It's not that IBKR somehow reduces their system capability in respect to these by denying clients to attach price and time conditions et cetera, it's just that such capabilities will not work with exchanges.?

These orders are executed atomically (even though not necessarily momentarily) at the opening and closing auctions, or "crosses" in Nasdaq speak. They must be submitted some time ahead of their respective daily trade cycle times. The submission time limit differs by exchange, auction kind (open/close) and order type - limit orders are allowed to be submitted closer to the auction in certain circumstances related to the accumulated balance of pre-orders. After some time once they are submitted and before the auction is carried out they also cannot be recalled. Also, no liquid trading on the exchange will happen in respective stocks before the opening auction and after the closing auction.

Certainly, you'll realize that any broker-imposed trading conditions would have zero chance of being respected or enforced under this scheme. Further, the idea that you can get an opening print and then quickly submit an OPG order is completely futile because the primary exchange will simply not start trading before the auction is executed, and even though trading may start a few moments earlier on non-primary exchanges and dark pools, by that time no OPG orders will be accepted by the primary exchange (and non-primary liquidity may not be?much better than in the early non-regular trading anyway).

--
Best,
DS