https://github.com/ormanli/order-book
Order Book implementation example
https://github.com/ormanli/order-book
java java19 orderbook
Last synced: 6 months ago
JSON representation
Order Book implementation example
- Host: GitHub
- URL: https://github.com/ormanli/order-book
- Owner: ormanli
- License: apache-2.0
- Created: 2023-04-15T11:45:13.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-25T13:50:44.000Z (over 1 year ago)
- Last Synced: 2025-03-30T08:41:39.310Z (9 months ago)
- Topics: java, java19, orderbook
- Language: Java
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Order Book #
An exchange allows the buyers and sellers of a product to discover each other and trade. Buyers and sellers (traders)
submit orders to the exchange and the exchange applies simple rules to determine if a trade has occurred. The dominant
kind of exchange is a central limit order book (CLOB) where orders are matched using ‘price time priority’.
When placing an order, traders specify if they wish to buy or sell, the limit price ie. worst possible price they will
trade at, and the quantity (number of shares) they wish to trade. Trades only occur during the
processing of a newly posted order, and happen immediately, which is known as ‘continuous trading’.
### Requirements ###
* Java 22+
* Maven 3
### Info ###
* Application starts and creates `InputStreamReader` from `System.in` and `OutputStreamWriter` from `System.out`.
* There two threads, first one is reading orders from `InputStreamReader` and pushing to a `LinkedBlockingQueue`.
* Second thread is consuming orders from `LinkedBlockingQueue` and adding to `OrderBook`. If trades happen after adding
an order, it prints trades to `OutputStreamWriter`.
* After both of the threads are finished, the order book is printed to `OutputStreamWriter`.
* If an exception is thrown, application tries to process the orders to order book as much as possible.
### How to create executable ###
```shell
mvn package
```
### How to run ###
```shell
java -jar ./target/orderbook-1.0-SNAPSHOT.jar < ./src/test/resources/test2.txt
```