CPlugin

MT5 :: Trade Databases :: Deals

API v1 (stable) · MT5 · 9 operations · base URL https://cloud.mywebapi.com · OpenAPI v1 (JSON) · Redoc

Every call needs Authorization: Bearer $TOKEN — an OAuth 2.0 client-credentials token from https://auth.cplugin.net/connect/token (scope webapi). $TRADE_PLATFORM_ID is the id of a trade platform registered in Toolbox.

Operations

Deals history by a login

GET /api/MT5/{tradePlatform}/DealRequest/{login}/{fromTime}/{toTime}

Timeout: 30 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: Nothing was changed; the request is safe to repeat.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes
login path integer (int64) yes
fromTime path string (date-time) no Default: 0.ToUnixTime64() (01.01.1970) will be used
toTime path string (date-time) no Default: UInt64.MaxValue.ToUnixTime64() will be used
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 30 s (history or report). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Responses

Example

curl "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealRequest/$LOGIN/$FROM_TIME/$TO_TIME" \
  -H "Authorization: Bearer $TOKEN"

Deals by user group mask

GET /api/MT5/{tradePlatform}/DealRequestByGroup/{mask}/{fromTime}/{toTime}

Timeout: 30 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: Nothing was changed; the request is safe to repeat.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes
mask path string yes The groups for which deals are requested. You can specify one group, several groups (comma separated) or a group mask. The mask is specified using * (any value) and ! (exception). For example: demo*,!demoforex - all groups with the names beginning with 'demo', except for the group demoforex.
fromTime path string (date-time) no Default: 0.ToUnixTime64() (01.01.1970) will be used
toTime path string (date-time) no Default: UInt64.MaxValue.ToUnixTime64() will be used
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 30 s (history or report). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Responses

Example

curl "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealRequestByGroup/$MASK/$FROM_TIME/$TO_TIME" \
  -H "Authorization: Bearer $TOKEN"

Deals by user group mask and symbol

GET /api/MT5/{tradePlatform}/DealRequestByGroupSymbol/{mask}/{symbol}/{fromTime}/{toTime}

Timeout: 30 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: Nothing was changed; the request is safe to repeat.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes
mask path string yes The groups for which deals are requested. You can specify one group, several groups (comma separated) or a group mask. The mask is specified using * (any value) and ! (exception). For example: demo*,!demoforex - all groups with the names beginning with 'demo', except for the group demoforex.
symbol path string yes The symbol for which you need to get deals. You can specify multiple symbols separated by commas.
fromTime path string (date-time) no Default: 0.ToUnixTime64() (01.01.1970) will be used
toTime path string (date-time) no Default: UInt64.MaxValue.ToUnixTime64() will be used
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 30 s (history or report). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Responses

Example

curl "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealRequestByGroupSymbol/$MASK/$SYMBOL/$FROM_TIME/$TO_TIME" \
  -H "Authorization: Bearer $TOKEN"

Deals by the list of tickets

GET /api/MT5/{tradePlatform}/DealRequestByTickets

Timeout: 30 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: Nothing was changed; the request is safe to repeat.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes
tickets query integer (int64)[] no
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 30 s (history or report). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Responses

Example

curl "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealRequestByTickets" \
  -H "Authorization: Bearer $TOKEN"

(Request) Deals by the list of tickets

POST /api/MT5/{tradePlatform}/DealRequestByTickets

Similar to the GET version, but using request body, you can send a much longer list of ticket

Timeout: 30 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: Nothing was changed; the request is safe to repeat.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 30 s (history or report). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Request body

integer (int64)[] (application/json)

Responses

Example

curl -X POST "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealRequestByTickets" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '[0]'

Deals by the list of logins

GET /api/MT5/{tradePlatform}/DealRequestByLogins/{fromTime}/{toTime}

Timeout: 30 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: Nothing was changed; the request is safe to repeat.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes
logins query integer (int64)[] no
fromTime path string (date-time) no Default: 0.ToUnixTime64() (01.01.1970) will be used
toTime path string (date-time) no Default: UInt64.MaxValue.ToUnixTime64() will be used
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 30 s (history or report). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Responses

Example

curl "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealRequestByLogins/$FROM_TIME/$TO_TIME" \
  -H "Authorization: Bearer $TOKEN"

Deal by a ticket

GET /api/MT5/{tradePlatform}/DealRequestByTicket/{ticket}

Timeout: 30 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: Nothing was changed; the request is safe to repeat.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes Trade platform id
ticket path integer (int64) yes
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 30 s (history or report). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Responses

Example

curl "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealRequestByTicket/$TICKET" \
  -H "Authorization: Bearer $TOKEN"

Update Deal

POST /api/MT5/{tradePlatform}/DealUpdate

It will request deal from MT5 and apply only received parameters. So, you can send only the ones you'd like to update and leave everything else as null.

Timeout: 5 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: The operation may still be completed by the server (X-Request-Outcome: unknown): check its result before repeating it.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes Trade platform id
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 5 s (trade operation). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Request body

MT5Deal (application/json) — Deal to be updated

Responses

Example

curl -X POST "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealUpdate" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "deal": 0, "externalID": "", "login": 0, "dealer": 0, "partyID": 0, "order": 0 }'

Delete deals from the server database in bulk

POST /api/MT5/{tradePlatform}/DealDeleteBatch

A deal can only be deleted from the applications connected to the trade server, on which the deals have been created. For all other applications, the response code MT_RET_ERR_NOTMAIN is returned. If the object is not found, the response code MT_RET_ERR_NOTFOUND is returned.

Please note that deletion of deals does not affect the client's balance and current positions. Therefore, IMTAdmin::PositionCheck and IMTManagerAPI::UserBalanbceCheckwill show that the client's positions and balance do not match the relevant deals history.

Bulk deletion is executed faster than deletion of the same number of deals in a cycle one by one, using IMTManagerAPI::DealDelete.The acceleration can be especially noticeable when deleting deals belonging to one account.

To improve performance, it is recommended to create arrays and perform group operations separately for each trading account.

Timeout: 5 s by default, adjustable per request with the X-Request-Timeout header. When the trade server does not answer in time: The operation may still be completed by the server (X-Request-Outcome: unknown): check its result before repeating it.

Parameters

NameInTypeRequiredDescription
tradePlatform path string (uuid) yes
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 5 s (trade operation). The query parameter requestTimeout does the same for clients that cannot set headers. The applied value is returned in the X-Request-Timeout-Applied response header.

Request body

integer (int64)[] (application/json)

Responses

Example

curl -X POST "https://cloud.mywebapi.com/api/MT5/$TRADE_PLATFORM_ID/DealDeleteBatch" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '[0]'

Schemas

Types the operations above take and return, with their first-level properties; * marks a required one. The full graph is in the OpenAPI specification.

MT5Deal

PropertyTypeDescription
deal * integer (int64) deal ticket
externalID string, nullable deal ticket in external system (exchange, ECN, etc)
login integer (int64), nullable client login
dealer integer (int64), nullable processed dealer login (0-means auto)
partyID integer (int64), nullable counterparty identification
order integer (int64), nullable deal order ticket
action DealAction DealAction
entry EntryFlag EntryFlags
digits integer (int32), nullable price digits
digitsCurrency integer (int32), nullable currency digits
contractSize number (double), nullable symbol contract size
time string (date-time), nullable deal creation datetime in seconds. If the value of this field is specified, the IMTDeal::TimeMsc value will be filled in automatically.
symbol string, nullable deal symbol
price number (double), nullable deal price
priceSL number (double), nullable order SL
priceTP number (double), nullable order TP
volume integer (int64), nullable deal volume
volumeExt integer (int64), nullable deal volume with extended accuracy
volumeClosed integer (int64), nullable closed volume
volumeClosedExt integer (int64), nullable closed volume with extended accuracy
profit number (double), nullable deal profit
value number (double), nullable value
storage number (double), nullable deal collected swaps
commission number (double), nullable deal commission
obsoleteValue number (double), nullable obsolete value
fee number (double), nullable fee
rateProfit number (double), nullable profit conversion rate (from symbol profit currency to deposit currency)
rateMargin number (double), nullable margin conversion rate (from symbol margin currency to deposit currency)
expertID integer (int64), nullable expert id (filled by expert advisor)
positionID integer (int64), nullable position id
comment string, nullable deal comment
profitRaw number (double), nullable deal profit in symbol's profit currency
pricePosition number (double), nullable closed position price
tickValue number (double), nullable tick value
tickSize number (double), nullable tick size
flags integer (int64), nullable flags
timeMsc string (date-time), nullable deal creation datetime in msc since 1970.01.01. If the value of this field is specified, the IMTDeal::Time value will be filled in automatically
reason DealReason DealReason
gateway string, nullable source gateway name
priceGateway number (double), nullable deal price on gateway
marketBid number (double), nullable Has No Setter In ManagerAPI, so all you can is to read this value. Get the market Bid price as at the time of deal execution by the server
marketAsk number (double), nullable Has No Setter In ManagerAPI, so all you can is to read this value. Get the market Ask price as at the time of deal execution by the server
marketLast number (double), nullable Has No Setter In ManagerAPI, so all you can is to read this value. Get the market Last price as at the time of deal execution by the server
modificationFlags TradeModifyFlags Has No Setter In ManagerAPI, so all you can is to read this value. modification flags

MT5Error

PropertyTypeDescription
errorDescription string, nullable MT5 ManagerAPI response code description.
errorCode MT5Result MT5 ManagerAPI response code
errorType MT5ResultType type of error described here
requestId string (uuid) Unique request tracking ID

MT5Result

Values: Ok, OkNone, Error, ErrParams, ErrData, ErrDisk, ErrMem, ErrNetwork, ErrPermissions, ErrTimeout, ErrConnection, ErrNoService, ErrFrequent, ErrNotfound, ErrPartial, ErrShutdown, ErrCancel, ErrDuplicate, AuthClientInvalid, AuthAccountInvalid, AuthAccountDisabled, AuthAdvanced, AuthCertificate, AuthCertificateBad, AuthNotConfirmed, AuthServerInternal, AuthServerBad, AuthUpdateOnly, AuthClientOld, AuthManagerNoConfig, AuthManagerIPBlock, AuthGroupInvalid, AuthCaDisabled, AuthInvalidID, AuthInvalidIp, AuthInvalidType, AuthServerBusy, AuthServerCert, AuthAccountUnknown, AuthServerOld, AuthServerLimit, AuthMobileDisabled, AuthManagerType, AuthDemoDisabled, AuthResetPassword, AuthOTPInvalid, AuthOTPNeedSecret, AuthMigrationMT4, AuthMigrationMT5, AuthInvalidVerify, AuthVerifyBadEmail, AuthVerifyBadPhone, AuthAPIDisabled, CfgLastAdmin, CfgLastAdminGroup, CfgNotEmpty, CfgInvalidRange, CfgNotManagerLogin, CfgBuiltin, CfgDuplicate, CfgLimitReached, CfgNoAccessToMain, CfgDealerIDExist, CfgBindAddressExist, CfgWorkingTrade, CfgGatewayNameExist, CfgSwitchToBackup, CfgNoBackupModule, CfgNoTradeModule, CfgNoHistoryModule, CfgAnotherSwitch, CfgNoLicenseFile, CfgGatewayLoginExist, CfgInvalidCompany, UsrLastAdmin, UsrLoginExhausted, UsrLoginProhibited, UsrLoginExist, UsrSuicide, UsrInvalidPassword, UsrLimitReached, UsrHasTrades, UsrDifferentServers, UsrDifferentCurrency, UsrImportBalance, UsrImportGroup, UsrAccountExist, UsrImportAccount, UsrImportPositions, UsrImportOrders, UsrImportDeals, UsrImportHistory, UsrAPILimitReached, TradeLimitReached, TradeOrderExist, TradeOrderExhausted, TradeDealExhausted, TradeMaxMoney, TradeDealExist, TradeOrderProhibited, TradeDealProhibited, TradeSplitVolume, ReportSnapshot, ReportNotSupported, ReportNodata, ReportTemplateBad, ReportTemplateEnd, ReportInvalidRow, ReportLimitRepeat, ReportLimitReport, HstSymbolNotfound, RequestInWay, RequestAccepted, RequestProcess, RequestRequote, RequestPrices, RequestReject, RequestCancel, RequestPlaced, RequestDone, RequestDonePartial, RequestError, RequestTimeout, RequestInvalid, RequestInvalidVolume, RequestInvalidPrice, RequestInvalidStops, RequestTradeDisabled, RequestMarketClosed, RequestNoMoney, RequestPriceChanged, RequestPriceOff, RequestInvalidExp, RequestOrderChanged, RequestTooMany, RequestNoChanges, RequestAtDisabledServer, RequestAtDisabledClient, RequestLocked, RequestFrozen, RequestInvalidFill, RequestConnection, RequestOnlyReal, RequestLimitOrders, RequestLimitVolume, RequestInvalidOrder, RequestPositionClosed, RequestExecutionSkipped, RequestInvalidCloseVolume, RequestCloseOrderExist, RequestLimitPositions, RequestRejectCancel, RequestLongOnly, RequestShortOnly, RequestCloseOnly, RequestProhibitedByFifo, RequestHedgeProhibited, RequestReturn, RequestDoneCancel, RequestRequoteReturn, ErrNotImplement, ErrNotMain, ErrNotSupported, ErrDeadlock, ErrLocked, MessengerInvalidPhone, MessengerNotMobile, SubsNotFound, SubsNotFoundCfg, SubsNotFoundUser, SubsDisabled, SubsPermissionUser, SubsPermissionSubscribe, SubsPermissionUnsubscribe, SubsRealOnly, SubsPaymentMethod, PayRealOnly, PayInvalidAmount, PayNotAllowedDeposit, PayNotAllowedWithdrawal, PayNotAllowedGroup, PayNotAllowedCountry, PayDeclineByRules, PayDeclineByAml, PayLimitDepositMin, PayLimitDepositMax, PayLimitWithdrawalMin, PayLimitWithdrawalMax, PayProviderPayment, PayProviderStatus, PayConversion, PayNotWaiting, PayVerification, PayInvoice, PayInvalidCurrency, PayLimitReached, PayProviderRefund, PayDeclineByCardholderName

DealAction

Values: Buy, Sell, Balance, Credit, Charge, Correction, Bonus, Commission, CommissionDaily, CommissionMonthly, AgentDaily, AgentMonthly, InterestRate, BuyCanceled, SellCanceled, Dividend, DividendFranked, Tax, Agent, SOCompensation, SOCompensationCredit

EntryFlag

Values: In, Out, InOut, OutBy

DealReason

Values: Client, Expert, Dealer, Sl, Tp, So, Rollover, ExternalClient, VMargin, Gateway, Signal, Settlement, Transfer, Sync, ExternalService, Migration, Mobile, Web, Split, CorporateAction

TradeModifyFlags

also used for Deal,Order,Position Flags: names of the set bits joined by ", " ("Admin, Manager"), "None" when none is set; a set bit without a name is "Bit<n>" (bit number). Bits: Admin = 0x1, Manager = 0x2, Position = 0x4, Restore = 0x8, ApiAdmin = 0x10, ApiManager = 0x20, ApiServer = 0x40, ApiGateway = 0x80. Accepted on input, never written: All = Admin, Manager, Position, Restore, ApiAdmin, ApiManager, ApiServer, ApiGateway.

MT5ResultType

type of error described here

Values: HTTP, MT4API, MT5API