> For the complete documentation index, see [llms.txt](https://ubit.gitbook.io/ubit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ubit.gitbook.io/ubit/fundamentals/trading-machine.md).

# Trading Machine

As a global leader in centralized cryptocurrency exchange, Ubit's technical framework encompasses several key components to ensure high performance, high security, and high scalability.

Trading Engine: One of the core components of Ubit, the trading engine is responsible for processing users' orders and trades. The engine must efficiently handle a large number of concurrent transactions and ensure fairness and justice in order execution. To achieve this, it usually employs highly optimized algorithms and data structures to swiftly execute transactions and maintain stability of the trade queue.

&#x20;① Order Management: The trading engine manages all orders submitted by users. When a user places an order, it enters the engine's order book. The order book, a data structure recording all buy and sell orders, is typically arranged in order of price priority. Based on the price and timestamps of orders, the engine quickly identifies the best price to execute the transaction.&#x20;

② Matching Engine: A crucial part of the trading engine, the matching engine pairs up buy and sell orders. A transaction occurs when the bidding price of the buyer is higher or equal to the asking price of the seller. The matching engine needs to efficiently implement matching logic and find the best price to match orders in the shortest time possible.&#x20;

③ High Performance: The trading engine must be high-performance, capable of swiftly processing numerous concurrent transactions. For a large exchange like Ubit, it may handle thousands of transactions per second, thus the engine needs to be highly optimized to ensure processing speed and throughput.

④ Fault Tolerance: The trading engine must be fault-tolerant, maintaining stable operation in the face of abnormal conditions. For instance, during a network attack or system failure, the engine should take appropriate measures like disconnecting the attack source or rolling back to a stable state.&#x20;

⑤ Preventing Trade Delay: The trading engine needs to adopt measures like first-in-first-out (FIFO) or time priority to prevent trade delays, ensuring users' orders are matched and executed promptly after submission.&#x20;

⑥ Order Status Management: The engine needs to accurately track and manage the status of orders. This includes the creation of orders, partial execution, full execution, or cancellation. The exchange should allow users to accurately query their order status and history.&#x20;

⑦ Support for Multiple Trading Pairs: For a large exchange like Ubit, it needs to support a substantial number of trading pairs. Hence, the trading engine needs to handle multiple different trading pairs concurrently to cater to users' diverse needs. Overall, the trading engine is one of the core components of a centralized cryptocurrency exchange. Its high performance, high fault tolerance, and high availability are crucial for successful operations of the exchange. As one of the leading exchanges worldwide, Ubit's trading engine plays a vital role in processing a large volume of transactions and maintaining market stability.
