A compact reference implementation of an order execution engine to satisfy Eterna Labs' backend task.
- Place LIMIT and MARKET BUY/SELL orders
- Price–time priority matching
- Generate trades and update order statuses (OPEN, PARTIAL, FILLED, CANCELED)
- Orderbook snapshot (top 50 bids/asks aggregated by price)
- WebSocket broadcast for real-time trades/orderbook updates
- SQLite persistent storage (no external DB needed)
- Simple demo UI at
/for your 1–2 min video
Node.js, Express, SQLite (sqlite3), ws (WebSocket)
npm install
npm run reset # optional: clears DB
npm start
# visit http://localhost:3000{
"side": "BUY|SELL",
"type": "LIMIT|MARKET",
"price": 100.5, // required for LIMIT
"quantity": 1.25
}Returns the saved order after matching.
Cancel an OPEN/PARTIAL order.
Returns aggregated bids/asks.
Recent trades (descending).
Debug list of orders.
Connect to ws://host/ws. Events: order, trade, cancel.
- SQLite keeps setup zero-friction and deterministic for reviewers.
- Matching is executed synchronously after order insert to keep logic simple.
- Price–time priority implemented by SQL ordering and FIFO within price.
- MARKET orders cross the book at counterparty price (common behavior).
- Aggregated orderbook computed by SQL
GROUP BYfor simplicity.
- User accounts + auth, symbols/multi-markets
- Fees, tick sizes, iceberg orders, stop orders
- Persistence with Postgres, Redis cache for book, snapshot APIs
- Resilient matching loop + queue (Kafka/SQS) for higher throughput
- Open
http://localhost:3000. - Place a SELL LIMIT at price
100qty1. - Place a BUY MARKET qty
0.5(shows a trade). - Show orderbook/ trades updating in real-time.
- Cancel a remaining order via
DELETE /orders/:idin terminal/curl (optional).
/src
server.js # REST + WebSocket + matching
init.js # DB reset
/public
index.html # tiny UI for demo
package.json
README.md
- This is intentionally lightweight but production-minded.
- If required, Dockerfile and CI can be added quickly.