The core elements of high concurrency java | Series 7 | LMAX-Disruptor achieve matching engine

Development Exchange is a difficult, technical content.
A complete securities trading system is user systems, accounting systems, order systems, matching and clearing system of systems, subsystems. Each subsystem cooperate with each other to complete the offer of securities trading.

       1  ┌───────────┐  2  ┌───────────┐  7  ┌───────────┐

Request ────>│ User │────>│ Account │<────│ Clearing │
└───────────┘ └───────────┘ └───────────┘
3│ ▲
▼ │
┌───────────┐ │
│ Order │ 6│
└───────────┘ │
4│ │
▼ │
┌───────────┐ 5 ┌───────────┐
│ Sequence │────>│ Match │
└───────────┘ └───────────┘


┌───────────┐
Market <────────────────────────────────────────│ Quotation │
└───────────┘

When a request for access to the trading system, the first system by the user (User) to identify the user, and then by the system account (Account) for users of the assets freeze, freeze to buy USD, sell frozen BTC, freeze if successful, given orders to enter sequence system (sequence).

Why do we need to design a sequencing system? Because all orders trading system is an orderly queue. Different users at the same time order, the order must be determined by the sequencer system.

After sequencing the order is sent to match engine (Match).

The match engine is the core of the exchange.

The matching engine is essentially to maintain a list of trading pan, then press the principle of price priority for order matching, can be traded on the output results of the transaction can not be traded into orders.
Let's talk about today, to develop a high-performance engine with a dealmaker disruptor.
First, let's simplify, a matching input-output engines.
For example, the input may include:

创建新的委托单(NewOrder):一个新的委托单可以作为交易撮合引擎的输入,引擎会尝试将其与已有的 委托单进行撮合。
取消已有的委托单(CancelOrder):用户也可以取消一个之前输入的委托单,如果它还没有执行的话,即开口订单。

Of course, you can define other input, the sake of simplicity, we now define only these two inputs.
Engine output dealmakers are some of the events, in order to promptly notify the other application processing. For example, when the engine brokered a deal later, it will trigger a TradesGenerated event; and when a cancel existing orders, the engine will trigger OrderCancelled. Similarly, you can define the output of the engine according to their needs, where we simply point, defines only two output events.

Reference article:

https://cloud.tencent.com/developer/article/1470996

https://www.liaoxuefeng.com/article/1185272483766752
https://juejin.im/post/5dd3479a518825786e79035b

Guess you like

Origin www.cnblogs.com/gyc567/p/12272645.html