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. |
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. |
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" | The type of sub-action. |
marketId | number | (Optional) Market ID. |
orderId | BigIntValue | (Optional) Order ID to cancel. |
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. |
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. |