Orderbook Service
Overview
The Orderbook service is a Node.js-based application that manages and maintains the order book system for options and perpetual futures trading. It provides comprehensive order management, matching engine functionality, and RFQ (Request for Quote) capabilities through a TypeScript implementation.
Quick Start
Prerequisites
- Node.js LTS
- Docker and Docker Compose
- NX CLI (
yarn nx
)
Setup & Running
-
Create and populate
.env
file using the template in .env.example -
Build the service:
- Start with Docker Compose:
- Stop and cleanup:
Development
Run tests:
# Unit tests
nx run orderbook:test
# Integration tests (requires .env file in tests/it/)
nx run orderbook:it
Technical Specifications
Core Technology Stack
- Runtime: Node.js LTS
- Language: TypeScript 4.x
- Build System: NX with ESBuild
- Service Type: Application Service
- Version: 0.0.1
Key Dependencies
-
Core:
-
ESBuild for TypeScript compilation
- FastAPI for API endpoints
- Redis for order storage and pub/sub
-
BigQuery for trade history
-
Testing:
-
Jest
- Supertest
-
Redis Mock
-
Development:
- ESLint
- NX Monorepo Tools
- TypeScript with strict mode
Service Architecture
Core Components
-
API Layer (app.ts)
-
RESTful endpoints
- Request validation
- Response handling
-
Error management
-
Order Management
-
Limit order handling
- Market order processing
- RFQ system
-
Order cancellation
-
Matching Engine
-
Order book maintenance
- Price-time priority matching
- Fill or Kill (FOK) orders
-
Immediate or Cancel (IOC) orders
-
Database Layer (db/)
-
Redis integration for order books
- BigQuery for trade history
- Data persistence strategies
-
Caching mechanisms
-
Types & Validation (types/, validators/)
-
Type definitions
- Input validation
- Schema enforcement
-
Signature verification
-
Utilities (utils/)
- Order processing helpers
- Signature validation
- Mathematical calculations
- Shared functionality
API Endpoints
Order Management
POST /limit
- Place limit ordersPOST /market
- Execute market ordersDELETE /orders
- Cancel specific ordersDELETE /orders_all
- Cancel all ordersGET /orders
- Query orders by maker
Market Data
GET /order_book
- Get orderbook stateGET /last_trades_by_instrument
- Get trade history
RFQ System
POST /rfq/request
- Submit RFQPOST /rfq/response
- Respond to RFQGET /rfq/request
- Get RFQ requestsGET /rfq/response
- Get RFQ responsesPOST /rfq/fill
- Execute RFQ trade
Infrastructure
Deployment
- Containerized deployment (Dockerfile provided)
- Redis requirement for order storage
- BigQuery integration for trade history
- Environment-based configuration
Build Configuration
- Development and production builds
- Source map support
- TypeScript strict mode
- ESLint integration
Testing Infrastructure
Unit Testing
- Jest framework
- Mocked dependencies
- Comprehensive test coverage
- Automated via CI/CD
Integration Testing
- End-to-end API testing
- Redis integration tests
- Sequenced test execution
- Environment-specific configurations
Development Tools
- ESLint configuration
- TypeScript strict mode
- Automated testing
- Hot reloading
Configuration
Environment Variables
Required variables:
ORDERBOOK_PORT=4000
REDIS_HOST=localhost
REDIS_PORT=6379
ORDERBOOK_SALT=your_salt
PROJECT_ID=your_gcp_project
SEQUENCER_API_URL=http://localhost:3000
PREMIA_API_KEY=your_api_key
ENV=local|dev|prod
Monitoring & Health
Endpoints
/healthcheck
- Service health check- Metrics endpoint (TODO)
Logging
- Structured JSON logging
- Error tracking
- Request tracing
- Performance monitoring
Contributing
- Fork the repository
- Create your feature branch
- Run tests before committing
- Submit pull request
License
Proprietary - All rights reserved
This documentation is generated from the service README. For the most up-to-date information, refer to the original README