Skip to main content

Monitor Positions

Retrieving details about positions held in liquidity pools is an essential part of managing your liquidity and monitoring performance. This guide explains how to use the SDK to gather information about all active positions held by a given wallet.

1. Overview of Position Monitoring

Monitoring positions helps developers retrieve information on liquidity positions associated with a specific wallet. It scans the Solana blockchain for token accounts owned by the wallet, determines which ones represent positions, and decodes the data to provide detailed information about each position.

With position monitoring, you can:

  • Identify all liquidity positions held by a wallet
  • Gather information about liquidity, price ranges, and fees earned
  • Track position performance over time
  • Make informed decisions about adjusting or closing positions

2. Fetching Positions

Fetching Positions for a Wallet

Fetching positions is a straightforward process:

  1. RPC Client: Use a Solana RPC client to interact with the blockchain.
  2. Wallet Address: Provide the wallet address of the user whose positions you want to fetch.
  3. Fetch Positions: Use the appropriate function to retrieve all positions held by the specified wallet.
import { fetchPositionsForOwner, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
const owner = address("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt"); // set an owner address

const positions = await fetchPositionsForOwner(devnetRpc, owner);

console.log(positions);

Fetching Positions in a Whirlpool

To fetch all positions in a specific Whirlpool:

  1. RPC Client: Use a Solana RPC client to interact with the blockchain.
  2. Whirlpool Address: Provide the whirlpool address for the positions you want to fetch.
  3. Fetch Positions: Use the appropriate function to retrieve all positions in a whirlpool.
import { fetchPositionsInWhirlpool, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
const whirlpoolAddress = address("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt");

const positions = await fetchPositionsInWhirlpool(devnetRpc, whirlpoolAddress);

console.log(positions);

3. Working with Position Data

After fetching position information, you can use it to:

  1. Track Position Performance: Monitor the performance of each position over time, including fees earned and value changes.
  2. Identify Optimal Actions: Determine when to adjust liquidity, harvest rewards, or close positions based on performance metrics.
  3. Calculate Returns: Compute the return on investment for each position by comparing current value to initial deposit.
  4. Build Trading Strategies: Develop automated strategies for position management based on market conditions.
  5. Portfolio Analytics: Create dashboards to visualize position performance across multiple pools.

4. Implementation Example

Suppose you're building a portfolio tracker for Whirlpool positions. You can create a monitoring service that periodically:

  1. Fetches all positions for a user's wallet
  2. Calculates current value and accumulated fees for each position
  3. Compares performance against market benchmarks
  4. Alerts users when positions require attention (e.g., out of range, significant fee accumulation)

This monitoring capability is essential for both manual traders and algorithmic strategies.

5. Next Steps

After monitoring positions, you might want to:

  • Adjust Liquidity: Modify the amount of liquidity in positions based on their performance.
  • Harvest Rewards: Collect accumulated fees and rewards from profitable positions.
  • Close Position: Exit positions that are no longer aligned with your strategy.

By effectively monitoring positions, you gain the insights needed to optimize your liquidity management strategy and maximize returns.