PnL Indexer
Historical PnL Indexer
The Solana Account Indexer is a specialized tool designed to accurately track and calculate the Profit and Loss (PnL) of any given Solana account across specified historical or current timeframes. Utilizing the First-In-First-Out (FIFO) accounting method, the indexer generates both cumulative and daily PnL metrics, empowering users to evaluate long-term gains or losses as well as day-to-day performance changes with precision
Functionality
Cumulative PnL: Calculates the total Profit and Loss across all transactions for the specified time frame, offering a comprehensive view of overall account performance.
Daily PnL: Provides a day-by-day breakdown of Profit and Loss, enabling users to assess daily performance and identify short-term trends in asset valuation.
Methodology
FIFO (First-In-First-Out) Calculation:
The FIFO methodology matches each outgoing asset (e.g., sale, trade) to the earliest-acquired position available, ensuring accurate and consistent cost-basis accounting. By systematically aligning asset transactions in chronological order, FIFO precisely reflects realized gains and losses, providing clarity even amid market volatility.
PnL Calculation
Realized PnL: Determined by matching each outgoing asset (sold or transferred out) to the earliest-acquired position using the FIFO method, accurately capturing profits or losses upon asset disposal.
Unrealized PnL: Assessed by comparing the current market value of assets still held in the account against their original acquisition cost, reflecting potential gains or losses.
Daily Tracking: Monitors realized and unrealized PnL on a daily basis, enabling detailed visibility into each day's cumulative financial performance.
Technical Insights
Transaction Parsing: The indexer systematically parses account transactions, accurately identifying activities such as deposits, withdrawals, and asset swaps to construct a comprehensive transaction history.
Price Updates: To ensure precise daily PnL calculations, the indexer retrieves token prices at defined intervals (e.g., end-of-day), maintaining accurate valuations for unrealized gains or losses.
Daily Rollover: The indexer performs a daily rollover, logging updated PnL data and retrieving the latest asset prices to maintain a continuous and reliable history for effective trend analysis.
Use Cases
Individual Account Analysis: Enables users to gain comprehensive insights into their personal trading activities and performance.
Portfolio Management: Assists portfolio managers in accurately monitoring, analyzing, and reporting daily Profit and Loss metrics across managed assets.
Tax Reporting: Facilitates tax preparation by providing detailed historical data on realized gains and losses, simplifying compliance and reporting requirements.
Try out the API on Swagger docs
The indexer exposes a set of API endpoints designed to initialize indexing, backfill historical transaction data, and retrieve comprehensive cumulative and daily Profit and Loss (PnL) metrics for any specified account.
Index creation flow
Create New Index
POST
{admin-base-url}/index/pnl
Purpose: Initializes a new index for tracking PnL data.
Start Backfill Job
POST
{admin-base-url}/index/{index_id}/backfill
Purpose: Starts a backfill job to populate historical PnL data based on the specified index ID.
Check Backfill Status
GET
{admin-base-url}/index/{index_id}/backfill
Purpose: Check the current status of the backfill job for the specified index.
Fetch Cumulative PnL Data
GET
{index-dataset-url}/api/v1/dataset/cumulative-pnl/{index_id}
Purpose: Retrieves the cumulative PnL data for the specified index ID over the specified time frame.
Fetch Daily PnL Data
GET
{index-dataset-url}/api/v1/dataset/daily-pnl/{index_id}
Purpose: Retrieves the daily PnL data for the specified index ID over the specified time frame.
Index creation example
1. Create a New Index
POST {admin-base}/index/pnl
Headers:x-api-key: <your_api_key>
Request Body:
Description: Initializes a new index to track Profit and Loss (PnL) data for the specified account over the provided date range.
Sample Response:
Payload Details:
name
Description: A user-defined identifier for the index, enabling easy reference and retrieval in the future.
Example:
"My Main Wallet Portfolio"
Purpose: Helps clearly label and organize indexes according to specific accounts, portfolios, or tracking purposes.
filters
Description: An array of filter objects, each containing criteria to specify which transactions should be included in the index.
Purpose: Filters establish specific conditions to determine which transactions and data are included within the index, with each filter targeting particular
columns
using definedpredicates
for precise data selection.Components: Each filter consists of a
column
field and a corresponding array ofpredicates
.
Filter 1: Account ID Filter
column
:"account_id"
:Description: Filters transactions by the
account_id
column, ensuring the index includes only transactions associated with the specified Solana account.predicates
:Type:
"eq"
(equals) — Matches transactions exactly to the specifiedaccount_id
Value: An array containing the user's specific Solana account ID.
User-Specific Element: The account ID uniquely identifies the user's Solana wallet address.
Example Value:
"4BjxyW2GTD1qBwUk96mAR7dV1A3Pq51hPx78WLqrXegX"
Purpose: Limits the index to include data solely related to the user's designated account.
Filter 2: Time Filter
column
:"time"
:Description: This filter applies to the
time
column, enabling users to specify an exact date and time range for transaction inclusion.predicates
:The
predicates
array includes two conditions:Greater Than (
gt
):Type:
"gt"
— Indicates that the time must be greater than the specified value.Description: The initial time of a range, given as a Unix timestamp (in seconds).
User-Created Timestamp: User-defined start datetime
Example Value:
"1718148102"
Less Than (
lt
):Type:
"lt"
— Indicates that the time must be earlier than the specified value.Description: The end time of the range, given as a Unix timestamp
User-Specific Element: The end timestamp is user-defined, representing the upper limit of the desired time range.
Example Value:
"1718339227"
Purpose: To include only transactions that fall within the user-defined time range. This timeframe is fully customizable, allowing tailored analysis based on specific periods.
2. Start Backfill Job
POST {admin-base-url}/index/{index_id}/backfill
Headers:x-api-key
: <your_api_key>
URL Parameters:
index_id
: The ID of the index created in the previous step.
Request Body:
Description: Initiates the backfill process for the specified index ID, retrieving and processing historical data to populate corresponding Profit and Loss (PnL) records.
Sample Response:
3. Check Backfill Status
GET {admin-base-url}/index/{index_id}/backfill
Headers:x-api-key
: <your_api_key>
URL Parameters:
index_id
: The ID of the index to check the backfill status.
Description: Retrieves the current status of the backfill job, enabling users to track its progress and monitor completion.
Sample Response:
4. Fetch Cumulative PnL Data
GET {index-dataset-url}/api/v1/dataset/cumulative-pnl/{index_id}
Headers:x-api-key
: <your_api_key>
URL Parameters:
index_id
: The unique identifier(ID) of the index for which cumulative PnL data is to be retrieved.
Description: Returns the cumulative Profit and Loss (PnL) data for a specified index within the given date range, providing a comprehensive overview of overall performance.
Sample Response:
5. Fetch Daily PnL Data
GET {index-dataset-url}/api/v1/dataset/daily-pnl/{index_id}
Headers:x-api-key
: <your_api_key>
URL Parameters:
index_id
: The ID of the index to fetch daily PnL data.
Description: Fetches the daily PnL data for the specified index within the provided date range.
URL Parameters:
index_id: The unique identifier of the index for which daily Profit and Loss (PnL) data is to be retrieved.
Description: Returns daily PnL data for the specified index across the defined date range, offering detailed insights into day-by-day performance.
Sample Response:
Last updated