HY

Hyperliquid MCP Server for Exchange Data Integration

Integrate Hyperliquid SDK with an MCP server to sync and stream exchange data securely for low-latency trading and analytics.

Overview

This MCP (Model Context Protocol) server bridges the Hyperliquid SDK and downstream consumers to provide synchronized, low-latency exchange data for trading systems and analytics. It connects to Hyperliquid, ingests exchange events (orderbook updates, trades, positions, fills), and republishes them over an MCP-compatible surface so clients can subscribe to consistent streams and snapshots. The server is designed to preserve ordering, optionally persist snapshots for replay, and minimize latency for time-sensitive use cases.

For developers building execution algorithms, monitoring dashboards, or backtesting systems, this server reduces integration complexity: it centralizes exchange connectivity, enforces authentication, and exposes a stable API over WebSocket/HTTP so multiple services can reuse the same live data feed without each implementing Hyperliquid connectivity.

Features

  • Secure integration with Hyperliquid SDK to ingest exchange events
  • MCP-compatible publishing of ordered model-context events (orderbooks, trades, fills, positions)
  • Real-time streaming over WebSocket and a simple HTTP API for snapshots
  • Snapshot & replay support for initial state and resynchronization
  • Built-in authentication and TLS support for secure data delivery
  • Pluggable adapters to add more exchange sources or custom message handlers
  • Lightweight persistence option for short-term replay and analytics

Installation / Configuration

Clone and install dependencies:

git clone https://github.com/mektigboy/server-hyperliquid.git
cd server-hyperliquid
npm install

Environment variables (example .env):

# Hyperliquid credentials
HYPERLIQUID_API_KEY=your_api_key
HYPERLIQUID_API_SECRET=your_api_secret

# Server config
MCP_WS_PORT=8080
MCP_HTTP_PORT=3000
MCP_API_KEY=server_api_key
TLS_CERT=/path/to/cert.pem       # optional
TLS_KEY=/path/to/key.pem         # optional
PERSISTENCE_DIR=/data/snapshots  # optional

Run the server:

# development
npm run dev

# production
node ./dist/index.js

Sample config file (config.json):

{
  "hyperliquid": {
    "apiKey": "your_api_key",
    "apiSecret": "your_api_secret"
  },
  "mcp": {
    "wsPort": 8080,
    "httpPort": 3000,
    "apiKey": "server_api_key"
  },
  "persistence": {
    "snapshotDir": "./snapshots",
    "retainMinutes": 60
  }
}

Available Resources

  • WebSocket streaming endpoint: ws://HOST:8080/mcp (or wss:// when TLS enabled)
  • HTTP snapshot API: GET http://HOST:3000/snapshot/:market (returns current model snapshot)
  • Health & metrics: GET http://HOST:3000/health and GET /metrics (Prometheus-compatible)
  • Authentication: simple API key header x-api-key for HTTP and a connection token parameter for WebSocket

Message channels handled (examples):

ChannelDescriptionExample payload (JSON)
orderbookIncremental orderbook updates{ “side”:“bid”,“price”:123.4,“size”:1 }
tradeExecuted trades{ “price”:123.4,“size”:0.5,“id”:“t1” }
fillOrder fills for accounts{ “orderId”:“o1”,“size”:0.5,“price”:123 }
positionPosition snapshots/updates{ “account”:“A”,“size”:2.0,“pnl”:1.2 }

Example snapshot response (HTTP):

{
  "market": "BTC-USD",
  "orderbook": {
    "bids":[[123.4,1.0],[123.3,2.2]],
    "asks":[[123.8,0.5],[123.9,3.0]],
    "lastUpdateId": 98765
  },
  "lastTrade": {"id":"t1","price":123.4,"size":0.5}
}

Integration Example

Server-side: hook Hyperliquid SDK events and forward to MCP

// pseudocode illustration
const Hyperliquid = require('hyperliquid-sdk')
const MCPServer = require('./mcp-server')

const sdk = new Hyperliquid({ apiKey: process.env.HYPERLIQUID_API_KEY })
const mcp = new MCPServer(config)

sdk.on('orderbookUpdate', (u) => mcp.publish('orderbook', u))
sdk.on('trade', (t) => mcp.publish('trade', t))

sdk.connect()
mcp.start()

Client-side: subscribe to streams via WebSocket

const ws = new WebSocket('wss://HOST:8080/mcp?token=CLIENT_TOKEN')

ws.onmessage = (evt) => {
  const msg = JSON.parse(evt.data)
  if (msg.channel === 'orderbook') handleOrderbook(msg.payload)
  if (msg.channel === 'trade') handleTrade(msg.payload)
}

Use Cases

  • Low-latency trading bot: subscribe to orderbook and trade channels to drive a matching engine or market-making logic with minimal footprint and consistent event ordering.
  • Real-time analytics dashboard: render live orderbook depth, trades, and positions for monitoring traders or compliance screens by fetching snapshots and subscribing for updates.
  • Backtesting and replay: use the persistence/replay feature to feed historical snapshots and event streams into backtest systems to recreate market conditions.
  • Multi-service architecture: share a single, authenticated MCP stream across multiple microservices (execution, risk, analytics) to avoid duplicated connectivity to Hyperliquid and centralize authorization.

Security and Operations

  • Use TLS (wss/https) in production and rotate API keys regularly.
  • Limit access with API keys and consider mutual TLS for stricter client authentication.
  • Monitor latency and packet loss metrics exposed on /metrics; enable persistence to mitigate transient disconnects and allow graceful resyncs for clients.

For developers new to the project, start by running the server locally, connecting the Hyperliquid SDK with test credentials, and subscribing as a client to validate the event shape and latency before deploying to production.