快速打字符
超液态 SDK
特征
- 类型:源代码为100% TypeScript.
- 已测试:良好的代码覆盖范围和类型相关性.
- 最小依赖性:几个小的可信赖的依赖关系.
- 跨环境支助: 与所有主要JS运行时间相兼容.
- 难分: 易于使用 维姆 当地(私人钥匙)或JSON-RPC (浏览器钱包).
文档
浏览 SDK 文档 安装、客户、运输、签署、, 公用事业和导游.
文档使用 福马多克 并在 GitHub Pages 上托管。 它的Markdown源 生活在
apps/docs/content/docs/ 输入 仓库。 。 。 .
安装
1.3.3+号舱
bun add @bloxwap/hyperliquid
节点.js 22.12+ / 反应土著 0.86+
npm i @bloxwap/hyperliquid
小时
pnpm add @bloxwap/hyperliquid
雅伦
yarn add @bloxwap/hyperliquid
本地反应需要多填充器
fastAssetCtxs订阅和低于0.86的版本——见 文档。 。 。 .
快速示例
读取
// 1. Import module
import { HttpTransport, InfoClient } from "@bloxwap/hyperliquid";
// 2. Set up client with transport
const transport = new HttpTransport();
const info = new InfoClient({ transport });
// 3. Query data
// Retrieve mids for all coins
const mids = await info.allMids();
// Retrieve a user's open orders
const openOrders = await info.openOrders({ user: "0x..." });
// L2 book snapshot
const book = await info.l2Book({ coin: "BTC" });
贸易
// 1. Import modules
import { ExchangeClient, HttpTransport } from "@bloxwap/hyperliquid";
import { privateKeyToAccount } from "viem/accounts";
// 2. Set up client with wallet and transport
const wallet = privateKeyToAccount("0x...");
const transport = new HttpTransport();
const exchange = new ExchangeClient({ transport, wallet });
// 3. Execute an action
// Place an order
const result = await exchange.order({
orders: [{
a: 0,
b: true,
p: "95000",
s: "0.01",
r: false,
t: { limit: { tif: "Gtc" } },
}],
grouping: "na",
});
// Update leverage
await exchange.updateLeverage({ asset: 0, isCross: true, leverage: 5 });
// Initiate a withdrawal request
await exchange.withdraw3({ destination: "0x...", amount: "1" });
对于低纬度接点,将原始的私钥串传递为 wallet: 然后客户端用 WASM secp256k1 签名 :
默认,带有一个纯-JS倒置, WASM 无法装入(在节点24上每顺序为~274至~104 μs,~155至~102 μs)
(bun 1.4) (中文(简体) ). 安装可选选项 hash-wasm 用于环境keccak加速的软件包。 信得过的人也可以通过
{ skipValidation: true }见
低纬度配方。 。 。 .
订阅
// 1. Import module
import { SubscriptionClient, WebSocketTransport } from "@bloxwap/hyperliquid";
// 2. Set up client with transport
const transport = new WebSocketTransport();
const subs = new SubscriptionClient({ transport });
// 3. Subscribe to events
// Subscribe to mids for all coins
await subs.allMids((data) => {
console.log(data);
});
// Subscribe to user's open orders
await subs.openOrders({ user: "0x..." }, (data) => {
console.log(data);
});
// Subscribe to L2 book snapshot
await subs.l2Book({ coin: "ETH" }, (data) => {
console.log(data);
});
[尖叫声]
- 从不硬码私钥 或将他们投入其中。 从环境变量或秘密中装入 存储( Bun 自动装入本地
.env,它在这个repo中被赋予了".- 对于交易的bots,更喜欢超液态 代理钱包 (API 钱包) 覆盖主账户密钥: 代理密钥可以 贸易但不能退出,并且可以不旋转主密钥而取消.
- 见 签名 用于钱包、签名和非纸币的操作.