CRXDocs

Get Data

Goal

Read your desk. You will pull your firm summary from the relayer, then read your exact balances, posted margin, and exposure from the chain. The chain is the source of truth; the relayer is the fast path.

Testnet only. Sonic Testnet, chain 14601.

Before you start

  • Your maker address.
  • The relayer base URL and the deployed core address (API reference, ~4 min).
  • A read client on the Sonic Testnet RPC.

Step 1 — Read your firm summary

GET /firm/:addr returns your general balance and your open-agreement count. No login for this read.

const firm = await fetch(`${RELAYER}/firm/${maker}`).then((r) => r.json());
// → { balance: "...", open_acas: N }

Step 2 — Read your free collateral on-chain

generalBalance(maker, token) is your free, global pool — deposits plus the VM you have won. Read it per token.

const free = await crx.read.generalBalance([maker, USDC]);

Step 3 — Read margin posted per agreement

For each Master Agreement you are bound in, sca(maId, maker, token) is the IM you posted to that relationship. Iterate your known maIds — you hold them from the binds you confirmed.

const posted = await crx.read.sca([maId, maker, USDC]);

Free margin in an agreement is SCA − requiredIM; the SCA holds only IM, never P&L.

Step 4 — Compute your exposure and settlement obligation

Your exposure on a position is the rate move against your side, scaled by notional:

value = (mark − lockedRate) × notional        // long side
value = (lockedRate − mark) × notional         // short side

You hold lockedRate, notional, and your side from the Terms. The mark is the venue's current forward rate. Your daily P&L has already been cleared by the VM cycle into your general balance, so the mark-versus-locked figure is your live exposure on top of what is already settled.

Your settlement obligation crystallizes at the agreement's settlement date: the position is marked at the settled rate and netted to one number. Until then, VM keeps the running balance current.

What you get — and the branch

  • Numbers return. Summary from the relayer, exact figures from the chain. Reconcile; the chain wins.
  • The relayer is down. Read your whole book from the chain. generalBalance and sca need no off-chain service — this is the failsafe. Your book is on-chain whether or not anything off-chain is running.

Read the chain when the number must be exact. Read the relayer when speed matters more.

Next: Monetize Your Desk (~5 min) — turn this book into revenue.