跳转到内容
去交易

TypeScript SDK

Web 前端使用的 SDK 直接位于 src/sdk/nexus,是对外的标准客户端。处理 session 生命周期、签名衍生、过期自动重连、资产 ID 解析。

import {
SessionClient,
PrivateKeyHashSigner,
InfoClient,
} from './sdk/nexus';
const baseUrl = 'https://api.bitnxs.com';
// 1. 用 API key 构造 signer(在「更多 → API Keys」页面创建)
const signer = new PrivateKeyHashSigner('0x...');
// 2. 把 session 绑到主钱包(与 API key 地址不同)
const session = new SessionClient({
signer,
userAddress: '0xABC...',
baseUrl,
});
// 3. 下单 — 首次调用时自动开 session
await session.order({
asset: 'BTC',
isBuy: true,
limitPx: '65000',
sz: '0.01',
reduceOnly: false,
orderType: { type: 'limit', tif: 'Gtc' },
});
// 4. 公开数据用 InfoClient
const info = new InfoClient({ baseUrl });
const fills = await info.userFills('0xABC...');