MM Worker API

Market Making Orders Management with Historical Data Storage

Overview

Purpose

Manages market making orders with real-time caching, R2 storage, and historical data archiving for market analysis.

Features

Order management, real-time caching, historical data storage, and API key authentication.

Storage

Cloudflare R2 for persistent storage and historical data archiving with daily partitioning.

Cache

In-memory caching with automatic expiry based on order timestamps and batch overlap.

API Endpoints

GET / Get current market making orders
Response
{ "data": { "timestamp": 1704067200000, "market_data": { "ETH": { "price": 2500.00, "volatility": 0.45 } }, "orders": [ { "order": { "instrument_name": "ETH-2500C-20240115", "side": "buy", "amount": 1, "price": 0.05, "orderExpiryTimestamp": 1704067200 } } ] }, "metadata": { "last_updated": 1704067200000, "current_time": 1704067200000 } }
200 OK 500 Internal Error
POST / Update market making orders (requires API key)
Headers
Parameter Type Required Description
Authorization string Required Bearer token: "Bearer {API_KEY}"
Content-Type string Required application/json
Request Body
{ "timestamp": 1704067200000, "market_data": { "ETH": { "price": 2500.00, "volatility": 0.45 } }, "orders": [ { "order": { "instrument_name": "ETH-2500C-20240115", "side": "buy", "amount": 1, "price": 0.05, "orderExpiryTimestamp": 1704067200 } } ] }
Response
{ "message": "Orders updated successfully", "metadata": { "last_updated": 1704067200000, "orders_count": 1 } }
200 OK 400 Bad Request 401 Unauthorized 500 Internal Error
GET /history/list List available historical data files (requires API key)
Headers
Parameter Type Required Description
Authorization string Required Bearer token: "Bearer {API_KEY}"
Response
{ "files": [ "day_20240101.jsonl.gz", "day_20240102.jsonl.gz", "day_20240103.jsonl.gz" ], "last_updated": 1704067200000 }
200 OK 401 Unauthorized 500 Internal Error
GET /history/download/{filename} Download specific historical data file (requires API key)
Path Parameters
Parameter Type Required Description
filename string Required Historical data filename (e.g., "day_20240101.jsonl.gz")
Headers
Parameter Type Required Description
Authorization string Required Bearer token: "Bearer {API_KEY}"
Response

Returns a gzipped JSONL file containing historical order data for the specified day.

200 OK 401 Unauthorized 404 Not Found 500 Internal Error

CORS Configuration

The following origins are whitelisted for CORS access:

Data Storage

Current Orders

Stored in Cloudflare R2 as orders.json with timestamp.txt for metadata

Historical Data

Daily partitioned gzipped JSONL files in historic_orders/ directory

Cache Strategy

In-memory cache with expiry based on orderExpiryTimestamp minus 60 second overlap

File Format

Historical files contain timestamp, market_data, and orders arrays in JSONL format