Skip to content

HookTradeProcessClose

HookTradeProcessClose

The hook is triggered while a trade is being closed.

Warning

This hook is highly sensitive and can affect the entire server. Do not use it unless necessary.

virtual int HookTradeProcessClose(
    const TradeRecord&   trade,        // reference to the trade request object
    const GroupRecord&   group,        // reference to the group configuration object
    const SymbolRecord&  symbol,       // reference to the symbol configuration object
    const AccountRecord&    user,         // reference to the account object
    const MarginLevel&   margin,       // reference to the margin state
    TradeDiffRecord&     trade_dif     // [in/out] reference to the trade changes to apply after processing the request (see below)
);

Parameters

  • trade [in] reference to the trade request object.

  • group [in] Reference to the client group configuration for which the request is processed.

  • symbol [in] Reference to the symbol configuration for which the request is processed.

  • user [in] Reference to the current account associated with the request.

  • margin [in] Reference to the current account associated with the request.

  • trade_dif [in/out] Reference to the new trade order object to create as a result of processing the request. It is populated only for requests that create a new order (see below). The order is ready to be added to the trading database, with every field except the ticket populated. The order is created and assigned a ticket only after the hook returns MT_RET_OK.


Return Value

  • If RET_OK is returned, the operation is confirmed.
  • Otherwise, the request is rejected with the corresponding code.

Notes

Depending on the trade request type, the hook can: - modify the request, - reject the request, - accept the request without changes.

trade_dif is populated only for the following request types (EnTradeActions):

  • TA_REQUEST
  • TA_INSTANT

Changes to trade_dif are not applied for other request types.