Your task is to create a simplified distributed exchange
- Each client will have its own instance of the orderbook.
- Clients submit orders to their own instance of orderbook. The order is distributed to other instances, too.
- If a client's order matches with another order, any remainer is added to the orderbook, too.
- Submit order worker operates on the
submit_order
event by storing the payload in a queue, the queue is stored and processed in FIFO and sent to a process order worker. - Process order worker operates on the
process_order
event and applies the business logic for new orders being submitted to the orderbook, when an order is matched or added to the orderbook, then the orderbook is stored in the DHT usinglink.put
, and then the update is broadcast to all instances of the orderbook in the Grenache network by publishing to theorderbook_updated
event usingPeerRPCClient.map
with thelink.put
DHT hash as the payload - Clients can submit orders to their own instance of orderbook, and the order is distributed to other instances, too by sending a request to the
submit_order
worker with the order payload - Clients can subscribe to the
orderbook_updated
event and get the updated orderbook from DHT usinglink.get
with the supplied DHThash
value
Find both client
and workers
under /bin
.
- Run
npm install
in the downlaoded folder - start two grapes
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
&&grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
- Run submit order worker with
node bin/submitOrderWorker.js
- Run process order worker with
node bin/processOrderWorker.js
- Run x number of clients with
node bin/client.js clientId=client1 type=Buy amount=10 price=100
Find reusable code under /lib
.
- Implement order matching logic that checks against existing orders in the orderbook, by checking buy sell price and remainder
- Error handling at each level to revert whilst maintaining a consistent state
- Input validation on communication between microservices
- Unit and integration tests against the proposed solution