Files
zeekayandHanzo Dev 70f6883235 Restore the regulated-markets papers; Lux holds the licences
A July commit removed eight papers on the premise "no license — DEX/non-custodial
only". That premise is wrong: Lux operates an ATS, a broker-dealer, a transfer
agent and a bank, and this material is resold at lux.financial. The merge that
brought main in preserved the removal because the commit stated a reason, which
is how a stale reason outlives the fact it rested on.

Back, at the versions main carried — main never received the removal, so its
copies are the later ones: the ATS architecture, the security-token standard,
smart order routing, institutional custody, MPC custody, post-quantum securities,
the SSB partnership and the CoinBridge brief. 83 files.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-30 15:58:05 -07:00

68 lines
2.0 KiB
TeX

\section{Order Matching}
\label{sec:matching}
\subsection{Matching Engine}
The matching engine implements price-time priority for continuous order matching:
\begin{lstlisting}[language=Go,caption={Matching engine core.}]
type MatchEngine struct {
books map[SecurityID]*OrderBook
mu sync.RWMutex
}
type OrderBook struct {
Bids *PriorityQueue // max-heap by price, FIFO by time
Asks *PriorityQueue // min-heap by price, FIFO by time
}
func (e *MatchEngine) Match(secID SecurityID) []Execution {
e.mu.Lock()
defer e.mu.Unlock()
book := e.books[secID]
var executions []Execution
for book.Bids.Len() > 0 && book.Asks.Len() > 0 {
bestBid := book.Bids.Peek()
bestAsk := book.Asks.Peek()
if bestBid.Price.LessThan(bestAsk.Price) {
break
}
qty := min(bestBid.Remaining, bestAsk.Remaining)
price := bestAsk.Price // price-time priority: aggressor pays
executions = append(executions, Execution{
BuyOrder: bestBid.ID,
SellOrder: bestAsk.ID,
Quantity: qty,
Price: price,
Timestamp: time.Now().UTC(),
})
bestBid.Remaining -= qty
bestAsk.Remaining -= qty
if bestBid.Remaining == 0 { book.Bids.Pop() }
if bestAsk.Remaining == 0 { book.Asks.Pop() }
}
return executions
}
\end{lstlisting}
\subsection{Order Types}
The ATS supports the following order types, consistent with standard equity market conventions:
\begin{itemize}[nosep]
\item \textbf{Limit}: Execute at specified price or better.
\item \textbf{Market}: Execute immediately at best available price.
\item \textbf{IOC} (Immediate-or-Cancel): Fill what is available, cancel remainder.
\item \textbf{GTC} (Good-Till-Cancelled): Remain on book until filled or cancelled.
\item \textbf{GTD} (Good-Till-Date): Remain on book until specified date.
\item \textbf{RFQ} (Request-for-Quote): Solicit quotes from registered market makers.
\end{itemize}