Skip to Content
API ReferencePortfolio API

Portfolio

Summary and component are separate reads. Both take a login token or the web app’s Privy JWT. Saved leverage takes either too. Share cards, the performance series, and the on-ramp and off-ramp take the Privy JWT only. A login token on those routes is 401.

GET /api/portfolio/summary and GET /api/portfolio/component are Cache-Control: private, no-store. A section of the component that could not be read is null. A list with no rows is []. The component fails only when every section fails: 503 when balances are temporarily unavailable, otherwise 500.

Endpoints

MethodPathAuthDescription
GET/api/portfolio/summaryLogin token or Privy JWTBalances, holdings, perps
GET/api/portfolio/componentLogin token or Privy JWTFees, orders, fills, transfers, funding, leverage
PUT/api/portfolio/perps-leverageLogin token or Privy JWTSaved leverage for one perp
GET/api/portfolio/holding/:ticker/pnl-cardPrivy JWTJPEG of one holding
GET/api/portfolio/performancePrivy JWTEquity and PnL series
GET/api/portfolio/performance/cardPrivy JWTJPEG of that series
POST/api/portfolio/onrampPrivy JWTFiat on-ramp URL
POST/api/portfolio/offrampPrivy JWTFiat off-ramp URL

There is no GET /api/portfolio/.

Summary

GET /api/portfolio/summary

curl 'https://api.loafmarkets.com/api/portfolio/summary' \ -H "authorization: Bearer $LOAF_LOGIN_TOKEN"
{ "balances": [ { "assetId": 3, "symbol": "USDC", "decimals": 6, "isQuote": true, "total": "100000000", "hold": "25000000", "available": "75000000" }, { "assetId": 7, "symbol": "TERA", "decimals": 18, "isQuote": false, "total": "10000000000000000000", "hold": "0", "available": "10000000000000000000" } ], "holdings": [ { "ticker": "TERA", "averageEntryPrice": 150.25, "marketPrice": 167.49, "isIpoAllocation": false, "assetId": 7 } ], "perps": { "collateral": { "assetId": 3, "symbol": "USDC", "decimals": 6, "tickSize": "1", "extensionMultiplier": "10000000" }, "l2AccountIndex": 4, "pools": [] }, "accountMode": "MANUAL", "withdrawable": "75", "withdrawFee": "0.05" }

balances are the account’s L2 balances. Amounts are decimal strings in the token’s base units ("1000000" with decimals: 6 is 1 USDC). available is total minus hold, or "0" when holds exceed total. Each field is rounded down to whole ticks on its own, so total can exceed hold + available by one tick. Rows are every asset with a balance or a hold, sorted by assetId. isQuote: true is cash. A user with no L2 account has no rows. If balances cannot be read, the summary returns 503.

A unified account’s spot buys are capped by withdrawable, not by the USDC available row. withdrawable is an exact USD string: what a withdrawal or a spot order can take now. withdrawFee is the current withdrawal fee in USD. accountMode is MANUAL or UNIFIED. accountMode and withdrawable are null when they could not be read. A user with no L2 account has accountMode MANUAL and withdrawable "0". withdrawFee is null when balances has no USDC row, or the fee could not be read.

A holding is { ticker, averageEntryPrice, marketPrice, isIpoAllocation } plus assetId or quantity. An IPO allocation is tokens a sale allocated to the account that are not in its L2 balances yet. Once they are deposited into its L2 balances, the same tokens are the L2 holding and are not listed twice.

FieldMeaning
tickerAsset ticker
averageEntryPriceNull when the entry price is not known yet
marketPriceMarket price
isIpoAllocationfalse with assetId, or true with quantity
assetIdPresent when isIpoAllocation is false. Its amounts are in the balances row with this assetId
quantityPresent when isIpoAllocation is true

perps is null only when it could not be read, never because the account has no positions. Otherwise:

FieldMeaning
collateral{ assetId: 3, symbol, decimals, tickSize, extensionMultiplier }
l2AccountIndexThe account, or null for a user with no L2 account, who has no pools
poolsPool 0 is cross. 1 to 7 are isolated.

Each pool:

FieldMeaning
poolInteger. 0 is cross. 1 to 7 are isolated
collateralUSD, as a decimal string
valueUSD, as a decimal string, or null
requirementUSD, as a decimal string, or null
liquidatableBoolean, or null
positionsThe rows below

Each position. base is in tokens, negative for a short. entryPrice, liquidationPrice, entryQuote, notional, and fundingOwed are in USD. fundingIndex is an opaque integer string.

FieldMeaning
marketThe perp’s market index
tickerFor example TERA-PERP
baseDecimal string
entryPriceDecimal string
entryQuoteDecimal string
notionalDecimal string
fundingIndexOpaque integer string
fundingOwedDecimal string
liquidationPriceDecimal string, or null when the position has none
adlRankOptional integer
qemDecimal string
riskInteger
maxLeverageInteger
bandInteger
signedPriceDecimalsInteger
signedQuantityDecimalsInteger

The summary waits briefly so that it includes fills the portfolio socket already sent. If the wait times out, it may not include them yet.

Component

GET /api/portfolio/component

The component waits briefly, as the summary does.

FieldMeaning
lifetimeVolumeNumber, or null if it could not be read
applicableFeesThe account’s current rates: { spot, perps }, each { takerFeeBps, makerFeeBps }. A spot order pays spot. A perp order pays perps, at most that market’s own fee. That fee is market.l2.takerFee or makerFee, where 100 is 1 bp
offeringOrdersIPO purchases. status is PENDING, ALLOCATED, REJECTED, or CANCELLED
openOrdersResting orders, including conditionals. Same row as History
tradeHistoryRecent fills
orderHistoryRecent orders
transfersDeposits and withdrawals
holdingDetailsMap of ticker to { name, totalTokens, imageUrl }. totalTokens is null when the asset is not a property
holdingSparklinesMap of ticker to up to 48 candle closes, oldest first
fundingHistoryRecent funding payments
perpsLeverage{ ticker, leverage } the matching engine holds for the account, at most that market’s maxLeverage. A perp with none set is not listed: the account trades it at that market’s maxLeverage. [] before the account exists

A transfer:

FieldMeaning
journalSeqJournal sequence
typeDEPOSIT or WITHDRAWAL
assetIdAsset id
symbolSymbol
decimalsToken decimals
isQuoteBoolean
amountBase units
statusPENDING, CONFIRMED, or REJECTED
blockchainTxHashL1 transaction hash
addressAddress
createdAtWhen the row was created
feePresent on a withdrawal
batch{ batchNumber, rowIndex, final } once the row is in a batch, or { batchNumberAtMost } before that
payout{ txHash, blockNumber, paidAt, final } once the withdrawal has been paid on L1

Saved leverage

PUT /api/portfolio/perps-leverage

ticker is a perp market ticker (TERA-PERP). leverage is an integer from 1 to that market’s maxLeverage. It sets the account’s initial margin on that market: the position value divided by the leverage, or the market’s own initial margin (with its tiers) where that is larger. The matching engine holds it, per market: a perp relisted on its ticker starts with none set. Nothing is kept for an account that does not exist yet (404).

curl -X PUT 'https://api.loafmarkets.com/api/portfolio/perps-leverage' \ -H "authorization: Bearer $LOAF_LOGIN_TOKEN" \ -H 'content-type: application/json' \ -d '{"ticker":"TERA-PERP","leverage":5}'
{ "ticker": "TERA-PERP", "leverage": 5 }

The portfolio socket sends perps_leverage_update with the same object.

Share cards and performance

GET /api/portfolio/holding/:ticker/pnl-card

:ticker is the asset ticker (TERA), not TERA-PERP. JPEG body.

GET /api/portfolio/performance?range=1D

range is 1D, 1W, 1M, 3M, or ALL.

{ "range": "1D", "bucketSeconds": 300, "t": [1764000000], "equity": [10000.5], "pnl": [12.25] }

GET /api/portfolio/performance/card?range=1D&mode=pnl

mode is pnl (default) or value. JPEG body.

POST /api/portfolio/onramp and POST /api/portfolio/offramp return { "widgetUrl": "https://…" }. Both require a completed identity check (KYC).

Errors

StatuscodeMeaning
400INVALID_REQUESTThe body, query, or path failed validation. details lists each problem
400Saved leverage: { "error": "perps: ticker is malformed" } when ticker matches ^[A-Z0-9]{1,10}-PERP$ but no perp market has it, or { "error": "perps: leverage is malformed" } when leverage is above that market’s maxLeverage. Any other ticker, such as TERA, is INVALID_REQUEST
401UNAUTHENTICATEDNo login token or Privy JWT, a refused one, or a login token on a Privy-only route
403{ "error": "KYC verification required" } on the on-ramp and off-ramp
404{ "error": "Asset not found" } or { "error": "No holding of this asset" } on the PnL card
404Saved leverage: { "error": "l2 account: no L2 account for this user" }. The account does not exist yet: it exists once its first deposit is credited, or at Enable trading for a deposit made before sign-up. Only a Privy JWT can get this, as a login token always has an account. Nothing is kept
409Saved leverage: { "error": "perps: your open orders do not fit their margin at this leverage; cancel them, then set it again" }. The leverage is unchanged
422PnL card only. The asset has no market price, or the holding’s averageEntryPrice is null
429RATE_LIMITEDToo many requests, or too many share cards, for this account. Retry after the Retry-After seconds
503SERVICE_UNAVAILABLEThe login token could not be checked right now. Try again in a moment
503Balances are temporarily unavailable, or share cards are busy. Retry shortly, after the Retry-After seconds when it is set
503Saved leverage: { "error": "perps: the engine did not confirm the leverage; set it again in a moment" }. The old or the new leverage may be in force. Set it again
500INTERNAL_ERROR{ "error": "Failed to authenticate request" }. Authentication of a Privy JWT failed on the server, not because of the JWT. Try again in a moment
500The read failed for another reason
Last updated on