Group of orders
To partially automate trading and reduce risks associated with market fluctuations, we recommend to combine the orders into groups.
A group of orders (also known as bracket orders) is a set of several orders united by a specific execution condition.
Creation of an order group means only combining several orders into one group and has nothing to do with group creation of orders. All orders to be combined into a group must be created by the corresponding requests beforehand.
General information
The possibility of combining several orders into a group has a number of features that must be noted. In particular, keep in mind that:
No order groups exist for the Exchange.
All information about the created group is storing on the Broker's servers and will not be passed to the Exchange, therefore the existence of the group is hidden from other traders and its existence can only be guessed by indirect signs.
Quantity of groups is not limited.
The user can create any number of order groups if his trading strategy requires it.
The group has no limit on orders.
Technically, a group of orders can contain an unlimited number of orders of any type and in any ratio. It can be only limit orders or only stop orders, and their quantity can be several hundreds. Market orders, if they were not executed for some reason, can also be included in to the group. Practically, such freedom is often excessive and will not be needed in most scenarios.
Orders have no limit on the number of groups.
The same order can be part of several groups at the same time. It makes possible to create linked groups, where execution, change or cancellation of one order in one group may also affect other groups. However, this also requires more attention to the execution conditions given to the groups and the orders that are included in those groups.
The groupA
group of orders contains orders order1
, order2
and order3
, while the groupB
group of orders contains order3
, order4
and order5
. Both groups contain order3
and the OnExecuteOrCancel
condition is set for both of them.
The order1
was fulfilled, which caused the cancellation of all other orders of groupA
, including order3
. Since order3
was also part of groupB
, its cancelation also caused order4
and order5
to be canceled.
Thus, groupB
was affected by the event that occurred in groupA
.
It is not recommended to change orders after they have been added to the group.
Modification of orders is made by canceling the old order and creating a new one. This new order will not have any relations with the group the old order belonged to. At the same time, if the OnExecuteOrCancel
condition is set for a group, changing one order will cancel all other orders in the group. If you need to change a single order in a fairly large group, we recommend to change the group type to IgnoreCancel
first and only then change the order included in it and then add the newly created order back to the group.
Conditions
The main execution condition for group of orders, in addition to own conditions of orders belonging to it, is the rule of processing other orders when one is fulfilled. This rule is defined by the executionPolicy
parameter and can take the following values:
Condition | Description |
---|---|
OnExecuteOrCancel | The rest of the orders in the group are canceled upon the execution, modification or cancellation of any of them |
IgnoreCancel | The rest of the orders in the group are canceled only when any of its orders is fulfilled. Cancellation or modification of an order excludes it from the group, leaving other orders active |
TriggerBracketOrders | Useful for groups with one limit order and several stop orders. Stop orders in a group have |
Groups with inactive orders
One of the requirements when creating a group with the TriggerBracketOrders
fulfillment condition is the inactive status of stop orders.
When inactive, stop orders ignore any instrument price conditions, even if it has reached the trigger price. The most typical scenario of using such orders is creating take profit and stop loss orders for an instrument that is not yet in the portfolio.
To create an inactive stop order, set "activate": false
parameter value:
{
"condition": "MoreOrEqual",
"triggerPrice": 330.40,
"stopEndUnixTime": 1719781199,
"activate": false, // Parameter making the stop order inactive
"side": "sell",
"quantity": 100,
"instrument": {
"symbol": "SBER",
"exchange": "MOEX",
"instrumentGroup": "TQBR"
},
"user": {
"portfolio": "D39004"
}
}
Then add it to a group with other orders.
Request example
Common requirements
When creating a group of orders, the following requirements shall be observed:
- Orders to be added to the group must not have the status of executed or canceled
- All orders associated with the order groups must be authorized
Authorization
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
Request example
Management of order groups is possible only via HTTP API. The way of placing orders themselves has no role.
Creating group of orders
Interactive description of this request is available at the Create order group page
Creating a group of orders does not mean group creation of orders. All orders to be grouped must be created beforehand.
To create an order group, use a POST request to the /commandapi/api/orderGroups
endpoint with a message containing all the group's parameters.
Complete URL looks as follows:
https://api.alor.ru/commandapi/api/orderGroups
https://apidev.alor.ru/commandapi/api/orderGroups
The message body should contain the group execution condition and the array of orders to be added with the basic data about them: order number and type, exchange, portfolio.
{
"orders": [
{
"portfolio": "D39004",
"exchange": "MOEX",
"orderId": "15...860",
"type": "Limit"
},
{
"portfolio": "D39004",
"exchange": "MOEX",
"orderId": "15856",
"type": "Stop"
}
],
"executionPolicy": "OnExecuteOrCancel"
}
A group of orders consisting of a limit order 15...860
and a market stop order 15856
has been created. According to the OnExecuteOrCancel
condition, execution of one order will lead to cancelation of the other.
If the request is successful, the API will return a message with response code 200 containing the group identifier (guid):
{
"message": "success",
"groupId": "eafb19d6-c578-4afe-aa95-d528c4531031"
}
If the request processing ended with an error, the API will return information about the cause of this error.
A complete list of all parameters and possible responses is available on the request description page.
Getting information on all groups of orders
Interactive description of this request is available at the All order grops page
To get information about all previously created order groups, use a GET request to the /commandapi/api/orderGroups
endpoint without additional parameters. Information about the portfolios involved is contained in the Access token passed with the request.
Complete URL looks as follows:
https://api.alor.ru/commandapi/api/orderGroups
https://apidev.alor.ru/commandapi/api/orderGroups
If the request is successful, the API will return a message with response code 200 containing an array of all previously created order groups. For each group its identifier, execution condition, current state, creation time and execution time (if the order group is fulfilled) will be returned. To help you determine which account each group belongs to, the response body also contains the login of the account used.
[
{
"id": "eafb19d6-c578-4afe-aa95-d528c4531031",
"login": "P039004",
"orders": [
{
"orderId": "15...860"
},
{
"orderId": "15856"
}
],
"executionPolicy": "OnExecuteOrCancel",
"status": "Active",
"createdAt": "2024-04-19T08:25:56.7164619",
"closedAt": null
}
]
The server returns all available groups of orders in a single array without filtering the results. Sorting and filtering mechanisms must be provided by the API client application used.
If the request processing ended with an error, the API will return information about the cause of this error.
A complete list of all parameters and possible responses is available on the request description page.
Getting information on individual group of orders
Interactive description of this request is available at the Selected order group page
To get information about a specific order group, use a GET request to the endpoint /commandapi/api/orderGroups/{orderGroupId}
, where {orderGroupId}
is the identifier (guid) of the group being viewed.
Complete URL looks as follows:
https://api.alor.ru/commandapi/api/orderGroups/eafb19d6-c578-4afe-aa95-d528c4531031
https://apidev.alor.ru/commandapi/api/orderGroups/eafb19d6-c578-4afe-aa95-d528c4531031
If the request is successful, the API will return a message with response code 200 containing information on the specified order group. For each group its identifier, execution condition, current state, creation time and execution time (if the order group is fulfilled) will be returned. To help you determine which account each group belongs to, the response body also contains the login of the account used.
{
"id": "eafb19d6-c578-4afe-aa95-d528c4531031",
"login": "P039004",
"orders": [
{
"orderId": "15...860"
},
{
"orderId": "15856"
}
],
"executionPolicy": "OnExecuteOrCancel",
"status": "Active",
"createdAt": "2024-04-19T08:25:56.7164619",
"closedAt": null
}
If the request processing ended with an error, the API will return information about the cause of this error.
A complete list of all parameters and possible responses is available on the request description page.
Changing group of orders
Interactive description of this request is available at the Update order group page
Only groups with Active
status can be modified.
To modify an existing order group, use a PUT request to the /commandapi/api/orderGroups/{orderGroupId}
endpoint, where {orderGroupId}
is the identifier (guid) of the group being modified.
Complete URL looks as follows:
https://api.alor.ru/commandapi/api/orderGroups/eafb19d6-c578-4afe-aa95-d528c4531031
https://apidev.alor.ru/commandapi/api/orderGroups/eafb19d6-c578-4afe-aa95-d528c4531031
The request must contain a message identical to the one sent when creating a group of orders. In the message body it is necessary to specify all group data - both new and old.
{
// The group's previous details:
"orders": [
{
"portfolio": "D39004",
"exchange": "MOEX",
"orderId": "15...860",
"type": "Limit"
},
{
"portfolio": "D39004",
"exchange": "MOEX",
"orderId": "15856",
"type": "Stop"
},
// A new order being added to the group:
{
"portfolio": "D39004",
"exchange": "MOEX",
"orderId": "15857",
"type": "Stop"
}
],
// Modification of a previously passed parameter:
"executionPolicy": "IgnoreCancel"
}
If the request is successful, the API will return a message with response code 200 containing only the textual status of the request execution:
success
If the request processing ended with an error, the API will return information about the cause of this error.
A complete list of all parameters and possible responses is available on the request description page.
Canceling group of orders
Interactive description of this request is available at the Cancel order group page
Only groups with the Active
status can be deleted.
Deleting a group affects only the connection of orders between each other. The state of orders remains the same when a group is deleted.
To delete an order group, use a DELETE request to the /commandapi/api/orderGroups/{orderGroupId}
endpoint, where {orderGroupId}
is the identifier (guid) of the group being deleted.
Complete URL looks as follows:
https://api.alor.ru/commandapi/api/orderGroups/eafb19d6-c578-4afe-aa95-d528c4531031
https://apidev.alor.ru/commandapi/api/orderGroups/eafb19d6-c578-4afe-aa95-d528c4531031
If the request is successful, the API will return a message with response code 200 containing only the textual status of the request execution:
success
If the request processing ended with an error, the API will return information about the cause of this error.
A complete list of all parameters and possible responses is available on the request description page.
What's next?
Additionally, we recommend reading the following related articles:
- Guide for Data receiption
- Market orders
- Limit orders
- Iceberg orders
- Conditional orders
- Guide for HTTP API
- Guide for WebSocket API
- Frequently asked questions
- Quick Start Guide for Production environment
- Quick Start Guide for Test environment