Price monitoring or sun capitalization (solana) tokens with python
As Bot focused on Solana, it is likely to be interested in monitoring the price and market capitalization of the newly minted tokens. In this article, we will explore how to trace these metrics using Python and interact with the API Solana.
Previous requirements:
- Has configured a sole node (for example, Solana Mainnet or Testnet) and created an account in Pumpfun.
- You have the library ‘pumpfun
installed (pip install pumpfun).
Step 1: Create a new Python Script
Create a new file with an extension.py, for example, solana_market_cap.py. This script will handle the interactions with the Solana API.
Python
Import operating system
Import requests
From dotenv import load_dtenv
Load environment variables from the .env file
Load_Dotenv ()
Def get_token_data (Token):
"" "Get token data from Pumpfun" ""
URL = F " Wold"
headers = {
"Authorization": OS.Getenv ("pumpfun_api_token"),
"Type of content": "application/json",
}
Answer = request.get (URL, headed = headers)
Return answer.json ()
Def get_market_cap_data (Token):
"" "Get market capitalization data for a solana token" ""
URL = F " Warket-capitalization"
headers = {
"Authorization": OS.Getenv ("pumpfun_api_token"),
"Type of content": "application/json",
}
Answer = request.get (URL, headed = headers)
Return answer.json ()
Def Main () ::
Token = input ("Enter the token sun that you want to track:")
data = get_token_data (token)
Obtain market capitalization data
Market_cap_data = get_market_cap_data (token)
print (f "market capitalization: {market_cap_data ['totalsupply']}")
Yes __name__ == "__main__":
major()
Step 2: Configure the sole node environment
Make sure your Solana node is executed and is accessible from your Python script. You can do this by adding an environment variable 'Solana to your file’ .env:
Bash
Pumpfun_api_token = your_api_token_here
Replaceyour_api_token_herewith the real Pumpfun token api.
Step 3: Execute the script
Save the script and run it with Python. When asked, enter the Token Sol you want to track.
Python solana_market_cap.py
This will print the market capitalization data for the specified Token Sol.
Tips and variations:

- To obtain price data instead of market capitalization, update theURL
function in thethoker_data ()function to aim at the feeding of the solana price.
- Consider adding errors and registration for your script to be more robust.
- You can use this script as a starting point and add more functionality, such as the mapping or filtering of Token ID.
Following these steps, he has successfully created a Python script that tracks the price and market capitalization of the recently coined tokens using the Pumpfun API.
