Skip to content

Rate limiting#

Our application limits the number of requests you can make during certain period of time. The restrictions are different for different REST API paths or websocket/SDK RPC API methods. If the request limit is exceeded, then error TooManyRequests (http status code - 429) will be returned. The error payload contains recommended time to repeat request at.

MetaApi API has following types of limits defined:

  • REST and RPC API rate limits
  • real-time market data streaming rate limits
  • real-time terminal state synchronization limits

REST and RPC API rate limiting#

REST and RPC API rate limiting use CPU credits system. There are several limits defined by the MetaApi app. According to each limit your app is granted with a number of credits per unit of time and you can consume the credits for making API calls.

REST and RPC API rate limits include 3 kinds of limits:

  1. Total number of CPU credits available per application
  2. Number of CPU credits available to be spent on a single server
  3. Number of CPU credits available to be spent on a single account

Historical market data API rate limits use the same system, however they are calculated independendtly of the rest of the API.

In addition to above, historical market data API limits number of concurrent requests per account.

Note, that small-scale applications are likely to hit limit #1 above. Large scale applications, which have more than 120 accounts deployed (as per time of writing this document) are likely to hit limit #2 first.

What should I do if I hit a REST/RPC API rate limit?#

If you hit a rate limit accidentally, just wait recommended time as per error payload and retry your request.

If you are consistently hitting rate limits this most likely means that you are not using our API efficiently. Consider switching from RPC-style API to real-time streaming API as it requires much less computational resources on server-side and thus scales much better. Feel free to contact our support to get some assistance on how to design more efficient application.

You can also contact support to request your rate limit quotas increase, however a justification might be required for rate limit quotas increase.

Total number of CPU credits available per application#

Below is a table of how many credits your entire application can spend for a period of time. Please note that you need to multiply these values by the number of accounts you have deployed to MetaApi to figure out your final quota.

Period Credits available
1 second 1000
1 minute 6000
1 hour 18000
6 hours 43200

Example: If you have 10 accounts deployed, then you end up with 10000 CPU credits quota per second because 1000 CPU credits per second is multiplied by the number of deployed accounts.

Error example:

{
  "id": 1,
  "error": "TooManyRequestsError",
  "message": "You cannot fulfill as many requests within 60 second(s). You have 1000 CPU credits available and have used 1000 CPU credits. Please try again later. Please contact support to increase your rate limit. For more information see https://metaapi.cloud/docs/client/rateLimiting/",
  "metadata": {
    "periodInSeconds": 60,
    "creditsAvailable": 1000,
    "creditsUsed": 1000,
    "creditsRequired": 50,
    "recommendedRetryTime": "2021-02-05T16:59:17.029Z",
    "type": "LIMIT_REQUEST_RATE_PER_USER"
  }
}

Number of CPU credits available on a single server#

In order to avoid overloading a server, there is a separate limit each front-end server (there are 12 front-end servers at the time of writing this doc).

If you reached the credit limit on one server you can switch servers by selecting different value of client-id HTTP header.

Allowed credits on one server per time period

Period Credits available (shared server)
1 second 2000
1 minute 18000
1 hour 180000
6 hours 432000

An example of an error in the case of using all credits on one server

{
  "id": 1,
  "error": "TooManyRequestsError",
  "message": "You cannot fulfill as many requests per server within 6 hour(s). You have 18000 CPU credits per server and have used 18000 CPU credits on this server. Please change client-id header value to execute your request on a different server. Please contact support to increase your rate limit. For more information see https://metaapi.cloud/docs/client/rateLimiting/",
  "metadata": {
    "periodInSeconds": 21600,
    "creditsAvailable": 18000,
    "creditsUsed": 18000,
    "creditsRequired": 50,
    "recommendedRetryTime": "2021-02-05T16:59:17.029Z",
    "type": "LIMIT_REQUEST_RATE_PER_USER_PER_SERVER"
  }
}

Number of CPU credits available to be spent on a single account#

Overloading a single account can adversely affect quality of service provided to your application, thus there is a separate limit of how many CPU credits you can spend making requests to a single account.

Available credits table for one account per time period

Period Credits available
10 seconds 5000

Error example:

{
  "id": 1,
  "error": "TooManyRequestsError",
  "message": "You cannot fulfill as many requests per account within 60 seconds(s). You have 5000 CPU credits per account and have used 5000 CPU credits for this account. Please try again later. Please contact support to increase your rate limit. For more information see https://metaapi.cloud/docs/client/rateLimiting/",
  "metadata": {
    "periodInSeconds": 60,
    "creditsAvailable": 5000,
    "creditsUsed": 5000,
    "creditsRequired": 50,
    "recommendedRetryTime": "2021-02-05T16:59:17.029Z",
    "type": "LIMIT_REQUEST_RATE_PER_ACCOUNT"
  }
}

Number of concurrent historical market data API requests per account#

MetaApi allows 5 concurrent historica market data requests per account.

Error example:

{
  "id": 1,
  "error": "TooManyRequestsError",
  "message": "It seems like you attempted to run too many concurrent historical market data requests for this account. You can execute a maximum of 5 concurrent historical market data requests per account. For more information see https://metaapi.cloud/docs/client/rateLimiting/",
  "metadata": {
    "maxRequestsPerAccount": 5,
    "concurrentRequestCount": 6,
    "recommendedRetryTime": "2021-02-05T16:59:17.029Z",
    "type": "LIMIT_CONCURRENT_MARKET_DATA_REQUESTS_PER_ACCOUNT"
  }
}

Cost of API calls in CPU credits#

Below is the table of the cost of each REST API request in credits.

Path Credits
GET /users/current/accounts/:accountId/accountInformation 50
GET /users/current/accounts/:accountId/positions 50
GET /users/current/accounts/:accountId/positions/:positionId 50
GET /users/current/accounts/:accountId/orders 50
GET /users/current/accounts/:accountId/orders/:orderId 50
GET /users/current/accounts/:accountId/history-orders/ticket/:ticket 50
GET /users/current/accounts/:accountId/history-orders/position/:positionId 50
GET /users/current/accounts/:accountId/history-orders/time/:startTime/:endTime 75 + (number of history orders found) * 0.65
GET /users/current/accounts/:accountId/history-deals/ticket/:ticket 50
GET /users/current/accounts/:accountId/history-deals/position/:positionId 50
GET /users/current/accounts/:accountId/history-deals/time/:startTime/:endTime 75 + (number of deals found) * 0.65
POST /users/current/accounts/:accountId/trade 50
GET /users/current/accounts/:accountId/symbols/symbols 500
GET /users/current/accounts/:accountId/symbols/:symbol/specification 50
GET /users/current/accounts/:accountId/symbols/:symbol/current-price 50
GET /users/current/accounts/:accountId/symbols/:symbol/current-candles/:timeframe 50
GET /users/current/accounts/:accountId/symbols/:symbol/current-tick 50
GET /users/current/accounts/:accountId/symbols/:symbol/current-book 50 + (number of book records) * 0.1
POST /users/current/accounts/:accountId/symbols/:symbol/unsubscribe 50
GET /users/current/accounts/:accountId/historical-market-data/symbols/:symbol/ticks 0.1 + (number of ticks returned) * 0.0002
GET /users/current/accounts/:accountId/historical-market-data/symbols/:symbol/timeframes/:timeframe/candles 0.1 + (number of candles returned) * 0.0004

Below is the table of the cost of each websocket/SDK API request in credits. Please note that only RPC API requests consume CPU credits. Real-time streaming API does not consume any credits.

Path Credits
getAccountInformation or get_account_information 50
getPositions or get_positions 50
getPosition or get_position 50
getOrders or get_orders 50
getOrder or get_order 50
getHistoryOrdersByTicket or get_history_orders_by_ticket 50
getHistoryOrdersByPosition or get_history_orders_by_position 50
getHistoryOrdersByTimeRange or get_history_orders_by_time_range 75 + (number of history orders found) * 0.65
getDealsByTicket or get_deals_by_ticket 50
getDealsByPosition or get_deals_by_position 50
getDealsByTimeRange or get_deals_by_time_range 75 + (number of deals found) * 0.65
trade methods 50
getSymbols or get_symbols 500
getSymbolSpecification or get_symbol_specification 50
getSymbolPrice or get_symbol_price 50
getCandle or get_candle 50
getTick or get_tick 50
getBook or get_book 50 + (number of book records) * 0.1
subscribeToMarketData or subscribe_to_market_data 50
unsubscribeFromMarketData or unsubscribe_from_market_data 50

Real-time market data streaming rate limiting#

If you hit a market data streaming rate limit, then server will send you downgradeSubscription event. You can handle it via onSubscriptionDowngraded / on_subscription_downgraded event handler in SDK.

What should I do if I hit a market data streaming rate limits?#

If you hit a rate limit for market data subscriptions please make sure you unsubscribe from unwanted market data and also make sure you did not accidentaly made any unwanted heavy subscriptions.

Note that MT platform will subscribe to quotes of some symbols implicitly. E.g. if you have an EUR account and subscribe to a symbol which is nominated in USD (such as GBPUSD) then MT will automatically subscribe to the quotes of the symbol required to convert USD to EUR, i.e. EURUSD.

If you have no excessive subscriptions but still hitting the limit, then distribute your market data subscriptions across several accounts.

How market data streaming rate limits are calculated#

Each market data streaming event server sends to you costs some market data streaming credits.

Each account maintains an independent market data streaming credit accounting.

Your available credits are listed in the table below.

Period Credits available
10 seconds 31500
1 minute 126000
5 minutes 315000

Each market data streaming packet sent to you cost 2 credits. Each quote or candle your receive costs 2 credits. Each tick or order book entry you receive costs 1 credit.

Obviously market depth data subscriptions are usually most heavy, followed by tick data subscriptions.

How much market data I can receive given these limits?#

5 minute limit allows you to receive approximately 200K ticks which approximately equals to daily throughput on most active EURUSD symbol.

5 minute limit allows you to receive approximately 20K order books (given the average size of order book equal to 10) which approximately equals to 10% of the daily throughput on most active EURUSD symbol.

Thus you should have plenty of room for your market data subscriptions.

Real-time terminal state synchronization limits#

SDK performs terminal state synchronization in several steps. First, it is emitting a subscribe request to subscribe to the account synchronization events. Then it issues a synchronize request to synchronize to the terminal state.

There are three types of rate limits defined:

  • subscribe request rate limits
  • limits on the number of account subscriptions your application can establish
  • limits on the number of terminal state synchronizations

You are unlikely to ever worry about these limits as SDK is designed to observe the limits and react to rate limiting errors correctly.

Subscribe request rate limits#

Subscribe request is rate-limited based on the number of requests allowed from one account.

The number of available requests is multiplied by the number of deployed accounts.

Below is a table of how many requests can be made over a period of time.

Period Requests available
1 minute 10

Limits on the number of account subscriptions your application can establish#

There are currently two account susbcriptions limits:

  • total number of account subscriptions per application per server
  • total number of account subscriptions per application
  • total number of account subscriptions per server (applied to all users)

Total number of account subscriptions per server#

One user can subscribe to more than 300 accounts on one server, if you try to subscribe to more accounts, the server will respond with error 429 (TooManyRequests).

Error example:

{
  "id": 1,
  "error": "TooManyRequestsError",
  "message": "One user can connect to one server no more than 300 accounts. Current number of connected accounts 300. For more information see https://metaapi.cloud/docs/client/rateLimiting/",
  "metadata": {
    "maxAccountsPerUserPerServer": 300,
    "accountsCount":  300,
    "recommendedRetryTime": "2021-02-05T16:59:17.029Z",
    "type": "LIMIT_ACCOUNT_SUBSCRIPTIONS_PER_USER_PER_SERVER"
  }
}

Total number of account subscriptions per application#

This limit is calculated as the number of accounts deployed by the user multiplied by 10.

For example, if you have 5 accounts, then you can make no more than total of 50 subscriptions on all servers in the system.

Error example:

{
  "id": 1,
  "error": "TooManyRequestsError",
  "message": "You have used all your account subscriptions quota. You have 50 account subscriptions available and have used 50 subscriptions. Please deploy more accounts to get more subscriptions. For more information see https://metaapi.cloud/docs/client/rateLimiting/",
  "metadata": {
    "maxAccountsPerUser":  50,
    "accountsCount": 50,
    "recommendedRetryTime": "2021-02-05T16:59:17.029Z",
    "type": "LIMIT_ACCOUNT_SUBSCRIPTIONS_PER_USER"
  }
}

Total number of account subscriptions per server (applied to all users)#

If the server is overloaded, it will ask you to try to connect to another server.

Error example:

{
  "id": 1,
  "error": "TooManyRequestsError",
  "message": "You can not subscribe to more accounts on this connection because server is out of capacity. Please establish a new connection with a different client-id header value to switch to a different server. For more information see https://metaapi.cloud/docs/client/rateLimiting/",
  "metadata": {
    "changeClientIdHeader": true,
    "recommendedRetryTime": "2021-02-05T16:59:17.029Z",
    "type": "LIMIT_ACCOUNT_SUBSCRIPTIONS_PER_SERVER"
  }
}

Limits on the number of terminal state synchronizations#

The MetaApi limits the number of simultaneous synchronizations from one user.

Your application can synchronize to not more than 10% of the total number of the accounts you have subscribed to. The value is rounded to the closest greater integer and can not be less than 1.

For example, if you have subscriebed to 23 accounts, then you can execute a maximum of 3 concurrent synchronizations.

Error example:

{
  "id": 1,
  "error": "TooManyRequestsError",
  "message": "It seems like you attempted to run too many concurrent synchronizations on this server. You can have maximum of 10 concurrent synchronizations on this server because you have subscribed to 100 accounts on the server and you are allowed to execute one concurrent synchronization per 10 account subscriptions. For more information see https://metaapi.cloud/docs/client/rateLimiting/",
  "metadata": {
    "maxSynchronizationsCount": 10,
    "subscribedAccountsCount": 100,
    "synchronizationsPerAccount": 10,
    "recommendedRetryTime": "2021-02-05T16:59:17.029Z",
    "type": "LIMIT_ACCOUNT_SYNCHRONIZATIONS_PER_USER_PER_SERVER"
  }
}