CPlugin

MT5 :: Trade Databases :: Positions

API v1 (stable) · MT5 · 6 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

Positions by login (pumping)

GET /api/MT5/{tradePlatform}/PositionGet/{login}

<small> Get an array of open positions of all symbols for the specified login.

To get a position when using the hedging accounting system (EnMarginMode::MARGIN_MODE_RETAIL_HEDGED), use the IMTManagerAPI::PositionGetByTicket method as a position in that case is identified by the ticket, not by the login and symbol. </small>

Timeout: 10 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 User's login
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 10 s (read). 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/PositionGet/$LOGIN" \
  -H "Authorization: Bearer $TOKEN"

Positions by logins (pumping)

GET /api/MT5/{tradePlatform}/PositionGetByLogins

Timeout: 10 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
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 10 s (read). 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/PositionGetByLogins" \
  -H "Authorization: Bearer $TOKEN"

Positions by tickets (pumping)

GET /api/MT5/{tradePlatform}/PositionGetByTickets

Timeout: 10 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: 10 s (read). 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/PositionGetByTickets" \
  -H "Authorization: Bearer $TOKEN"

Positions by user group mask (pumping)

GET /api/MT5/{tradePlatform}/PositionRequestByGroup/{mask}

Timeout: 10 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 positions 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.
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 10 s (read). 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/PositionRequestByGroup/$MASK" \
  -H "Authorization: Bearer $TOKEN"

Positions by user group mask and symbol (pumping)

GET /api/MT5/{tradePlatform}/PositionGetBySymbol/{mask}/{symbol}

Timeout: 10 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 positions 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 positions. You can specify multiple symbols separated by commas.
X-Request-Timeout header number (double) no How long to wait for the trade server, in seconds (1–300). Default for this operation: 10 s (read). 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/PositionGetBySymbol/$MASK/$SYMBOL" \
  -H "Authorization: Bearer $TOKEN"

Delete positions from the server database in bulk

POST /api/MT5/{tradePlatform}/PositionDeleteBatch

Positions can only be deleted from the applications connected to the trade server, on which the positions 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 positions does not affect the client's current deals. Therefore, IMTAdmin::PositionCheck will show that the client's positions do not match the history of deals.

Bulk deletion is executed faster than deletion of the same number of positions in a cycle one by one, using IMTManagerAPI::PositionDelete.The acceleration can be especially noticeable when deleting positions 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/PositionDeleteBatch" \
  -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.

MT5Position

PropertyTypeDescription
login integer (int64), nullable Gets the login of the client, to whom the trade position belongs
symbol string, nullable position symbol
action PositionActions PositionAction
digits integer (int32), nullable price digits
digitsCurrency integer (int32), nullable currency digits
contractSize number (double), nullable symbol contract size
position integer (int64), nullable position ticket
externalId string, nullable The ticket of a position in an external trading system
timeCreate string (date-time), nullable position create time
timeUpdate string (date-time), nullable position last update time
timeCreateMsc string (date-time), nullable position create time in msc since 1970.01.01 If the value of this field is specified, the TimeCreate value will be filled in automatically.
timeUpdateMsc string (date-time), nullable position last update time in msc since 1970.01.01 If the value of this field is specified, the TimeUpdate value will be filled in automatically.
priceOpen number (double), nullable position weighted average open price
priceCurrent number (double), nullable position current price
priceSL number (double), nullable position SL price
priceTP number (double), nullable position TP price
volume integer (int64), nullable position volume
volumeExt integer (int64), nullable position volume
profit number (double), nullable position floating profit
storage number (double), nullable position accumulated swaps
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)
expertPositionId integer (int64), nullable expert position id
comment string, nullable
dealer integer (int64), nullable The login of a dealer, who has processed the order that opened the position. 0 means that the order was processed automatically by the server
activationMode ActivationModes order activation state, time and price
activationTime string (date-time), nullable
activationPrice number (double), nullable
activationFlags TradeActivationFlags
modificationFlags TradeModifyFlags modification flags
reason PositionReasons position reason - PositionReason

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

PositionActions

PositionReason

Values: Buy, Sell

ActivationModes

Values: None, SL, TP, StopOut

TradeActivationFlags

Flags: names of the set bits joined by ", " ("NoLimit, NoStop"), "None" when none is set; a set bit without a name is "Bit<n>" (bit number). Bits: NoLimit = 0x1, NoStop = 0x2, NoSLimit = 0x4, NoSL = 0x8, NoTP = 0x10, NoSO = 0x20, NoExpiration = 0x40. Accepted on input, never written: All = NoLimit, NoStop, NoSLimit, NoSL, NoTP, NoSO, NoExpiration.

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.

PositionReasons

Values: Client, Expert, Dealer, SL, TP, SO, Rollover, ExternalClient, VMargin, Gateway, Signal, Settlement, Transfer, Sync, ExternalService, Migration, Mobile, Web, Split, CorporateAction

MT5ResultType

type of error described here

Values: HTTP, MT4API, MT5API