Positions
This page is also Markdown, for agents: /api/reference/positions.md, and /llms.txt lists every page.
positions.get
Section titled “positions.get”An account’s positions, built from its swaps, newest trade first. HTTP: /positions.
| Param | Description |
|---|---|
account |
Required |
limit |
1 to 1000, default 1000 |
Every account’s positions are built from its first swap on, and kept current with every block, a few seconds behind height, and longer while a swap’s transaction is still executing.
Result:
{ "height": 220122260, "timestamp_millis": 1792093696887, "since_millis": 1790709119408, "columns": ["token", "opened_at_millis", "closed_at_millis", "last_trade_millis", "amount", "cost_usd", "bought", "bought_usd", "sold", "sold_usd", "realized_pnl_usd", "buys", "sells"], "rows": [["ribbit-426.meme-cooking.near", 1791563912000, null, 1792086520230, "600000000000000000000000", 3600, "1000000000000000000000000", 6000, "400000000000000000000000", 4000, 1600, 3, 1]]}since_millis: the account’s first swap,nullwhen it has none. Liquidity changes don’t count.- A position is open while
closed_at_millisisnull. An account has at most one open position per token. amount,boughtandsoldare in the token’s smallest units.amountis what’s held now, andcost_usdwhat it cost.realized_pnl_usd: what sells got, minus what the part sold cost, at average cost. For an open position, what it’s worth now is up to you:amountat the token’s price.
How swaps count
Section titled “How swaps count”- A transaction’s trades, one per pool, count as one swap. A token passed from one pool to the next nets to nothing.
- A swap buys what the account got and sells what it gave. wNEAR, USDC, USDt and their bridged forms are what positions are paid in, so they never hold one.
- A buy opens a position in the token, or adds to the open one at a new average entry.
- A sell takes from the open position. The position closes once 1% or less of what was bought is left.
- A sell of more than the position holds, like of tokens the account was sent, sells only what it holds, for that share of what it got.
- Tokens sent out of an open position, or burned, shrink it as if they were never bought:
amountandboughtby the tokens sent, andcost_usdandbought_usdby the share of the cost they carry. One left with 1% or less of what was bought is closed if it sold before, and deleted if it never did. - Tokens sent in don’t count, and neither do deposits to and withdrawals from DEXes, which stay the account’s.