Skip to content

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

  1. A new tick arrives for symbol AAABBB.
  2. The current price of open positions and pending orders for symbol AAABBB is updated (TradeRecord::close_price).
  3. For pending orders on AAABBB:

    • If the order is not processed through an STP gateway (ConGatewayRule), the SrvTradePendingsFilter hook 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.
  4. 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 SrvTradeStopsFilter hook 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.
    • The FIFO rule is checked if enabled for the group (ConGroup::close_fifo).
    • Position closure is prepared: profit and conversion rates are recalculated.
    • The SrvTradeStopsApply hook 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.
    • Stop Loss is checked and executed in the same manner.
  5. Pending orders saved in step 3 are activated.

    • The SrvTradePendingsFilter hook 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.
    • Permission to open new positions is checked (ConSymbol::trade). If opening is forbidden, the order is deleted with the comment deleted [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 comment deleted [hedge is prohibited].
    • A new position is prepared from the pending order: commission, initial profit, and conversion rates are calculated.
    • The SrvTradePendingsApply hook 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.
  6. 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 SrvTradeStopoutsFilter hook 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.
    • The SrvTradeStopoutsApply hook 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.