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
| Method | Path | Auth | Description |
|---|---|---|---|
GET | /api/portfolio/summary | Login token or Privy JWT | Balances, holdings, perps |
GET | /api/portfolio/component | Login token or Privy JWT | Fees, orders, fills, transfers, funding, leverage |
PUT | /api/portfolio/perps-leverage | Login token or Privy JWT | Saved leverage for one perp |
GET | /api/portfolio/holding/:ticker/pnl-card | Privy JWT | JPEG of one holding |
GET | /api/portfolio/performance | Privy JWT | Equity and PnL series |
GET | /api/portfolio/performance/card | Privy JWT | JPEG of that series |
POST | /api/portfolio/onramp | Privy JWT | Fiat on-ramp URL |
POST | /api/portfolio/offramp | Privy JWT | Fiat 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.
| Field | Meaning |
|---|---|
ticker | Asset ticker |
averageEntryPrice | Null when the entry price is not known yet |
marketPrice | Market price |
isIpoAllocation | false with assetId, or true with quantity |
assetId | Present when isIpoAllocation is false. Its amounts are in the balances row with this assetId |
quantity | Present when isIpoAllocation is true |
perps is null only when it could not be read, never because the account has no positions. Otherwise:
| Field | Meaning |
|---|---|
collateral | { assetId: 3, symbol, decimals, tickSize, extensionMultiplier } |
l2AccountIndex | The account, or null for a user with no L2 account, who has no pools |
pools | Pool 0 is cross. 1 to 7 are isolated. |
Each pool:
| Field | Meaning |
|---|---|
pool | Integer. 0 is cross. 1 to 7 are isolated |
collateral | USD, as a decimal string |
value | USD, as a decimal string, or null |
requirement | USD, as a decimal string, or null |
liquidatable | Boolean, or null |
positions | The 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.
| Field | Meaning |
|---|---|
market | The perp’s market index |
ticker | For example TERA-PERP |
base | Decimal string |
entryPrice | Decimal string |
entryQuote | Decimal string |
notional | Decimal string |
fundingIndex | Opaque integer string |
fundingOwed | Decimal string |
liquidationPrice | Decimal string, or null when the position has none |
adlRank | Optional integer |
qem | Decimal string |
risk | Integer |
maxLeverage | Integer |
band | Integer |
signedPriceDecimals | Integer |
signedQuantityDecimals | Integer |
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.
| Field | Meaning |
|---|---|
lifetimeVolume | Number, or null if it could not be read |
applicableFees | The 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 |
offeringOrders | IPO purchases. status is PENDING, ALLOCATED, REJECTED, or CANCELLED |
openOrders | Resting orders, including conditionals. Same row as History |
tradeHistory | Recent fills |
orderHistory | Recent orders |
transfers | Deposits and withdrawals |
holdingDetails | Map of ticker to { name, totalTokens, imageUrl }. totalTokens is null when the asset is not a property |
holdingSparklines | Map of ticker to up to 48 candle closes, oldest first |
fundingHistory | Recent 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:
| Field | Meaning |
|---|---|
journalSeq | Journal sequence |
type | DEPOSIT or WITHDRAWAL |
assetId | Asset id |
symbol | Symbol |
decimals | Token decimals |
isQuote | Boolean |
amount | Base units |
status | PENDING, CONFIRMED, or REJECTED |
blockchainTxHash | L1 transaction hash |
address | Address |
createdAt | When the row was created |
fee | Present 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
| Status | code | Meaning |
|---|---|---|
400 | INVALID_REQUEST | The body, query, or path failed validation. details lists each problem |
400 | Saved 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 | |
401 | UNAUTHENTICATED | No 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 | |
404 | Saved 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 | |
409 | Saved leverage: { "error": "perps: your open orders do not fit their margin at this leverage; cancel them, then set it again" }. The leverage is unchanged | |
422 | PnL card only. The asset has no market price, or the holding’s averageEntryPrice is null | |
429 | RATE_LIMITED | Too many requests, or too many share cards, for this account. Retry after the Retry-After seconds |
503 | SERVICE_UNAVAILABLE | The login token could not be checked right now. Try again in a moment |
503 | Balances are temporarily unavailable, or share cards are busy. Retry shortly, after the Retry-After seconds when it is set | |
503 | Saved 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 | |
500 | INTERNAL_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 |
500 | The read failed for another reason |