Tick and Order Processing¶
This section describes the processing flow for new ticks in client groups, including validation and triggering of pending orders and position stop levels (Stop Loss, Take Profit, Stop Out).
Main Processing Stages¶
- A new tick arrives for symbol AAABBB.
- The current price of open positions and pending orders for symbol AAABBB is updated (
TradeRecord::close_price). -
For pending orders on AAABBB:
- If the order is not processed through an STP gateway (
ConGatewayRule), theSrvTradePendingsFilterhook is called (default return:RET_OK_NONE). - If the hook returns
RET_OK, the system then checks whether the new tick has triggered the pending order. - If the hook returns anything other than
RET_OK, trigger validation continues only if the symbol group is not set to "Manual only, no automation" mode (ConGroupSec::execution). - If the order is triggered, it is stored for later activation.
- If the order is not processed through an STP gateway (
-
For positions (not pending orders) on AAABBB:
- Profit is recalculated (
TradeRecord::close_profit) using the new price. - If stop levels are not handled through an STP gateway, the system checks Take Profit execution.
- If Take Profit is reached, the
SrvTradeStopsFilterhook is called (default return:RET_OK_NONE):- If the hook returns
RET_OK, the position is closed by Take Profit unconditionally. - If the hook returns anything other than
RET_OK, Take Profit closure continues only in "Automatic only" mode or when no online dealers are available in "Manual, but automatic if no dealers" mode.
- If the hook returns
- The FIFO rule is checked if enabled for the group (
ConGroup::close_fifo). - Position closure is prepared: profit and conversion rates are recalculated.
- The
SrvTradeStopsApplyhook is called (default return:RET_OK):- If the hook returns
RET_OK, the position is closed and agent commission is charged. If the close price has changed, profit and rates are recalculated. - If not
RET_OK, Take Profit closure is skipped until the next trigger.
- If the hook returns
- Stop Loss is checked and executed in the same manner.
- Profit is recalculated (
-
Pending orders saved in step 3 are activated.
- The
SrvTradePendingsFilterhook is called again (default return:RET_OK_NONE):- If the hook returns
RET_OK, the pending order is activated unconditionally. - If not
RET_OK, activation continues only in "Automatic only" mode or when no online dealers are available in the corresponding mode.
- If the hook returns
- Permission to open new positions is checked (
ConSymbol::trade). If opening is forbidden, the order is deleted with the commentdeleted [close only]. - Client margin is checked. If funds are insufficient, the order is deleted with the comment
deleted [no money]. - Hedging prohibition is checked (
ConGroup::hedge_prohibited). If hedging is prohibited, the order is deleted with the commentdeleted [hedge is prohibited]. - A new position is prepared from the pending order: commission, initial profit, and conversion rates are calculated.
- The
SrvTradePendingsApplyhook is called (default return:RET_OK):- If the hook returns
RET_OK, the pending order is activated. If the price has changed, profit and rates are recalculated. - If not
RET_OK, the server skips further activation.
- If the hook returns
- The
-
If Stop Out is not processed through an STP gateway, margin requirements are checked:
- For all accounts with recalculated positions (see step 4), margin level is compared with Stop Out conditions.
- For accounts that reached Stop Out, a position is selected for closure (largest loss, subject to FIFO).
- Position closure is prepared. The
SrvTradeStopoutsFilterhook is called (default return:RET_OK_NONE):- If the hook returns
RET_OK, Stop Out is processed unconditionally. - If not
RET_OK, Stop Out is executed only in "Automatic only" mode or when no online dealers are available.
- If the hook returns
- The
SrvTradeStopoutsApplyhook is called (default return:RET_OK):- If the hook returns
RET_OK, the position is closed and agent commission is charged. If the close price has changed, profit and rates are recalculated. - If not
RET_OK, Stop Out closure is skipped until the next trigger.
- If the hook returns