| name | gdex-portfolio |
| description | Cross-chain portfolio overview, chain-specific token balances, and paginated trade history |
GDEX: Portfolio & Balances
Query cross-chain portfolio summaries, chain-specific balances, and trade history.
When to Use
- Getting a user's total portfolio value across all chains
- Checking token balances on a specific chain
- Retrieving trade history with pagination and filters
Prerequisites
@gdexsdk/gdex-skill installed
- Authenticated via
loginWithApiKey() — see gdex-authentication
Cross-Chain Portfolio
WARNING (Live-Tested): The high-level getPortfolio() and getBalances() methods send walletAddress + chain to the backend, but the backend expects userId + chainId + data (encrypted session key). These methods return empty or incorrect results. Use the raw client workaround below.
Correct Way — Raw Client (Live-Tested, Works)
import { GdexSkill, GDEX_API_KEY_PRIMARY, buildGdexUserSessionData } from '@gdexsdk/gdex-skill';
const skill = new GdexSkill();
skill.loginWithApiKey(GDEX_API_KEY_PRIMARY);
const data = buildGdexUserSessionData(sessionKey, GDEX_API_KEY_PRIMARY);
const portfolio = await skill.client.get('/v1/portfolio', {
params: {
userId: controlAddress,
chainId: 622112261,
data,
}
});
Incorrect Way — High-Level Methods (SDK Bug)
const portfolio = await skill.getPortfolio({ walletAddress: '0x...', chain: 'solana' });
const balances = await skill.getBalances({ walletAddress: '0x...', chain: 8453 });
Portfolio Response
interface Portfolio {
totalValueUsd: number;
balances: Balance[];
perpPositions?: PerpPosition[];
realizedPnl?: number;
unrealizedPnl?: number;
totalPnl?: number;
}
interface Balance {
tokenAddress: string;
symbol: string;
name: string;
decimals: number;
rawBalance: string;
balance: string;
usdValue: number;
priceUsd: number;
change24h?: number;
chain: string | number;
}
Chain-Specific Balances
WARNING (Live-Tested): Same issue as portfolio — use raw client. On
backend v1.1.0 balances are embedded in the portfolio response under
portfolio.balances[] (there is no separate /v1/balances endpoint).
const portfolio = await skill.client.get('/v1/portfolio', {
params: {
userId: controlAddress,
chainId: 622112261,
data,
}
});
const balances = portfolio.balances ?? [];
Parameters
| Parameter | Type | Required | Description |
|---|
walletAddress | string | Yes | Wallet address to query |
chain | string | ChainId | Yes | Chain to query balances on |
tokenAddress | string | No | Filter to a specific token |
Trade History
WARNING (Live-Tested): The backend expects param user (NOT userId), and managed Solana chainId for trade history is 900 (NOT 622112261). Use the raw client:
const history = await skill.client.get('/v1/user_history', {
params: {
user: controlAddress,
chainId: 900,
data,
page: 1,
limit: 20,
}
});
The high-level getTradeHistory() sends wrong param names. Use raw client above.
Trade Record
interface TradeRecord {
id: string;
type: string;
inputToken: string;
outputToken: string;
amountIn: string;
amountOut: string;
usdValue?: number;
chain: string | number;
dex?: string;
txHash: string;
timestamp: number;
status: string;
}
Example: Portfolio Dashboard (Autonomous Agent — Live-Tested)
import { GdexSkill, GDEX_API_KEY_PRIMARY, buildGdexUserSessionData } from '@gdexsdk/gdex-skill';
const skill = new GdexSkill();
skill.loginWithApiKey(GDEX_API_KEY_PRIMARY);
const data = buildGdexUserSessionData(sessionKey, GDEX_API_KEY_PRIMARY);
const userId = controlAddress;
const portfolio = await skill.client.get('/v1/portfolio', {
params: { userId, chainId: 622112261, data }
});
const balances = portfolio.balances ?? [];
const history = await skill.client.get('/v1/user_history', {
params: { user: userId, chainId: 900, data, page: 1, limit: 20 }
});
Autonomous Agent Notes
- Always use raw client for portfolio, balances, and trade history. The high-level SDK methods send incorrect parameter names.
- Portfolio/balances chainId: Use
622112261 for Solana, standard EVM chain IDs for others.
- Trade history chainId: Use
900 for Solana (not 622112261). This is a backend quirk.
- Trade history param: Use
user (not userId) — backend expects different param name for this endpoint.
- Data param: Always pass the encrypted session key from
buildGdexUserSessionData().
- userId: Always use the control wallet address, never the managed address.
Related Skills
- gdex-authentication — Auth setup required for portfolio queries
- gdex-spot-trading — Execute trades based on portfolio analysis
- gdex-perp-trading — View perp positions in portfolio
- gdex-token-discovery — Research tokens found in portfolio