syntax = "proto2";

// ─── Payload type enum ──────────────────────────────────────────────────────

enum ProtoOAPayloadType {
  PROTO_OA_APPLICATION_AUTH_REQ = 2100;
  PROTO_OA_APPLICATION_AUTH_RES = 2101;
  PROTO_OA_ACCOUNT_AUTH_REQ = 2102;
  PROTO_OA_ACCOUNT_AUTH_RES = 2103;
  PROTO_OA_VERSION_REQ = 2104;
  PROTO_OA_VERSION_RES = 2105;
  PROTO_OA_NEW_ORDER_REQ = 2106;
  PROTO_OA_TRAILING_SL_CHANGED_EVENT = 2107;
  PROTO_OA_CANCEL_ORDER_REQ = 2108;
  PROTO_OA_AMEND_ORDER_REQ = 2109;
  PROTO_OA_AMEND_POSITION_SLTP_REQ = 2110;
  PROTO_OA_CLOSE_POSITION_REQ = 2111;
  PROTO_OA_ASSET_LIST_REQ = 2112;
  PROTO_OA_ASSET_LIST_RES = 2113;
  PROTO_OA_SYMBOLS_LIST_REQ = 2114;
  PROTO_OA_SYMBOLS_LIST_RES = 2115;
  PROTO_OA_SYMBOL_BY_ID_REQ = 2116;
  PROTO_OA_SYMBOL_BY_ID_RES = 2117;
  PROTO_OA_SYMBOLS_FOR_CONVERSION_REQ = 2118;
  PROTO_OA_SYMBOLS_FOR_CONVERSION_RES = 2119;
  PROTO_OA_SYMBOL_CHANGED_EVENT = 2120;
  PROTO_OA_TRADER_REQ = 2121;
  PROTO_OA_TRADER_RES = 2122;
  PROTO_OA_RECONCILE_REQ = 2124;
  PROTO_OA_RECONCILE_RES = 2125;
  PROTO_OA_EXECUTION_EVENT = 2126;
  PROTO_OA_SUBSCRIBE_SPOTS_REQ = 2127;
  PROTO_OA_SUBSCRIBE_SPOTS_RES = 2128;
  PROTO_OA_UNSUBSCRIBE_SPOTS_REQ = 2129;
  PROTO_OA_UNSUBSCRIBE_SPOTS_RES = 2130;
  PROTO_OA_SPOT_EVENT = 2131;
  PROTO_OA_ORDER_ERROR_EVENT = 2132;
  PROTO_OA_DEAL_LIST_REQ = 2133;
  PROTO_OA_DEAL_LIST_RES = 2134;
  PROTO_OA_SUBSCRIBE_LIVE_TRENDBAR_REQ = 2135;
  PROTO_OA_UNSUBSCRIBE_LIVE_TRENDBAR_REQ = 2136;
  PROTO_OA_GET_TRENDBARS_REQ = 2137;
  PROTO_OA_GET_TRENDBARS_RES = 2138;
  PROTO_OA_EXPECTED_MARGIN_REQ = 2139;
  PROTO_OA_EXPECTED_MARGIN_RES = 2140;
  PROTO_OA_MARGIN_CHANGED_EVENT = 2141;
  PROTO_OA_ERROR_RES = 2142;
  PROTO_OA_CASH_FLOW_HISTORY_LIST_REQ = 2143;
  PROTO_OA_CASH_FLOW_HISTORY_LIST_RES = 2144;
  PROTO_OA_GET_TICKDATA_REQ = 2145;
  PROTO_OA_GET_TICKDATA_RES = 2146;
  PROTO_OA_ACCOUNTS_TOKEN_INVALIDATED_EVENT = 2147;
  PROTO_OA_CLIENT_DISCONNECT_EVENT = 2148;
  PROTO_OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_REQ = 2149;
  PROTO_OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_RES = 2150;
  PROTO_OA_GET_CTID_PROFILE_BY_TOKEN_REQ = 2151;
  PROTO_OA_GET_CTID_PROFILE_BY_TOKEN_RES = 2152;
  PROTO_OA_ASSET_CLASS_LIST_REQ = 2153;
  PROTO_OA_ASSET_CLASS_LIST_RES = 2154;
  PROTO_OA_DEPTH_EVENT = 2155;
  PROTO_OA_SUBSCRIBE_DEPTH_QUOTES_REQ = 2156;
  PROTO_OA_SUBSCRIBE_DEPTH_QUOTES_RES = 2157;
  PROTO_OA_UNSUBSCRIBE_DEPTH_QUOTES_REQ = 2158;
  PROTO_OA_UNSUBSCRIBE_DEPTH_QUOTES_RES = 2159;
  PROTO_OA_SYMBOL_CATEGORY_REQ = 2160;
  PROTO_OA_SYMBOL_CATEGORY_RES = 2161;
  PROTO_OA_ACCOUNT_LOGOUT_REQ = 2162;
  PROTO_OA_ACCOUNT_LOGOUT_RES = 2163;
  PROTO_OA_ACCOUNT_DISCONNECT_EVENT = 2164;
  PROTO_OA_SUBSCRIBE_LIVE_TRENDBAR_RES = 2165;
  PROTO_OA_UNSUBSCRIBE_LIVE_TRENDBAR_RES = 2166;
  PROTO_OA_MARGIN_CALL_LIST_REQ = 2167;
  PROTO_OA_MARGIN_CALL_LIST_RES = 2168;
  PROTO_OA_MARGIN_CALL_UPDATE_REQ = 2169;
  PROTO_OA_MARGIN_CALL_UPDATE_RES = 2170;
  PROTO_OA_MARGIN_CALL_UPDATE_EVENT = 2171;
  PROTO_OA_MARGIN_CALL_TRIGGER_EVENT = 2172;
  PROTO_OA_REFRESH_TOKEN_REQ = 2173;
  PROTO_OA_REFRESH_TOKEN_RES = 2174;
  PROTO_OA_ORDER_LIST_REQ = 2175;
  PROTO_OA_ORDER_LIST_RES = 2176;
  PROTO_OA_GET_DYNAMIC_LEVERAGE_REQ = 2177;
  PROTO_OA_GET_DYNAMIC_LEVERAGE_RES = 2178;
  PROTO_OA_DEAL_LIST_BY_POSITION_ID_REQ = 2179;
  PROTO_OA_DEAL_LIST_BY_POSITION_ID_RES = 2180;
  PROTO_OA_ORDER_DETAILS_REQ = 2181;
  PROTO_OA_ORDER_DETAILS_RES = 2182;
  PROTO_OA_ORDER_LIST_BY_POSITION_ID_REQ = 2183;
  PROTO_OA_ORDER_LIST_BY_POSITION_ID_RES = 2184;
  PROTO_OA_DEAL_OFFSET_LIST_REQ = 2185;
  PROTO_OA_DEAL_OFFSET_LIST_RES = 2186;
  PROTO_OA_GET_POSITION_UNREALIZED_PNL_REQ = 2187;
  PROTO_OA_GET_POSITION_UNREALIZED_PNL_RES = 2188;
}

// ─── Auth ───────────────────────────────────────────────────────────────────

message ProtoOAApplicationAuthReq {
  optional uint32 payloadType = 1 [default = 2100];
  required string clientId = 2;
  required string clientSecret = 3;
}

message ProtoOAApplicationAuthRes {
  optional uint32 payloadType = 1 [default = 2101];
}

message ProtoOAAccountAuthReq {
  optional uint32 payloadType = 1 [default = 2102];
  required int64 ctidTraderAccountId = 2;
  required string accessToken = 3;
}

message ProtoOAAccountAuthRes {
  optional uint32 payloadType = 1 [default = 2103];
  required int64 ctidTraderAccountId = 2;
}

// ─── Error ──────────────────────────────────────────────────────────────────

message ProtoOAErrorRes {
  optional uint32 payloadType = 1 [default = 2142];
  optional int64 ctidTraderAccountId = 2;
  required string errorCode = 3;
  optional string description = 4;
  optional int64 maintenanceEndTimestamp = 5;
  optional uint64 retryAfter = 6;
}

// ─── Account list ───────────────────────────────────────────────────────────

message ProtoOAGetAccountListByAccessTokenReq {
  optional uint32 payloadType = 1 [default = 2149];
  required string accessToken = 2;
}

message ProtoOACtidTraderAccount {
  required uint64 ctidTraderAccountId = 1;
  optional bool isLive = 2;
  optional int64 traderLogin = 3;
  optional int64 lastClosingDealTimestamp = 4;
  optional int64 lastBalanceUpdateTimestamp = 5;
  optional string brokerTitleShort = 6;
}

message ProtoOAGetAccountListByAccessTokenRes {
  optional uint32 payloadType = 1 [default = 2150];
  required string accessToken = 2;
  repeated ProtoOACtidTraderAccount ctidTraderAccount = 4;
}

// ─── Symbols ────────────────────────────────────────────────────────────────

message ProtoOASymbolsListReq {
  optional uint32 payloadType = 1 [default = 2114];
  required int64 ctidTraderAccountId = 2;
  optional bool includeArchivedSymbols = 3 [default = false];
}

message ProtoOALightSymbol {
  required int64 symbolId = 1;
  optional string symbolName = 2;
  optional bool enabled = 3;
  optional int64 baseAssetId = 4;
  optional int64 quoteAssetId = 5;
  optional int64 symbolCategoryId = 6;
  optional string description = 7;
  optional double sortingNumber = 8;
}

message ProtoOASymbolsListRes {
  optional uint32 payloadType = 1 [default = 2115];
  required int64 ctidTraderAccountId = 2;
  repeated ProtoOALightSymbol symbol = 3;
}

// ─── Refresh token ──────────────────────────────────────────────────────────

message ProtoOARefreshTokenReq {
  optional uint32 payloadType = 1 [default = 2173];
  required string refreshToken = 2;
}

message ProtoOARefreshTokenRes {
  optional uint32 payloadType = 1 [default = 2174];
  required string accessToken = 2;
  required string tokenType = 3;
  required int64 expiresIn = 4;
  required string refreshToken = 5;
}

// ─── Version ────────────────────────────────────────────────────────────────

message ProtoOAVersionReq {
  optional uint32 payloadType = 1 [default = 2104];
}

message ProtoOAVersionRes {
  optional uint32 payloadType = 1 [default = 2105];
  required string version = 2;
}
