# Reference: Order Response Types
The tables below provide detailed reference for specific validation scenarios and their responses.
## New Orders
### Stateless validation

Order requests with below errors are validated and rejected by the gateway. They do not send any request to the engine, and do not create an order or execution. They result in either 400 (invalid input) or 401 (unauthorized)

| Problem	                                                                  | Response Code	 | Response	                                    |
|---------------------------------------------------------------------------|----------------|----------------------------------------------|
| Not logged in                                                             | 401            | Invalid Request                              |
| Symbol length is more than 23 characters or contains non-ascii characters | 400            | Invalid symbol                               |
| Cannot determine order type from input                                    | 400            | Invalid ordType                              |
| Contains an ExecInst that does not exist                                  | 400            | Invalid execInst                             |
| Order quantity is not set and is not a close order                        | 400            | orderQty is required                         |
| Close stop order does not specify side                                    | 400            | Invalid side                                 |
| Order quantity is zero for a non-close whole position order               | 400            | Invalid orderQty                             |
| Side is not 'Buy' or 'Sell'                                               | 400            | Invalid side                                 |
| Side is buy, but quantity is negative                                     | 400            | Inconsistent side/orderQty                   |
| Price is not specified on a Limit, StopLimit or LimitIfTouched order      | 400            | Invalid price                                |
| Price is specified on a Market, Stop or MarketIfTouched order             | 400            | Invalid price                                |
| Specified price is not finite                                             | 400            | Invalid price                                |
| Display quantity is larger than quantity                                  | 400            | Invalid displayQty                           |
| Stop price specified on non-stop order                                    | 400            | Invalid stopPx for ordType                   |
| Client order id is longer than 36 characters                              | 400            | clOrdID must be at most 36 characters.       |
| Client order id contains non-ascii characters                             | 400            | Invalid clOrdLinkID                          |
| Expire time set for a non-goodtilldate order                              | 400            | expireTime is not valid for this TimeInForce |
| Stop price type specified on a non-stop order                             | 400            | Invalid ordType for execInst                 |
| Price type not set on a stop order                                        | 400            | Invalid execInst                             |
| Order is ParticipateDoNotInitiate and also ImmediateOrCancel              | 400            | Invalid ordType or timeInForce for execInst  |
| Contingency type is set but not OneCancelsTheOther or OneTriggersTheOther | 400            | Invalid contingencyType                      |
| Contingency type is set but clOrdLinkID is not                            | 400            | Invalid clOrdLinkID for contingencyType      |
| Text is longer than 128 characters                                        | 400            | text must be at most 128 characters.         |
| Text contains non-ascii characters                                        | 400            | Invalid text                                 |
| Text is longer than 128 characters                                        | 400            | text must be at most 128 characters.         |

### Stateful validation

Order requests with below errors are validated causing a command to be sent to the engine. They are then rejected by the engine. The engine sends an immediate rejection and does not create an order, nor does it create an execution.

| Problem	                                                               | Response Code	 | Response	                                                                    | Notes                                                                                           |
|------------------------------------------------------------------------|----------------|------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| Instrument does not exist                                              | 400            | Unknown or expired instrument                                                |                                                                                                 |
| Account number is negative                                             | 400            | Specified account number must be positive                                    |                                                                                                 |
| Exchange is suspended                                                  | 400            | Exchange is suspended                                                        |                                                                                                 |
| Expire time on good-till-date order is in the past                     | 400            | Expire time on a GoodTillDate order must be in the future                    |                                                                                                 |
| Another order with this client order id already exists on this account | 400            | Duplicate clOrdID                                                            |                                                                                                 |
| Instrument has expired                                                 | 400            | Instrument expired                                                           |                                                                                                 |
| Order entered before instrument listingTime                            | 400            | Market is not open yet                                                       |                                                                                                 |
| Price is above the maximum price                                       | 400            | Price is above the maximum                                                   |                                                                                                 |
| Price is below the minimum price                                       | 400            | Price is below the minimum                                                   |                                                                                                 |
| Price divided by tick size is not an integer                           | 400            | Price must be a multiple of {tickSize}                                       | If price / tick size is within 0.000001, it's rounded to the 'correct' price. Otherwise reject. |
| Marked price stop order on a last-priced instrument                    | 400            | Cannot place a market price stop order on a last-priced instrument: {symbol} |                                                                                                 |
| Stop price is above the maximum price                                  | 400            | Price is above the maximum                                                   |                                                                                                 |
| Stop price is below the minimum price                                  | 400            | Price is below the minimum                                                   |                                                                                                 |
| Stop price divided by tick size is not an integer                      | 400            | Price must be a multiple of {tickSize}                                       |                                                                                                 |
| Quantity exceeds max order quantity                                    | 400            | Order quantity is above the maximum for this instrument                      |                                                                                                 |
| Quantity is not a multiple of the lot size                             | 400            | Order quantity must be a multiple of lot size: {lotsize}                     |                                                                                                 |
| Display quantity is not a multiple of the lot size                     | 400            | Display quantity must be a multiple of lot size: {lotsize}                   |                                                                                                 |
| Too many open orders                                                   | 400            | Too many open orders                                                         | Limit of 200 per instrument by default                                                          |
| Contingent link id is not valid for the contingency type               | 400            | This contingency link ID is invalid                                          |                                                                                                 |
| Position count limit exceeded                                          | 400            | Cannot have positions/orders on more than {limit} instruments                | If a limit is set on the exchange                                                               |

### Market validation

Order requests below are valid and result in a new order being created and subsequently canceled

| Problem	                                                      | Creates Execution	  | Response Code	 | Response	                                                                     | OrdRejReason	                  | Notes                     |
|---------------------------------------------------------------|---------------------|----------------|-------------------------------------------------------------------------------|--------------------------------|---------------------------|
| Close order quantity increases the position                   | New,Cancel          | 200            |                                                                               | OrderIncreasesPosition         |                           |
| Order would exceed the open value cap                         | New,Cancel          | 400            | Exchange would exceed the maximum available open interest for this instrument | InstrumentOpenValueCapExceeded |                           |
| Post only trade would match immediately                       | New,Cancel          | 200            |                                                                               | ImmediateMatchPostOnly         |                           |
| Fill or kill trade cannot be immediately filled               | New,Cancel          | 200            |                                                                               | UnfilledFillOrKill             |                           |
| Insufficient margin                                           | New,Cancel          | 400            | Account has insufficient Available Balance, {amount} {currency} required      | InsufficientBalance            |                           |
| Exceeds risk limit                                            | New,Cancel          | 400            | Order would exceed the risk limit on the account                              | RiskLimitExceeded              |                           |
| ImmediateOrCancel order could not be completely filled        | New,(Trade,)*Cancel | 200            |                                                                               | UnfilledImmediateOrCancel      | Can contain partial fills |
| Market order could not be completely filled                   | New,(Trade,)*Cancel | 200            |                                                                               | UnfilledMarketOrder            |                           |
| Trigger order for OneTriggersTheOther is already canceled     | New,Cancel          | 200            |                                                                               | TriggerCanceled                |                           |
| Another order in a OneCancelsTheOther group is already filled | New,Cancel          | 200            |                                                                               | OcoFilled                      |                           |
| Implied price on a pegged order be above max price            | New,Cancel          | 200            |                                                                               | PeggedOrderPriceAboveMaxPrice  |                           |
| Implied price on a pegged order be below min price            | New,Cancel          | 200            |                                                                               | PeggedOrderPriceBelowMinPrice  |                           |
| Market lacks a bid/offer to use for creating a pegged order   | New,Cancel          | 200            |                                                                               | NoLiquidityForPeg              |                           |

## Amends
### Stateless validation

Amend requests with below errors are validated and rejected by the gateway. They do not send any command to the engine. They result in either 400 (invalid input) or 401 (unauthorized)

| Problem	                                               | Response Code	 | Response	                              |
|--------------------------------------------------------|----------------|----------------------------------------|
| Not logged in                                          | 401            | Invalid Request                        |
| orderId is not a valid UUID                            | 400            | OrderID {orderId} is not a valid UUID  |
| Client order id is longer than 36 characters           | 400            | clOrdID must be at most 36 characters. |
| Client order id contains non-ascii characters          | 400            | Invalid clOrdLinkID                    |
| Original client order id is longer than 36 characters  | 400            | clOrdID must be at most 36 characters. |
| Original client order id contains non-ascii characters | 400            | Invalid clOrdLinkID                    |
| Text is longer than 128 characters                     | 400            | text must be at most 128 characters.   |
| Text contains non-ascii characters                     | 400            | Invalid text                           |

### Stateful validation

Amend requests with below errors are validated and rejected by the engine. The engine sends an immediate rejection and does not amend the order.

| Problem	                                                                   | Creates Command	 | Amends Order	 | Creates Execution	 | Response Code	 | Response	                                                                                     | Notes                                                                                           |
|----------------------------------------------------------------------------|------------------|---------------|--------------------|----------------|-----------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| Exchange is suspended                                                      | TRUE             | FALSE         |                    | 400            | Exchange is suspended                                                                         |                                                                                                 |
| Amending an unknown orderId                                                | TRUE             | FALSE         |                    | 400            | Unknown orderID                                                                               |                                                                                                 |
| new clOrderId already exists                                               | TRUE             | FALSE         |                    | 400            | Duplicate clOrdID                                                                             |                                                                                                 |
| passed an orderId and a clOrdId that refer to different orders             | TRUE             | FALSE         |                    | 400            | orderID and clientOrderId resolve to different orders                                         |                                                                                                 |
| Amending an unknown clOrdId                                                | TRUE             | FALSE         |                    | 400            | Invalid clientOrderId                                                                         | This applies to amend that are exclusively referencing a clOrdId                                |
| Amending a Filled order                                                    | TRUE             | FALSE         |                    | 400            | Cannot amend a filled order                                                                   |                                                                                                 |
| Amending a Canceled order                                                  | TRUE             | FALSE         |                    | 400            | Cannot amend a cancelled order                                                                |                                                                                                 |
| Amending an Expired order                                                  | TRUE             | FALSE         |                    | 400            | Cannot amend an expired order                                                                 |                                                                                                 |
| Price is below the minimum price                                           | TRUE             | FALSE         |                    | 400            | Price is below the minimum                                                                    |                                                                                                 |
| Quantity exceeds max order quantity                                        | TRUE             | FALSE         |                    | 400            | Order quantity is above the maximum for this instrument                                       |                                                                                                 |
| Quantity is not a multiple of the lot size                                 | TRUE             | FALSE         |                    | 400            | Order quantity must be a multiple of lot size: {lotsize}                                      |                                                                                                 |
| Price is above the maximum price                                           | TRUE             | FALSE         |                    | 400            | Price is above the maximum                                                                    |                                                                                                 |
| Price is below the minimum price                                           | TRUE             | FALSE         |                    | 400            | Price is below the minimum                                                                    |                                                                                                 |
| Price divided by tick size is not an integer                               | TRUE             | FALSE         |                    | 400            | Price must be a multiple of {tickSize}                                                        | If price / tick size is within 0.000001, it's rounded to the 'correct' price. Otherwise reject. |
| Amending stop price on an already activated stop order                     | TRUE             | FALSE         |                    | 400            | Cannot amend stop price on an already activated stop order                                    |                                                                                                 |
| Stop price is above the maximum price                                      | TRUE             | FALSE         |                    | 400            | Price is above the maximum                                                                    |                                                                                                 |
| Stop price is below the minimum price                                      | TRUE             | FALSE         |                    | 400            | Price is below the minimum                                                                    |                                                                                                 |
| Stop price divided by tick size is not an integer                          | TRUE             | FALSE         |                    | 400            | Price must be a multiple of {tickSize}                                                        | If price / tick size is within 0.000001, it's rounded to the 'correct' price. Otherwise reject. |
| Amending expire time on an order that is not a GoodTillDate order          | TRUE             | FALSE         |                    | 400            | Can only amend expire time on GoodTillDate orders                                             |                                                                                                 |
| Amending an order in a way that doesn't change anything on the order       | TRUE             | FALSE         |                    | 400            | Invalid amend: orderQty, leavesQty, price, stopPx, client order Id, and expire time unchanged |                                                                                                 |
| Amending price on post only order in a way that makes it immediately match | TRUE             | FALSE         |                    | 400            | Post only order would match immediately                                                       |                                                                                                 |
| Amending the order in a way that exceeds risk limit                        | TRUE             | FALSE         |                    | 400            | Order would exceed the risk limit on the account                                              |                                                                                                 |
| Amending the order in a way that exceeds open value cap                    | TRUE             | FALSE         |                    | 400            | Exchange would exceed the maximum available open interest for this instrument                 |                                                                                                 |
| Amending the order in a way that requires more margin than available       | TRUE             | FALSE         |                    | 400            | Account has insufficient Available Balance, {amount} {currency} required                      |                                                                                                 |

### Market validation

Amend requests below are valid and result in an order being amended and subsequently cancelled

| Problem	                                                                | Creates Command	 | Amends Order	 | Creates Execution	 | Response Code	 | Response	 | Notes                                                                       |
|-------------------------------------------------------------------------|------------------|---------------|--------------------|----------------|-----------|-----------------------------------------------------------------------------|
| Amend quantity to 0 or negative number                                  | TRUE             | TRUE          | Cancel             | 200            | Success   | quantity on amends is in absolute value as we can't change side on an order |
| Amend quantity to less than the amount already filled cancels the order | TRUE             | TRUE          | Cancel             | 200            | Success   |                                                                             |
| Amend leaves quantity to 0 or negative number                           | TRUE             | TRUE          | Cancel             | 200            | Success   | quantity on amends is in absolute value as we can't change side on an order |
| Amend expire time to the past on GoodTillDate order                     | TRUE             | TRUE          | Cancel             | 200            | Success   |                                                                             |
| Amend an order price in a way that makes it match in the market         | TRUE             | TRUE          | Fill/PartialFill   | 200            | Success   |                                                                             |

## Cancels
### Stateless validation

Cancel requests with below errors are validated and rejected by the gateway. They do not send any request to the engine. They result in either 400 (invalid input) or 401 (unauthorized)

| Problem	                                      | Creates Command	 | Response Code	 | Response	                                           | Notes                                                                    |
|-----------------------------------------------|------------------|----------------|-----------------------------------------------------|--------------------------------------------------------------------------|
| Not logged in                                 | FALSE            | 401            | Invalid Request                                     |                                                                          |
| Text is longer than 128 characters            | FALSE            | 400            | text must be at most 128 characters.                |                                                                          |
| Text contains non-ascii characters            | FALSE            | 400            | Invalid text                                        |                                                                          |
| Cancelling too many orders                    | FALSE            | 400            | OrderID list is too long, the maximum is 256 orders |                                                                          |
| orderId is not a valid UUID                   | FALSE            | 400            | OrderID {orderId} is not a valid UUID               |                                                                          |
| Client order id is longer than 36 characters  | FALSE            | 400            | clOrdID must be at most 36 characters.              |                                                                          |
| Client order id contains non-ascii characters | FALSE            | 400            | Invalid clOrdLinkID                                 |                                                                          |
| Not specifying any order to cancel            | FALSE            | 400            | No orders were specified                            |                                                                          |
| Cancel all after doesn't specify a timeout    | FALSE            | 400            | timeout required                                    | a timeout of 0 is valid and annuls the previous cancel all after command |

### Stateful validation

Cancel requests with below errors are validated and rejected by the engine. The engine sends an error for the impacted order ids but could still proceed to cancel other valid order ids in the same cancel request

| Problem	                              | Creates Command	 | Response Code	 | Response	                                | Notes                                                                                                                                                          |
|---------------------------------------|------------------|----------------|------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Cancelling an unknown order Id        | TRUE             | 200            | NotFound                                 | The cancel order commands can take multiple order IDs. The response is 200 but can still contain errors for some of the orderIds while valid ones get canceled |
| Cancelling an unknown client order Id | TRUE             | 200            | NotFound                                 | The cancel order commands can take multiple order IDs. The response is 200 but can still contain errors for some of the orderIds while valid ones get canceled |
| Cancelling an already cancelled order | TRUE             | 200            | Cannot cancel an already cancelled order |                                                                                                                                                                |
| Cancelling an already filled order    | TRUE             | 200            | Cannot cancel an already filled order    |                                                                                                                                                                |
| Cancelling an already expired order   | TRUE             | 200            | Cannot cancel an expired order           |                                                                                                                                                                |

### Other reasons an order could get canceled

| Problem	                                                      	         | Creates Execution	   |
|-------------------------------------------------------------------------|----------------------|
| Timeout of "cancel all after" is reached                                | Cancel               |
| Another "oneCancelsTheOther" contingent order is PartiallyFilled/Filled | Cancel               |
| Trigger of "oneTriggersTheOther" contingent order is Cancelled          | Cancel               |
| Instrument is expired                                                   | Cancel               |
| Account is liquidated                                                   | Cancel               |
| Amend quantity down to leave 0 quantity to be filled                    | Cancel               |
| Market order is not fully filled                                        | PartialFill*, Cancel |
| ImmediateOrCancel is not fully filled                                   | PartialFill*, Cancel |
