Open the app

API: reading the ledger

Every GET route, its query and the full shape of what it returns.

None of these routes needs a wallet signature: the register is public. Each response is JSON in the shape below; types such as U64 and Address are defined in API. With the TypeScript client, each route is the method named in the routes table, and its response is parsed with the same schema the API validates against.

Config

GET /v1/config returns the ledger's configuration: read it once at start.

FieldTypeDescription
networkLabelstringThe network's name as the app shows it.
cluster"localnet" | "mainnet"localnet or mainnet.
programIdAddressAgora's program address.
cashMintAddress | nullThe SPL mint of ledger cash. null until the ledger is initialized.
cashDecimalsintegerDecimals of ledger cash amounts.
feeBpsintegerThe settlement fee in basis points.
feeCapBpsintegerThe highest fee the admin can set.
feeRecipientAddressThe wallet that receives settlement fees.
operatorAddressThe key that co-signs admissions.
admissionMode"instant" | "review"instant when the API approves requests at once; review when the operator approves them.
faucetAvailablebooleantrue where POST /v1/faucet sends test USD.
lookupTableAddress | nullThe address lookup table built transactions compile over. null until set up.
repoMinTermSecondsintegerThe shortest repo term, in seconds.
repoMaxTermSecondsintegerThe longest repo term, in seconds.
bondFaceU64A bond unit's face value in cash atoms.

GET /health says whether the API is serving the ledger.

FieldTypeDescription
status"fixture" | "waiting" | "ready"fixture on the fixture API, waiting before the program is deployed, ready once it serves the ledger.

Accounts

GET /v1/accounts/{wallet} returns one wallet's whole account: admission, cash, positions, open offers and repo offers, repos on both sides and its settlements. A wallet that was never admitted returns admission.state: "none" and empty lists.

FieldTypeDescription
walletAddressThe wallet's address.
admissionAdmissionThe wallet's admission state.
cashobjectThe wallet's ledger cash.
cash.freeU64Free cash atoms.
cash.lockedU64Cash atoms locked in bids and repo offers.
positionsPosition[]One entry per instrument the wallet holds.
offersOffer[]The wallet's open offers.
repoOffersRepoOffer[]The wallet's open repo offers.
borrowedReposRepo[]Repos the wallet borrowed in, every status.
lentReposRepo[]Repos the wallet lent in, every status.
settlementsSettlement[]Settlements that touched the wallet, newest first.

Admission

FieldTypeDescription
state"none" | "pending" | "admitted" | "rejected"none, pending, admitted or rejected.
approvedbooleantrue once the request is approved, so the wallet can build admit.
entitystring | nullThe entity name requested. null before any request.
role"holder" | "issuer" | nullThe role requested. null before any request.
reasonstring | nullWhy a request was rejected. null otherwise.

Position

FieldTypeDescription
codeCodeThe instrument code.
namestringThe instrument's name.
kind"equity" | "bond"equity or bond.
freeU64Free units.
lockedU64Units locked in asks.
pledgedU64Units pledged to repos.
valueBaseUnits | nullAll units times the last price, in cash atoms. null before the first fill.
incomeToClaimU64Income in cash atoms the position can claim now.

Party

Every account the API names comes with its entity name.

FieldTypeDescription
walletAddressThe wallet's address.
entitystringThe member's entity name.

Instruments

GET /v1/instruments lists every instrument; GET /v1/instruments/{code} returns one. GET /v1/issuers/{wallet}/instruments lists those one issuer listed.

FieldTypeDescription
codeCodeThe instrument code.
namestringThe instrument's name.
kind"equity" | "bond"equity or bond.
issuerPartyThe issuer.
faceU64 | nullFace value per unit in cash atoms. null for an equity.
couponBpsinteger | nullYearly coupon in basis points. null for an equity.
maturityTimestamp | nullBond maturity. null for an equity.
listedAtTimestampWhen the instrument was listed.
outstandingU64Units on the register.
lastPriceU64 | nullPrice of the latest fill, cash atoms per unit. null before the first fill.
change24hBpsinteger | nullChange of the last price against the last fill at or before 24 hours ago, in basis points. null without both prices.
volume24hUnitsBaseUnitsUnits filled in the last 24 hours.
volume24hCashBaseUnitsCash atoms filled in the last 24 hours.
bestBidU64 | nullHighest open bid price. null with no bids.
bestAskU64 | nullLowest open ask price. null with no asks.
holderCountintegerOwners with units in any lane.
incomePaidBaseUnitsCash atoms of income paid into the instrument, all time.

Book

GET /v1/instruments/{code}/book returns the open offers: bids highest price first, asks lowest first.

FieldTypeDescription
bidsOffer[]Open bids, highest price first.
asksOffer[]Open asks, lowest price first.

Offer

FieldTypeDescription
idAddressThe Offer account's address.
codeCodeThe instrument code.
side"buy" | "sell"buy (a bid) or sell (an ask).
makerPartyThe maker.
priceU64Cash atoms per unit.
unitsOpenU64Units still open.
status"open" | "closed"open or closed.
postedAtTimestampWhen it was posted.

Register

GET /v1/instruments/{code}/register returns one entry per owner holding units.

FieldTypeDescription
ownerPartyThe owner.
freeU64Free units.
lockedU64Units locked in asks.
pledgedU64Units pledged to repos.
shareBpsintegerThe owner's share of units outstanding, in basis points, rounded to the nearest.

Income

GET /v1/instruments/{code}/income returns every distribution the issuer paid.

FieldTypeDescription
amountU64Cash atoms paid.
perUnitScaledBaseUnitsCash atoms per outstanding unit, scaled by 10^12.
outstandingU64Units outstanding at the payment.
timeTimestampWhen it was paid.
signatureSignatureThe payment's transaction signature.

Candles

GET /v1/instruments/{code}/candles folds fills into OHLC candles.

QueryTypeRequiredDescription
interval"S1" | "M1" | "M5" | "M15" | "H1"no (default H1)Candle width: S1, M1, M5, M15 or H1.
FieldTypeDescription
interval"S1" | "M1" | "M5" | "M15" | "H1"S1, M1, M5, M15 or H1.
startAtTimestampStart of the candle.
openPriceFirst fill's price in the candle.
highPriceHighest fill price.
lowPriceLowest fill price.
closePriceLast fill's price.
volumeBaseBaseUnitsUnits filled.
volumeQuoteBaseUnitsCash atoms filled.
tradesintegerFills in the candle.

Each price keeps the exact fill it came from as a Price, so no rounding happens until you divide:

FieldTypeDescription
quoteBaseUnitsCash atoms.
basePositiveU64Units. The price per unit is quote divided by base.

Repos

GET /v1/repo-offers lists repo offers; the ones a borrower can take have status: "open". GET /v1/repos lists repos, every status, filtered to one wallet's with wallet.

QueryTypeRequiredDescription
walletAddressnoOnly repos this wallet borrowed or lent in.

RepoOffer

FieldTypeDescription
idAddressThe RepoOffer account's address.
codeCodeThe instrument code.
lenderPartyThe lender.
advancePerUnitU64Cash atoms advanced per pledged unit.
rateBpsintegerYearly rate in basis points.
termSecondsintegerRepo term in seconds.
cashAvailableU64Locked cash still available.
unitsAvailableU64Units the available cash can still advance against.
status"open" | "closed"open or closed.
postedAtTimestampWhen it was posted.

Repo

FieldTypeDescription
idAddressThe Repo account's address.
codeCodeThe pledged instrument.
lenderPartyThe lender.
borrowerPartyThe borrower.
unitsU64Units pledged.
advanceU64Cash atoms advanced.
repurchaseAmountU64Cash atoms to repay, fixed at opening.
rateBpsintegerYearly rate in basis points.
openedAtTimestampWhen the repo opened.
maturityTimestampWhen the repo matures.
status"active" | "repaid" | "defaulted"active, repaid or defaulted.

Settlements

GET /v1/settlements pages through every settlement, newest first. For the next page, pass page.nextCursor back as cursor with the same filters.

QueryTypeRequiredDescription
cursorstringnonextCursor from the previous page.
limitnumberno (default 24)Settlements per page, 1 to 100.
instrumentCodenoOnly settlements in this instrument code.
accountAddressnoOnly settlements that touched this wallet.
FieldTypeDescription
itemsSettlement[]Settlements, newest first.
pagePageInfoPaging state.
asOfTimestampWhen the page was read.
FieldTypeDescription
nextCursorstring | nullPass as cursor, with the same filters, for the next page. null on the last page.
hasMorebooleantrue when a next page exists.

Settlement

FieldTypeDescription
idstringThe settlement's id, also its cursor.
kind"admission" | "deposit" | "withdraw" | "list" | "issue" | "post-offer" | "cancel-offer" | "trade" | "post-repo-offer" | "cancel-repo-offer" | "repo-open" | "repo-repay" | "default" | "income" | "claim"What settled. One kind per instruction (see the table on this page).
codeCode | nullThe instrument, or null for a cash or admission settlement.
accountsParty[]Every party the settlement touched.
legsSettlementLeg[]What moved, one leg per asset and pair of endpoints.
slotintegerThe slot it landed in.
signatureSignatureIts transaction signature.
timeTimestampBlock time of the slot.
KindInstructionWhat settled
admissionadmitA wallet was admitted.
depositdepositUSDC deposited into free ledger cash.
withdrawwithdrawFree ledger cash withdrawn as USDC.
listlist_instrumentAn instrument was listed.
issueissueUnits were issued to a member.
post-offerpost_offerAn offer was posted and its side locked.
cancel-offercancel_offerAn offer was cancelled and its lock released.
tradetake_offerAn offer was filled, in part or in full.
post-repo-offerpost_repo_offerA repo offer was posted and its cash locked.
cancel-repo-offercancel_repo_offerA repo offer was cancelled and its cash released.
repo-opentake_repo_offerA repo opened: units pledged, cash advanced.
repo-repayrepay_repoA repo was repaid and its pledge released.
defaultsettle_defaultA matured repo's pledged units went to the lender.
incomepay_incomeAn issuer paid income into an instrument.
claimclaim_incomeA holder claimed income into free cash.

SettlementLeg

A leg moves one amount of one asset from one endpoint to another. An endpoint of null means the amount was created (an issue) or left the register.

FieldTypeDescription
assetstringAn instrument code, or USDC for cash.
amountBaseUnitsUnits, or cash atoms.
fromobjectWhere it left. null when it was created (an issue).
from.accountPartyThe party.
from.lane"free" | "locked" | "pledged" | "external" | "income"free, locked, pledged, external (outside the register) or income (an instrument's income pool).
toobjectWhere it arrived. null when it left the ledger.
to.accountPartyThe party.
to.lane"free" | "locked" | "pledged" | "external" | "income"free, locked, pledged, external or income.

Live settlements

GET /v1/events is a server-sent event stream, filtered with the same instrument and account as settlements. Each message is named by its type and carries id, timestamp, type and data:

TypeDataDo
settlementa Settlementadd it to what you show
readya Healththe stream is live
resync{ "reason": string }refetch the current page: the stream may have missed some

Other types may appear; ignore those you don't know.

QueryTypeRequiredDescription
instrumentCodenoOnly settlements in this instrument code.
accountAddressnoOnly settlements that touched this wallet.
ts
import { SettlementEvent } from '@agora/contract'

const stream = new EventSource(api.eventsUrl({ instrument: 'CALDER' }))
stream.addEventListener('settlement', (event) => {
  const { data } = SettlementEvent.parse(JSON.parse(event.data))
  console.log(data.kind, data.signature, data.legs)
})
stream.addEventListener('resync', () => {
  void api.settlements({ instrument: 'CALDER' })
})