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. Note, that this URL is valid for new-york region only. You can find URLs for other regions on API access page.

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. See the schema for these trade types on the corresponding MetatraderTrade page section.

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.new-york.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. Submits market order to the trading terminal. See the schema for these trade types on the corresponding MetatraderTrade page section.

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.new-york.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_TYPE_BUY_STOP_LIMIT or ORDER_TYPE_SELL_STOP_LIMIT#

Submits pending stop limit order to the trading terminal. Submits market order to the trading terminal. See the schema for these trade types on the corresponding MetatraderTrade page section.

Examples#

Example request:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'auth-token: token' -d '{
"actionType": "ORDER_TYPE_BUY_STOP_LIMIT",
"symbol":"AUDNZD",
"volume": 0.01,
"openPrice": 1.03,
"stopLimitPrice": "1.01"
}' 'https://mt-client-api-v1.new-york.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. Submits market order to the trading terminal. See the schema for this trade type on the corresponding MetatraderTrade page section.

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.new-york.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. See the schema for this trade type on the corresponding MetatraderTrade page section.

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.new-york.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. See the schema for this trade type on the corresponding MetatraderTrade page section.

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.new-york.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. See the schema for this trade type on the corresponding MetatraderTrade page section.

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.new-york.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",
}

POSITION_CLOSE_BY#

Closes a position by an opposite position. See the schema for this trade type on the corresponding MetatraderTrade page section.

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",
"closeByPositionId":"46648046"
}' 'https://mt-client-api-v1.new-york.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",
  "closeByPositionId":"46648046"
}

ORDER_MODIFY#

Modifies a pending order. See the schema for this trade type on the corresponding MetatraderTrade page section.

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.new-york.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. See the schema for this trade type on the corresponding MetatraderTrade page section.

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.new-york.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#

Responses: - 200 - Trade executed successfully for a specified MetaTrader account or with a metatrader error. 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