Are you in search of a simple method to monitor wallet profit and loss (PnL)? You’ve arrived at the perfect spot! This guide will walk you through Moralis’ crypto PnL feature, offering detailed insights into the profitability of wallets and tokens. With this tool, you can effortlessly assess the overall profitability of a specific address, analyze the PnL status of individual tokens, and discover the most profitable wallets related to a specific ERC-20 token!
Ready to explore the coding aspect? Here’s a look at 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));
Requesting this endpoint provides the total trading volume, total PnL, PnL percentage, and other vital metrics of the specified wallet. Here’s a sample 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' }
That’s all there is to it! Monitoring wallet profit and loss is straightforward with Moralis. For a comprehensive tutorial on how this operates and additional information on our other endpoints, stay with us in this article or explore our Wallet API documentation page!
Excited to make use of our crypto PnL feature? Sign up for free with Moralis and enjoy immediate access to our top-notch development tools!
Overview
Crypto PnL is a vital financial metric utilized to determine a portfolio’s net profit or loss. Traders, investors, and analysts depend on this metric to appraise asset performance over specific timeframes. This metric is essential for developing tools such as cryptocurrency wallets and trading platforms, as it provides users with a transparent view of their portfolio’s performance.
Historically, gathering this data necessitated extensive manual data aggregation, including tracking trades and cryptocurrency prices. However, this method can now be simplified by using a Web3 data provider such as Moralis.
With Moralis’ crypto PnL feature, you can quickly ascertain the overall profitability of a particular address, evaluate the PnL status of ERC-20 tokens, and pinpoint the top profitable wallets tied to specific tokens. For further insights into how this feature operates and the advantages it can deliver, continue with our extensive guide. Let’s dive in!
What is PnL in Crypto?
Crypto PnL, which stands for “profit and loss,” encapsulates the financial results of your trading activities. It is derived from the difference between the buying and selling prices of your cryptocurrency tokens. Consequently, crypto PnL offers an overview of how your assets are faring over a defined period.
Crypto PnL is an indispensable metric for traders and analysts, providing a thorough overview of portfolio performance. Traders leverage this metric to evaluate the success of their strategies while analysts utilize it for various tasks, including tax reporting.
If you are developing decentralized finance (DeFi) platforms, cryptocurrency wallets, decentralized exchanges (DEXs), portfolio trackers, or other Web3 solutions, incorporating crypto PnL is crucial. This feature will give your users a clear representation of how their assets perform directly within your platform, enhancing engagement and retention.
However, calculating crypto PnL from scratch can be intricate and time-consuming. It involves tracking all trades a user conducts and monitoring prices at specific times, which can become tedious if handled manually.
Fortunately, a Web3 data provider like Moralis can facilitate this process, removing the complexity of manual calculations and enabling you to concentrate on refining 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 effortlessly query the profit and loss status of any wallet, providing all-inclusive insights into wallet and token profitability. This makes it far easier to track and analyze profits/losses across tokens and to identify the most successful wallets for any ERC-20 token!
The realized crypto PnL feature includes three key endpoints:
Wallet PnL Summary
Get the overall profitability of a specific address over a designated time frame, including total trading volume, total profit/loss, and other critical 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 Breakdown
Receive a detailed breakdown of buys, sells, and profit/loss for each ERC-20 token traded by a wallet. This endpoint aids in understanding the performance of individual tokens within 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 Token
Discover the most profitable wallets that have traded a specific token, offering insights into the top 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 summary outlines our crypto PnL feature. Next, we will guide you through a tutorial on how to employ these endpoints to track wallet profit and loss!
3-Step Tutorial: How to Track Wallet Profit & Loss
We will now demonstrate how to monitor the profit and loss status of any wallet. Thanks to the accessibility of our leading API, you can retrieve the necessary data in three straightforward steps:
- Obtain a Moralis API Key
- Create a Script that Calls the Wallet PnL Summary Endpoint
- Execute the Code
Before we proceed, ensure you have a few prerequisites fulfilled!
Prerequisites
Before moving forward, confirm that you have the following installed and configured:
Step 1: Obtain a Moralis API Key
Click on the “Start for Free” button located at the top right to register for an account with Moralis:
From there, your API key can be located directly under the “Home” tab:
Keep the key handy, as you will need it in the following step!
Step 2: Create a Script that Calls 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 necessary dependencies using this terminal command:
npm install node-fetch --save npm install moralis @moralisweb3/common-evm-utils
Next, open your “package.json” file and add “type”: “module”
to the list:
Create a new “index.js” file and append the following code:
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));
Now, configure the code slightly. First, insert your Moralis API key by replacing YOUR_API_KEY
. Second, adjust the address
and chain
parameters for your specific query:
That’s all for the code. The last step is to run the script!
Step 3: Execute the Code
Open your terminal, navigate to your project’s root folder, and run this command:
node index.js
In return, you will receive a response displaying the wallet’s total trading volume, total realized profit/loss, realized profit/loss percentage, and more. Here’s a sample of what the output could look 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' }
And that’s it! Tracking wallet profit and loss is as simple as this with Moralis!
Use Case – Develop a Crypto PnL Tracker
Now that you’re equipped to track wallet profit and loss, consider leveraging this data to build tools like a crypto PnL tracker. A crypto PnL tracker is a tool designed to assist users in effectively monitoring their portfolio performance!
Key features of a crypto PnL tracker encompass:
- Real-Time Portfolio Monitoring: Keep track of portfolio performance in real-time, including profit/loss status for individual ERC-20 tokens.
- Historical Performance Analysis: Access past performance data to evaluate how investments fared over specific durations.
- Tax Reporting Assistance: Utilize PnL data for aiding users with their cryptocurrency tax obligations.
A crypto PnL tracker can enhance various platforms, such as portfolio trackers, cryptocurrency wallets, DEXs, and more, contributing to a superior user experience of your dapps!
Going Beyond Crypto PnL & Wallet Profit & Loss Tracking – Exploring More with Moralis
Moralis is recognized as the leading Web3 data provider, offering a wide array of Web3 APIs and RPC nodes in addition to the crypto PnL feature. With Moralis, you can consolidate all crypto data in one place, simplifying the development of sophisticated platforms such as cryptocurrency wallets, portfolio trackers, and more.
So why opt for Moralis’ Web3 APIs and RPC nodes?
- Comprehensive Data: Moralis provides the most detailed API responses in the industry, delivering ample data with fewer requests. This capability allows you to build dapps more quickly and effectively.
- Cross-Chain Support: Moralis is compatible with over 30 chains, including Ethereum, Polygon, BSC, and Optimism, ensuring full feature parity across all networks. Thus, you need only one provider for all your crypto necessities.
- Secure: Enjoy enterprise-level data security since Moralis is Web3’s first SOC 2 Type 2 certified data provider.
To explore the extensive capabilities of Moralis, let’s take a deeper look at our suite of development tools, starting with our Web3 APIs!
Web3 APIs
Within our suite of Web3 APIs, you will find ten use-case-specific interfaces. Here, we will spotlight three prominent examples:
- Wallet API: The Wallet API enables the effortless retrieval of any wallet’s crypto PnL, token balances, transaction history, net worth, and much more. By harnessing this tool, you can seamlessly integrate wallet functionality into your dapps.
- Token API: This API provides access to token balances, metadata, pricing data, and more with minimal coding. Hence, it’s an excellent resource for dapps needing ERC-20 data, such as DEXs and portfolio trackers.
- NFT API: Using the NFT API, you can easily query NFT balances, metadata, pricing information, and other data. If your goal is to create NFT marketplaces, Web3 games, or similar platforms, be sure to check out the NFT API.
- Streams API: With the Streams API, establishing Web3 data pipelines takes mere clicks, allowing you to stream data directly into your projects. This powerful tool is ideal for setting up real-time alerts, populating databases, or enriching dapps with real-time insights regarding tokens, wallets, and smart contracts.
- Price API: The Price API allows you to extract prices for any ERC-20 token or NFT seamlessly. This advanced tool supports batch requests, enabling concurrent queries for multiple token prices, making it ideal for DEXs, token trackers, or any platform needing accurate pricing information.
Explore our official Web3 API page to gain additional insights into the examples highlighted above and our other interfaces!
RPC Nodes
Moralis offers RPC nodes for over 30 different blockchains, including Ethereum, Polygon, BSC, and many more. Plus, our intuitive point-and-click interface simplifies the process of setting up nodes!
What distinguishes our RPC nodes?
- Speed: Enjoy ultra-fast response times, starting at just 70 ms, ensuring you receive data promptly.
- Reliability: Our nodes are engineered for optimal dependability, boasting an impressive 99.9% uptime.
- Security: Experience top-tier data protection as the industry’s foremost SOC 2 Type 2 certified data provider.
To discover more, please visit our official RPC nodes page or check out one of the following guides where we delve into Fantom RPC nodes and Blast RPC nodes!
Summary: Crypto PnL API – How to Track Wallet Profit & Loss
Crypto PnL represents a vital financial metric used to ascertain the net profit or loss of a cryptocurrency portfolio. Traders, analysts, and investors leverage this statistic to monitor asset performance over defined periods, making it essential for constructing everything from wallets to portfolio trackers.
However, computing the profit and loss of a wallet from scratch can be laborious and intricate, necessitating constant monitoring of user transactions, token prices, and other factors. Fortunately, you can now conveniently query the crypto PnL of any portfolio with a single line of code using a Web3 data provider like Moralis.
Moralis’ crypto PnL feature includes three principal endpoints:
- Wallet PnL Summary: Acquire the overall profitability of a particular wallet over a specified duration, including total trading volume, total profit/loss, profit/loss percentage, and other essential metrics.
- Wallet PnL Breakdown: Retrieve a detailed breakdown of buys, sells, and profit/loss for each token that a wallet has traded. This endpoint offers a nuanced understanding of the performance of individual tokens within a portfolio.
- Top Profitable Wallets by Token: Pinpoint the top profitable wallets that have traded a specific token, providing insights into the most successful traders for that particular asset.
Thus, utilizing Moralis makes it effortless to monitor wallet profit and loss!
If you found this crypto PnL tutorial useful, you may want to explore additional content on our blog. For instance, take a look at our article on the DeBank API featuring our DeFi positions capability, or read about our Alchemy Webhooks guide for supplemental information on streams.
Additionally, if you wish to independently track wallet profit and loss, sign up with Moralis. Creating an account is free, providing immediate access to our comprehensive suite of advanced tools.