NordUser (Trading & Account)
The NordUser class is for interacting with the Nord protocol as an authenticated user. It handles trading, balance management, and sub-account operations.
Trading Operations
placeOrder
Places an order on the exchange.
Signature:
placeOrder(params: PlaceOrderParams): Promise<PlaceOrderResponse>Arguments (PlaceOrderParams):
| Name | Type | Required | Description |
|---|---|---|---|
marketId | number | Yes | Target market identifier. |
side | Side | Yes | Order side (Side.Bid or Side.Ask). |
fillMode | FillMode | Yes | FillMode.Limit, FillMode.PostOnly, FillMode.ImmediateOrCancel, or FillMode.FillOrKill. |
isReduceOnly | boolean | Yes | If true, order only decreases position. |
size | Decimal.Value | No | Quantity of base asset. Required for most orders. |
price | Decimal.Value | No | Limit price. Required for Limit orders. |
quoteSize | QuoteSize | No | Quote-sized order representation for market orders. |
accountId | number | No | Sub-account ID executing the order. |
clientOrderId | BigIntValue | No | Optional client-specified identifier. |
Response (PlaceOrderResponse):
| Field | Type | Description |
|---|---|---|
actionId | bigint | Unique identifier for the transaction action. |
orderId | bigint | (Optional) The ID assigned to the resting order if posted. |
fills | Receipt_Trade[] | Array of trade receipts if the order was filled. |
reducedOrders | ReducedOrder[] | Orders that were shrunk or cancelled by in-engine reduce-only maintenance. |
ReducedOrder Fields:
| Field | Type | Description |
|---|---|---|
orderId | bigint | The order that was reduced. |
remainingSize | bigint | Size remaining after reduction (0 if fully cancelled). |
cancelledSize | bigint | Size that was removed. |
price | bigint | Order price. |
cancelOrder
Cancels an existing order.
Signature:
cancelOrder(orderId: BigIntValue, accountId?: number): Promise<CancelResult>Arguments:
| Name | Type | Required | Description |
|---|---|---|---|
orderId | BigIntValue | Yes | The ID of the order to cancel. |
accountId | number | No | The sub-account ID that placed the order. |
Response (CancelResult):
| Field | Type | Description |
|---|---|---|
actionId | bigint | Action identifier for the cancellation. |
orderId | bigint | The cancelled order ID. |
accountId | number | The account ID involved. |
cancelOrderByClientId
Cancels an existing order using the client-provided identifier.
Signature:
cancelOrderByClientId(clientOrderId: BigIntValue, accountId?: number): Promise<CancelResult>Arguments:
| Name | Type | Required | Description |
|---|---|---|---|
clientOrderId | BigIntValue | Yes | The client-specified order identifier set when placing the order. |
accountId | number | No | The sub-account ID that placed the order. |
Response (CancelResult):
| Field | Type | Description |
|---|---|---|
actionId | bigint | Action identifier for the cancellation. |
orderId | bigint | The cancelled order ID. |
accountId | number | The account ID involved. |
clientOrderId | bigint | The client order ID that was cancelled. |
atomic
Executes multiple operations (place/cancel) atomically in a single transaction.
Signature:
atomic(userActions: UserAtomicSubaction[], providedAccountId?: number): Promise<AtomicResponse>UserAtomicSubaction Fields:
| Field | Type | Description |
|---|---|---|
kind | "place" | "cancel" | "cancelByClientId" | The type of sub-action. |
marketId | number | (Optional) Market ID. |
orderId | BigIntValue | (Optional) Order ID to cancel. |
clientOrderId | BigIntValue | (Optional) Client order ID to cancel (for cancelByClientId). |
side | Side | (Optional) Order side. |
fillMode | FillMode | (Optional) Fill mode. |
size | Decimal.Value | (Optional) Quantity. |
price | Decimal.Value | (Optional) Price. |
Trigger Operations
[!CAUTION] Experimental Feature: Trigger orders (TP/SL) are currently unstable and may change. Use with caution in production.
addTrigger
Adds a stop-loss or take-profit trigger.
Arguments:
| Name | Type | Required | Description |
|---|---|---|---|
marketId | number | Yes | Market to watch. |
side | Side | Yes | Order side for the trigger. |
kind | TriggerKind | Yes | TriggerKind.StopLoss or TriggerKind.TakeProfit. |
triggerPrice | Decimal.Value | Yes | Price that activates the trigger. |
limitPrice | Decimal.Value | No | Optional limit price once triggered. |
intent | Intent | Yes | Intent.Decrease (close/reduce position) or Intent.Increase (add to position). |
removeTrigger
Removes a previously added trigger.
Signature:
removeTrigger(params: RemoveTriggerParams): Promise<void>Arguments:
| Name | Type | Required | Description |
|---|---|---|---|
marketId | number | Yes | Market identifier. |
side | Side | Yes | Side.Bid or Side.Ask. |
kind | TriggerKind | Yes | TriggerKind.StopLoss or TriggerKind.TakeProfit. |
intent | Intent | Yes | Intent.Decrease or Intent.Increase. Must match the intent used when adding. |
triggerPrice | Decimal.Value | No | Trigger price for exact-match removal. |
limits | OrderLimit | No | Same limit fields as on add-trigger for exact-match removal. If the trigger was added without size limits, omit here too. |
Fund Management
deposit
Deposits SPL tokens to the exchange.
Arguments:
| Name | Type | Required | Description |
|---|---|---|---|
amount | number | Yes | Amount to deposit. |
tokenId | number | Yes | Token identifier (e.g., 1 for USDC). |
recipient | PublicKey | No | Recipient address; defaults to user’s address. |
Response:
Returns { signature: string, buffer: PublicKey }.
withdraw
Withdraws tokens from the exchange to your wallet.
Arguments:
| Name | Type | Required | Description |
|---|---|---|---|
amount | number | Yes | Amount to withdraw. |
tokenId | number | Yes | Token identifier. |
destPubkey | string | No | Optional destination registration pubkey (base58). |
Information & State
fetchInfo
Refreshes the local state of the user, including balances, orders, and positions.
await user.fetchInfo();
console.log(user.balances);getSolanaBalances
Checks token balances in your Solana wallet context (not on-exchange).
Arguments:
| Name | Type | Default | Description |
|---|---|---|---|
includeZeroBalances | boolean | true | Include tokens with 0 balance. |
includeTokenAccounts | boolean | false | Include specific token account addresses. |
WebSocket Subscriptions
Nord.subscribe
Subscribe to real-time WebSocket events.
Signature:
Nord.subscribe(options: SubscribeOptions): voidOptions:
| Name | Type | Description |
|---|---|---|
liquidations | boolean | Subscribe to liquidation events (backstop take-all and position liquidations). |
Example:
nord.subscribe({ liquidations: true });See WebSocket Examples for handling liquidation events.