Skip to Content
API ReferenceHistory API

History

Your orders, fills, and funding. Each route takes a login token or the web app’s Privy JWT. GET /api/portfolio/component returns the same rows, except that its fills have no proof. These routes page them.

Reads wait briefly, as the portfolio summary does, so that they include the order changes, fills, and funding payments the portfolio socket already sent. If the wait times out, a read may not include them yet.

Endpoints

MethodPathDescription
GET/api/history/ordersOrder history, booked and conditional
GET/api/history/orders/activeResting orders
GET/api/history/orders/cancelledCancelled orders
GET/api/history/tradesFills, including perps closes that are not book trades
GET/api/history/fundingFunding payments

page defaults to 1. pageSize defaults to 20 and is at most 100. cursor is the opaque nextCursor from the previous page. Pass it back unchanged: a cursor the API did not serve returns the first page, not a 400. Funding has pageSize and cursor only. It refuses any other parameter, page included, with 400. Cancelled orders read cursor only and ignore page and pageSize. Active orders take no parameters and are not paged. Orders and trades refuse a page beyond a maximum depth with 400. Follow nextCursor to page deeper. On an account with a long history, total can be lower than the real number of rows. Page until nextCursor is null.

curl 'https://api.loafmarkets.com/api/history/orders?page=1&pageSize=20' \ -H "authorization: Bearer $LOAF_LOGIN_TOKEN"

Orders

GET /api/history/orders, /orders/active, and /orders/cancelled.

GET /api/history/orders:

{ "orders": [], "total": 0, "page": 1, "pageSize": 20, "nextCursor": null }

A booked order:

FieldMeaning
idOrder id
typeMARKET or LIMIT
statusOPEN, PARTIALLY_FILLED, FILLED, CANCELLED, REJECTED
marketIndex, tickerMarket. ticker is TERA or TERA-PERP
sideBUY or SELL
timeInForceGTC, IOC, or FOK. Placement also accepts POST_ONLY
quantity, priceHuman units. price is null when the row has none
filledQuantity, filledAtFill progress. filledAt is unix seconds or null
rejectionReasonText when REJECTED, else null
cancelReasonWhy the engine cancelled the remainder, or null
expiryMsThe signed expiry
poolPerp pool, or null on spot
reduceOnlyPerp flag
feeRateCapThe signed l2FeeRateCap, per million
l2OrderIndex, orderTagPresent when the order has them
cancelledAt, createdAtUnix seconds. cancelledAt is null until then

A conditional row has no filledQuantity, filledAt, or cancelReason. It adds:

FieldMeaning
typeSTOP_LIMIT, STOP_MARKET, TAKE_LIMIT, or TAKE_MARKET
statusPENDING, ARMED, PLACED, FAILED, or CANCELLED
rejectionReasonWhy it could not be placed, when FAILED. Else null
triggerPriceThe trigger
parentOrderIdThe parent, when this leg was attached
placedOrderIdThe booked order, after the trigger fires
triggeredAtWhen it fired

cancelReason is the engine’s text for a cancel, including a cancel the engine initiated. It is null when you cancelled the order with POST /api/orders/cancel, /api/orders/cancel-all, or /api/orders/cancel-by-index, and on some cancels the engine makes without giving a reason. It is also null on an order that is not cancelled.

GET /api/history/orders/cancelled:

{ "cancelledOrders": [{ "orderId": 880, "cancelledAt": 1764000000 }], "nextCursor": null }

It lists your booked orders that were cancelled, newest order first. Conditionals are not listed. cancelledAt is unix seconds. A page can be short or empty while older cancelled orders remain. Keep paging until nextCursor is null.

GET /api/history/orders/active:

{ "activeOrders": [{ "orderId": 880, "quantityLeft": 1.5, "createdAt": 1764000000 }] }

It lists your booked orders that are OPEN or PARTIALLY_FILLED, newest first. Conditionals are not listed. quantityLeft is the unfilled quantity in tokens. createdAt is unix seconds.

Trades

GET /api/history/trades

{ "trades": [ { "tradeId": 9001, "marketIndex": 2048, "ticker": "TERA", "side": "BUY", "role": "TAKER", "quantity": "2.5", "price": "167.49", "executedAt": 1764000000, "fee": "0.25", "pool": null, "direction": "BUY", "closedPnl": null, "orderId": 880, "txHash": "0xabc…", "source": "TRADE", "proof": null } ], "total": 1, "page": 1, "pageSize": 20, "nextCursor": null }

quantity, price, and fee are decimal strings. role is MAKER or TAKER. closedPnl is set when the fill closed part of a position.

sourceMeaning
TRADEA book trade. Carries txHash and orderId
LIQUIDATION, BACKSTOP_LIQUIDATION, DELEVERAGE, EXIT, SETTLE, FORCED, FORCED_DELEVERAGEA perps event. txHash is null. orderId is null when the event had no order
directionWhen
BUY, SELLA spot trade
OPEN_LONG, CLOSE_LONG, OPEN_SHORT, CLOSE_SHORTA perps fill, including a book trade

proof is always null when source is not TRADE. On a TRADE row it is null when proof status is unavailable, otherwise { "status": "PENDING" } or an IN_BATCH row:

FieldMeaning
statusIN_BATCH
batchNumberBatch number
l2BlockNumberL2 block number
rowIndexRow in the batch
l2TradeDigestTrade digest
batchTxHashBatch transaction hash. Null until the batch executes on L1
finalWhether the batch is final

Funding

GET /api/history/funding?pageSize=20

{ "funding": [ { "journalSeq": 1200, "marketIndex": 4, "ticker": "TERA-PERP", "pool": 0, "base": "2.5", "payment": "0.006281", "rateCbp": 15, "atMs": 1764000000000 } ], "nextCursor": null }

payment is the USD the account paid (positive) or received (negative). rateCbp is the rate for one funding period, in centi-basis-points of the oracle price. It is the payment rate on Funding, the funding rate ÷ 8, within the market’s cap. base is the position size in tokens, negative for a short. Page with cursor set to nextCursor. There is no page or total.

Errors

StatuscodeMeaning
401UNAUTHENTICATEDNo login token or Privy JWT, or a refused one
400INVALID_REQUESTpage or pageSize failed validation, or cursor is empty or too long
429RATE_LIMITEDToo many requests for this account. Retry after the Retry-After seconds
503SERVICE_UNAVAILABLEThe login token could not be checked right now. Try again in a moment
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
500{ "error": "Failed to fetch order history" }, "Failed to fetch trade history", "Failed to fetch funding history", "Failed to fetch cancelled orders", or "Failed to fetch active orders"
Last updated on