Spring Boot + PostgreSQL backend for idempotent order submission, cancellation, and simulated executions.
This service manages the lifecycle of equity orders and executions, including idempotent order creation using the Idempotency-Key header, cancellation, and query endpoints. A scheduled simulated fill engine generates full and partial fills using deterministic stub prices and marketable limit-order checks. Orders and executions are persisted in PostgreSQL with Flyway migrations, and basic metrics/logging are exposed via Micrometer and Actuator.
- Spring Boot REST API
- JPA/Hibernate for persistence
- Flyway migrations on startup
- PostgreSQL database
- Scheduled simulated fill engine with deterministic stub prices, marketable limit checks, and full/partial fills
- Domain events published after transaction commit
- Structured lifecycle logs and Micrometer counters
POST /orders- Optional header:
Idempotency-Key - Body:
symbol,side,quantity,price(limit),orderType
- Optional header:
GET /orders/{id}GET /orders?symbol=&status=POST /orders/{id}/cancel
Make sure Docker Desktop (or another Docker daemon) is running before you execute these commands.
- Start Postgres (example using Docker Compose):
docker compose up -d postgres
- Run the API:
./mvnw spring-boot:run
Defaults are configured in src/main/resources/application.yml:
- DB host:
localhost - DB port:
5432 - DB name:
ordertrade - DB user:
ordertrade - DB pass:
ordertrade
Override using environment variables: DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS.
Make sure Docker Desktop (or another Docker daemon) is running before you execute these commands.
docker compose up --buildPorts:
- API:
http://localhost:8080 - Postgres:
localhost:5432
Stop:
docker compose down -v./mvnw verifyThis runs unit tests and Testcontainers-based integration tests.
PowerShell demo script:
.\scripts\demo.ps1Manual curl examples:
# Create
curl -s -X POST http://localhost:8080/orders \
-H "Content-Type: application/json" \
-d '{"symbol":"AAPL","side":"BUY","quantity":10,"price":100.5,"orderType":"LIMIT"}'
# Idempotent create
curl -s -X POST http://localhost:8080/orders \
-H "Content-Type: application/json" \
-H "Idempotency-Key: demo-123" \
-d '{"symbol":"AAPL","side":"BUY","quantity":10,"price":100.5,"orderType":"LIMIT"}'
# Get
curl -s http://localhost:8080/orders/<id>
# Cancel
curl -s -X POST http://localhost:8080/orders/<id>/cancelPowerShell-safe examples:
# Create
@'
{"symbol":"AAPL","side":"BUY","quantity":10,"price":100.5,"orderType":"LIMIT"}
'@ | curl.exe -s -X POST "http://localhost:8080/orders" -H "Content-Type: application/json" --data-binary "@-"
# Idempotent create
@'
{"symbol":"AAPL","side":"BUY","quantity":10,"price":100.5,"orderType":"LIMIT"}
'@ | curl.exe -s -X POST "http://localhost:8080/orders" -H "Content-Type: application/json" -H "Idempotency-Key: demo-123" --data-binary "@-"
# Get
curl.exe -s "http://localhost:8080/orders/<id>"
# Cancel
curl.exe -s -X POST "http://localhost:8080/orders/<id>/cancel"Note: the simulator can fill orders quickly; cancel immediately after create or set simulator.enabled: false for deterministic cancels.
Actuator endpoints (local):
GET /actuator/healthGET /actuator/metricsGET /actuator/prometheus
Custom counters:
orders.acceptedorders.rejectedwith tagreason=validation|idempotencyorders.canceledorders.fills.createdwith tagtype=partial|full
- Add authentication and authorization
- Add pagination and filtering improvements to order queries
- Add OpenAPI documentation
- Add retry/backoff for external dependencies (if added later)
- Improve Docker image build caching and size