# How to Get Wallet Holdings Using AutoHedge: A Complete Developer Guide

> Learn how to get wallet holdings using AutoHedge with this developer guide. This Python wrapper for Jupiter Ultra Swap API retrieves Solana wallet balances programmatically.

- Repository: [Swarms/AutoHedge](https://github.com/The-Swarm-Corporation/AutoHedge)
- Tags: how-to-guide
- Published: 2026-09-09

---

**AutoHedge bundles a lightweight Python wrapper around the Jupiter Ultra Swap API that enables you to retrieve Solana wallet balances programmatically via the `get_holdings` function or the built-in CLI.**

AutoHedge is an open-source automation framework for Solana trading strategies. If you need to monitor token balances as part of your trading workflow, the library provides a direct interface to fetch complete wallet snapshots without managing RPC connections manually.

## Understanding the `get_holdings` Implementation

The core functionality resides in [`autohedge/tools/ultra_tools.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/ultra_tools.py). This module exposes a thin wrapper that communicates with Jupiter's Ultra API to fetch on-chain balance data.

### Method Signature and API Endpoint

The `get_holdings` function accepts a single parameter and returns a JSON string:

```python
get_holdings(address: str) -> str

```

Internally, the function constructs a GET request to:

```

https://api.jup.ag/ultra/v1/holdings/<address>

```

When the **JUPITER_API_KEY** environment variable is present, the request automatically includes the `x-api-key` header for higher rate limits. The function validates the supplied address and propagates HTTP errors with detailed logging.

### Tool Registry Integration

According to the AutoHedge source code, `get_holdings` is registered in [`autohedge/tools/tools_registry.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/tools_registry.py). This registration makes the function discoverable to the CLI and other components that load the tool pool, ensuring consistent access patterns across the application.

## Environment Setup

Before querying holdings, configure your environment variables in a `.env` file at the project root:

```text
JUPITER_API_KEY=your-jupiter-api-key

```

While `JUPITER_API_KEY` is optional for basic queries, it provides elevated rate limits. Note that `SOLANA_PRIVATE_KEY` is only required for signed transactions, not for balance queries.

## How to Query Wallet Holdings

AutoHedge offers two primary interfaces for retrieving holdings: direct Python import and command-line access.

### Programmatic Access with Python

Import `get_holdings` directly from the ultra_tools module to integrate balance checks into your trading scripts:

```python
from autohedge.tools.ultra_tools import get_holdings

wallet_address = "BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV"

try:
    holdings_json = get_holdings(wallet_address)
    print("Wallet holdings:", holdings_json)
except Exception as e:
    print("Error retrieving holdings:", e)

```

The function returns a JSON string containing your **SOL balance** in lamports and a comprehensive dictionary of **SPL-token accounts**. Each token entry includes fields such as `amount`, `uiAmount`, and `decimals` for precise balance calculations.

### Command Line Interface

After installing the package from the repository root with `pip install .`, the `autohedge` CLI becomes available:

```bash
autohedge holdings BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV

```

The CLI entry point in [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py) parses this command and invokes `get_holdings` internally, streaming the JSON response to stdout for shell scripting or manual inspection.

## Summary

- **AutoHedge** provides the `get_holdings` function in [`autohedge/tools/ultra_tools.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/ultra_tools.py) as a thin wrapper around the Jupiter Ultra API.
- The function queries `https://api.jup.ag/ultra/v1/holdings/<address>` and returns JSON containing SOL and SPL-token balances.
- Set **JUPITER_API_KEY** in your environment for higher API rate limits, though it remains optional for basic queries.
- Access holdings programmatically via Python import or through the `autohedge holdings <address>` CLI command.
- The function is registered in [`autohedge/tools/tools_registry.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/tools_registry.py) for discovery by automated agents and CLI tools.

## Frequently Asked Questions

### Do I need a Jupiter API key to check wallet holdings using AutoHedge?

No, the **JUPITER_API_KEY** environment variable is optional for balance queries. However, as implemented in [`autohedge/tools/ultra_tools.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/ultra_tools.py), providing this key attaches the `x-api-key` header to your requests, which unlocks higher rate limits from the Jupiter Ultra API.

### What information does the `get_holdings` function return?

The function returns a JSON string containing your wallet's **SOL balance** measured in lamports, plus a dictionary of all **SPL-token accounts** associated with the address. Each token entry includes raw `amount`, human-readable `uiAmount`, and `decimals` for accurate financial calculations.

### Can I query any Solana wallet address, or only my own?

You can query any valid Solana public address. The `get_holdings` function in [`autohedge/tools/ultra_tools.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/ultra_tools.py) performs read-only queries against the Jupiter Ultra API, requiring no private key signature. You only need `SOLANA_PRIVATE_KEY` for transaction signing, not for balance retrieval.

### Where is the holdings function registered in the AutoHedge codebase?

The `get_holdings` function is exposed through the tools registry in [`autohedge/tools/tools_registry.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/tools_registry.py). This registration pattern allows the CLI handler in [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py) and other autonomous agents to discover and invoke the function dynamically without hard-coding import paths.