Account data & positions

Balances, positions, orders, fills and transaction status for an account.

REST

# Public account snapshot: collateral, positions, sub-accounts
curl "https://mainnet.zklighter.elliot.ai/api/v1/account?by=index&value=123"

Private endpoints such as accountActiveOrders, accountInactiveOrders, pnl and the history endpoints require an auth token:

const { authToken } = check(lighter.CreateAuthToken(Math.floor(Date.now() / 1000) + 3600, API_KEY_INDEX, ACCOUNT_INDEX));

const orders = await fetch(
  `${BASE_URL}/api/v1/accountActiveOrders?account_index=${ACCOUNT_INDEX}&market_id=0`,
  { headers: { Authorization: authToken } },
).then(r => r.json());

Check a submitted transaction with tx (status values are in Data Structures, Constants and Errors):

curl "https://mainnet.zklighter.elliot.ai/api/v1/tx?by=hash&value=<tx_hash>"

WebSocket (recommended)

Add auth to the subscribe message for private channels:

{ "type": "subscribe", "channel": "account_all_orders/123", "auth": "<AUTH_TOKEN>" }

Which channel to use:

You needChannel
Positions, trades, funding across all marketsAccount All
Open ordersAccount All Orders
Whether a transaction executed or was rejectedAccount Tx
Collateral, leverage, margin usageAccount Stats
Liquidations, deleverages, announcementsNotification

Every account channel, with its auth requirement and payload, is in the WebSocket reference.

Recommended pattern for apps

  1. On load: REST snapshot (account) + subscribe to account_all/{account} and account_all_orders/{account}.
  2. After every sendTx: optimistically show the order as pending; reconcile when it appears in account_all_orders or a failure arrives on account_tx.
  3. On reconnect: resubscribe and replace local state with the new snapshot.

Read-only access for third parties

For portfolio trackers, accountants, or AI agents, ask the user for a read-only token (ro:…). It works anywhere an auth token is accepted for reading and can never trade. See Read-only Authentication.


Did this page help you?