Skip to content

Trading

Hooks

Method Description
HookTradeRequestAdd Adds a validated trade request to the queue
HookTradeRequestRoute Routes a queued trade request
HookTradeRequestProcess Executes a trade request
HookTradeRequestProcessCloseBy Executes a Close By request
HookTradeRequestRuleFilter Checks whether a request matches a routing rule
HookTradeRequestRuleApply Applies a routing rule to a trade request
HookTradeRollover Accrues rollover
HookTradeInterest Calculates annual interest
HookTradeInterestCharge Credits or debits calculated annual interest
HookTradeInterestChargeDeal Creates the balance operation for an interest charge
HookTradeCommissionOrder Calculates commission reserved when an order is placed
HookTradeCommissionDeal Calculates commission charged when a deal executes
HookTradeCommissionCharge Performs final daily or monthly commission settlement
HookTradeExecution Applies deal execution

To receive trade events, a plugin must subscribe through IMTServerAPI::TradeSubscribe.

Client Request Processing

Instant Execution

The client trades at current market prices displayed in Market Watch. The server validates:

  • symbol trading permissions, stop levels, freeze levels, and volume;
  • margin requirements for opening or closing a position;
  • whether the client accepts execution at a better price;
  • whether the requested price remains available when the group option for checking Instant Execution prices is enabled.

If the requested price is unavailable or stale, the server returns a requote with the current price.

Request Execution

The client first requests a current price and then has a limited time to accept it. The server validates:

  • symbol trading permissions, stop levels, freeze levels, and volume;
  • dealer-price availability;
  • dealer prices against market prices;
  • the decision timeout;
  • margin requirements.

Market Execution

The client accepts execution at the current market price, which the dealer can adjust in either direction. The server validates the main request parameters and margin requirements.

Pending Orders

On every tick, the server checks pending orders for activation. Before activation, it checks free margin. If funds are insufficient, the order is removed with the comment cancelled by dealer.

Stop Loss and Take Profit

On every tick, the server checks open positions for triggered Stop Loss and Take Profit levels. When the conditions are met, the corresponding event is processed according to the trading rules and configuration.

Hooks and Events

Events Hooks
Sent after an action occurs Called before an action is performed
Provide notifications only Can affect the action being performed
All parameters are read-only Some parameters can be modified
Every subscriber is notified Processed in plugin priority and subscription order
Event methods return void Hook methods return a result code
Processing continues for every subscriber Processing stops at the first code other than MT_RET_OK, unless documented otherwise

Hook Processing Flow

Hook processing flow

  1. The server invokes a hook, such as HookUserAdd.
  2. Each configured plugin receives control in priority order.
  3. MT_RET_OK passes control to the next plugin; any other code stops the chain.
  4. If every plugin returns MT_RET_OK, the server completes the operation.