syntax = "proto2";

option java_multiple_files = true;

option java_generate_equals_and_hash = true;

option java_package = "com.xtrader.protocol.openapi.v2";

option java_outer_classname = "ContainerOpenApiV2Messages";

import "OpenApiModelMessages.proto";

/** Request for the authorizing an application to work with the cTrader platform Proxies. */
message ProtoOAApplicationAuthReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_APPLICATION_AUTH_REQ];

    required string clientId = 2; //The unique Client ID provided during the registration.
    required string clientSecret = 3; //The unique Client Secret provided during the registration.
}

/** Response to the ProtoOAApplicationAuthReq request. */
message ProtoOAApplicationAuthRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_APPLICATION_AUTH_RES];
}

/** Request for the authorizing trading account session. Requires established authorized connection with the client application using ProtoOAApplicationAuthReq. */
message ProtoOAAccountAuthReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ACCOUNT_AUTH_REQ];

    required int64 ctidTraderAccountId = 2; // The unique identifier of the trader's account in cTrader platform.
    required string accessToken = 3; // The Access Token issued for providing access to the Trader's Account.
}

/** Response to the ProtoOAApplicationAuthRes request. */
message ProtoOAAccountAuthRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ACCOUNT_AUTH_RES];

    required int64 ctidTraderAccountId = 2; // The unique identifier of the trader's account in cTrader platform.
}

/** Generic response when an ERROR occurred. */
message ProtoOAErrorRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ERROR_RES];

    optional int64 ctidTraderAccountId = 2; //The unique identifier of the trader's account in cTrader platform.
    required string errorCode = 3; // The name of the ProtoErrorCode or the other custom ErrorCodes (e.g. ProtoCHErrorCode).
    optional string description = 4; // The error description.
    optional int64 maintenanceEndTimestamp = 5; // The timestamp in seconds when the current maintenance session will be ended.
}

/** Event that is sent when the connection with the client application is cancelled by the server. All the sessions for the traders' accounts will be terminated. */
message ProtoOAClientDisconnectEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_CLIENT_DISCONNECT_EVENT];

    optional string reason = 2; // The disconnection reason explained. For example: The application access was blocked by cTrader Administrator.
}

/** Event that is sent when a session to a specific trader's account is terminated by the server but the existing connections with the other trader's accounts are maintained. */
message ProtoOAAccountsTokenInvalidatedEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ACCOUNTS_TOKEN_INVALIDATED_EVENT];

    repeated int64 ctidTraderAccountIds = 2; // The unique identifier of the trader's account in cTrader platform.
    optional string reason = 3; // The disconnection reason explained. For example: Access Token is expired or recalled.
}

/** Request for getting the proxy version. Can be used to check the current version of the Open API scheme. */
message ProtoOAVersionReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_VERSION_REQ];
}

/** Response to the ProtoOAVersionReq request. */
message ProtoOAVersionRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_VERSION_RES];

    required string version = 2; // The current version of the server application.
}

/** Request for sending a new trading order. Allowed only if the accessToken has the "trade" permissions for the trading account. */
message ProtoOANewOrderReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_NEW_ORDER_REQ];

    required int64 ctidTraderAccountId = 2; // The unique identifier of the trader's account in cTrader platform.
    required int64 symbolId = 3; // The unique identifier of a symbol in cTrader platform.
    required ProtoOAOrderType orderType = 4; // The type of an order - MARKET, LIMIT, STOP, MARKET_RANGE, STOP_LIMIT.
    required ProtoOATradeSide tradeSide = 5; // The trade direction - BUY or SELL.
    required int64 volume = 6; // The volume represented in 0.01 of a unit (e.g. US$ 10.00 = 1000).
    optional double limitPrice = 7; // The limit price, can be specified for the LIMIT order only.
    optional double stopPrice = 8; // Stop Price, can be specified for the STOP and the STOP_LIMIT orders only.
    optional ProtoOATimeInForce timeInForce = 9 [default = GOOD_TILL_CANCEL]; // The specific order execution or expiration instruction - GOOD_TILL_DATE, GOOD_TILL_CANCEL, IMMEDIATE_OR_CANCEL, FILL_OR_KILL, MARKET_ON_OPEN.
    optional int64 expirationTimestamp = 10; // The exact Order expiration time. Should be set for the Good Till Date orders.
    optional double stopLoss = 11; // The absolute Stop Loss price (1.23456 for example). Not supported for the MARKER orders.
    optional double takeProfit = 12; // The absolute Take Profit price (1.23456 for example). Unsupported for the MARKER orders.
    optional string comment = 13; // User-specified comment. MaxLength = 512.
    optional double baseSlippagePrice = 14; // Base price to calculate relative slippage price for MARKET_RANGE order.
    optional int32 slippageInPoints = 15; // Slippage distance for MARKET_RANGE and STOP_LIMIT order.
    optional string label = 16; // User-specified label. MaxLength = 100.
    optional int64 positionId = 17; // Reference to the existing position if the Order is intended to modify it.
    optional string clientOrderId = 18; // Optional user-specific clientOrderId (similar to FIX ClOrderID). MaxLength = 50.
    optional int64 relativeStopLoss = 19; // Relative Stop Loss that can be specified instead of the absolute as one. Specified in 1/100000 of unit of a price. For BUY stopLoss = entryPrice - relativeStopLoss, for SELL stopLoss = entryPrice + relativeStopLoss.
    optional int64 relativeTakeProfit = 20; // Relative Take Profit that can be specified instead of the absolute one. Specified in 1/100000 of unit of a price. For BUY takeProfit = entryPrice + relativeTakeProfit, for SELL takeProfit = entryPrice - relativeTakeProfit.
    optional bool guaranteedStopLoss = 21; // If TRUE then stopLoss is guaranteed. Available for the French Risk or the Guaranteed Stop Loss Accounts.
    optional bool trailingStopLoss = 22; // If TRUE then the Stop Loss is Trailing.
    optional ProtoOAOrderTriggerMethod stopTriggerMethod = 23 [default = TRADE]; // Trigger method for the STOP or the STOP_LIMIT pending order.
}

/** Event that is sent following the successful order acceptance or execution by the server. Acts as response to the ProtoOANewOrderReq, ProtoOACancelOrderReq, ProtoOAAmendOrderReq, ProtoOAAmendPositionSLTPReq, ProtoOAClosePositionReq requests. Also, the event is sent when a Deposit/Withdrawal took place. */
message ProtoOAExecutionEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_EXECUTION_EVENT];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required ProtoOAExecutionType executionType = 3; // Type of the order operation. For example: ACCEPTED, FILLED, etc.
    optional ProtoOAPosition position = 4; // Reference to the position linked with the execution
    optional ProtoOAOrder order = 5; // Reference to the initial order.
    optional ProtoOADeal deal = 6; // Reference to the deal (execution).
    optional ProtoOABonusDepositWithdraw bonusDepositWithdraw = 7; // Reference to the Bonus Deposit or Withdrawal operation.
    optional ProtoOADepositWithdraw depositWithdraw = 8; // Reference to the Deposit or Withdrawal operation.
    optional string errorCode = 9; //The name of the ProtoErrorCode or the other custom ErrorCodes (e.g. ProtoCHErrorCode).
    optional bool isServerEvent = 10; // If TRUE then the event generated by the server logic instead of the trader's request. (e.g. stop-out).
}

/** Request for cancelling existing pending order. Allowed only if the accessToken has "trade" permissions for the trading account. */
message ProtoOACancelOrderReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_CANCEL_ORDER_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 orderId = 3; // The unique ID of the order.
}

/** Request for amending the existing pending order. Allowed only if the Access Token has "trade" permissions for the trading account. */
message ProtoOAAmendOrderReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_AMEND_ORDER_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 orderId = 3; // The unique ID of the order.
    optional int64 volume = 4; // Volume, represented in 0.01 of a unit (e.g. cents).
    optional double limitPrice = 5; // The Limit Price, can be specified for the LIMIT order only.
    optional double stopPrice = 6; // The Stop Price, can be specified for the STOP and the STOP_LIMIT orders.
    optional int64 expirationTimestamp = 7; // The exact Order expiration time. Should be set for the Good Till Date orders.
    optional double stopLoss = 8; // The absolute Stop Loss price (e.g. 1.23456). Not supported for the MARKER orders.
    optional double takeProfit = 9; // The absolute Take Profit price (e.g. 1.23456). Not supported for the MARKER orders.
    optional int32 slippageInPoints = 10; // Slippage distance for the MARKET_RANGE and the STOP_LIMIT orders.
    optional int64 relativeStopLoss = 11; // The relative Stop Loss can be specified instead of the absolute one. Specified in 1/100000 of a unit of price. For BUY stopLoss = entryPrice - relativeStopLoss, for SELL stopLoss = entryPrice + relativeStopLoss.
    optional int64 relativeTakeProfit = 12; // The relative Take Profit can be specified instead of the absolute one. Specified in 1/100000 of a unit of price. For BUY takeProfit = entryPrice + relativeTakeProfit, for SELL takeProfit = entryPrice - relativeTakeProfit.
    optional bool guaranteedStopLoss = 13; // If TRUE then the Stop Loss is guaranteed. Available for the French Risk or the Guaranteed Stop Loss Accounts.
    optional bool trailingStopLoss = 14; // If TRUE then the Trailing Stop Loss is applied.
    optional ProtoOAOrderTriggerMethod stopTriggerMethod = 15 [default = TRADE]; // Trigger method for the STOP or the STOP_LIMIT pending order.
}

/** Request for amending StopLoss and TakeProfit of existing position. Allowed only if the accessToken has "trade" permissions for the trading account. */
message ProtoOAAmendPositionSLTPReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_AMEND_POSITION_SLTP_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 positionId = 3; // The unique ID of the position to amend.
    optional double stopLoss = 4; // Absolute Stop Loss price (1.23456 for example).
    optional double takeProfit = 5; // Absolute Take Profit price (1.26543 for example).
    optional bool guaranteedStopLoss = 7; //If TRUE then the Stop Loss is guaranteed. Available for the French Risk or the Guaranteed Stop Loss Accounts.
    optional bool trailingStopLoss = 8; //If TRUE then the Trailing Stop Loss is applied.
    optional ProtoOAOrderTriggerMethod stopLossTriggerMethod = 9 [default = TRADE]; // The Stop trigger method for the Stop Loss/Take Profit order.
}

/** Request for closing or partially closing of an existing position. Allowed only if the accessToken has "trade" permissions for the trading account. */
message ProtoOAClosePositionReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_CLOSE_POSITION_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 positionId = 3; // The unique ID of the position to close.
    required int64 volume = 4; // Volume to close, represented in 0.01 of a unit (e.g. cents).
}

/** Event that is sent when the level of the Trailing Stop Loss is changed due to the price level changes. */
message ProtoOATrailingSLChangedEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_TRAILING_SL_CHANGED_EVENT];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 positionId = 3; // The unique ID of the position.
    required int64 orderId = 4; // The unique ID of the order.
    required double stopPrice = 5; // New value of the Stop Loss price.
    required int64 utcLastUpdateTimestamp = 6; // The exact UTC time when the Stop Loss was updated.
}

/** Request for the list of assets available for a trader's account. */
message ProtoOAAssetListReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ASSET_LIST_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Response to the ProtoOAAssetListReq request. */
message ProtoOAAssetListRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ASSET_LIST_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOAAsset asset = 3; // The list of assets.
}

/** Request for a list of symbols available for a trading account. Symbol entries are returned with the limited set of fields. */
message ProtoOASymbolsListReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOLS_LIST_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    optional bool includeArchivedSymbols = 3 [default = false]; // Whether to include old archived symbols into response.
}

/** Response to the ProtoOASymbolsListReq request. */
message ProtoOASymbolsListRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOLS_LIST_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOALightSymbol symbol = 3; // The list of symbols.
    repeated ProtoOAArchivedSymbol archivedSymbol = 4; // The list of archived symbols.
}

/** Request for getting a full symbol entity. */
message ProtoOASymbolByIdReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOL_BY_ID_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated int64 symbolId = 3; // Unique identifier of the symbol in cTrader platform.
}

/** Response to the ProtoOASymbolByIdReq request. */
message ProtoOASymbolByIdRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOL_BY_ID_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOASymbol symbol = 3; // Symbol entity with the full set of fields.
    repeated ProtoOAArchivedSymbol archivedSymbol = 4; // Archived symbols.
}

/** Request for getting a conversion chain between two assets that consists of several symbols. Use when no direct quote is available */
message ProtoOASymbolsForConversionReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOLS_FOR_CONVERSION_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 firstAssetId = 3; // The ID of the firs asset in the conversation chain. e.g.: for EUR/USD the firstAssetId is EUR ID and lastAssetId is USD ID.
    required int64 lastAssetId = 4; // The ID of the last asset in the conversation chain. e.g.: for EUR/USD the firstAssetId is EUR ID and lastAssetId is USD ID.
}

/** Response to the ProtoOASymbolsForConversionReq request. */
message ProtoOASymbolsForConversionRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOLS_FOR_CONVERSION_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOALightSymbol symbol = 3; // Conversion chain of the symbols (e.g. EUR/USD, USD/JPY, GBP/JPY -> EUR/GBP).
}

/** Event that is sent when the symbol is changed on the Server side. */
message ProtoOASymbolChangedEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOL_CHANGED_EVENT];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated int64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
}

/** Request for a list of asset classes available for the trader's account. */
message ProtoOAAssetClassListReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ASSET_CLASS_LIST_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Response to the ProtoOAAssetListReq request. */
message ProtoOAAssetClassListRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ASSET_CLASS_LIST_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOAAssetClass assetClass = 3; // List of the asset classes.
}

/** Request for getting data of Trader's Account. */
message ProtoOATraderReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_TRADER_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Response to the ProtoOATraderReq request. */
message ProtoOATraderRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_TRADER_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required ProtoOATrader trader = 3; // The Trader account information.
}

/** Event that is sent when a Trader is updated on Server side. */
message ProtoOATraderUpdatedEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_TRADER_UPDATE_EVENT];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required ProtoOATrader trader = 3; // The Trader account information.
}

/** Request for getting Trader's current open positions and pending orders data. */
message ProtoOAReconcileReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_RECONCILE_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** The response to the ProtoOAReconcileReq request. */
message ProtoOAReconcileRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_RECONCILE_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOAPosition position = 3; // The list of trader's account open positions.
    repeated ProtoOAOrder order = 4; // The list of trader's account pending orders.
}

/** Event that is sent when errors occur during the order requests. */
message ProtoOAOrderErrorEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ORDER_ERROR_EVENT];

    required int64 ctidTraderAccountId = 5; //Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required string errorCode = 2; // The name of the ProtoErrorCode or the other custom ErrorCodes (e.g. ProtoCHErrorCode).
    optional int64 orderId = 3; // The unique ID of the order.
    optional int64 positionId = 6; // The unique ID of the position.
    optional string description = 7; // The error description.
}

/** Request for getting Trader's deals historical data (execution details). */
message ProtoOADealListReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_DEAL_LIST_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 fromTimestamp = 3; // The UNIX time from which the search starts >=0 (1-1-1970). Validation: toTimestamp - fromTimestamp <= 604800000 (1 week).
    required int64 toTimestamp = 4; // The UNIX time where to stop searching <= 2147483646000 (19-1-2038).
    optional int32 maxRows = 5; // The maximum number of the deals to return.
}

/** The response to the ProtoOADealListRes request. */
message ProtoOADealListRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_DEAL_LIST_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOADeal deal = 3; // The list of the deals.
    required bool hasMore = 4; // If TRUE then the response will provide more than 10000 deals.
}

/** Request for getting Trader's closed orders filtered by timestamp */
message ProtoOAOrderListReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ORDER_LIST_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 fromTimestamp = 3; // The UNIX time from which the search starts >=0 (1-1-1970). Validation: toTimestamp - fromTimestamp <= 604800000 (1 week).
    required int64 toTimestamp = 4; // The UNIX time where to stop searching <= 2147483646000 (19-1-2038).
}

/** The response to the ProtoOAOrderListReq request. */
message ProtoOAOrderListRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ORDER_LIST_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOAOrder order = 3; // The list of the orders.
    required bool hasMore = 4; // If TRUE then the response will provide more than 10000 orders.
}

/** Request for getting the margin estimate. Can be used before sending a new order request. */
message ProtoOAExpectedMarginReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_EXPECTED_MARGIN_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
    repeated int64 volume = 4; // Volume represented in 0.01 of a unit (e.g. cents).
}

/** The response to the ProtoOAExpectedMarginReq request. */
message ProtoOAExpectedMarginRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_EXPECTED_MARGIN_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOAExpectedMargin margin = 3; // The buy and sell margin estimate.
    optional uint32 moneyDigits = 4; // Specifies the exponent of the monetary values. E.g. moneyDigits = 8 must be interpret as business value multiplied by 10^8, then real balance would be 10053099944 / 10^8 = 100.53099944. Affects margin.buyMargin, margin.sellMargin.
}

/** Event that is sent when the margin allocated to a specific position is changed. */
message ProtoOAMarginChangedEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_MARGIN_CHANGED_EVENT];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required uint64 positionId = 3; // The unique ID of the position.
    required uint64 usedMargin = 4; // The new value of the margin used.
    optional uint32 moneyDigits = 5; // Specifies the exponent of the monetary values. E.g. moneyDigits = 8 must be interpret as business value multiplied by 10^8, then real balance would be 10053099944 / 10^8 = 100.53099944. Affects usedMargin.
}

/** Request for getting Trader's historical data of deposits and withdrawals. */
message ProtoOACashFlowHistoryListReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_CASH_FLOW_HISTORY_LIST_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 fromTimestamp = 3; // The UNIX time from which the search starts >=0 (1-1-1970). Validation: toTimestamp - fromTimestamp <= 604800000 (1 week).
    required int64 toTimestamp = 4; // The UNIX time where to stop searching <= 2147483646000 (19-1-2038).
}

/** Response to the ProtoOACashFlowHistoryListReq request. */
message ProtoOACashFlowHistoryListRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_CASH_FLOW_HISTORY_LIST_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOADepositWithdraw depositWithdraw = 3; // The list of deposit and withdrawal operations.
}

/** Request for getting the list of granted trader's account for the access token. */
message ProtoOAGetAccountListByAccessTokenReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_REQ];

    required string accessToken = 2; // The Access Token issued for providing access to the Trader's Account.
}

/** Response to the ProtoOAGetAccountListByAccessTokenReq request. */
message ProtoOAGetAccountListByAccessTokenRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_RES];

    required string accessToken = 2; // The Access Token issued for providing access to the Trader's Account.
    optional ProtoOAClientPermissionScope permissionScope = 3; // SCOPE_VIEW, SCOPE_TRADE.
    repeated ProtoOACtidTraderAccount ctidTraderAccount = 4; // The list of the accounts.
}

/** Request to refresh the access token using refresh token of granted trader's account. */
message ProtoOARefreshTokenReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_REFRESH_TOKEN_REQ];

    required string refreshToken = 2; // The Refresh Token issued for updating Access Token.
}

/** Response to the ProtoOARefreshTokenReq request. */
message ProtoOARefreshTokenRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_REFRESH_TOKEN_RES];

    required string accessToken = 2; // The Access Token issued for providing access to the Trader's Account.
    required string tokenType = 3; // bearer
    required int64 expiresIn = 4; // Access Token expiration in seconds.
    required string refreshToken = 5; // Your new Refresh Token.
}

//+------------------------------------------------------------------+
//|                              Quotes                              |
//+------------------------------------------------------------------+
/** Request for subscribing on spot events of the specified symbol. */
message ProtoOASubscribeSpotsReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SUBSCRIBE_SPOTS_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated int64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
    optional bool subscribeToSpotTimestamp = 4; // If TRUE you will also receive the timestamp in ProtoOASpotEvent.
}

/** Response to the ProtoOASubscribeSpotsReq request. */
message ProtoOASubscribeSpotsRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SUBSCRIBE_SPOTS_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Request for unsubscribing from the spot events of the specified symbol. */
message ProtoOAUnsubscribeSpotsReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_UNSUBSCRIBE_SPOTS_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated int64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
}

/** Response to the ProtoOASubscribeSpotsRes request. */
message ProtoOAUnsubscribeSpotsRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_UNSUBSCRIBE_SPOTS_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Event that is sent when a new spot event is generated on the server side. Requires subscription on the spot events, see ProtoOASubscribeSpotsReq. First event, received after subscription will contain latest spot prices even if market is closed. */
message ProtoOASpotEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SPOT_EVENT];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
    optional uint64 bid = 4; // Bid price. Specified in 1/100_000 of unit of a price. (e.g. 1.23 -> 123_000)
    optional uint64 ask = 5; // Ask price. Specified in 1/100_000 of unit of a price.
    repeated ProtoOATrendbar trendbar = 6; // Returns live trend bar. Requires subscription on the trend bars.
    optional uint64 sessionClose = 7;// Last session close. Specified in 1/100_000 of unit of a price.
    optional int64 timestamp = 8; // The UNIX timestamp for spot.
}

/** Request for subscribing for live trend bars. Requires subscription on the spot events, see ProtoOASubscribeSpotsReq. */
message ProtoOASubscribeLiveTrendbarReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SUBSCRIBE_LIVE_TRENDBAR_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required ProtoOATrendbarPeriod period = 3; // Specifies period of trend bar series (e.g. M1, M10, etc.).
    required int64 symbolId = 4; // Unique identifier of the Symbol in cTrader platform.
}

/** Response to the ProtoOASubscribeLiveTrendbarReq request. */
message ProtoOASubscribeLiveTrendbarRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SUBSCRIBE_LIVE_TRENDBAR_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Request for unsubscribing from the live trend bars. */
message ProtoOAUnsubscribeLiveTrendbarReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_UNSUBSCRIBE_LIVE_TRENDBAR_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required ProtoOATrendbarPeriod period = 3; // Specifies period of trend bar series (e.g. M1, M10, etc.).
    required int64 symbolId = 4; // Unique identifier of the Symbol in cTrader platform.
}

/** Response to the ProtoOASubscribeLiveTrendbarReq request. */
message ProtoOAUnsubscribeLiveTrendbarRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_UNSUBSCRIBE_LIVE_TRENDBAR_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Request for getting historical trend bars for the symbol. */
message ProtoOAGetTrendbarsReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_TRENDBARS_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 fromTimestamp = 3; // The exact time of starting the search in milliseconds. Must be bigger or equal to zero (1-1-1970). Validation: toTimestamp - fromTimestamp <= X, where X depends on series period: M1, M2, M3, M4, M5: 302400000 (5 weeks); M10, M15, M30, H1: 21168000000 (35 weeks), H4, H12, D1: 31622400000 (1 year); W1, MN1: 158112000000 (5 years).
    required int64 toTimestamp = 4; // The exact time of finishing the search in milliseconds. Smaller or equal to 2147483646000 (19-1-2038).
    required ProtoOATrendbarPeriod period = 5; // Specifies period of trend bar series (e.g. M1, M10, etc.).
    required int64 symbolId = 6; // Unique identifier of the Symbol in cTrader platform.
    optional uint32 count = 7; // Limit number of trend bars in response back from toTimestamp.
}

/** Response to the ProtoOAGetTrendbarsReq request. */
message ProtoOAGetTrendbarsRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_TRENDBARS_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required ProtoOATrendbarPeriod period = 3; // Specifies period of trend bar series (e.g. M1, M10, etc.).
    required int64 timestamp = 4; // Equals to toTimestamp from the request.
    repeated ProtoOATrendbar trendbar = 5; // The list of trend bars.
    optional int64 symbolId = 6; // Unique identifier of the Symbol in cTrader platform.
}

/** Request for getting historical tick data for the symbol. */
message ProtoOAGetTickDataReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_TICKDATA_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
    required ProtoOAQuoteType type = 4; // Bid/Ask (1/2).
    required int64 fromTimestamp = 5; // The exact time of starting the search in milliseconds. Must be bigger of equal to zero (1-1-1970). Validation: toTimestamp - fromTimestamp <= 604800000 (1 week).
    required int64 toTimestamp = 6; // The exact time of finishing the search in milliseconds <= 2147483646000 (19-1-2038).
}

/** Response to the ProtoOAGetTickDataReq request. */
message ProtoOAGetTickDataRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_TICKDATA_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOATickData tickData = 3; // The list of ticks in chronological order. The first tick contains Unix timestamp in milliseconds while all subsequent ticks have the time difference in milliseconds between previous and the current one.
    required bool hasMore = 4; // If TRUE then the number of records by filter is larger than chunkSize, the response contains the number of records that is equal to chunkSize.
}

//+------------------------------------------------------------------+
//|                      End quotes section                          |
//+------------------------------------------------------------------+

/** Request for getting details of Trader's profile. Limited due to GDRP requirements. */
message ProtoOAGetCtidProfileByTokenReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_CTID_PROFILE_BY_TOKEN_REQ];

    required string accessToken = 2; // The Access Token issued for providing access to the Trader's Account.
}

/** Response to the ProtoOAGetCtidProfileByTokenReq request. */
message ProtoOAGetCtidProfileByTokenRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_CTID_PROFILE_BY_TOKEN_RES];

    required ProtoOACtidProfile profile = 2; // Trader's profile.
}

/** Event that is sent when the structure of depth of market is changed. Requires subscription on the depth of markets for the symbol, see ProtoOASubscribeDepthQuotesReq. */
message ProtoOADepthEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_DEPTH_EVENT];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required uint64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
    repeated ProtoOADepthQuote newQuotes = 4; // The list of changes in the depth of market quotes.
    repeated uint64 deletedQuotes = 5 [packed = true]; // The list of quotes to delete.
}

/** Request for subscribing on depth of market of the specified symbol. */
message ProtoOASubscribeDepthQuotesReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SUBSCRIBE_DEPTH_QUOTES_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated int64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
}

/** Response to the ProtoOASubscribeDepthQuotesReq request. */
message ProtoOASubscribeDepthQuotesRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SUBSCRIBE_DEPTH_QUOTES_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Request for unsubscribing from the depth of market of the specified symbol. */
message ProtoOAUnsubscribeDepthQuotesReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_UNSUBSCRIBE_DEPTH_QUOTES_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated int64 symbolId = 3; // Unique identifier of the Symbol in cTrader platform.
}

/** Response to the ProtoOAUnsubscribeDepthQuotesReq request. */
message ProtoOAUnsubscribeDepthQuotesRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_UNSUBSCRIBE_DEPTH_QUOTES_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Request for a list of symbol categories available for a trading account. */
message ProtoOASymbolCategoryListReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOL_CATEGORY_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
}

/** Response to the ProtoSymbolCategoryListReq request. */
message ProtoOASymbolCategoryListRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_SYMBOL_CATEGORY_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOASymbolCategory symbolCategory = 3; // The list of symbol categories.
}

/** Request for logout of  trading account session.*/
message ProtoOAAccountLogoutReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ACCOUNT_LOGOUT_REQ];

    required int64 ctidTraderAccountId = 2; // The unique identifier of the trader's account in cTrader platform.
}

/** Response to the ProtoOATraderLogoutReq request. */
message ProtoOAAccountLogoutRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ACCOUNT_LOGOUT_RES];

    required int64 ctidTraderAccountId = 2; // The unique identifier of the trader's account in cTrader platform.
}

/** Event that is sent when the established session for an account is dropped on the server side. A new session must be authorized for the account.  */
message ProtoOAAccountDisconnectEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_ACCOUNT_DISCONNECT_EVENT];

    required int64 ctidTraderAccountId = 2; // The unique identifier of the trader's account in cTrader platform.
}

/** Request for a list of existing margin call thresholds configured for a user. */
message ProtoOAMarginCallListReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_MARGIN_CALL_LIST_REQ];

    required int64 ctidTraderAccountId = 2;
}

/** Response with a list of existing user Margin Calls, usually contains 3 items. */
message ProtoOAMarginCallListRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_MARGIN_CALL_LIST_RES];

    repeated ProtoOAMarginCall marginCall = 2;
}

/** Request to modify marginLevelThreshold of specified marginCallType for ctidTraderAccountId. */
message ProtoOAMarginCallUpdateReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_MARGIN_CALL_UPDATE_REQ];

    required int64 ctidTraderAccountId = 2;
    required ProtoOAMarginCall marginCall = 3;
}

/** If this response received, it means that margin call was successfully updated. */
message ProtoOAMarginCallUpdateRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_MARGIN_CALL_UPDATE_RES];
}

/** Event that is sent when a Margin Call threshold configuration is updated. */
message ProtoOAMarginCallUpdateEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_MARGIN_CALL_UPDATE_EVENT];

    required int64 ctidTraderAccountId = 2;
    required ProtoOAMarginCall marginCall = 3;
}

/** Event that is sent when account margin level reaches target marginLevelThreshold. Event is sent no more than once every 10 minutes to avoid spamming. */
message ProtoOAMarginCallTriggerEvent {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_MARGIN_CALL_TRIGGER_EVENT];

    required int64 ctidTraderAccountId = 2;
    required ProtoOAMarginCall marginCall = 3;
}

/** Request for getting a dynamic leverage entity referenced in ProtoOASymbol.leverageId. */
message ProtoOAGetDynamicLeverageByIDReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_DYNAMIC_LEVERAGE_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 leverageId = 3;
}

/** Response to the ProtoOAGetDynamicLeverageByIDReq request. */
message ProtoOAGetDynamicLeverageByIDRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_GET_DYNAMIC_LEVERAGE_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required ProtoOADynamicLeverage leverage = 3;
}

/** Request for retrieving the deals related to a position. */
message ProtoOADealListByPositionIdReq {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_DEAL_LIST_BY_POSITION_ID_REQ];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    required int64 positionId = 3; // The unique ID of the position.
    required int64 fromTimestamp = 4; // The exact time of starting the search in milliseconds. Must be bigger of equal to zero (1-1-1970). Validation: toTimestamp - fromTimestamp <= 604800000 (1 week).
    required int64 toTimestamp = 5; // The exact time of finishing the search in milliseconds <= 2147483646000 (19-1-2038).
}

/** Response to the ProtoOADealListByPositionIdReq request. */
message ProtoOADealListByPositionIdRes {
    optional ProtoOAPayloadType payloadType = 1 [default = PROTO_OA_DEAL_LIST_BY_POSITION_ID_RES];

    required int64 ctidTraderAccountId = 2; // Unique identifier of the trader's account. Used to match responses to trader's accounts.
    repeated ProtoOADeal deal = 3; // The list of deals.
    required bool hasMore = 4; // If TRUE then the number of records by filter is larger than chunkSize, the response contains the number of records that is equal to chunkSize.
}