Skip to main content

Overview

@n1xyz/nord-ts is the TypeScript client for Nord. It handles action signing, decimal scaling, nonce management, and WebSocket subscriptions, and exposes typed wrappers over the REST API.

Install

npm install @n1xyz/nord-ts @solana/web3.js
# or: yarn add @n1xyz/nord-ts @solana/web3.js
# or: bun add @n1xyz/nord-ts @solana/web3.js

Create a client

import { Connection } from "@solana/web3.js";
import { Nord } from "@n1xyz/nord-ts";

const nord = await Nord.new({
webServerUrl: "https://api-mainnet.n1.xyz",
app: process.env.APP_ADDRESS!,
solanaConnection: new Connection("https://api.mainnet-beta.solana.com"),
});
OptionRequiredPurpose
webServerUrlyesNord API base URL for the target network
appyesApp address you trade against
solanaConnectionyesSolana RPC connection, used for deposits
protonUrlnoProton URL; defaults to webServerUrl

Nord.new fetches /info, so after it resolves the client already knows the deployment's markets and tokens:

nord.markets; // marketId, symbol, priceDecimals, sizeDecimals, mode, ...
nord.tokens; // tokenId, symbol, decimals, mintAddr, ...

Because the client holds these decimals, SDK methods take ordinary decimal prices, sizes, and amounts and scale them to wire integers for you.

note

Nord.initNord is a deprecated alias of Nord.new, and the initWebSockets config flag is deprecated. New code should use Nord.new and create subscriptions explicitly.

Two objects

  • Nord — connection and read paths: exchange configuration, market data, account queries, WebSocket subscriptions. No key material.
  • NordUser — a wallet, its accounts, and its session; everything that submits a signed action.
import { NordUser } from "@n1xyz/nord-ts";

const user = NordUser.fromPrivateKey(nord, process.env.PRIVATE_KEY!);
await user.updateAccountId();
await user.fetchInfo();
await user.refreshSession();

After fetchInfo, user.balances, user.positions, user.orders, and user.margins are populated, each keyed by account ID:

const accountId = user.accountIds![0];
user.balances[accountId]; // [{ accountId, symbol, balance }, ...]
user.positions[accountId];
user.orders[accountId]; // [{ orderId, marketId, side, size, price, ... }, ...]

This is a snapshot taken at fetch time, not a live view — refetch, or subscribe to account updates, after submitting actions.

Errors

SDK failures throw NordError, which wraps the underlying error in cause. Order-entry calls also throw when the session is missing or expired, so distinguish "session invalid" from "exchange rejected the order" when handling failures.

Where to next

These materials are provided for informational purposes only and do not constitute financial, investment, legal, or tax advice, or an offer or solicitation to buy or sell any asset. Trading digital assets and derivatives involves substantial risk, including the possible loss of some or all capital. Products may not be available in all jurisdictions. Users are responsible for evaluating suitability and complying with applicable laws.