gRPC streaming examples for Hyperliquid with zstd compression support.
- JavaScript - Node.js with
@grpc/grpc-js - Python -
grpciowithzstandard - Go -
google.golang.org/grpcwithklauspost/compress - Rust -
tonicwithzstd
The raw stream proto definition is in proto/hyperliquid.proto.
The dedicated orderbook streaming proto definition is in proto/orderbook.proto. See Orderbook Streaming for runnable examples using your QuickNode endpoint.
Both mainnet and testnet are supported. Set your GRPC_ENDPOINT accordingly:
| Network | Endpoint Format |
|---|---|
| Mainnet | your-endpoint.hype-mainnet.quiknode.pro:10000 |
| Testnet | your-endpoint.hype-testnet.quiknode.pro:10000 |
All stream types are available on both networks, except MEMPOOL_TXS which is testnet-only.
| Type | Description | Networks |
|---|---|---|
TRADES |
Trade executions | Mainnet, Testnet |
ORDERS |
Order updates | Mainnet, Testnet |
EVENTS |
General events | Mainnet, Testnet |
BOOK_UPDATES |
Order book changes | Mainnet, Testnet |
TWAP |
TWAP orders | Mainnet, Testnet |
BLOCKS |
Raw blocks | Mainnet, Testnet |
WRITER_ACTIONS |
Writer actions | Mainnet, Testnet |
MEMPOOL_TXS |
Testnet mempool transactions, including priority order submissions | Testnet only |
The hyperliquid.OrderBookStreaming service exposes full-book streams plus lower-bandwidth derived streams:
| Method | Description |
|---|---|
StreamL2Book |
Existing full aggregated L2 snapshots for one coin |
StreamL4Book |
Existing full L4 snapshot for one coin, then raw JSON diffs |
StreamBboBook |
New best bid/offer updates for one or more coins |
StreamL2BookDiff |
New incremental L2 price-level changes |
StreamL4BookUpdates |
New typed L4 order-level changes |
StreamTpslUpdates |
New typed TP/SL trigger-order lifecycle changes |
Run BBO with your hosted QuickNode endpoint:
cd javascript/orderbookStreamExample
npm install
export GRPC_ENDPOINT="your-endpoint.hype-mainnet.quiknode.pro:10000"
export AUTH_TOKEN="YOUR_QUICKNODE_TOKEN"
node orderbook_stream_example.js --mode=bbo --coin=BTC --max-messages=5Priority transactions can be observed on the testnet-only MEMPOOL_TXS stream. Each priority example starts a gRPC watcher against your QuickNode testnet endpoint and prints mempool payloads that contain priority grouping.
cd python/priorityOrderExample
pip install -r requirements.txt
python -m grpc_tools.protoc -I../../proto --python_out=. --grpc_python_out=. ../../proto/hyperliquid.proto
export GRPC_ENDPOINT="your-endpoint.hype-testnet.quiknode.pro:10000"
export AUTH_TOKEN="YOUR_QUICKNODE_TOKEN"
python watch_priority_mempool.py --max-messages 5Priority examples are available in:
javascript/priorityOrderExample/python/priorityOrderExample/golang/priorityOrderExample/rust/src/priorityOrderExample/
Each language includes a dedicated filter_example file demonstrating server-side filtering.
# JavaScript
node filter_example.js
# Python
python filter_example.py
# Go
go run filter_example.go
# Rust
cargo run --bin filter_exampleFilters are applied server-side via the filters field in the subscription request:
// JavaScript example
call.write({
subscribe: {
stream_type: 'TRADES',
filters: {
coin: { values: ['ETH', 'BTC'] },
user: { values: ['0x123...'] }
},
filter_name: 'my-filter'
}
});The main examples also support filtering via command line:
# JavaScript
node index.js TRADES --filter coin=ETH,BTC --filter user=0x123
# Python
python main.py TRADES --filter coin=ETH,BTC
# Go
go run main.go -stream TRADES -filter "coin=ETH,BTC;user=0x123"
# Rust
cargo run --bin main -- -s TRADES -f coin=ETH,BTC -f user=0x123cd javascript
npm install
# Edit index.js to set GRPC_ENDPOINT and AUTH_TOKEN
node index.js TRADEScd python
pip install -r requirements.txt
./generate_proto.sh
# Edit main.py to set GRPC_ENDPOINT and AUTH_TOKEN
python main.py TRADEScd golang
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
./generate_proto.sh
go mod tidy
# Edit main.go to set grpcEndpoint and authToken
go run main.go -stream TRADEScd rust
# Edit src/main.rs to set GRPC_ENDPOINT and AUTH_TOKEN
cargo run -- -s TRADESEach example requires:
- GRPC_ENDPOINT - Your QuickNode endpoint (e.g.,
your-endpoint.hype-mainnet.quiknode.pro:10000oryour-endpoint.hype-testnet.quiknode.pro:10000) - AUTH_TOKEN - Your authentication token
- Port:
10000(gRPC streaming port) - TLS: Required - all connections must use TLS/SSL
- Authentication: Pass your token via the
x-tokenmetadata header
All examples automatically detect and decompress zstd-compressed data by checking for the magic number 0x28 0xB5 0x2F 0xFD.
gRPC streams are long-lived connections that can disconnect due to network issues, server restarts, or idle timeouts. Production systems should implement proper connection management.
The server expects periodic pings to keep the connection alive. The examples send pings every 30 seconds:
// JavaScript
setInterval(() => {
call.write({ ping: { timestamp: Date.now() } });
}, 30000);# Python
yield pb.SubscribeRequest(ping=pb.Ping(timestamp=int(time.time() * 1000)))The server responds with a pong message. If you stop receiving pongs, the connection may be dead.
When a disconnect occurs, implement exponential backoff:
Attempt 1: Wait 1s
Attempt 2: Wait 2s
Attempt 3: Wait 4s
Attempt 4: Wait 8s
...
Max backoff: 60s
When your connection drops, you'll miss blocks. On reconnect:
- Track the last
block_numberyou received - Reconnect with
start_blockset to resume from where you left off - For the
BLOCKSstream specifically, historical data isn't available via gRPC - see thereplicaCmdsOnS3Examplefor backfilling from the Hyperliquid Foundation S3 bucket
1. Connect to gRPC stream
2. Subscribe with start_block=0 (or last known block)
3. Process incoming data, track last block_number
4. Send pings every 30s
5. On disconnect:
- Log last block_number received
- Wait with exponential backoff
- Reconnect and subscribe with start_block=last_block_number
6. Repeat
Note: These examples are starting points. Production systems should add error handling, metrics, circuit breakers, and dead letter queues based on your reliability requirements.