import { MT5DealEntry, MT5TradeSide } from '../../common/constants/mt5.constant'; /** * `data.event` discriminator values emitted by the backend. Not every payload * carries one (e.g. the `tick` topic omits it — see {@link ITickEvent}); those * are dispatched on `topic` instead. Kept here so consumers can route without * hard-coding string literals. */ export declare const WS_EVENT_NAME: { readonly ACCOUNT_STATE: "account_state"; readonly POSITION: "position"; readonly ORDER: "order"; readonly DEAL: "deal"; readonly SYMBOL_TICK: "symbol_tick"; readonly LAST_TICK: "last_tick"; }; export type WsEventName = (typeof WS_EVENT_NAME)[keyof typeof WS_EVENT_NAME]; /** * Per-position row embedded inside an {@link IAccountStateEvent} snapshot * (ws-guide §7.4.1). The `server`, `login`, and `timestampServer` columns that * live on the parent envelope are stripped here by the CMS `account_bridge`. * * Note the `action` divergence: this snapshot uses the **numeric** MT5 type * (`0` = Buy, `1` = Sell), whereas the live {@link IPositionEvent} / * {@link IDealEvent} use the decoded **string** (`'BUY' | 'SELL'`). Consumers * that merge both feeds must coerce once at their boundary. */ export interface IAccountStatePosition { /** MT5 `Position` ticket — stable identity. */ positionId: number; symbol: string; /** `0` = Buy, `1` = Sell (numeric — see interface note above). */ action: number; /** Initial open lot size. */ volume: number; /** Cumulative volume already closed by partial fills. */ volumeClosed: number; /** Still-open size (`volume − volumeClosed`). */ volumeRemaining: number; /** Current market price at `wave_ts`. */ price: number; /** Entry / open price. */ pricePosition: number; /** Stop-loss price; `0` if not set. */ priceSl: number; /** Take-profit price; `0` if not set. */ priceTp: number; /** Gross floating PnL (before swap/commission). */ profit: number; /** Net floating PnL (after swap/commission/fee). */ netProfit: number; /** * Swap/rollover accumulated on the open position. The BE emits this on the * wire but the ws-guide §7.4.1 field list has not been updated to include * it — optional so consumers on older BE envs stay honest. */ swap?: number; /** Broker open-time, unix-**millisecond** tick. */ timestampOpen: number; /** Wave snapshot time (ISO-8601). */ timestamp: string; /** Broker comment (≤ 31 chars). */ comment: string; } /** * Per-order row embedded inside an {@link IAccountStateEvent} snapshot * (ws-guide §7.4). The pending orders the account holds at `wave_ts`. The * `server` / `login` columns that live on the parent envelope are stripped * here by the CMS `account_bridge`, mirroring {@link IAccountStatePosition}. */ export interface IAccountStateOrder { /** MT5 `Order` ticket — stable identity. */ orderId: number; symbol: string; /** Initial requested lot size. */ volume: number; /** Limit / stop trigger price. */ price: number; /** Order stop-loss level; `0` if not set. */ priceSl: number; /** Order take-profit level; `0` if not set. */ priceTp: number; /** Raw MT5 integer code; `orderTypeStr` is the decoded form. */ orderType: number; /** Decoded order type, e.g. `'BUY_LIMIT' | 'SELL_STOP' | …`. */ orderTypeStr: string; /** Raw MT5 integer state code; `stateStr` is the decoded form. */ state: number; /** `PLACED` | `STARTED` | … (snapshot rows are pending). */ stateStr: string; /** `'DAY' | 'GTC' | …`. */ duration: string; /** Setup time, unix-**millisecond** integer. */ timestampSetup: number; /** Wave snapshot time (ISO-8601). */ timestamp: string; /** Broker comment (≤ 31 chars). */ comment: string; } /** * Aggregate account-state payload delivered on topic `account:` * (ws-guide §7.4). Carries the balance/equity/margin summary **and** the * authoritative open-positions + pending-orders lists. This is the camelCase * form the SDK hands to `onEvent` handlers — consumers no longer need a * `toAccountState` adapter. */ export interface IAccountStateEvent { event: typeof WS_EVENT_NAME.ACCOUNT_STATE; /** `Mt5Account.uuid` — matches the topic suffix. */ accountUuid: string; server: string; login: number; /** Statement wave's `wave_ts` (not the publish time). */ timestamp: string; balance: number; equity: number; /** Used margin (in use by open positions). */ margin: number; /** `equity − margin`. */ marginFree: number; /** `equity / margin × 100` (percentage). */ marginLevel: number; /** Closed-trade PnL. */ profit: number; /** Unrealised PnL of all open positions. */ floating: number; /** Wave-snapshot open-position count (should equal `positions.length`). */ openPositions: number; /** Wave-snapshot pending-order count (should equal `orders.length`). */ pendingOrders: number; positions: IAccountStatePosition[]; /** Authoritative pending-orders list at `wave_ts`. */ orders: IAccountStateOrder[]; currency: string; currencyDigits: number; group: string; leverage: number; publisher: string; } /** Live position event (Appendix A.3, topic `mt5:events::position`). */ export interface IPositionEvent { event: typeof WS_EVENT_NAME.POSITION; eventId: string; server: string; login: number; positionId: number; symbol: string; action: MT5TradeSide; volume: number; volumeClosed: number; volumeRemaining: number; price: number | null; pricePosition: number; priceSl: number | null; priceTp: number | null; profit: number; netProfit: number; /** Swap/rollover — the wire key is `swap`. */ swap: number; /** @deprecated Legacy key — the BE now emits `swap`. Optional for consumers still on older wires. */ storage?: number; timestamp: string; timestampServer: number; /** Broker open-time, unix-**millisecond** integer. */ timestampOpen: number; timestampOpenServer: number; durationOfPosition: number; comment: string; } /** Live order event (Appendix A.2, topic `mt5:events::order`). */ export interface IOrderEvent { event: typeof WS_EVENT_NAME.ORDER; eventId: string; server: string; login: number; orderId: number; symbol: string; volume: number; price: number; priceSl: number; priceTp: number; /** Raw MT5 integer code; `orderTypeStr` is the decoded form. */ orderType: number; orderTypeStr: string; /** Raw MT5 integer code; `stateStr` is the decoded form. */ state: number; stateStr: string; duration: string; timestampSetup: number; timestamp: string; comment: string; } /** Live deal event (Appendix A.4, topic `mt5:events::deal`). */ export interface IDealEvent { event: typeof WS_EVENT_NAME.DEAL; eventId: string; server: string; login: number; dealId: number; orderId: number; positionId: number; action: MT5TradeSide; entry: MT5DealEntry; symbol: string; volume: number; price: number; profit: number; commission: number; fee: number; storage: number; swap: number; comment: string; reason: number; externalId: string; timestamp: string; timestampServer: number; group: string; currency: string; } /** * Tick event (Appendix A.1, topic `mt5:events::tick` **or** * `symbol::`). Note: there is **no** `event` discriminator in * the payload — dispatch on `topic` (or on `data.event: "symbol_tick"`). */ export interface ITickEvent { eventId: string; server: string; symbol: string; bid: number; ask: number; last: number; volume: number; timestamp: string; flags: number; } /** * Single depth-of-market (DOM) ladder level. The backend emits one DOM * snapshot per symbol; consumers aggregate the levels into a bid/ask ladder. */ export interface IDomEntry { price: number; quantity: number; } /** * Depth-of-market snapshot event. Delivered on a per-symbol DOM topic; there is * no `event` discriminator — dispatch on `topic` + the `symbol` field. The * ladder (`dom[]`) is the authoritative bid/ask depth at the snapshot time. */ export interface IDomEvent { symbol: string; dom: IDomEntry[]; } /** * Time & sales (the tape) event. Each frame is one executed print for a symbol; * dispatched on `topic` (no `event` discriminator). `side` uses the decoded * `'BUY' | 'SELL'` form. */ export interface ITimeNSaleEvent { symbol: string; price: number; side: MT5TradeSide; quantity: number; timestamp: string; } //# sourceMappingURL=ws.events.d.ts.map