Skip to content

Calculate margin#


Calculates margin required to open a trade on the specified trading account.

For more information see Async api documentation


In order to execute a trade, your application needs to emit request event with one of the payloads below.

General part of the request#

Name Type Required Description
type string Yes request type, must be calculateMargin if you want to calculate margin requirements for an order
accountId string Yes Trading account id. You can retrieve account id from Web application after you add your trading account to our platform. The account id can also be obtained via Provisioning API
requestId string Yes request id which your application must supply. Request id must be unique during an API connection
application string MetaApi application id. Default is MetaApi
order object Yes MarginOrder to calculate margin for.


After executing your request the API server will emit response event with the following payload.

Name Type Required Description
type string Yes the value of this field will be response in the response to the above request
requestId string Yes request id the response relates to
accountId string Yes account id specified in the request
margin object Yes margin required to open a trade. Schema: Margin

Code example:

import ioClient from '';

const socket = ioClient('', {
    path: '/ws',
    reconnection: false,
    query: {
        'auth-token': 'token'

const request = {
    accountId: '865d3a4d-3803-486d-bdf3-a85679d9fad2',
    type: 'calculateMargin',
    requestId: '28d4492c-bfc7-40d3-9c3f-0a9203a9c285',
    order: {
        symbol: 'EURUSD',
        type: 'ORDER_TYPE_BUY',
        volume: 0.1,
        openPrice: 1.1

socket.on('connect', () => {
    socket.emit('request', request);

socket.on('response', response => {

socket.on('processingError', err => {

Response example:

  "type": "response",
  "margin": {
    "margin": 110
  "requestId": "28d4492c-bfc7-40d3-9c3f-0a9203a9c285",
  "accountId": "865d3a4d-3803-486d-bdf3-a85679d9fad2"