- Couchbase for Orders/Trades storage
- Influx for marketdata storage quote/query
- uWebsocket for TCP/UDP
- Order types
- market order - execute an order as fast as possible, cross the spread
- limit order - execute an order with a limit on bid/ask price (e.g. $x or less for a bid, or $y or more for an ask)
- Order params
- AON - all or nothing, don't allow partial fills
- IOC - immediate or cancel, immediately fill what's possible, cancel the rest
- FOK - AON+IOC, immediately match an order in full (without partial fills) or cancel it
- β stop orders
- β GFD, GTC, GTD parameters
- logic surrounding the order book - trading hours, pre/after market restrictions
- basic middle & back office functionalities - risk assessment, limits
- β Websocket: TCP/UDP server that accepts orders
- β HTTP: TCP/UDP server that accepts orders
- β reporting market volume, share price
- β reporting acknowledgments & updates to clients (share price, displayed/hidden orders...)
- Master-slave cluster, auto-re-elect master
- Same-sync
- Tradebook cronjobs
Market orders are always given priority above all other orders, then sorted according to time of arrival.
- orders are FIFO based
- bids - price (descending), time (ascending)
- asks - price (ascending), time (ascending)
- quantity does not matter in sorting
When a match occurs between two limit orders the price is set on the bid price. Bid of $25 and ask of $24 will be matched at $25.
Order book & trade books are per-instrument objects, one order book can only handle one instrument.
-
OrderBook (Order model) - stores active orders in memory, db & handles order matching
-
TradeBook (Trade model) - stores daily trades in memory, db & provides additional data about trading
-
Historical Orders (OrderRecord model) - persistent storage of all historical orders
Order
model/collection is used to persist all orders in couchbase- All orders whether active/or not are stored in couchbase under the
Order
collection - When an Order has been filled it is deleted from the
Order
collection and a copy of it is stored inOrderRecords
- All trades are saved in the
Trade
collection of couchbase
-
Matching system full documentation
-
Practical .NET for Financial Markets by Samir Jayaswal and Yogesh Shetty
- excellent reading material for functional and technical details about financial markets
- good explanation of the order matching algorithm
-
- insight into technical aspects regarding trading speed, efficiency...
-
https://www.investopedia.com/investing/basics-trading-stock-know-your-orders/
- great summary of order types
-
https://github.com/enewhuis/liquibook
- inspiration for some of the data structures and approaches to the problem