{"id":22138907,"url":"https://github.com/stoqey/dior","last_synced_at":"2025-08-22T14:14:31.033Z","repository":{"id":53212539,"uuid":"338542287","full_name":"stoqey/dior","owner":"stoqey","description":"Christian Dior 💃🕺👗👔📈📉 - (Order Matching Engine) - match hundreds of thousands of orders per second","archived":false,"fork":false,"pushed_at":"2021-04-01T07:47:01.000Z","size":2089,"stargazers_count":32,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-26T03:47:47.338Z","etag":null,"topics":["couchbase","influxdb","matching-algorithm","matching-engine","matching-networks","order-matching","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stoqey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"ceddybi","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-02-13T09:47:04.000Z","updated_at":"2025-07-08T15:29:42.000Z","dependencies_parsed_at":"2022-09-15T06:12:23.035Z","dependency_job_id":null,"html_url":"https://github.com/stoqey/dior","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stoqey/dior","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoqey%2Fdior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoqey%2Fdior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoqey%2Fdior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoqey%2Fdior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stoqey","download_url":"https://codeload.github.com/stoqey/dior/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoqey%2Fdior/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271650860,"owners_count":24796725,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["couchbase","influxdb","matching-algorithm","matching-engine","matching-networks","order-matching","typescript"],"created_at":"2024-12-01T20:12:18.735Z","updated_at":"2025-08-22T14:14:31.004Z","avatar_url":"https://github.com/stoqey.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ceddybi"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003e Christian Dior \u003c/h1\u003e\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"./docs/christiandior.jpg\"\u003e\u003c/img\u003e\n\u003cp align=\"center\"\u003e\n  \u003ch5 align=\"center\"\u003e Order Matching Engine - match hundreds of thousands of orders per second \u003c/h5\u003e\n\u003c/p\u003e\n\u003c/div\u003e\n\n\n## Tech\n- **Couchbase** for Orders/Trades storage\n- **Influx** for marketdata storage quote/query\n- **uWebsocket** for TCP/UDP\n\n\n* Order types\n    * **market** order - execute an order as fast as possible, cross the spread\n    * **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)\n* Order params\n    * **AON** - all or nothing, don't allow partial fills\n    * **IOC** - immediate or cancel, immediately fill what's possible, cancel the rest\n    * **FOK** - **AON+IOC**, immediately match an order in full (without partial fills) or cancel it\n\n## TODO\n\n* ✅ stop orders\n* ✅ GFD, GTC, GTD parameters\n* logic surrounding the order book - trading hours, pre/after market restrictions\n* basic middle \u0026 back office functionalities - risk assessment, limits\n* ✅ Websocket: TCP/UDP server that accepts orders\n* ✅ HTTP: TCP/UDP server that accepts orders\n* ✅ reporting market volume, share price\n* ✅ reporting acknowledgments \u0026 updates to clients (share price, displayed/hidden orders...)\n* Master-slave cluster, auto-re-elect master\n* Same-sync\n* Tradebook cronjobs\n\n## Market behaviour\n\nMarket orders are always given priority above all other orders, then sorted according to time of arrival.\n\n* orders are FIFO based\n    * bids - price (descending), time (ascending)\n    * asks - price (ascending), time (ascending)\n    * quantity does not matter in sorting\n\nWhen a match occurs between two limit orders the price is set on the bid price. Bid of $25 and ask of $24 will be\nmatched at $25.\n\n## Architecture\n\nOrder book \u0026 trade books are per-instrument objects, one order book can only handle one instrument.\n\n* OrderBook (**Order model**) - stores active orders in memory, db \u0026 handles order matching\n* TradeBook (**Trade model**) - stores daily trades in memory, db \u0026 provides additional data about trading\n\n* Historical Orders (**OrderRecord model**) - persistent storage of all historical orders\n\n\n### OrderBook\n* `Order` model/collection is used to persist all orders in couchbase\n* All orders whether active/or not are stored in couchbase under the `Order` collection \n* When an Order has been filled it is deleted from the `Order` collection and a copy of it is stored in `OrderRecords`\n\n### TradeBook\n* All trades are saved in the `Trade` collection of couchbase\n\n\n\n## Acknowledgements\n* Matching system full documentation\n  * https://gist.github.com/jdrew1303/e06361070468f6614d52216fb91b79e5\n\n\n* Practical .NET for Financial Markets by Samir Jayaswal and Yogesh Shetty\n    * excellent reading material for functional and technical details about financial markets\n    * good explanation of the order matching algorithm\n* https://web.archive.org/web/20110219163448/http://howtohft.wordpress.com/2011/02/15/how-to-build-a-fast-limit-order-book/\n    * insight into technical aspects regarding trading speed, efficiency...\n* https://www.investopedia.com/investing/basics-trading-stock-know-your-orders/\n    * great summary of order types\n* https://github.com/enewhuis/liquibook\n    * inspiration for some of the data structures and approaches to the problem\n\n\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"docs/footer.jpg\"\u003e\u003c/img\u003e\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\" \u003e\n\u003ch3\u003eStoqey Inc\u003ch3\u003e\n\u003c/div\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstoqey%2Fdior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstoqey%2Fdior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstoqey%2Fdior/lists"}