Solana: How to track the price or market cap of spl tokens?

Monitoring the price or market cap of a SOL (Solana) token using Python

As a Solana-focused bot, you probably want to track the price and market cap of newly minted SOL tokens. In this article, we will explore how to monitor these metrics using Python and interact with the Solana API.

Prerequisites:

  • You have set up a Solana node (e.g. Solana Mainnet or Testnet) and created an account on PumpFun.
  • You have the pumpfun library installed (pip install pumpfun).

Step 1: Create a new Python script

Create a new file with the extension .py, e.g. salt_market_cap.py. This script will handle the interaction with the Solana API.

import axis

import requirements

from dotenv import load_dotenv


Load environment variables from .env file

load_dotenv()

def get_token_data(token):

"""Get token data from PumpFun""

url = f"

headers = {

"Authorization": os.getenv("PUMPFUN_API_TOKEN"),

"Content-Type": "application/json",

}

response = requests.get(url, headers=headers)

return response.json()

def get_market_cap_data(token):

"""Get Solana token market cap data"""

url = f"

headers = {

"Authorization": os.getenv("PUMPFUN_API_TOKEN"),

"Content-Type": "application/json",

}

response = requests.get(url, headers=headers)

return response.json()

def main():

token = input ("Enter the SOL token you want to track: ")

data = get_token_data(token)


Get market cap data

market_cap_data = get_market_cap_data(token)

print(f"Market cap: {market_cap_data['totalSupply']}")

if __name__ == "__main__":

main()

Step 2: Set up the Solana node environment

Check that your Solana node is running and can be accessed from a Python script. You can do this by adding the solana environment variable to your .env file:

PUMPFUN_API_TOKEN=your_api_token_here

Replace “your_api_token_here” with your actual API token from PumpFun.

Step 3: Run the script

Save the script and run it using Python. When prompted, enter the SOL token you want to monitor.

python solana_market_cap.py

This will print the market cap data for the specified SOL token.

Tips and Variations:

  • To get price data instead of market cap, update the url in the get_token_data() function to point to the Solana price source.
  • Consider adding error handling and logging to make the script more robust.
  • You can use this script as a starting point and add more functionality, such as mapping or filtering token IDs.

With these steps, you have successfully created a Python script that tracks the price and market cap of newly created SOL tokens using the PumpFun API.

Bitcoin Bitcoin Mini

11.02.2025 Автор: admin Категория: CRYPTOCURRENCY 6 Просмотров

Поделиться в социальных сетях
Нет комментариев
Solana: How to track the price or market cap of spl tokens?
Есть что сказать? Оставьте комментарий: