exchange.IO("lp.history", ...)
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
| Type | Description |
object / null value |
|
Arguments
| Name | Type | Required | Description |
k | string | Yes | Set to |
positionId | string / number | Yes | Position ID. |
See Also
Uniswap / PancakeSwap Aerodrome / Velodrome exchange.IO exchange.IO("lp.positions") exchange.IO("lp.collect")
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.