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.
Requirement:
- Use Grenache for communication between nodes
- Simple order matching engine
- You don't need to create a UI or HTTP API
npm i -g grenache-grape
# boot two grape servers
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
npm install --save grenache-nodejs-http
npm install --save grenache-nodejs-link
git clone https://github.com/simonmullaney/SimplifiedDistributedExchange.git
npm i -g grenache-grape
# boot two grape servers
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
git clone https://github.com/simonmullaney/SimplifiedDistributedExchange.git
Change directory into rpcSever
and run:
npm i
node server.js
Change directory into client1
and client2
respectively and run:
npm i
node client.js
As each client is started they will automatically send preconfigured trades to the RPC server.
You can change the payload of the respective clients to send different messages to the RPC server:
const payload = {id:"client1",trade: "Buy", pair: "tBTCUSD", amount: 1.0860}
Re-run the client with the new payload to send your new message to the RPC server.
- Not properly tested, no test suite to guarantee required functionality
- Race conditions need some more thought and need tests written to ensure correct functionality