XDEX Trading Engine module powers a protocol-based marketplace function built on top of the consensus and operations layer of the XDEX Network blockchain.
It is a native, protocol-level application feature that does not rely on user defined code execution, as all functionality is built into the protocol node software itself.
The XDEX Trading Engine permits XDEX Network Authorized Users to create limit orders to trade different digital assets on the XDEX Network blockchain. When an Authorized User creates a trade, it is placed on a market. The market tracks all open and filled orders for a certain trading pair and tracks the last price and 24h volume. XDEX Trading Engine supports an arbitrary number of markets (as well as assets). Any order is matched within the engine logic by the criteria of best price and time of creation once a fitting order is created. The orders can be partially filled, with the remainder remaining in an open position. A user also has the option to create a fill-or-kill order that must be matched on creation. Authorized Users may also cancel open orders at any time.
The XDEX Trading Engine order book is enabled by user signed operations that create and cancel limit orders. The user must properly sign a valid create limit order operation in order to create a limit order. The operation is considered valid if the user has enough verified funds to create the order. Once the operation is executed, the XDEX Trading Engine will attempt to match the order. This is NOT tied to block creation or the consensus mechanism of confirming transactions. The XDEX Trading Engine will proceed to search all limit orders for a given market pair sorted by price ratio and time of creation. If a match is made, and the order is fully filled, the XDEX Trading Engine will exchange the assets between trading accounts, swapping the appropriate amounts of tokens to complete the trade.
If the order is partially matched, or if it is not matched, a unique order object is created on the global share state, and the authorized user is notified of its id. This unique order object contains the information about the amount and type of tokens to sell, as well as the minimal amount to receive. The values are equal to the original values input by the user in the create limit order operation if the order was not filled, or they are adjusted to match the partial filling of the order if a match has happened, but the order was not fully filled. This object persists in the state until it is either filled entirely by another created limit order or cancelled by the authorized user. The user may cancel an open limit order by properly signing a valid cancel limit order operation. The operation is valid if it contains an id of an existing limit order object and is signed by the creator of the object (and the limit order itself).
An important thing to note is that trades are executed immediately, regardless of confirmation. To achieve additional confidence, the user may wish to wait for a confirmed limit order to appear, meaning only such order that was confirmed in a block, and then trade in accordance with the confirmed order.
Depending on the jurisdiction, asset class, and token, there are potential regulatory issues that require XDEX Business Rule Engine to ensure the regulatory compliance of a particular trade operation and venue between Authorized Users.
For example, securities are only legally tradable on a licensed securities exchange. In this case, the entire XDEX Trading Engine and tokens constituting securities would only be activated for active order trading through a licensed securities exchange or broker dealer operating as an ATS (Alternative Trading System) with regulatory approval.