Skip to content

Latest commit

 

History

History
 
 

README.md

@nktkas/hyperliquid

A community-supported Hyperliquid API SDK for all major JS runtimes, written in TypeScript.

Installation

{% tabs %}

{% tab title="npm" %}

npm i @nktkas/hyperliquid

{% endtab %}

{% tab title="pnpm" %}

pnpm add @nktkas/hyperliquid

{% endtab %}

{% tab title="yarn" %}

yarn add @nktkas/hyperliquid

{% endtab %}

{% tab title="bun" %}

bun add @nktkas/hyperliquid

{% endtab %}

{% tab title="deno" %}

deno add jsr:@nktkas/hyperliquid

{% endtab %}

{% tab title="CDN" %}

<script type="module">
  import * as hl from "https://esm.sh/jsr/@nktkas/hyperliquid";
</script>

{% endtab %}

{% endtabs %}

Quick start

{% tabs %}

{% tab title="InfoClient" %}

Read market data, account state, order book. Learn more

import { HttpTransport, InfoClient } from "@nktkas/hyperliquid";

const transport = new HttpTransport();
const client = new InfoClient({ transport });

const mids = await client.allMids();

{% endtab %}

{% tab title="ExchangeClient" %}

Place orders, transfer funds, manage accounts. Learn more

import { ExchangeClient, HttpTransport } from "@nktkas/hyperliquid";
import { privateKeyToAccount } from "viem/accounts";

const wallet = privateKeyToAccount("0x...");

const transport = new HttpTransport();
const client = new ExchangeClient({ transport, wallet });

await client.order({
  orders: [{
    a: 0,
    b: true,
    p: "50000",
    s: "0.01",
    r: false,
    t: { limit: { tif: "Gtc" } },
  }],
  grouping: "na",
});

{% endtab %}

{% tab title="SubscriptionClient" %}

Receive real-time updates via WebSocket. Learn more

import { SubscriptionClient, WebSocketTransport } from "@nktkas/hyperliquid";

const transport = new WebSocketTransport();
const client = new SubscriptionClient({ transport });

await client.allMids((data) => {
  console.log(data.mids);
});

{% endtab %}

{% endtabs %}