CRXDocs

Get Data

Goal

Read your book. You will pull your firm summary from the relayer and your exact balances and positions from the chain. The relayer is fast and convenient; the chain is the source of truth.

Testnet only. Sonic Testnet, chain 14601.

Before you start

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

Step 1 — Read your firm summary

GET /firm/:addr returns your general balance and your open-agreement count. This is the quick health check — no signature, no login.

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

Step 2 — Read your general balance on-chain

generalBalance(party, token) is your free, global collateral — and where variation margin lands as you win. Read it per token.

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

Step 3 — Read the margin posted to a position

Each Master Agreement holds your initial margin in its SCA. Read sca(maId, party, token) for the agreement you care about.

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

Free margin is SCA − requiredIM; the SCA holds only IM, never accumulated P&L. The P&L has already been recycled into your general balance by the VM cycle.

Step 4 — Compute the mark and PnL

The forward mark moves with the reference price feed. Your position's value is the move against your locked rate, scaled by notional and direction:

value = (mark − lockedRate) × notional        // if you are long
value = (lockedRate − mark) × notional         // if you are short

You already hold lockedRate, notional, and your side from the Terms you signed. The mark is the venue's current forward rate for the pair. Continuous PnL is not a number you chase — it has been cleared into your general balance every VM cycle. The mark-versus-locked figure is your unrealized position on top of what VM has already settled.

What you get — and the branch

  • Numbers return. Firm summary from the relayer; exact balances and posted margin from the chain. Reconcile the two — the chain wins on any disagreement.
  • The relayer is unreachable. Read everything from the chain directly. generalBalance and sca need no off-chain service. This is the failsafe: your data is on-chain whether or not the relayer is up.

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

Next: Variation Margin (~4 min) — how the P&L you just read got cleared.