exchange.IO("lp.collect", ...)
Collects the fees accrued to positions without touching the principal; several positions go into one transaction.
exchange.IO(k, positionIds)
exchange.IO(k, positionIds, sell)Examples
Collect the positions whose uncollected fees exceed 5 USDC in one go.
javascript
function main() {
var ids = exchange.IO("lp.positions").filter(function (p) {
return p.feesValue > 5
}).map(function (p) { return p.id })
if (ids.length == 0) {
return
}
var r = exchange.IO("lp.collect", ids)
if (!r) {
Log("Collect failed:", GetLastError())
return
}
r.positions.forEach(function (p) {
Log(p.id, p.symbol, "fees:", p.feesBase, "+", p.feesQuote)
})
}Returns
| Type | Description |
object / null value |
|
Arguments
| Name | Type | Required | Description |
k | string | Yes | Set to |
positionIds | string / number / array | Yes | Position IDs: one ID (string or number) or an array of IDs, such as |
sell | bool | No |
|
See Also
Uniswap / PancakeSwap Aerodrome / Velodrome exchange.IO exchange.IO("lp.positions") exchange.IO("lp.decrease") exchange.IO("lp.remove") exchange.IO("lp.claim")
Remarks
Fields: txHash is the transaction; positions gives, per position, the withdrawn principal principalBase and principalQuote, the collected fees feesBase and feesQuote, and what actually arrived, receivedBase and receivedQuote (principal plus fees); sells lists the market orders selling back to the quote token, [{symbol, qty, txHash}], with {symbol, qty, error} for a sale that failed without affecting the others, and is empty without selling. Amounts are in token units, oriented by the position's pair (the stablecoin is the quote by default). The principal is 0 when collecting.
Several positions share one transaction where possible; when several transactions are needed (such as V3 and V4/Infinity CL positions together, which have different PositionManagers), txHash is the last one and txHashes lists them all.
Aerodrome and Velodrome: staked positions earn no trading fees (they go to voters), so collecting fails with a hint to claim the rewards with exchange.IO("lp.claim"); basic pools collect the fees accrued to the wallet's LP tokens with the pool's claimFees, one transaction per pool.