Skip to content

About

Minimal Order Execution Engine (Backend Task for Eterna Labs)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Minimal Order Execution Engine (Node.js + Express + SQLite + WebSocket)

A compact reference implementation of an order execution engine to satisfy Eterna Labs' backend task.

Features

  • 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

Stack

Node.js, Express, SQLite (sqlite3), ws (WebSocket)

Run locally

npm install
npm run reset   # optional: clears DB
npm start
# visit http://localhost:3000

API

POST /orders

{
  "side": "BUY|SELL",
  "type": "LIMIT|MARKET",
  "price": 100.5,   // required for LIMIT
  "quantity": 1.25
}

Returns the saved order after matching.

DELETE /orders/:id

Cancel an OPEN/PARTIAL order.

GET /orderbook

Returns aggregated bids/asks.

GET /trades

Recent trades (descending).

GET /orders

Debug list of orders.

WebSocket

Connect to ws://host/ws. Events: order, trade, cancel.

Design Decisions

  • 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 BY for simplicity.

Possible Extensions

  • 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

Demo Script (for your video)

  1. Open http://localhost:3000.
  2. Place a SELL LIMIT at price 100 qty 1.
  3. Place a BUY MARKET qty 0.5 (shows a trade).
  4. Show orderbook/ trades updating in real-time.
  5. Cancel a remaining order via DELETE /orders/:id in terminal/curl (optional).

Repository Structure

/src
  server.js      # REST + WebSocket + matching
  init.js        # DB reset
/public
  index.html     # tiny UI for demo
package.json
README.md

Notes

  • This is intentionally lightweight but production-minded.
  • If required, Dockerfile and CI can be added quickly.

About

Minimal Order Execution Engine (Backend Task for Eterna Labs)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages