Debank Unofficial Wallet Portfolio Balance API

ÜCRETSİZ PREMIUM
Taraf RainAPI | Güncelleyen vor 4 Tagen | Finance
Popülerlik

9.5 / 10

Gecikme

762ms

Hizmet Düzeyi

100%

Health Check

N/A

Tüm Eğitimlere Dön (2)

Python Tutorial: Check and Log Wallet Portfolio Balance

Python Tutorial: Check and Log Wallet Portfolio Balance

In this tutorial, we’ll walk through how to use Python to retrieve and log the portfolio balance of a cryptocurrency wallet across various EVM chains. We’ll be using the requests library to make HTTP requests.

Prerequisites

Before you begin, ensure you have the following:

  pip install requests

Step 1: Set Up Your Python Script

Create a new Python file, for example, check_portfolio.py, and open it in your text editor.

Step 2: Import Requests

At the beginning of your check_portfolio.py file, import the requests library:

import requests

Step 3: Configure the API Request

Define the API request details with your RapidAPI key and the wallet address:

url = "https://debank-unofficial-wallet-portfolio-balance-api.p.rapidapi.com/user/total_balance"
headers = {
    'X-RapidAPI-Key': 'YourRapidAPIKey',  # Replace with your API key
    'X-RapidAPI-Host': 'debank-unofficial-wallet-portfolio-balance-api.p.rapidapi.com'
}
params = {'address': '0xYourWalletAddress'}  # Replace with the wallet address

Step 4: Send the Request and Handle the Response

Create a function to send the request and process the response:

def get_portfolio_balance():
    response = requests.get(url, headers=headers, params=params)
    if response.status_code == 200:
        print('Portfolio Balance:', response.json())
    else:
        print('Error fetching portfolio balance:', response.status_code)

get_portfolio_balance()

Step 5: Run Your Script

Execute your script using Python:

python check_portfolio.py

You should see the portfolio balance of the specified wallet address in the console, including individual balances for each chain and the total USD worth.

Conclusion

Congratulations! You’ve successfully created a Python script to retrieve and log the portfolio balance of a cryptocurrency wallet. This script can be further customized or integrated into larger projects for enhanced crypto asset management.