Looking for the easiest way to track wallet profit and loss (PnL)? You’ve come to the right place! In this guide, we’ll introduce Moralis’ crypto PnL feature, providing comprehensive insights into wallet and token profitability. With this feature, you can seamlessly get the overall profitability of a given address, gain insight into the PnL status of individual tokens, and fetch the top profitable wallets for a given ERC-20 token!
Are you eager to dive into the code? Here’s our Wallet PnL Summary endpoint in action:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY' }, }; fetch('https://deep-index.developers.moralis.com/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/profitability/summary?chain=eth', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
Calling this endpoint returns the specified wallet’s total trading volume, total PnL, PnL percentage, and other key metrics. Here’s an example of what it looks like:
{ total_count_of_trades: 12, total_trade_volume: '3793782.5812942344', total_realized_profit_usd: '-20653.121064896484', total_realized_profit_percentage: -1.350177388165031, total_buys: 8, total_sells: 20, total_sold_volume_usd: '1509006.703335308', total_bought_volume_usd: '2284775.8779589264' }
That’s it; tracking wallet profit and loss doesn’t have to be more challenging than this when using Moralis. For a more in-depth tutorial on how this works and further information on our other endpoints, join us in this article or check out the Wallet API documentation page!
Ready to use our crypto PnL feature? Sign up for free with Moralis and gain immediate access to our industry-leading development tools!
Overview
Crypto PnL is a crucial financial metric used to determine a portfolio’s net profit or loss. Traders, investors, and analysts rely on this metric to assess asset performance over specific periods. As such, it is fundamental for creating tools such as cryptocurrency wallets and trading platforms since it provides users with a clear overview of their portfolios’ performance.
Traditionally, obtaining this information requires extensive manual data aggregation, including tracking trades and cryptocurrency prices. However, this process can now be streamlined using a Web3 data provider like Moralis.
With Moralis’ crypto PnL feature, you can easily determine the overall profitability of a given address, analyze the PnL status of ERC-20s, and identify the top profitable wallets for specific tokens. To learn more about how this feature works and how it can benefit you, follow our comprehensive guide. Let’s dive in!
What is PnL in Crypto?
Crypto PnL, short for “profit and loss,” refers to the financial outcome of your trading activities. It is calculated based on the difference between the buying and selling prices of your cryptocurrency tokens. As such, crypto PnL provides an overview of how your assets are performing over a given period.

Crypto PnL is an essential metric for traders and analysts alike, offering a comprehensive overview of portfolio performance. Traders rely on it to assess the effectiveness of their strategies, while analysts use it for various purposes, including tax reporting.
If you’re building decentralized finance (DeFi) platforms, cryptocurrency wallets, decentralized exchanges (DEXs), portfolio trackers, or other Web3 platforms, incorporating crypto PnL is crucial. This feature will give your users a clear indication of how their assets are performing directly within your platform, boosting both engagement and retention.
However, calculating crypto PnL from scratch can be complex and time-consuming. It requires tracking all trades a user makes and monitoring prices at specific times, a process that can be tedious if done manually.
Fortunately, a Web3 data provider like Moralis can streamline this process. It eliminates the hassle of manual calculations, allowing you to focus on enhancing your platform’s features and user experience!
Introducing Moralis – The Industry’s Leading Crypto PnL API for Tracking Wallet Profit & Loss
With Moralis’ realized crypto PnL feature, you can seamlessly query the profit and loss status of any wallet. As such, this feature offers comprehensive insights into wallet and token profitability, making it easier to track and analyze profits/losses across tokens and identify the most profitable wallets for any ERC-20 token!
The realized crypto PnL feature includes three endpoints:
Wallet PnL SummaryFetch the overall profitability of a given address over a specific time period, including total trading volume, total profit/loss, and other key metrics:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY' }, }; fetch('https://deep-index.developers.moralis.com/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/profitability/summary?chain=eth', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
Example Response:
{ total_count_of_trades: 12, total_trade_volume: '3793782.5812942344', total_realized_profit_usd: '-20653.121064896484', total_realized_profit_percentage: -1.350177388165031, total_buys: 8, total_sells: 20, total_sold_volume_usd: '1509006.703335308', total_bought_volume_usd: '2284775.8779589264' }
Wallet PnL BreakdownGet a detailed breakdown of buys, sells, and profit/loss for each ERC-20 token traded by a wallet. This endpoint helps you understand the performance of individual tokens in a portfolio:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY' }, }; fetch('https://deep-index.developers.moralis.com/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/profitability?chain=eth', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
Example Response:
{ result: [ { token_address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', avg_buy_price_usd: '1250.89117636677242138858', avg_sell_price_usd: '1217.57108487456170834445', total_usd_invested: '765334.18465647742708110434311858', total_tokens_bought: '611.831148157427433472', total_tokens_sold: '611.831148157427433472', total_sold_usd: '744947.914822087616974748507047918740485538176519383', avg_cost_of_quantity_sold: '1250.89117636677242138858', count_of_trades: 5, realized_profit_usd: '-20386.26983438981010635958779520045817511936', realized_profit_percentage: -2.663708252302914, total_buys: 3, total_sells: 18, name: 'Wrapped Ether', symbol: 'WETH', decimals: 'WETH', logo: 'https://logo.developers.moralis.com/0x1_0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_018112a9229b4bf1bf0d042beb7c2c55', logo_hash: '0a7fc292596820fe066ce8ce3fd6e2ad9d479c2993f905e410ef74f2062a83ec', thumbnail: 'https://logo.developers.moralis.com/0x1_0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_018112a9229b4bf1bf0d042beb7c2c55', possible_spam: false }, //... ] }
Top Profitable Wallets by TokenFetch the top profitable wallets that have traded a certain token, providing insights into the most successful traders for that asset:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY' }, }; fetch('https://deep-index.developers.moralis.com/api/v2.2/erc20/0x7c9f4c87d911613fe9ca58b579f737911aad2d43/top-gainers?chain=eth', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
Example Response:
{ name: 'Wrapped Matic', symbol: 'WMATIC', decimals: '18', logo: 'https://logo.developers.moralis.com/0x1_0x7c9f4c87d911613fe9ca58b579f737911aad2d43_128bc82fe3d945e59c5e67b540eb7ab5', possible_spam: false, result: [ { address: '0x202bb2fab1e35d940fde99b214ba49dafbcef62a', avg_buy_price_usd: '0.9183155718922578201779330700749389942841', avg_sell_price_usd: '1.59952463158282389246', total_tokens_bought: '50.425564410689794636', total_usd_invested: '46.30658101979248190652763127006057463808', total_tokens_sold: '50.423563438810080581', total_sold_usd: '80.6537317325558427356221252383435353256', avg_cost_of_quantity_sold: '0.91831557189225782928', count_of_trades: 2, realized_profit_usd: '34.34898823639942076774324344951973710758', realized_profit_percentage: 74.18027969262069 }, //... ] }
This overview covers our crypto PnL feature. Next, we’ll walk you through a tutorial on how to use these endpoints to track wallet profit and loss!
3-Step Tutorial: How to Track Wallet Profit & Loss
We’ll now show you how to track the profit and loss status of any wallet. And thanks to the accessibility of our premier API, you can get the data you need in three simple steps:
- Get a Moralis API Key
- Write a Script Calling the Wallet PnL Summary Endpoint
- Run the Code
However, before we get going, you’ll need to take care of a couple of prerequisites!
Prerequisites
Before moving on, make sure you have the following installed and set up:
Step 1: Get a Moralis API Key
Click the “Start for Free” button at the top right to sign up for an account with Moralis:

From there, you’ll find your API key directly under the “Home” tab:

Copy and keep the key for the moment, as you’ll need it during the next step!
Step 2: Write a Script Calling the Wallet PnL Summary Endpoint
Open your preferred IDE, set up a folder, launch a terminal, and initialize a project with this command:
npm init
Install the needed dependencies with this terminal command:
npm install node-fetch --save npm install moralis @moralisweb3/common-evm-utils
From here, open your “package.json” file and add “type”: “module” to the list: