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

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

TypeDescription

object / null value

{txHash, positions: [{id, symbol, principalBase, principalQuote, feesBase, feesQuote, receivedBase, receivedQuote}], sells}; see the remarks. Null with an error on failure.

Arguments

NameTypeRequiredDescription

k

string

Yes

Set to lp.collect to collect fees.

positionIds

string / number / array

Yes

Position IDs: one ID (string or number) or an array of IDs, such as "1381183" or ["v4:123", "456"]; several IDs may also be written as the leading arguments.

sell

bool

No

true sells the collected base token for the quote token at market; false by default.

See Also

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.