Skip to main content

Market orders

Market order is an order to conclude a transaction to buy/sell stated number of lots of a financial instrument at the current market price. Price of the best counter offer in the order book will be used as the market price.


General information

Market orders have a few features that must be noted when trading using them. In particular, keep in mind that:

Market order is a direct order.

Direct orders passing to the Exchange without additional processing or waiting for specific conditions on the trading system side. Such orders are visible for all traders and affect the order book of the selected instrument. Also, the funds (money/lots) required to fulfill a direct order will be reserved at the moment of its posting.

Market order affects the order book but does not fill it.

Unlike limit orders, market orders are not queued for fulfillment in the order book. Instead, such order takes the best counter offer from the book and consumes the volume that is requested or available. The only exception is when the requested volume exceeds total volume of all available counter offers.

Market order has the highest potential for fulfillment.

Transactions on market orders are made at the current market price, which means that there is no need to wait for matching counter offers, as it happens with limit orders. The only condition under which the market order will not be completely fulfilled is the absence of counter offers on the market.

Example

Trader posts a market order to buy 1000 lots of the instrument. If the total volume of counter offers in the order book is more than this value then the order will be fulfilled. If less - the order will be partially fulfilled or canceled depending on the selected timeInForce value.

Medium lot price may differ from the best lot price for the moment when the order was posted.

Market orders are affected by the slippage effect: if the counter offer with the best lot price does not fully fill the order placed, the next counter offer will be used to cover the missing part. So, the price of the next offer will become the new best price of the lot and the deal for the rest will be made at this price.

Example

Trader posts a market order to buy 1000 lots of an instrument. The counter offer with the best price of RUB 300 per lot contains only 200 lots. The next offer with the price of RUB 301 contains 600 lots. The third offer in the book also contains 600 lots, but at the price of RUB 302. When fulfilling the order, the first two offers will be consumed in full, while the third one will be used to fill the part missing after the first two. Transactions will be concluded at the price of counter offers, because of which the medium price of a lot will be equal to RUB 301 in such an order instead of RUB 300 of the price that was the best at the time of placing the order.

Order collateralization

Market order must be collateralized in accordance with the client's risk level and trading method:

  • For non-marginal trading, the collateral for the order is the full value of the order with a 5% surcharge in case of price changes;

  • For margin trading, collateral depends on the client's risk level with a 1% surcharge in case of price changes.

You can check the sufficiency of funds by the order evaluation request. To find out the terms and conditions of the order collateral depending on the risk level, click here.

Market orders should be considered as an almost guaranteed way to make a deal with the selected instrument as quick as it possible by any price.

If this method does not fit the trading strategy you use, we recommend to try limit orders to make trades at the desired price.


Conditions

The main condition for order execution is the timeInForce parameter, which regulates the processing of the order balance after exhaustion of all counter offers of the market. Possible values:

Condition

Description

oneday

Order shall be valid during the trading day. The balance after withdrawal of the entire available volume of counter offers shall be placed in the queue for execution and shall be held until order fulfillment, cancellation or the end of the trading day within which the order was placed.

goodtillcancelled

Similar to oneday, but with no time limit — the balance is held in the queue until the order is complete or canceled.

immediateorcancel

Order is fulfilled for the volume available at the moment of placement, the rest is canceled.

fillorkill

Order can be fulfilled only in its entirety. If the available volume does not allow to fulfill the order, it will not be placed at all.


Request examples

Common requirements

An order through the API can be posted, changed and canceled if it has not been executed before. In this case, regardless of the selected action and interaction protocol, all requests must:

  • be authorized
  • be identifiable
  • contain a message with all order parameters

How these conditions should be met, however, depends on the interaction protocol.

Authorization

Authorization is necessary to confirm that the sender has the rights to use the requested resource. Request authorization uses a JWT token, which acts as an Access token. A full description of available authorization methods is available in the Authorization section.

HTTP API uses the Authorization header parameter to pass the token. The header must be passed with each executed request.

This token should be passed as a Bearer token, so the header must contain the Bearer prefix before the passed value. A correctly filled Authorization header looks as follows:

Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJzdWIiOiJMb2dpblNhbXBsZSIsImVudCI6ImNsaWVudCIsImVpbiI6IjAxMjM0IiwiY2xpZW50aWQiOiIwMTIzNDU2IiwiYXpwIjoiMDEyMzQ1Njc4OWFiY2RlZjAxMjMiLCJhZ3JlZW1lbnRzIjoiQWdyZWVtZW50U2FtcGxlMSBBZ3JlZW1lbnRTYW1wbGUyIEFncmVlbWVudFNhbXBsZTMiLCJwb3J0Zm9saW9zIjoiUG9ydGZvbGlvU2FtcGxlMSBQb3J0Zm9saW9TYW1wbGUyIFBvcnRmb2xpb1NhbXBsZTMiLCJzY29wZSI6Ik9yZGVyc1JlYWQgT3JkZXJzQ3JlYXRlIFRyYWRlcyBQZXJzb25hbCBTdGF0cyIsImV4cCI6Mjg3MTc2MzE5OSwiaWF0IjowLCJpc3MiOiJBbG9yLklkZW50aXR5IiwiYXVkIjoiQ2xpZW50IFdBUlAgV2FycEFUQ29ubmVjdG9yIHN1YnNjcmlwdGlvbnNBcGkgQ29tbWFuZEFwaSBJbnN0cnVtZW50QXBpIFRyYWRpbmdWaWV3UGxhdGZvcm0ifQ.QOQVMIAoZ6SnF5urnIzJ0EvtQd9P5Sx355069kXoID207wHOTW0wkKNMcrIKXmENEQQ_0yDjqH_kjeqWLBJuqA

Identification

Request identification is needed to sort out a dozen of similar requests into unique ones. The identifier must be provided by the user and passed as a value of the X-REQID header parameter, so the API client used must be able to generate it.

Any character combination can be used as a request identifier, including the wildcard characters !@##;%:?*()-_=+/|''. Identifier has two restrictions:

  • The identifier value must be unique for the trading system. If the value has been previously used for another request, a copy of the response to the first request with this identifier will be returned instead of execution of the new request

  • Wildcard characters that violate the integrity of a JSON object must be escaped

Thus, the system will accept both Dxxxxx-Order-Market-No-812643-@-MOEX and d3c886f1-ea1e-4634-aff4-119c902ad926 as the request identifier, provided that these values have not been previously passed to the system by any API user.

A properly filled X-REQID parameter does not require any additional prefixes and looks as follows:

X-REQID: d3c886f1-ea1e-4634-aff4-119c902ad926


Order management

Interchangeability

Order management options are interchangeable. For example, an order placed via HTTP API can be changed or canceled via WebSocket API, and vice versa.

Creating order

Interactive description

Interactive description of this request is available at the Create Market order page

To create a market order via HTTP API, use a POST request to the /commandapi/warptrans/TRADE/v2/client/orders/actions/market endpoint with a message containing all order parameters.

Complete URL looks as follows:

https://api.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/actions/market

https://apidev.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/actions/market

The message body should contain basic information about the order: side, number of lots, instrument data, portfolio and condition for execution of the order. If necessary, you can add a custom comment to make it easier to identify the order by a human.

Request body example
{
"side": "buy",
"quantity": 100,
"instrument": {
"symbol": "SBER",
"exchange": "MOEX",
"instrumentGroup": "TQBR"
},
"comment": "Custom comment",
"user": {
"portfolio": "D39004"
},
"timeInForce": "oneday"
}
Expected result

A market order was created to buy 100 lots of SBER on the Moscow Exchange (MOEX) in the T+2 (TQBR) mode at the price that is the best lot price at the moment of execution.

If the request is successful, the API will return a message with response code 200 containing the exchange order number:

Response body example
{
"message": "success",
"orderNumber": "189...559"
}

If the request processing ended with an error, the API will return information about the cause of this error.

Request parameters

A complete list of all parameters and possible responses is available on the request description page.

Changing order

Interactive description

Interactive description of this request is available at the Update Market order page

To change a previously posted order via the HTTP API, a PUT request to the /commandapi/warptrans/TRADE/v2/client/orders/market/{orderId} endpoint is used, where {orderId} is a Path parameter that passes the order number.

How the order will be changed?

Modification of the order is made by canceling the previously placed order and publishing a new one. It is not possible to change fulfilled or canceled orders.

Complete URL looks as follows:

https://api.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/actions/market/189...559

https://apidev.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/actions/market/189...559

Where 189...559 is the actual value of the {orderId} parameter.

When changing an existing order, a message identical to the order posting request is used. The difference is in other parameter values.

Request body example
{
"side": "buy",
"quantity": 10,
"instrument": {
"symbol": "SBER",
"exchange": "MOEX",
"instrumentGroup": "TQBR"
},
"comment": "Custom comment",
"user": {
"portfolio": "D39004"
},
"timeInForce": "oneday"
}
Expected result

The order with the number 189...559 has been canceled. A new market order was created to buy 10 lots of the SBER on the Moscow Exchange (MOEX) in the T+2 (TQBR) mode at the price that is the best price of the lot at the moment of execution.

If the request is successful, the previous order will be canceled and the API will return a message with response code 200 containing the exchange number of the new order:

Response body example
{
"message": "success",
"orderNumber": "189...560"
}

If the request processing ended with an error, the API will return information about the cause of this error.

Request parameters

A complete list of all parameters and possible responses is available on the request description page.

Cancelling order

Interactive description

Interactive description of this request is available at the Cancel one order page

What orders can be canceled?

Only pending orders can be canceled. It is impossible to cancel fulfilled orders.

To cancel a previously posted order via HTTP API, a DELETE request to the /commandapi/warptrans/TRADE/v2/client/orders/{orderId} endpoint is used, where {orderId} is a Path parameter that passes the order number.

In addition to the order number, the following attributes of the order are also required:

Query parameters

    portfolio stringrequired

    Client portfolio Id

    Example: D39004
    exchange stringrequired

    Possible values: [MOEX]

    Exchange code

    stop booleanrequired

    Is it a stop order?

    Example: false

So, the complete URL of the request to cancel the order looks as follows:

https://api.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/189...560?portfolio=D39004&exchange=MOEX&stop=false

https://apidev.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/189...560?portfolio=D39004&exchange=MOEX&stop=false

Expected result

Order with number 189...560 has been canceled.

If the request is successful, the previous order will be canceled and the API will return a message with response code 200:

success

If the request processing ended with an error, the API will return information about the cause of this error.

Request parameters

A complete list of all parameters and possible responses is available on the request description page.

Group of orders

If necessary, a market order can be grouped with other orders for cohesive execution.


What's next?

Additionally, we recommend reading the following related articles: