Skip to content

Trade#

About#

Executes a trade on a connected MetaTrader account

POST /users/current/accounts/:accountId/trade

For more information see Swagger documentation

Headers#

Name Type Required Description
auth-token string Yes authorization token. See Authentication & authorization

Path parameters#

Name Type Required Description
accountId string Yes MetaTrader account id. You can retrieve account id from Web application after you add your MetaTrader account to our platform. The account id can also be obtained via Provisioning API

Body#

To execute the command, it is necessary to supply the request body in the format of the MetatraderTrade model.

The following describes schemas for each type of command.

ORDER_TYPE_SELL or ORDER_TYPE_BUY#

Submits market order to the trading terminal

Name Type Required Description
actionType string Yes action type, enum: ORDER_TYPE_SELL, ORDER_TYPE_BUY
symbol string Yes symbol to trade
volume number Yes order volume, min: 0
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on position, history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "ORDER_TYPE_SELL",
"symbol":"AUDNZD",
"volume": 0.01,
"takeProfit": 1.03
}' 'https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai/users/current/accounts/865d3a4d-3803-486d-bdf3-a85679d9fad2/trade'

Example response:

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "orderId": "47137555"
}

ORDER_TYPE_BUY_LIMIT or ORDER_TYPE_SELL_LIMIT or ORDER_TYPE_BUY_STOP or ORDER_TYPE_SELL_STOP#

Submits pending order to the trading terminal

Name Type Required Description
actionType string Yes action type, enum: ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP, ORDER_TYPE_SELL_STOP
symbol string Yes symbol to trade
volume number Yes order volume, min: 0
openPrice number Yes order limit or stop price, min: 0
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on position, history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
expiration object pending order expiration settings. See Pending order expiration settings section.
Pending order expiration settings#
Name Type Required Description
type string Yes pending order expiration type. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_time for the list of possible options. MetaTrader4 platform supports only ORDER_TIME_SPECIFIED expiration type. enum: ORDER_TIME_GTC, ORDER_TIME_DAY, ORDER_TIME_SPECIFIED, ORDER_TIME_SPECIFIED_DAY.
time datetime pending order expiration time. Ignored if expiration type is not one of ORDER_TIME_DAY or ORDER_TIME_SPECIFIED
Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "ORDER_TYPE_BUY_LIMIT",
"symbol":"AUDNZD",
"volume": 0.01,
"openPrice": 1.03
}' 'https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai/users/current/accounts/865d3a4d-3803-486d-bdf3-a85679d9fad2/trade'

Example response:

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "orderId": "47067192"
}

POSITION_MODIFY#

Modifies a position TP/SL price

Name Type Required Description
actionType string Yes action type, enum: POSITION_MODIFY
positionId string Yes position id (ticket number)
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "POSITION_MODIFY",
"positionId":"46648037",
"takeProfit": 1.06
}' 'https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai/users/current/accounts/865d3a4d-3803-486d-bdf3-a85679d9fad2/trade'

Example response:

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "positionId": "46648037"
}

POSITION_PARTIAL#

Partially closes a position

Name Type Required Description
actionType string Yes action type, enum: POSITION_PARTIAL
positionId string Yes position id
volume number Yes volume to close, min: 0
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "POSITION_PARTIAL",
"positionId":"46648037",
"volume": 0.01
}' 'https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai/users/current/accounts/865d3a4d-3803-486d-bdf3-a85679d9fad2/trade'

Example response:

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "orderId": "47138322",
  "positionId": "46648037"
}

POSITION_CLOSE_ID#

Closes a position fully

Name Type Required Description
actionType string Yes action type, enum: POSITION_CLOSE_ID
positionId string Yes position id
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "POSITION_CLOSE_ID",
"positionId":"46648037"
}' 'https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai/users/current/accounts/865d3a4d-3803-486d-bdf3-a85679d9fad2/trade'

Example response:

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "orderId": "47138393",
  "positionId": "46648037"
}

POSITIONS_CLOSE_SYMBOL#

Close positions by symbol

Name Type Required Description
actionType string Yes action type, enum: POSITIONS_CLOSE_SYMBOL
symbol string Yes symbol to trade
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "POSITIONS_CLOSE_SYMBOL",
"symbol": "AUDNZD"
}' 'https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai/users/current/accounts/865d3a4d-3803-486d-bdf3-a85679d9fad2/trade'

Example response:

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "orderId": "46879076",
  "positionId": "46732826"
}

Response example for an account that does not support this feature:

{
  "numericCode": 10006,
  "stringCode": "TRADE_RETCODE_REJECT",
  "message": "Request rejected",
}

ORDER_MODIFY#

Modifies a pending order

Name Type Required Description
actionType string Yes action type, enum: ORDER_MODIFY
orderId string Yes order id (ticket number)
openPrice number Yes limit or stop price, required for a pending order, min: 0
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "ORDER_MODIFY",
"orderId":"47067192",
"openPrice": 1.03,
"stopLoss": 1.05
}' 'https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai/users/current/accounts/865d3a4d-3803-486d-bdf3-a85679d9fad2/trade'

Example response:

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "orderId": "47067192"
}

ORDER_CANCEL#

Cancels an order

Name Type Required Description
actionType string Yes action type, enum: ORDER_CANCEL
orderId string Yes order id (ticket number)
Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "ORDER_CANCEL",
"orderId":"47067192"
}' 'https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai/users/current/accounts/865d3a4d-3803-486d-bdf3-a85679d9fad2/trade'

Example response:

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "orderId": "47067192"
}

Response#

Possible error response codes are listed here.

Responses:

  • 200 - Trade executed successfully for a specified MetaTrader account. Response schema: MetatraderTradeResponse
  • 400 - Payload is not valid. Response schema: Error
  • 401 - Authorization failed. Response schema: Error
  • 404 - MetaTrader account not found or not provisioned yet. Response schema: Error