This repo is a HTTP wrapper around an open source orderbook engine with some modifications to allow creating new order books for different assets.
Can be run locally with go run main.go. Connect to http://localhost:5341.
With docker:
docker run -p 80:5341 orderbook-server
There is a docker compose file included also. This allows you to have two containers running orderbooks so you can have separate ones for different environments, running on port 80 and 8080. The Dockerfile is stored on my private registry but it should be moved to a Dyon owned one moving forward.
Orders are represented in the orderbook with the following JSON schema. Any endpoints returning order details will be in the following format.
{
side: "ASK" | "BID",
id: string,
timestamp: Date,
quantity: decimal,
price: decimal
}/addAsset creates a new orderbook for an asset if it doesn't already exist.
Request:
{
"Asset": string
}Response: 200 if success.
/addLimitOrder adds a new limit order to the book
Request:
{
Asset: string,
Side: "ASK" | "BID",
OrderId: string, // unique id that identifies order in exchange database. Use whatever you want for this as long as its unique for each order. UUID is fine.
Quantity: decimal,
Price: decimal
}Response:
{
Done: []Order, // any orders that were filled. This will include your order if it was filled.
Partial: Order, // any order that was partially filled. This will be your order if it was partially filled,
PartialQuantityProcessed: decimal // the amount in the partial order that was filled
}/addMarketOrderadds a new market order to the orderbook
Request:
{
Asset: string,
Side: "ASK"|"BID",
OrderId: string,
Quantity: decimal,
Price: decimal
}Response:
{
Done: []Order,
Partial: Order,
PartialQuantityProcessed: decimal,
QuantityLeft: decimal // the the remainder from your market order that wasn't filled
}/cancelOrder removes an order from the orderbook.
Request:
{
"OrderId": string,
"Asset": string
}Response:
{
Order: Order // order that was canceled
}/calculateMarketPrice calculates the market price for a buy or sell of specified quantity of an asset.
Request:
{
"Asset": string,
"Side": "ASK" | "BID",
"Quantity": decimal
}Response:
{
Price: decimal
}/healthCheck confirms the service is alive. In future this should ping the external datastore of the orderbook.
Response:
{
"alive": true
}/getOrdersreturns all the orderbooks on the server. Will just dump out the entire state of the orderbook so it will be complicated to make sense of it. Useful for debugging with a CTRL-F of a particular orderId.
/resetresets the orderbook and deletes all orders. Useful for development and testing.