Order Types

Market On Open Orders


Market on open (MOO) orders fill at the official opening auction price for a security. Market that operate 24/7 don't support MOO orders.

Brokerage Support

Each brokerage has a set of assets and order types they support. To avoid issues with MOO orders, set the brokerage model to a brokerage that supports them.


To check if your brokerage has any special requirements for MOO orders, see the Orders section of the brokerage integration documentation.

Place Orders

To send a MOO order, call the MarketOnOpenOrder method and provide a Symbol and quantity. Submit the order at least two minutes before the market opens to be included in the opening auction. If you do not have sufficient capital for the order, it's rejected.

// Buy 100 shares of IBM at the market open
MarketOnOpenOrder("IBM", 100);

// Sell 100 shares of IBM at the market open
MarketOnOpenOrder("IBM", -100);
# Buy 100 shares of IBM at the market open
self.MarketOnOpenOrder("IBM", 100)

# Sell 100 shares of IBM at the market open
self.MarketOnOpenOrder("IBM", -100)

You can provide a tag and order properties to the MarketOnOpenOrder method.

MarketOnOpenOrder(symbol, quantity, tag: tag, orderProperties: orderProperties);
self.MarketOnOpenOrder(symbol, quantity, tag=tag, orderProperties=order_properties)

Monitor Order Fills

MOO orders fill at the opening auction. If the auction is heavily skewed to one side of the market, your MOO order may not fill. To monitor the fills of your order, save a reference to the order ticket.

// Buy 10 shares of SPY at the market open
var ticket = MarketOnOpenOrder("SPY", 10);
Debug($"Quantity filled: {ticket.QuantityFilled}; Fill price: {ticket.AverageFillPrice}");
# Buy 10 shares of SPY at the market open
ticket = self.MarketOnOpenOrder("SPY", 10)
self.Debug(f"Quantity filled: {ticket.QuantityFilled}; Fill price: {ticket.AverageFillPrice}")

You won't know the fill price of the order until after the market opens. If the asset price moves before the market open to where you can't afford the quantity of the order, the brokerage rejects your order. To increase the probability of a successful trade, leave a sufficient buying power buffer to handle daily price gaps.

For more information about how LEAN models order fills in backtests, see Trade Fills.

Update Orders

You can update the quantity and tag of MOO orders until the order fills or the brokerage prevents modifications. To update an order, pass an UpdateOrderFields object to the Update method on the OrderTicket. The Update method returns an OrderResponse to signal the success or failure of the update request.

// Create a new order and save the order ticket
var ticket = MarketOnOpenOrder("AAPL", 100, "original tag");

// Update the order
var response = ticket.Update(new UpdateOrderFields()
    Quantity = 75,
    Tag = "new tag"

// Check if the update was successful
if (response.IsSuccess)
    Debug("Order updated successfully");
# Create a new order and save the order ticket
ticket = self.MarketOnOpenOrder("AAPL", 100, "original tag")

# Update the order
update_settings = UpdateOrderFields()
update_settings.Quantity = 75
update_settings.Tag = "new tag"
response = ticket.Update(update_settings)

# Check if the update was successful
if response.IsSuccess:
    self.Debug("Order updated successfully")

To update individual fields of an order, call any of the following methods:

  • UpdateQuantity
  • UpdateTag
var quantityResponse = ticket.UpdateQuantity(quantity, tag);

var tagResponse = ticket.UpdateTag(tag);

response = ticket.UpdateQuantity(quantity, tag)

response = ticket.UpdateTag(tag)

When you update an order, LEAN creates an UpdateOrderRequest object, which have the following attributes:

To get a list of UpdateOrderRequest objects for an order, call the UpdateRequests method.

var updateRequests = orderTicket.UpdateRequests();
update_requests = order_ticket.UpdateRequests()


The following backtest verifies the MarketOnOpenOrder behavior. The following table shows the first trade in the backtest:

Submitted TimeFilled TimeSymbolPriceQuantityTypeStatusValueTag
2021-07-01T10:31:00Z2021-07-02T09:31:00ZSPY431.6710Market On OpenFilled4316.70

On July 1, 2021 at 10:31 AM Eastern Time (ET), the algorithm places a market on open order to buy SPY. The fill model fills the order on July 2, 2021 at 9:31 AM at a price of $431.67, which is the official opening auction price for July 2, 2021.

To reproduce these results, backtest the following algorithm:

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: