Go - Between
A distributed fault-tolerant order book matching engine.
Features
- Limit orders
- Market orders
- Order book depth
- Calculate market price for a given quantity
- Standard price/time priority
- Distributed and fault-tolerant based on Raft Consensus Algorithm
Download binaries
You can download a pre-built binary here.
Build from source
First, install Go.
Next, fetch and build the binary.
go get -u github.com/danielgatis/go-between
How to init a cluster
First of all, start a new cluster:
go-between start --id=1 --market=USD/BTC --port=3001
And add a two more nodes:
go-between start --id=2 --market=USD/BTC --port=3002 --join=localhost:3001
go-between start --id=3 --market=USD/BTC --port=3003 --join=localhost:3001
API Endpoints
Each node publishes a REST API with the following endpoints.
Adding a new limit order
curl --request POST \
--url http://127.0.0.1:3001/orders/limit \
--header 'Content-Type: application/json' \
--data '{
"orderId": "1",
"traderId": "1",
"market": "USD/BTC",
"side": "sell",
"quantity": "1",
"price": "400.00"
}'
Adding a new market order
curl --request POST \
--url http://127.0.0.1:3001/orders/market \
--header 'Content-Type: application/json' \
--data '{
"orderId": "2",
"traderId": "1",
"market": "USD/BTC",
"side": "sell",
"quantity": "1",
"price": "400.00"
}'
Cancel an order
curl --request DELETE --url http://127.0.0.1:3001/orders/1
Calculate a market price
curl --request POST \
--url http://127.0.0.1:3001/prices/market \
--header 'Content-Type: application/json' \
--data '{
"traderId": "1",
"market": "USD/BTC",
"side": "sell",
"quantity": "10"
}'
Get the order book price depth
curl --request GET --url http://127.0.0.1:3001/prices/depth
Get the full order book
curl --request GET --url http://127.0.0.1:3001/orderbook
Get the raft node stats
curl --request GET --url http://127.0.0.1:3001/raft/stats
License
Copyright (c) 2021-present Daniel Gatis
Licensed under MIT License
Buy me a coffee
Liked some of my work? Buy me a coffee (or more likely a beer)