---
title: "Discussion on \"Hyperliquid API guide: WebSocket feeds and order management\" | Hashnode"
description: "Discussion on \"Hyperliquid API guide: WebSocket feeds and order management\". Navigating the world of decentralized exchanges (DEXs) can be daunting, especially when trying to automate your trading strategies. Hyperliquid, a DEX focused on perpetual futures, offers a WebSocket API that provides real-time market data—a crucial ..."
url: "https://hashnode.com/posts/hyperliquid-api-guide-websocket-feeds-and-order-management/69ddc8588a2aa55360411862"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Hyperliquid API guide: WebSocket feeds and order management](https://python-bots.hashnode.dev/hyperliquid-api-guide-websocket-feeds-and-order-management?utm_source=hashnode&utm_medium=feed)

Navigating the world of decentralized exchanges (DEXs) can be daunting, especially when trying to automate your trading strategies. Hyperliquid, a DEX focused on perpetual futures, offers a WebSocket API that provides real-time market data—a crucial ...

Apr 14 · 3 min read · python-bots.hashnode.dev  
Read the article

-   [#crypto](https://hashnode.com/tag/crypto)
-   [#python](https://hashnode.com/tag/python)
-   [#trading](https://hashnode.com/tag/trading)

## Written by

[Lucas Gragg](https://hashnode.com/@dopienerd)

@dopienerd · Maine, USA

  
[View profile](https://hashnode.com/@dopienerd)

Creator of botfarm - autonomous trading bots & Python automation tools

I build and operate a fleet of 7 self-improving Python bots that trade crypto derivatives, scan freelance markets, and generate digital products automatically. Writing about trading bot architecture, web scraping, API integrations, and autonomous agents. All source code available at payhip.com/botfarm.

## Responses 1

Markdown supported · ⌘↵ to post

[Siebly](https://hashnode.com/@siebly)

[18h ago](https://hashnode.com/posts/hyperliquid-api-guide-websocket-feeds-and-order-management/69ddc8588a2aa55360411862/comment/6b1232cc7a7e0e1f353693cd)

Thanks for putting this together, Lucas. A quick note for readers who try the snippets: Hyperliquid's API is served from api.hyperliquid.xyz (api.hyperliquid.com has no DNS record), and subscriptions use a "method"/"subscription" message. This version of the WebSocket part streams live BTC trades (I ran it this morning):

```python
import json, threading, websocket

def on_message(ws, message):
    data = json.loads(message)
    if data.get("channel") == "trades":
        for t in data["data"]:
            print(t["coin"], t["side"], t["px"], t["sz"])

def on_open(ws):
    ws.send(json.dumps({
        "method": "subscribe",
        "subscription": {"type": "trades", "coin": "BTC"}
    }))

ws = websocket.WebSocketApp("wss://api.hyperliquid.xyz/ws",
                            on_open=on_open, on_message=on_message)
threading.Timer(10, ws.close).start()
ws.run_forever(ping_interval=50, ping_payload='{"method":"ping"}')
```

Orders work a little differently from exchanges with key and secret headers: Hyperliquid has no API key. You approve an API wallet on the API page of the app, and each order is signed by that wallet and posted to the /exchange endpoint on api.hyperliquid.xyz. The Signing page in the Hyperliquid docs covers the details.

For anyone building in Node.js, our open-source Hyperliquid SDK handles the signing, heartbeats and reconnects. The same trade stream there:

```js
import { WebsocketClient } from '@siebly/hyperliquid-api';

const ws = new WebsocketClient({ connectionTimeout: 5_000 });
ws.on('message', (e) => {
  if (e.channel === 'trades') {
    for (const t of e.data) console.log(t.coin, t.side, t.px, t.sz);
  }
});
await ws.subscribe({ type: 'trades', coin: 'BTC' });
```

More examples are in the Siebly Hyperliquid SDK docs on siebly.io.

Daisy, Siebly
