Skip to content

Commit 568652a

Browse files
committed
Added holdings endpoint
1 parent 3d88a57 commit 568652a

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

examples/holdings/main.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from dotenv import load_dotenv
2+
from jup_python_sdk.clients.ultra_api_client import UltraApiClient
3+
4+
load_dotenv()
5+
client = UltraApiClient()
6+
7+
address = client._get_public_key()
8+
9+
try:
10+
holdings_response = client.holdings(str(address))
11+
12+
print("Holdings API Response:")
13+
print(f"Total Portfolio Value: {holdings_response['uiAmount']} ({holdings_response['uiAmountString']})")
14+
15+
print("\nToken Holdings:")
16+
for mint, token_accounts in holdings_response['tokens'].items():
17+
print(f"\nToken Mint: {mint}")
18+
for account in token_accounts:
19+
print(f" Account: {account['account']}")
20+
print(f" Amount: {account['uiAmountString']}")
21+
print(f" Decimals: {account['decimals']}")
22+
print(f" Is ATA: {account['isAssociatedTokenAccount']}")
23+
print(f" Is Frozen: {account['isFrozen']}")
24+
print(f" Exclude From Net Worth: {account['excludeFromNetWorth']}")
25+
26+
except Exception as e:
27+
print("Error occurred while fetching holdings:", str(e))
28+
finally:
29+
client.close()

jup_python_sdk/clients/ultra_api_client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ def balances(self, address: str) -> Dict[str, Any]:
109109

110110
return response.json() # type: ignore
111111

112+
def holdings(self, address: str) -> Dict[str, Any]:
113+
"""
114+
Get token holdings of an account from the Jupiter Ultra API.
115+
116+
Args:
117+
address (str): The public key of the account to get holdings for.
118+
119+
Returns:
120+
dict: The dict api response containing portfolio value and detailed
121+
token account information organized by mint address.
122+
"""
123+
url = f"{self.base_url}/ultra/v1/holdings/{address}"
124+
response = self.client.get(url, headers=self._get_headers())
125+
response.raise_for_status()
126+
127+
return response.json() # type: ignore
128+
112129
def shield(self, mints: list[str]) -> Dict[str, Any]:
113130
"""
114131
Get token information and warnings for specific mints

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "jup-python-sdk"
3-
version = "1.1.1"
3+
version = "1.2.0"
44
description = "Python SDK for Jupiter Exchange APIs."
55
authors = ["Fiji <[email protected]>"]
66
license = "MIT"

tests/test_ultra_holdings.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from dotenv import load_dotenv
2+
3+
from jup_python_sdk.clients.ultra_api_client import UltraApiClient
4+
5+
6+
def test_ultra_get_holdings() -> None:
7+
"""
8+
Test the UltraApiClient holdings method.
9+
"""
10+
load_dotenv()
11+
client = UltraApiClient()
12+
13+
address = client._get_public_key()
14+
15+
try:
16+
holdings_response = client.holdings(str(address))
17+
assert (
18+
"amount" in holdings_response
19+
), "Response does not contain 'amount' key."
20+
assert (
21+
"tokens" in holdings_response
22+
), "Response does not contain 'tokens' key."
23+
24+
print()
25+
print("Holdings API Response:")
26+
print(
27+
f"Total Portfolio Value: {holdings_response['uiAmount']} ({holdings_response['uiAmountString']})"
28+
)
29+
30+
print("\nToken Holdings:")
31+
for mint, token_accounts in holdings_response["tokens"].items():
32+
print(f"\nToken Mint: {mint}")
33+
for account in token_accounts:
34+
print(f" Account: {account['account']}")
35+
print(f" Amount: {account['uiAmountString']}")
36+
print(f" Decimals: {account['decimals']}")
37+
print(f" Is ATA: {account['isAssociatedTokenAccount']}")
38+
print(f" Is Frozen: {account['isFrozen']}")
39+
40+
except Exception as e:
41+
print("Error occurred while fetching holdings:", str(e))
42+
finally:
43+
client.close()

0 commit comments

Comments
 (0)