---
title: "Order Errors"
description: "If an error occurs with one of your orders, LEAN logs the error message and stops executing."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-errors
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-errors.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/22%20Trading%20and%20Orders/11%20Order%20Errors
modified: 2026-10-30
index: https://www.quantconnect.com/llms.txt
---

# Order Errors

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Trading and Orders > Order Errors

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

If an error occurs with one of your orders, LEAN logs the error message and stops executing.

## Types of Order Errors

Errors can occur when you place orders or after you place them.

### Errors at Order Submission

The following errors can occur when you submit an order:

- `ALGORITHM_WARMING_UP`
- `BROKERAGE_FAILED_TO_SUBMIT_ORDER`
- `BROKERAGE_MODEL_REFUSED_TO_UPDATE_ORDER`
- `CONVERSION_RATE_ZERO`
- `EUROPEAN_OPTION_NOT_EXPIRED_ON_EXERCISE`
- `EXCEEDED_MAXIMUM_ORDERS`
- `EXCEEDS_SHORTABLE_QUANTITY`
- `EXCHANGE_NOT_OPEN`
- `FOREX_BASE_AND_QUOTE_CURRENCIES_REQUIRED`
- `FOREX_CONVERSION_RATE_ZERO`
- `INSUFFICIENT_BUYING_POWER`
- `MARKET_ON_CLOSE_ORDER_TOO_LATE`
- `MISSING_SECURITY`
- `NON_EXERCISABLE_SECURITY`
- `NON_TRADABLE_SECURITY`
- `OPTION_ORDER_ON_STOCK_SPLIT`
- `ORDER_ALREADY_EXISTS`
- `ORDER_QUANTITY_LESS_THAN_LOT_SIZE`
- `ORDER_QUANTITY_ZERO`
- `PRE_ORDER_CHECKS_ERROR`
- `QUOTE_CURRENCY_REQUIRED`
- `SECURITY_HAS_NO_DATA`
- `UNSUPPORTED_REQUEST_TYPE`

### Errors After Order Submission

The following errors can occur for active orders:

- `BROKERAGE_FAILED_TO_UPDATE_ORDER`
- `BROKERAGE_MODEL_REFUSED_TO_SUBMIT_ORDER`
- `INVALID_NEW_ORDER_STATUS`
- `INVALID_ORDER_STATUS`
- `INVALID_REQUEST`
- `REQUEST_CANCELED`
- `UNABLE_TO_FIND_ORDER`

## Common Errors

There are a few common order errors you may experience.

### Why is my order converted to a market on open order?

If you place a market order when the market is closed, LEAN automatically converts the order into market on open order. This most commonly happens when you use daily or hourly data, which your algorithm can receive when the market is closed. With the `daily_precise_end_time` [setting](https://www.quantconnect.com/docs/v2/writing-algorithms/initialization.md#10-Set-Algorithm-Settings) enabled, your algorithm receives daily bars and the last hourly bar of each day at 4 PM Eastern Time (ET). To avoid LEAN from converting your market order to market on open orders, submit your market orders when the market is open. To check if the market is open, call the `is_market_open` method.

```python
# Check the market status before placing an order to avoid unintended market-on-open trades.
if self.is_market_open(self._symbol):
    self.market_order(self._symbol, quantity)
```

### Why am I seeing the "stale price" warning?

Stale fills occur when you fill an order with price data that is timestamped an hour or more into the past. Stale fills usually only occur if you trade illiquid assets or if your algorithm uses daily data but you trade intraday with Scheduled Events. If your order is filled with stale data, the fill price may not be realistic. The pre-built fill models can only fill market orders with stale data. To adjust the length of time that needs to pass before an order is considered stale, set the `stale_price_time_span` setting.

```python
def initialize(self) -> None:
    # Adjust the stale price time span to be 10 minutes.
    self.settings.stale_price_time_span = timedelta(minutes=10)
```

### Why do I get "Backtest Handled Error: The security with symbol '/ES' is marked as non-tradable"?

This error occurs when you place an order for a continuous Futures contract, which isn't a tradable security. To fix the issue, place the order for a specific Futures contract. To access the currently selected contract in the continuous contract series, use the `mapped` property of the `Future` object.

### Why do I get "Backtest Handled Error: Order Error: ids: [1], Insufficient buying power to complete orders" from a Crypto order?

When you place Crypto trades, ensure you have a sufficient balance of the base or quote currency before each trade. If you hold multiple assets and you want to put all of your capital into BTCUSDT, you need to first convert all your non-BTC assets into USDT and then purchase BTCUSDT.

By default, the account currency is USD and your starting cash is $100,000. Some Crypto exchanges don't support fiat currencies, which means you can't convert the $100,000 USD to the pair's [quote currency](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/key-concepts.md#05-Quote-Currency). In this case, [set your account currency](https://www.quantconnect.com/docs/v2/writing-algorithms/initialization.md#03-Set-Account-Currency) to the quote currency with a positive quantity.

```python
self.set_account_currency("USDT", 1000)   # Set the account currency to Tether and its quantity to 1,000 USDT
```

## Error Code Reference

The `OrderError` enumeration has the following members:

*Members of `QuantConnect.Orders.OrderError` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.Orders.OrderError&language=python*

## Order Response Error Reference

The following sections explain why each `OrderResponseErrorCode` occurs and how to avoid it.

### None

The `OrderResponseErrorCode.NONE` (0) error means there is no order response error.

### Processing Error

The `OrderResponseErrorCode.PROCESSING_ERROR` (-1) error occurs in the following situations:

- When you submit a new order, but LEAN throws an exception while checking if you have sufficient [buying power](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/buying-power.md) for the order.
- When you try to update or cancel an order, but LEAN throws an exception.

To investigate this order response error further, see the `HandleSubmitOrderRequest`, `UpdateOrder`, and `CancelOrder` methods of the [BrokerageTransactionHandler](https://github.com/QuantConnect/Lean/blob/master/Engine/TransactionHandlers/BrokerageTransactionHandler.cs) in the LEAN GitHub repository.

### Order Already Exists

The `OrderResponseErrorCode.ORDER_ALREADY_EXISTS` (-2) error occurs when you submit a new order but you already have an open order or a completed order with the same order ID. This order response error usually comes from a concurrency issue.

To avoid this order response, don't place two asynchronous orders at the same time.

### Insufficient Buying Power

The `OrderResponseErrorCode.INSUFFICIENT_BUYING_POWER` (-3) error occurs when you place an order but the [buying power model](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/buying-power.md) determines you can't afford it.

To avoid this order response error, [ensure you have enough margin remaining to cover the initial margin requirements](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/buying-power.md#13-Get-Initial-Margin-Requirements) of the order before placing it.

This error also commonly occurs when you place a market on open order with daily data. If you place the order with `set_holdings` or use `calculate_order_quantity` to determine the order quantity, LEAN calculates the order quantity based on the market close price. If the open price on the following day makes your order more expensive, then you may have insufficient buying power. To avoid the order response error in this case, either use intraday data and place trades when the market is open or [adjust your buying power buffer](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/position-sizing.md#06-Buying-Power-Buffer).

```python
self.settings.free_portfolio_value_percentage = 0.05
```

### Brokerage Model Refused to Submit Order

The `OrderResponseErrorCode.BROKERAGE_MODEL_REFUSED_TO_SUBMIT_ORDER` (-4) error occurs when you place an order but the [brokerage model](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/key-concepts.md) determines it's invalid. The brokerage model usually checks your order meets the following requirements before sending it to the brokerage:

- Supported security types
- Supported order types and their respective requirements
- Supported time in force options
- The order size is larger than the minimum order size

Each brokerage model can have additional order requirements that the brokerage declares. To avoid this order response error, see the **Orders** section of the [brokerage model documentation](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models.md).

To investigate this order response error further, see the `CanSubmitOrder` method definition of your [brokerage model](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models.md). This order response error occurs when the `CanSubmitOrder` method returns `False`.

### Brokerage Failed to Submit Order

The `OrderResponseErrorCode.BROKERAGE_FAILED_TO_SUBMIT_ORDER` (-5) error occurs when you place an order but the brokerage implementation fails to submit the order to your brokerage.

To investigate this order response error further, see the `PlaceOrder` method definition of your [brokerage](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models.md) or the [BacktestingBrokerage](https://github.com/QuantConnect/Lean/blob/master/Brokerages/Backtesting/BacktestingBrokerage.cs) in the LEAN GitHub repository. This order response error occurs when the `PlaceOrder` method throws an error or returns `false`.

### Brokerage Failed to Update Order

The `OrderResponseErrorCode.BROKERAGE_FAILED_TO_UPDATE_ORDER` (-6) error occurs when you try to update an order but the brokerage implementation fails to submit the order update request to your brokerage.

To avoid this order response error, see the **Orders** section of the [brokerage model documentation](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models.md).

To investigate this order response error further, see the `UpdateOrder` method definition of your [brokerage](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/brokerages.md) or the [BacktestingBrokerage](https://github.com/QuantConnect/Lean/blob/master/Brokerages/Backtesting/BacktestingBrokerage.cs) in the LEAN GitHub repository. This order response error occurs when the `UpdateOrder` method throws an error or returns `false`.

### Brokerage Failed to Cancel Order

The `OrderResponseErrorCode.BROKERAGE_FAILED_TO_CANCEL_ORDER` (-8) error occurs when you try to cancel an order but the brokerage implementation fails to submit the cancel request to your brokerage.

To investigate this order response error further, see the `CancelOrder` method definition of your [brokerage](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models.md) or the [BacktestingBrokerage](https://github.com/QuantConnect/Lean/blob/master/Brokerages/Backtesting/BacktestingBrokerage.cs) in the LEAN GitHub repository. This order response error occurs when `CancelOrder` method throws an error or returns `false`.

### Invalid Order Status

The `OrderResponseErrorCode.INVALID_ORDER_STATUS` (-9) error occurs when you try to update or cancel an order but the order is already complete. An order is complete if it has `OrderStatus.FILLED`, `OrderStatus.CANCELED`, or `OrderStatus.INVALID`.

To avoid this order response error, check the `status` of an [order ticket](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-management/order-tickets.md) or [order event](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-events.md) before you update or cancel the order.

```python
if not OrderExtensions.is_closed(order_ticket.status):
    order_ticket.cancel()
```

### Unable to Find Order

The `OrderResponseErrorCode.UNABLE_TO_FIND_ORDER` (-10) error occurs when you try to place, update, or cancel an order, but the `BrokerageTransactionHandler` doesn't have a record of the order ID.

To investigate this order response error further, see [BrokerageTransactionHandler.cs](https://github.com/QuantConnect/Lean/blob/master/Engine/TransactionHandlers/BrokerageTransactionHandler.cs) in the LEAN GitHub repository. This order response error occurs when the `BrokerageTransactionHandler` can't find the order ID in it's `_completeOrders` or `_completeOrderTickets` dictionaries.

### Order Quantity Zero

The `OrderResponseErrorCode.ORDER_QUANTITY_ZERO` (-11) error occurs when you place an order that has zero quantity or when you update an order to have a zero quantity. This error commonly occurs if you use the [SetHoldings](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/position-sizing.md) method but the portfolio weight you provide to the method is too small to translate into a non-zero order quantity.

To avoid this order response error, check if the quantity of the order is non-zero before you place the order. If you use the `set_holdings` method, replace it with a combination of the [CalculateOrderQuantity](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/position-sizing.md#05-Calculate-Order-Quantities) and [MarketOrder](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/market-orders.md) methods.

```python
quantity = self.calculate_order_quantity(self._symbol, 0.05)
if quantity:
    self.market_order(self._symbol, quantity)
```

### Unsupported Request Type

The `OrderResponseErrorCode.UNSUPPORTED_REQUEST_TYPE` (-12) error occurs in the following situations:

- When you try to exercise an Option contract for which you hold a short position
- When you try to exercise more Option contracts than you hold

To avoid this order response error, check the quantity of your holdings before you try to exercise an Option contract.

```python
holding_quantity = self.portfolio[self._contract_symbol].quantity
if holding_quantity > 0:
    self.exercise_option(self._contract_symbol, max(holding_quantity, exercise_quantity))
```

### Missing Security

The `OrderResponseErrorCode.MISSING_SECURITY` (-14) error occurs when you place an order for a security but you don't have a subscription for the security in your algorithm.

To avoid this order response error, create a subscription for each security you want to trade. To create subscriptions, see the Requesting Data page of the [documentation for each asset class](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/asset-classes.md).

### Exchange Not Open

The `OrderResponseErrorCode.EXCHANGE_NOT_OPEN` (-15) error occurs in the following situations:

- When you try to exercise an Option while the exchange is not open
  To avoid the order response error in this case, check if the exchange is open before you exercise an Option contract.
  ```python
  if self.is_market_open(self.contract_symbol):
      self.exercise_option(self.contract_symbol, quantity)
  ```
- When you try to place a market on open order for a Futures contract or a Future Option contract

### Security Price Zero

The `OrderResponseErrorCode.SECURITY_PRICE_ZERO` (-16) error occurs when you place an order or exercise an Option contract while the security price is $0. The security price can be $0 for the following reasons:

- The data is missing
  Investigate if it's a data issue. If it is a data issue, [report it](https://www.quantconnect.com/docs/v2/cloud-platform/datasets/data-issues.md#04-Report-New-Issues).
- The algorithm hasn't received data for the security yet
  If you subscribe to a security and place an order for the security in the same [time step](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/time-modeling/timeslices.md), you'll get this error. To avoid this order response error, enable the `seed_initial_prices` [setting](https://www.quantconnect.com/docs/v2/writing-algorithms/initialization.md#10-Set-Algorithm-Settings) to seed new assets with their last known price.
  ```python
  self.settings.seed_initial_prices = True
  ```

### Forex Base and Quote Currencies Required

The `OrderResponseErrorCode.FOREX_BASE_AND_QUOTE_CURRENCIES_REQUIRED` (-17) error occurs when you place a trade for a Forex or Crypto pair but you don't have the base currency and [quote currency](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/key-concepts.md#05-Quote-Currency) in your [cash book](https://www.quantconnect.com/docs/v2/writing-algorithms/portfolio/cashbook.md). This error should never occur. If it does, create a bug report.

### Forex Conversion Rate Zero

The `OrderResponseErrorCode.FOREX_CONVERSION_RATE_ZERO` (-18) error occurs when you place a trade for a Forex or Crypto pair and LEAN can't convert the value of the base currency to your account currency. This error usually indicates a lack of data. Investigate the data and if there is some missing, [report it](https://www.quantconnect.com/docs/v2/cloud-platform/datasets/data-issues.md#04-Report-New-Issues).

### Security Has No Data

The `OrderResponseErrorCode.SECURITY_HAS_NO_DATA` (-19) error occurs when you place an order for a security before your algorithm receives any data for it. If you subscribe to a security and place an order for the security in the same [time step](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/time-modeling/timeslices.md), you'll get this error. To avoid this order response error, enable the `seed_initial_prices` [setting](https://www.quantconnect.com/docs/v2/writing-algorithms/initialization.md#10-Set-Algorithm-Settings) to seed new assets with their last known price.

```python
self.settings.seed_initial_prices = True
```

### Exceeded Maximum Orders

The `OrderResponseErrorCode.EXCEEDED_MAXIMUM_ORDERS` (-20) error occurs when exceed your order quota in a backtest. The number of orders you can place in a single backtest depends on the tier of your [organization](https://www.quantconnect.com/docs/v2/cloud-platform/organizations/getting-started.md). The following table shows the number of orders you can place on each tier:

| Tier | Orders Quota |
| --- | --- |
| Free | 10K |
| Quant Researcher | 10M |
| Team | Unlimited |
| Trading Firm | Unlimited |
| Institution | Unlimited |

To avoid this order response error, reduce the number of orders in your backtest or [upgrade your organization](https://www.quantconnect.com/docs/v2/cloud-platform/organizations/billing.md#07-Change-Organization-Tiers).

### Market on Close Order Too Late

The `OrderResponseErrorCode.MARKET_ON_CLOSE_ORDER_TOO_LATE` (-21) error occurs when you try to place a market on close (MOC) order too early in the trading day.

To avoid this order response error, place the MOC order closer to the market close or adjust the submission time buffer. By default, you must place MOC orders at least 15.5 minutes before the close, but some exchanges let you submit them closer to the market closing time. To adjust the buffer period that's required, set the `MarketOnCloseOrder.submission_time_buffer` property.

```python
MarketOnCloseOrder.submission_time_buffer = timedelta(minutes=10)
```

### Invalid Request

The `OrderResponseErrorCode.INVALID_REQUEST` (-22) error occurs when you try to cancel an order multiple times.

To avoid this order response error, only try to cancel an order one time.

### Request Canceled

The `OrderResponseErrorCode.REQUEST_CANCELED` (-23) error occurs when you try to cancel an order multiple times.

To avoid this order response error, only try to cancel an order one time.

### Algorithm Warming Up

The `OrderResponseErrorCode.ALGORITHM_WARMING_UP` (-24) error occurs in the following situations:

- When you try to place, update, or cancel an order during the [warm-up period](https://www.quantconnect.com/docs/v2/writing-algorithms/historical-data/warm-up-periods.md)
- When the [Option assignment simulator](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/option-exercise-orders.md#04-Option-Assignments) assigns you to an Option during the warm-up period

To avoid this order response error, only manage orders after the warm-up period ends. To avoid trading during the warm-up period, add an `is_warming_up` guard to the top of the `on_data` method.

```python
if self.is_warming_up: return
```

### Brokerage Model Refused to Update Order

The `OrderResponseErrorCode.BROKERAGE_MODEL_REFUSED_TO_UPDATE_ORDER` (-25) error occurs in backtests when you try to update an order in a way that the [brokerage model](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/key-concepts.md) doesn't support.

To avoid this issue, see the **Orders** section of the [brokerage model documentation](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models.md) to check its order requirements.

To investigate this order response error further, see the `CanUpdateOrder` method definition of your [brokerage model](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models.md).

### Quote Currency Required

The `OrderResponseErrorCode.QUOTE_CURRENCY_REQUIRED` (-26) error occurs when you place an order for a Forex or Crypto pair and don't have the [quote currency](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/key-concepts.md#05-Quote-Currency) of the pair in your [cash book](https://www.quantconnect.com/docs/v2/writing-algorithms/portfolio/cashbook.md). This error should never occur. If it does, create a bug report.

### Conversion Rate Zero

The `OrderResponseErrorCode.CONVERSION_RATE_ZERO` (-27) error occurs when you place an order for a Forex or Crypto pair and LEAN can't convert the value of the [quote currency](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/key-concepts.md#05-Quote-Currency) in the pair to your account currency. This order response error usually indicates a lack of data. Investigate the data and if there is data missing, [report it](https://www.quantconnect.com/docs/v2/cloud-platform/datasets/data-issues.md#04-Report-New-Issues).

### Non-Tradable Security

The `OrderResponseErrorCode.NON_TRADABLE_SECURITY` (-28) error occurs when you place an order for a security that's not [tradable](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/key-concepts.md#05-Tradable-Status). To avoid this order response error, check if a security is tradable before you trade it.

```python
if self.securities[self._symbol].is_tradable:
    self.market_order(self._symbol, quantity)
```

### Non-Exercisable Security

The `OrderResponseErrorCode.NON_EXERCISABLE_SECURITY` (-29) error occurs when you call the [exercise_option](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/option-exercise-orders.md) method with a `Symbol` that doesn't reference an Option contract.

### Order Quantity Less Than Lot Size

The `OrderResponseErrorCode.ORDER_QUANTITY_LESS_THAN_LOT_SIZE` (-30) error occurs when you place an order with a quantity that's less than the lot size of the security.

To avoid this order response error, check if the order quantity is greater than or equal to the security lot size before you place an order.

```python
lot_size = self.securities[self._symbol].symbol_properties.lot_size
if quantity >= lot_size:
    self.market_order(self._symbol, quantity)
```

### Exceeds Shortable Quantity

The `OrderResponseErrorCode.EXCEEDS_SHORTABLE_QUANTITY` (-31) error occurs when you place an order to short a security but the [shortable provider](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/short-availability/key-concepts.md) of the brokerage model states there isn't enough shares to borrow. The following algorithm demonstrates this error by using a custom shortable provider that limits shorts to 10 shares and then trying to short 12 shares.

```python
# Demonstrate ExceedsShortableQuantity error with a custom shortable provider.
class ExceedsShortableQuantityAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2021, 7, 23)
        self.set_end_date(2021, 7, 30)
        self.set_cash(100000)
        self.set_brokerage_model(CustomShortBrokerageModel())
        self.add_equity("SPY", Resolution.MINUTE)

    def on_data(self, data):
        if not self.portfolio.invested:
            self.market_order("SPY", 1)
        else:
            # Try to short 12 shares, which exceeds the shortable quantity of 10.
            self.market_order("SPY", -12)

    def on_order_event(self, order_event):
        self.debug(f"{self.time} -- {order_event.message}")

# Custom shortable provider that limits shorts to 10 shares.
class CustomShortableProvider:
    def all_shortable_symbols(self, local_time):
        return None
    def shortable_quantity(self, symbol, local_time):
        return 10

# Custom brokerage model using the shortable provider.
class CustomShortBrokerageModel(DefaultBrokerageModel):
    def __init__(self):
        super().__init__(AccountType.MARGIN)
        self.shortable_provider = CustomShortableProvider()
```

To avoid this order response error, check if there are enough shares available before you place an order to short a security.

```python
if quantity_to_borrow <= self.shortable_quantity(self._symbol):
    self.market_order(self._symbol, -quantity_to_borrow)
```

### Invalid New Order Status

The `OrderResponseErrorCode.INVALID_NEW_ORDER_STATUS` (-32) error occurs in live trading when you try to update or cancel an order while it still has `OrderStatus.NEW` status.

To avoid this order response error, check the `status` property of the [order ticket](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-management/order-tickets.md) or [order event](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-events.md) before you update or cancel an order.

```python
if self.order_ticket.status != OrderStatus.NEW:
    self.order_ticket.cancel()
```

### European Option Not Expired on Exercise

The `OrderResponseErrorCode.EUROPEAN_OPTION_NOT_EXPIRED_ON_EXERCISE` (-33) error occurs when you try to exercise a European Option contract before its expiry date.

To avoid this order response error, check the type and expiry date of the contract before you exercise it.

```python
if self.contract_symbol.id.option_style == OptionStyle.EUROPEAN && self.contract_symbol.id.date == self.time.date:
    self.exercise_option(self.contract_symbol, quantity)
```

### Option Order on Stock Split

The `OrderResponseErrorCode.OPTION_ORDER_ON_STOCK_SPLIT` (-34) error occurs when you try to submit an order for an Equity Option contract when the current [time slice](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/time-modeling/timeslices.md) contains a [split](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/asset-classes/us-equity/corporate-actions.md#02-Splits) for the underlying Equity.

To avoid this order response error, check if the time slice has a split event for the underlying Equity of the contract before you place an order for the contract.

```python
if self.contract_symbol.underlying not in slice.splits:
    self.market_order(self.contract_symbol, quantity)
```

### Market on Open Not Allowed During Regular Hours

The `OrderResponseErrorCode.MARKET_ON_OPEN_NOT_ALLOWED_DURING_REGULAR_HOURS` (-35) error occurs when you try to place a [market on open order](https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/market-on-open-orders.md) for an asset when it's during regular trading hours.

To avoid this order response error, place the order when the market is closed.

```python
if not self.is_market_open(self._symbol):
    self.market_on_open_order(self._symbol, quantity)
```

## Warnings

The following sections explain why each some warnings occur and how to avoid them.

### Limit Price Exceeds Precision Requirements

Limit prices must be a multiple of the security's `minimum_price_variation` [property](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/key-concepts.md#06-Symbol-Properties). Otherwise, LEAN rounds the limit price for you and throws the following warning message:

`Backtest Handled Error: Warning: To meet brokerage precision requirements, order LimitPrice was rounded to 6136.00 from 6136.125`

To avoid the warning, round the limit price to the nearest value that respects the `minimum_price_variation` before you place the order.

```python
def _adjust_limit_price(self, security, price, round_up=True):
    pip = security.price_variation_model.get_minimum_price_variation(
        GetMinimumPriceVariationParameters(security, price)
    )
    return (int(price / pip) + int(round_up)) * pip
```

## Examples

The following examples demonstrate common practices for handling order errors.

### Example 1: Pre-Open Order Error

The following algorithm simulate extended market hour trading on [Tradier Brokerage](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/tradier.md). We place a market-on-open order at 7:30am and expect the order cannot submit to the broker since it is not supported, resulting into an error.

```python
class OrderErrorsAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        # Simulate Tradier brokerage, which does not support the market-on-open orders.
        self.set_brokerage_model(BrokerageName.TRADIER_BROKERAGE, AccountType.CASH)

        # Request extended market hour SPY data for trading.
        self.spy = self.add_equity("SPY", extended_market_hours=True).symbol

        # Set a scheduled event to trade 2 hours pre-open to place the market-on-open-order.
        self.schedule.on(
            self.date_rules.every_day(self.spy),
            self.time_rules.before_market_open(self.spy, 120),
            self.open_position
        )

    def open_position(self) -> None:
        # Buy on market open will result in an error since Tradier does not support it.
        self.market_on_open_order(self.spy, 10)

    # It will be triggered on live trading.
    def on_brokerage_message(self, message: BrokerageMessageEvent) -> None:
        if message.type == BrokerageMessageType.ERROR:
            self.log(f"{self.time}: {message.type}: Message: {message.message}")
```
