Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stoqey/dior
Christian Dior ππΊππππ - (Order Matching Engine) - match hundreds of thousands of orders per second
https://github.com/stoqey/dior
couchbase influxdb matching-algorithm matching-engine matching-networks order-matching typescript
Last synced: 24 days ago
JSON representation
Christian Dior ππΊππππ - (Order Matching Engine) - match hundreds of thousands of orders per second
- Host: GitHub
- URL: https://github.com/stoqey/dior
- Owner: stoqey
- License: mit
- Created: 2021-02-13T09:47:04.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-01T07:47:01.000Z (over 3 years ago)
- Last Synced: 2024-05-01T11:35:33.067Z (8 months ago)
- Topics: couchbase, influxdb, matching-algorithm, matching-engine, matching-networks, order-matching, typescript
- Language: TypeScript
- Homepage:
- Size: 1.99 MB
- Stars: 28
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Christian Dior
Order Matching Engine - match hundreds of thousands of orders per second
## Tech
- **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## TODO
* β 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 behaviour
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 sortingWhen 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.## Architecture
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
### OrderBook
* `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 in `OrderRecords`### TradeBook
* All trades are saved in the `Trade` collection of couchbase## Acknowledgements
* Matching system full documentation
* https://gist.github.com/jdrew1303/e06361070468f6614d52216fb91b79e5* 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
* https://web.archive.org/web/20110219163448/http://howtohft.wordpress.com/2011/02/15/how-to-build-a-fast-limit-order-book/
* 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 problemStoqey Inc