This code sample helps us create an exchange that contains a simple order matching algorithm implementation along with communication based on grenache.
The setup process is very simple, clone this repoistory and do npm install
. This should install all the dependencies.
Our project is dependent on this npm package named grenache-grape
. In order to install this dependency, you can run the following command npm i -g grenache-grape
.
In order to run this, we need to perform a couple of steps mentioned below:
- We need to boot grape servers first, the following commands should help:
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
Once you have the servers running, run the following commands:
# Starts exchange setup
node exchange/manage.js
# Starts orderbook setup
node orderbook/handler.js
Once we have all the grape servers, orderbook and exchange code running, we are in a position to place orders to our exchange using client.
In order to run the client, we can use the following command:
# the numerical value denotes the clientId ( unique identifier )
node client/send_order.js 10
At the point of time, you should ideally see something like this in your console/s:
We have 3 entities as part of our system:
- Client
- Exchange
- Orderbook
These entities have access to certain methods / functions as mentioned below:
-
Client
- send order
- show orders ( specific to client )
-
Exchange
- handle incoming orders
-
Orderbook
- handle incoming orders
- Show complete order history
- updates order book
The current system doesn't handle the condition where a small order is placed first and then a large order. The settlement for the large order can not be done from small order.
I believe I have limited knowledge of the system that I built and there can be a lot more things that we can develop / improve up in the current setup given I get mentorship by peers.
Based on my experience so far, I would like to
- Add methods for testing the code.
- Add setup for creating / adding methods in a modular fashion ( CLI based approach )
If anything more comes in my mind, I will be adding that here.