Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

Queries a position's cash flow and PnL: deposited and withdrawn principal and collected fees, valued at the current pool price.

exchange.IO(k, positionId)

Examples

Look at a position's collected fees and PnL.

javascript
function main() { var h = exchange.IO("lp.history", "1381183") if (!h) { Log("Query failed:", GetLastError()) return } h.events.forEach(function (e) { Log(e.action, "block", e.block, e.amountBase, "+", e.amountQuote) }) Log("Collected fees:", h.feesCollectedBase, "+", h.feesCollectedQuote, "PnL:", h.pnlQuote) }

Returns

TypeDescription

object / null value

{id, symbol, events, depositedBase, depositedQuote, withdrawnBase, withdrawnQuote, feesCollectedBase, feesCollectedQuote, price, pnlQuote, note}; see the remarks. Null with an error when the node cannot serve historical logs.

Arguments

NameTypeRequiredDescription

k

string

Yes

Set to lp.history to query a position's history.

positionId

string / number

Yes

Position ID.

See Also

Remarks

events lists each liquidity change [{action, block, txHash, liquidity, amountBase, amountQuote}] (action is add, remove or collect); deposited*, withdrawn* and feesCollected* total the deposited and withdrawn principal and the collected fees; pnlQuote is the PnL at the current pool price (current value + collected fees + withdrawn principal − deposits, gas excluded).

It needs a node that serves historical logs; public nodes often do not and fail with an error such as lp.history needs a node that serves historical logs: …, so add a node with archive access to the node URL of the exchange configuration.

V4/Infinity CL events on Uniswap and PancakeSwap record no token amounts, so for those positions only each liquidity change and the current position are given: {id, pool, symbol, events: [{action, block, txHash, liquidity}], position, note}. Basic-pool LP tokens on Aerodrome and Velodrome have no per-position events and are not supported.