> For the complete documentation index, see [llms.txt](https://docs.hypertracker.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hypertracker.io/websocket-streams/connecting-with-the-sdk.md). Agents can also search and read this documentation through its [MCP server](https://docs.hypertracker.io/~gitbook/mcp).

# Connecting with the SDK

## Connecting with the SDK

The SDK maintains connections, answers pings, reconnects, and replays missed data. Use it for most applications.

* JavaScript and TypeScript: [`centrifuge-js`](https://github.com/centrifugal/centrifuge-js)
* Async Python: [`centrifuge-python`](https://github.com/centrifugal/centrifuge-python)

### JavaScript

```bash
npm install centrifuge
npm install eventsource ws
```

```js
import { Centrifuge } from 'centrifuge';

const client = new Centrifuge('wss://jp-ws.hypertracker.io/connection/websocket', {
  websocket: globalThis.WebSocket,
  data: { token: API_KEY },
});
client.on('connected', (ctx) => console.log('connected:', ctx.client));
client.on('disconnected', (ctx) => console.error(ctx.code, ctx.reason));
client.on('error', (ctx) => console.error(ctx.error?.message ?? ctx.error));

const sub = client.newSubscription('rooms:fills');
sub.on('subscribed', (ctx) => console.log(ctx.streamPosition, ctx.recovered));
sub.on('publication', (ctx) => console.log(ctx.offset, ctx.data));
sub.on('error', (ctx) => console.error(ctx.error?.message ?? ctx.error));
sub.subscribe();
client.connect();
```

Use `tagsFilter` for `rooms:*` filters and `since` for saved recovery positions:

```js
client.newSubscription('rooms:fills', {
  tagsFilter: { op: '', key: 'coin', cmp: 'eq', val: 'HYPE' },
  since: { epoch: '<epoch>', offset: 12345 },
});
client.newSubscription('orders:feed', {
  data: { filter: { op: '', key: 'address', cmp: 'eq', val: '0x…' } },
});
```

### SSE

Configure both transports. The SDK uses WebSocket when available.

```js
const client = new Centrifuge([
  { transport: 'websocket', endpoint: 'wss://jp-ws.hypertracker.io/connection/websocket' },
  { transport: 'sse', endpoint: 'https://jp-ws.hypertracker.io/connection/sse' },
], {
  data: { token: API_KEY },
  eventsource: EventSource,
  emulationEndpoint: 'https://jp-ws.hypertracker.io/emulation',
});
```

In Node, `emulationEndpoint` must be absolute.

### Python

```bash
pip install centrifuge-python
```

```python
import asyncio, os
from centrifuge import Client, ClientEventHandler, SubscriptionEventHandler

class ClientHandler(ClientEventHandler):
    async def on_connected(self, ctx): print('connected:', ctx.client)
class SubHandler(SubscriptionEventHandler):
    async def on_publication(self, ctx): print(ctx.pub.offset, ctx.pub.data)

async def main():
    client = Client('wss://jp-ws.hypertracker.io/connection/websocket',
        events=ClientHandler(), data={'token': os.environ['API_KEY']})
    sub = client.new_subscription('rooms:fills', events=SubHandler())
    await client.connect(); await sub.subscribe(); await asyncio.Event().wait()
asyncio.run(main())
```

Python supports `data`, so `orders:feed` filters work. Some versions do not expose `tf` or `since`. Use a plain WebSocket for `rooms:*` filters or replay. Always pass the key as `data={"token": API_KEY}`.

| Scenario                                  | Recommended option  |
| ----------------------------------------- | ------------------- |
| JavaScript or browser                     | `centrifuge-js`     |
| Python basic use or `orders:feed` filters | `centrifuge-python` |
| Python `rooms:*` filters or replay        | Plain WebSocket     |
| No SDK                                    | Plain WebSocket     |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hypertracker.io/websocket-streams/connecting-with-the-sdk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
