solanab-jup-python-sdk 2.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- jup_python_sdk/__init__.py +0 -0
- jup_python_sdk/clients/__init__.py +0 -0
- jup_python_sdk/clients/jupiter_client.py +136 -0
- jup_python_sdk/clients/ultra_api_client.py +213 -0
- jup_python_sdk/models/__init__.py +0 -0
- jup_python_sdk/models/common/__init__.py +0 -0
- jup_python_sdk/models/common/dex_enum.py +57 -0
- jup_python_sdk/models/ultra_api/__init__.py +0 -0
- jup_python_sdk/models/ultra_api/ultra_execute_request_model.py +16 -0
- jup_python_sdk/models/ultra_api/ultra_order_request_model.py +20 -0
- solanab_jup_python_sdk-2.0.3.dist-info/METADATA +158 -0
- solanab_jup_python_sdk-2.0.3.dist-info/RECORD +14 -0
- solanab_jup_python_sdk-2.0.3.dist-info/WHEEL +4 -0
- solanab_jup_python_sdk-2.0.3.dist-info/licenses/LICENSE +21 -0
File without changes
|
File without changes
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import base64
|
2
|
+
import json
|
3
|
+
import os
|
4
|
+
from typing import Any, Optional
|
5
|
+
|
6
|
+
import base58
|
7
|
+
from curl_cffi import AsyncSession, requests
|
8
|
+
from solders.solders import Keypair, VersionedTransaction
|
9
|
+
|
10
|
+
|
11
|
+
class _CoreJupiterClient:
|
12
|
+
"""
|
13
|
+
Core non-network-dependent logic for Jupiter clients.
|
14
|
+
Handles private key loading and transaction signing.
|
15
|
+
"""
|
16
|
+
|
17
|
+
def __init__(self, api_key: Optional[str], private_key_env_var: str):
|
18
|
+
self.api_key = api_key
|
19
|
+
self.base_url = "https://api.jup.ag" if api_key else "https://lite-api.jup.ag"
|
20
|
+
self.private_key_env_var = private_key_env_var
|
21
|
+
|
22
|
+
def _get_headers(self) -> dict[str, str]:
|
23
|
+
headers = {
|
24
|
+
"Accept": "application/json",
|
25
|
+
}
|
26
|
+
if self.api_key:
|
27
|
+
headers["x-api-key"] = self.api_key
|
28
|
+
return headers
|
29
|
+
|
30
|
+
def _post_headers(self) -> dict[str, str]:
|
31
|
+
headers = {
|
32
|
+
"Accept": "application/json",
|
33
|
+
"Content-Type": "application/json",
|
34
|
+
}
|
35
|
+
if self.api_key:
|
36
|
+
headers["x-api-key"] = self.api_key
|
37
|
+
return headers
|
38
|
+
|
39
|
+
def _load_private_key_bytes(self) -> bytes:
|
40
|
+
"""Loads the private key from the environment
|
41
|
+
variable as base58 or uint8 array."""
|
42
|
+
pk_raw = os.getenv(self.private_key_env_var, "")
|
43
|
+
pk_raw = pk_raw.strip()
|
44
|
+
if pk_raw.startswith("[") and pk_raw.endswith("]"):
|
45
|
+
try:
|
46
|
+
arr = json.loads(pk_raw)
|
47
|
+
if isinstance(arr, list) and all(
|
48
|
+
isinstance(x, int) and 0 <= x <= 255 for x in arr
|
49
|
+
):
|
50
|
+
return bytes(arr)
|
51
|
+
else:
|
52
|
+
raise ValueError
|
53
|
+
except Exception as e:
|
54
|
+
raise ValueError(f"Invalid uint8-array private key format: {e}") from e
|
55
|
+
try:
|
56
|
+
return base58.b58decode(pk_raw)
|
57
|
+
except Exception as e:
|
58
|
+
raise ValueError(f"Invalid base58 private key format: {e}") from e
|
59
|
+
|
60
|
+
def get_public_key(self) -> str:
|
61
|
+
wallet = Keypair.from_bytes(self._load_private_key_bytes())
|
62
|
+
return str(wallet.pubkey())
|
63
|
+
|
64
|
+
async def get_public_key_async(self) -> str:
|
65
|
+
return self.get_public_key()
|
66
|
+
|
67
|
+
def _sign_base64_transaction(self, transaction_base64: str) -> VersionedTransaction:
|
68
|
+
transaction_bytes = base64.b64decode(transaction_base64)
|
69
|
+
versioned_transaction = VersionedTransaction.from_bytes(transaction_bytes)
|
70
|
+
return self._sign_versioned_transaction(versioned_transaction)
|
71
|
+
|
72
|
+
def _sign_versioned_transaction(
|
73
|
+
self, versioned_transaction: VersionedTransaction
|
74
|
+
) -> VersionedTransaction:
|
75
|
+
wallet = Keypair.from_bytes(self._load_private_key_bytes())
|
76
|
+
account_keys = versioned_transaction.message.account_keys
|
77
|
+
wallet_index = account_keys.index(wallet.pubkey())
|
78
|
+
|
79
|
+
signers = list(versioned_transaction.signatures)
|
80
|
+
signers[wallet_index] = wallet # type: ignore
|
81
|
+
|
82
|
+
return VersionedTransaction(
|
83
|
+
versioned_transaction.message,
|
84
|
+
signers, # type: ignore
|
85
|
+
)
|
86
|
+
|
87
|
+
def _serialize_versioned_transaction(
|
88
|
+
self, versioned_transaction: VersionedTransaction
|
89
|
+
) -> str:
|
90
|
+
return base64.b64encode(bytes(versioned_transaction)).decode("utf-8")
|
91
|
+
|
92
|
+
|
93
|
+
class JupiterClient(_CoreJupiterClient):
|
94
|
+
"""
|
95
|
+
The synchronous client for interacting with the Jupiter API.
|
96
|
+
Powered by curl_cffi.
|
97
|
+
"""
|
98
|
+
|
99
|
+
def __init__(
|
100
|
+
self,
|
101
|
+
api_key: Optional[str] = None,
|
102
|
+
private_key_env_var: str = "PRIVATE_KEY",
|
103
|
+
client_kwargs: Optional[dict[str, Any]] = None,
|
104
|
+
):
|
105
|
+
super().__init__(api_key, private_key_env_var)
|
106
|
+
kwargs = client_kwargs or {}
|
107
|
+
kwargs.setdefault("impersonate", "chrome110")
|
108
|
+
self.client = requests.Session(**kwargs)
|
109
|
+
|
110
|
+
def close(self) -> None:
|
111
|
+
self.client.close()
|
112
|
+
|
113
|
+
|
114
|
+
class AsyncJupiterClient(_CoreJupiterClient):
|
115
|
+
"""
|
116
|
+
The asynchronous client for interacting with the Jupiter API.
|
117
|
+
Powered by curl_cffi.
|
118
|
+
"""
|
119
|
+
|
120
|
+
def __init__(
|
121
|
+
self,
|
122
|
+
api_key: Optional[str] = None,
|
123
|
+
private_key_env_var: str = "PRIVATE_KEY",
|
124
|
+
client_kwargs: Optional[dict[str, Any]] = None,
|
125
|
+
):
|
126
|
+
super().__init__(api_key, private_key_env_var)
|
127
|
+
kwargs = client_kwargs or {}
|
128
|
+
kwargs.setdefault("impersonate", "chrome110")
|
129
|
+
self.client = AsyncSession(**kwargs)
|
130
|
+
|
131
|
+
async def close(self) -> None:
|
132
|
+
await self.client.close()
|
133
|
+
|
134
|
+
# Override get_public_key for async context consistency
|
135
|
+
async def get_public_key(self) -> str: # type: ignore[override]
|
136
|
+
return super().get_public_key()
|
@@ -0,0 +1,213 @@
|
|
1
|
+
from typing import Any
|
2
|
+
|
3
|
+
from jup_python_sdk.clients.jupiter_client import AsyncJupiterClient, JupiterClient
|
4
|
+
from jup_python_sdk.models.ultra_api.ultra_execute_request_model import (
|
5
|
+
UltraExecuteRequest,
|
6
|
+
)
|
7
|
+
from jup_python_sdk.models.ultra_api.ultra_order_request_model import (
|
8
|
+
UltraOrderRequest,
|
9
|
+
)
|
10
|
+
|
11
|
+
|
12
|
+
class UltraApiClient(JupiterClient):
|
13
|
+
"""
|
14
|
+
A synchronous client for interacting with the Jupiter Ultra API.
|
15
|
+
"""
|
16
|
+
|
17
|
+
def order(self, request: UltraOrderRequest) -> dict[str, Any]:
|
18
|
+
"""
|
19
|
+
Get an order from the Jupiter Ultra API (synchronous).
|
20
|
+
|
21
|
+
Args:
|
22
|
+
request (UltraOrderRequest): The request parameters for the order.
|
23
|
+
|
24
|
+
Returns:
|
25
|
+
dict: The dict api response.
|
26
|
+
"""
|
27
|
+
params = request.to_dict()
|
28
|
+
|
29
|
+
url = f"{self.base_url}/ultra/v1/order"
|
30
|
+
response = self.client.get(url, params=params, headers=self._get_headers())
|
31
|
+
response.raise_for_status()
|
32
|
+
|
33
|
+
return response.json() # type: ignore[no-any-return] # type: ignore
|
34
|
+
|
35
|
+
def execute(self, request: UltraExecuteRequest) -> dict[str, Any]:
|
36
|
+
"""
|
37
|
+
Execute the order with the Jupiter Ultra API (synchronous).
|
38
|
+
|
39
|
+
Args:
|
40
|
+
request (UltraExecuteRequest): The execute request parameters.
|
41
|
+
|
42
|
+
Returns:
|
43
|
+
dict: The dict api response.
|
44
|
+
"""
|
45
|
+
payload = request.to_dict()
|
46
|
+
|
47
|
+
url = f"{self.base_url}/ultra/v1/execute"
|
48
|
+
response = self.client.post(url, json=payload, headers=self._get_headers())
|
49
|
+
response.raise_for_status()
|
50
|
+
|
51
|
+
return response.json() # type: ignore[no-any-return] # type: ignore
|
52
|
+
|
53
|
+
def order_and_execute(self, request: UltraOrderRequest) -> dict[str, Any]:
|
54
|
+
"""
|
55
|
+
Get and execute an order in a single call (synchronous).
|
56
|
+
|
57
|
+
Args:
|
58
|
+
request (UltraOrderRequest): The request parameters for the order.
|
59
|
+
|
60
|
+
Returns:
|
61
|
+
dict: The dict api response.
|
62
|
+
"""
|
63
|
+
order_response = self.order(request)
|
64
|
+
|
65
|
+
request_id = order_response["requestId"]
|
66
|
+
signed_transaction = self._sign_base64_transaction(
|
67
|
+
order_response["transaction"]
|
68
|
+
)
|
69
|
+
|
70
|
+
execute_request = UltraExecuteRequest(
|
71
|
+
request_id=request_id,
|
72
|
+
signed_transaction=self._serialize_versioned_transaction(
|
73
|
+
signed_transaction
|
74
|
+
),
|
75
|
+
)
|
76
|
+
|
77
|
+
return self.execute(execute_request)
|
78
|
+
|
79
|
+
def balances(self, address: str) -> dict[str, Any]:
|
80
|
+
"""
|
81
|
+
Get token balances of an account (synchronous).
|
82
|
+
|
83
|
+
Args:
|
84
|
+
address (str): The public key of the account to get balances for.
|
85
|
+
|
86
|
+
Returns:
|
87
|
+
dict: The dict api response.
|
88
|
+
"""
|
89
|
+
url = f"{self.base_url}/ultra/v1/balances/{address}"
|
90
|
+
response = self.client.get(url, headers=self._get_headers())
|
91
|
+
response.raise_for_status()
|
92
|
+
|
93
|
+
return response.json() # type: ignore[no-any-return] # type: ignore
|
94
|
+
|
95
|
+
def shield(self, mints: list[str]) -> dict[str, Any]:
|
96
|
+
"""
|
97
|
+
Get token info and warnings for specific mints (synchronous).
|
98
|
+
|
99
|
+
Args:
|
100
|
+
mints (list[str]): List of token mint addresses
|
101
|
+
to get information for.
|
102
|
+
|
103
|
+
Returns:
|
104
|
+
dict: The dict api response with warnings information.
|
105
|
+
"""
|
106
|
+
params = {"mints": ",".join(mints)}
|
107
|
+
|
108
|
+
url = f"{self.base_url}/ultra/v1/shield"
|
109
|
+
response = self.client.get(url, params=params, headers=self._get_headers())
|
110
|
+
response.raise_for_status()
|
111
|
+
|
112
|
+
return response.json() # type: ignore[no-any-return] # type: ignore
|
113
|
+
|
114
|
+
|
115
|
+
class AsyncUltraApiClient(AsyncJupiterClient):
|
116
|
+
"""
|
117
|
+
An asynchronous client for interacting with the Jupiter Ultra API.
|
118
|
+
"""
|
119
|
+
|
120
|
+
async def order(self, request: UltraOrderRequest) -> dict[str, Any]:
|
121
|
+
"""
|
122
|
+
Get an order from the Jupiter Ultra API (asynchronous).
|
123
|
+
|
124
|
+
Args:
|
125
|
+
request (UltraOrderRequest): The request parameters for the order.
|
126
|
+
|
127
|
+
Returns:
|
128
|
+
dict: The dict api response.
|
129
|
+
"""
|
130
|
+
params = request.to_dict()
|
131
|
+
|
132
|
+
url = f"{self.base_url}/ultra/v1/order"
|
133
|
+
response = await self.client.get(
|
134
|
+
url, params=params, headers=self._get_headers()
|
135
|
+
)
|
136
|
+
response.raise_for_status()
|
137
|
+
|
138
|
+
return response.json() # type: ignore[no-any-return]
|
139
|
+
|
140
|
+
async def execute(self, request: UltraExecuteRequest) -> dict[str, Any]:
|
141
|
+
"""
|
142
|
+
Execute the order with the Jupiter Ultra API (asynchronous).
|
143
|
+
|
144
|
+
Args:
|
145
|
+
request (UltraExecuteRequest): The execute request parameters.
|
146
|
+
|
147
|
+
Returns:
|
148
|
+
dict: The dict api response.
|
149
|
+
"""
|
150
|
+
payload = request.to_dict()
|
151
|
+
|
152
|
+
url = f"{self.base_url}/ultra/v1/execute"
|
153
|
+
response = await self.client.post(
|
154
|
+
url, json=payload, headers=self._get_headers()
|
155
|
+
)
|
156
|
+
response.raise_for_status()
|
157
|
+
|
158
|
+
return response.json() # type: ignore[no-any-return]
|
159
|
+
|
160
|
+
async def order_and_execute(self, request: UltraOrderRequest) -> dict[str, Any]:
|
161
|
+
"""
|
162
|
+
Get and execute an order in a single call (asynchronous).
|
163
|
+
|
164
|
+
Args:
|
165
|
+
request (UltraOrderRequest): The request parameters for the order.
|
166
|
+
|
167
|
+
Returns:
|
168
|
+
dict: The dict api response.
|
169
|
+
"""
|
170
|
+
order_response = await self.order(request)
|
171
|
+
|
172
|
+
request_id = order_response["requestId"]
|
173
|
+
signed_transaction = self._sign_base64_transaction(
|
174
|
+
order_response["transaction"]
|
175
|
+
)
|
176
|
+
|
177
|
+
execute_request = UltraExecuteRequest(
|
178
|
+
request_id=request_id,
|
179
|
+
signed_transaction=self._serialize_versioned_transaction(
|
180
|
+
signed_transaction
|
181
|
+
),
|
182
|
+
)
|
183
|
+
|
184
|
+
return await self.execute(execute_request)
|
185
|
+
|
186
|
+
async def balances(self, address: str) -> dict[str, Any]:
|
187
|
+
"""
|
188
|
+
Get token balances of an account (asynchronous).
|
189
|
+
|
190
|
+
Args:
|
191
|
+
address (str): The public key of the account to get balances for.
|
192
|
+
|
193
|
+
Returns:
|
194
|
+
dict: The dict api response.
|
195
|
+
"""
|
196
|
+
url = f"{self.base_url}/ultra/v1/balances/{address}"
|
197
|
+
response = await self.client.get(url, headers=self._get_headers())
|
198
|
+
response.raise_for_status()
|
199
|
+
|
200
|
+
return response.json() # type: ignore[no-any-return]
|
201
|
+
|
202
|
+
async def shield(self, mints: list[str]) -> dict[str, Any]:
|
203
|
+
"""
|
204
|
+
Get token info and warnings for specific mints (asynchronous).
|
205
|
+
"""
|
206
|
+
params = {"mints": ",".join(mints)}
|
207
|
+
url = f"{self.base_url}/ultra/v1/shield"
|
208
|
+
response = await self.client.get(
|
209
|
+
url, params=params, headers=self._get_headers()
|
210
|
+
)
|
211
|
+
response.raise_for_status()
|
212
|
+
|
213
|
+
return response.json() # type: ignore[no-any-return]
|
File without changes
|
File without changes
|
@@ -0,0 +1,57 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
from urllib.parse import quote
|
3
|
+
|
4
|
+
|
5
|
+
class DexEnum(str, Enum):
|
6
|
+
WOOFI = "Woofi"
|
7
|
+
PUMP_FUN = "Pump.fun"
|
8
|
+
WHIRLPOOL = "Whirlpool"
|
9
|
+
VIRTUALS = "Virtuals"
|
10
|
+
DAOS_FUN = "Daos.fun"
|
11
|
+
LIFINITY_V2 = "Lifinity V2"
|
12
|
+
STABBLE_STABLE_SWAP = "Stabble Stable Swap"
|
13
|
+
TOKEN_MILL = "Token Mill" # noqa: S105
|
14
|
+
METEORA = "Meteora"
|
15
|
+
OASIS = "Oasis"
|
16
|
+
ALDRIN = "Aldrin"
|
17
|
+
GOOSEFX_GAMMA = "GooseFX GAMMA"
|
18
|
+
PERPS = "Perps"
|
19
|
+
SOLFI = "SolFi"
|
20
|
+
DEXLAB = "DexLab"
|
21
|
+
TOKEN_SWAP = "Token Swap" # noqa: S105
|
22
|
+
ZEROFI = "ZeroFi"
|
23
|
+
CROPPER = "Cropper"
|
24
|
+
OBRIC_V2 = "Obric V2"
|
25
|
+
STABBLE_WEIGHTED_SWAP = "Stabble Weighted Swap"
|
26
|
+
SANCTUM_INFINITY = "Sanctum Infinity"
|
27
|
+
MOONIT = "Moonit"
|
28
|
+
SANCTUM = "Sanctum"
|
29
|
+
RAYDIUM_CP = "Raydium CP"
|
30
|
+
PHOENIX = "Phoenix"
|
31
|
+
PUMP_FUN_AMM = "Pump.fun Amm"
|
32
|
+
SABER = "Saber"
|
33
|
+
SABER_DECIMALS = "Saber (Decimals)"
|
34
|
+
RAYDIUM_CLMM = "Raydium CLMM"
|
35
|
+
DEX_1 = "1DEX"
|
36
|
+
PENGUIN = "Penguin"
|
37
|
+
ORCA_V2 = "Orca V2"
|
38
|
+
FLUXBEAM = "FluxBeam"
|
39
|
+
RAYDIUM = "Raydium"
|
40
|
+
METEORA_DLMM = "Meteora DLMM"
|
41
|
+
BONKSWAP = "Bonkswap"
|
42
|
+
SOLAYER = "Solayer"
|
43
|
+
STEPN = "StepN"
|
44
|
+
HELIUM_NETWORK = "Helium Network"
|
45
|
+
MERCURIAL = "Mercurial"
|
46
|
+
PERENA = "Perena"
|
47
|
+
ORCA_V1 = "Orca V1"
|
48
|
+
ALDRIN_V2 = "Aldrin V2"
|
49
|
+
SAROS = "Saros"
|
50
|
+
OPENBOOK_V2 = "OpenBook V2"
|
51
|
+
CREMA = "Crema"
|
52
|
+
OPENBOOK = "Openbook"
|
53
|
+
INVARIANT = "Invariant"
|
54
|
+
GUACSWAP = "Guacswap"
|
55
|
+
|
56
|
+
def __str__(self) -> str:
|
57
|
+
return quote(self.value)
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from typing import Any
|
2
|
+
|
3
|
+
from pydantic import BaseModel
|
4
|
+
from pydantic.alias_generators import to_camel
|
5
|
+
|
6
|
+
|
7
|
+
class UltraExecuteRequest(BaseModel):
|
8
|
+
signed_transaction: str
|
9
|
+
request_id: str
|
10
|
+
|
11
|
+
def to_dict(self) -> dict[str, Any]:
|
12
|
+
params = self.model_dump(exclude_none=True)
|
13
|
+
|
14
|
+
camel_case_params = {to_camel(key): value for key, value in params.items()}
|
15
|
+
|
16
|
+
return camel_case_params
|
@@ -0,0 +1,20 @@
|
|
1
|
+
from typing import Any, Optional
|
2
|
+
|
3
|
+
from pydantic import BaseModel
|
4
|
+
from pydantic.alias_generators import to_camel
|
5
|
+
|
6
|
+
|
7
|
+
class UltraOrderRequest(BaseModel):
|
8
|
+
input_mint: str
|
9
|
+
output_mint: str
|
10
|
+
amount: int
|
11
|
+
taker: Optional[str] = None
|
12
|
+
referral_account: Optional[str] = None
|
13
|
+
referral_fee: Optional[int] = None
|
14
|
+
|
15
|
+
def to_dict(self) -> dict[str, Any]:
|
16
|
+
params = self.model_dump(exclude_none=True)
|
17
|
+
|
18
|
+
camel_case_params = {to_camel(key): value for key, value in params.items()}
|
19
|
+
|
20
|
+
return camel_case_params
|
@@ -0,0 +1,158 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: solanab-jup-python-sdk
|
3
|
+
Version: 2.0.3
|
4
|
+
Summary: High-performance sync/async Python SDK for Jupiter Exchange APIs, powered by curl_cffi.
|
5
|
+
Project-URL: homepage, https://github.com/solanab/jup-python-sdk
|
6
|
+
Project-URL: repository, https://github.com/solanab/jup-python-sdk
|
7
|
+
Author-email: Fiji <charismoutafidis@gmail.com>, solanab <whiredj@gmail.com>
|
8
|
+
License: MIT
|
9
|
+
License-File: LICENSE
|
10
|
+
Keywords: jupiter,sdk,solana
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Requires-Python: >=3.9
|
14
|
+
Requires-Dist: base58>=2.1.1
|
15
|
+
Requires-Dist: curl-cffi>=0.12
|
16
|
+
Requires-Dist: pydantic>=2.11.3
|
17
|
+
Requires-Dist: solana>=0.36.6
|
18
|
+
Requires-Dist: solders>=0.26.0
|
19
|
+
Provides-Extra: dev
|
20
|
+
Requires-Dist: bandit>=1.7; extra == 'dev'
|
21
|
+
Requires-Dist: black>=25.1.0; extra == 'dev'
|
22
|
+
Requires-Dist: flake8>=7.1.1; extra == 'dev'
|
23
|
+
Requires-Dist: isort>=6.0.0; extra == 'dev'
|
24
|
+
Requires-Dist: mypy>=1.15.0; extra == 'dev'
|
25
|
+
Requires-Dist: pre-commit>=4.1.0; extra == 'dev'
|
26
|
+
Requires-Dist: pytest-asyncio>=0.23.7; extra == 'dev'
|
27
|
+
Requires-Dist: pytest-cov>=6.1.1; extra == 'dev'
|
28
|
+
Requires-Dist: pytest>=8.3.4; extra == 'dev'
|
29
|
+
Requires-Dist: python-dotenv>=1.1.0; extra == 'dev'
|
30
|
+
Requires-Dist: responses>=0.25.6; extra == 'dev'
|
31
|
+
Requires-Dist: safety>=2.3; extra == 'dev'
|
32
|
+
Description-Content-Type: text/markdown
|
33
|
+
|
34
|
+
# **Jup Python SDK**
|
35
|
+
|
36
|
+
A high-performance, async-first Python SDK for seamless interaction with the Jupiter Ultra API, powered by `curl_cffi` for maximum speed and flexibility.<br>
|
37
|
+
With Ultra API, you don't need to manage or connect to any RPC endpoints, or deal with complex configurations.<br>
|
38
|
+
Everything from getting quotes to transaction execution happens directly through a powerful API.<br>
|
39
|
+
|
40
|
+
Or as we like to say around here:<br>
|
41
|
+
**"RPCs are for NPCs."**
|
42
|
+
|
43
|
+
For a deeper understanding of the Ultra API, including its features and benefits, check out the [Ultra API Docs](https://dev.jup.ag/docs/ultra-api/).
|
44
|
+
|
45
|
+
## **Installation**
|
46
|
+
|
47
|
+
To install the SDK in your project, run:
|
48
|
+
```sh
|
49
|
+
pip install jup-python-sdk
|
50
|
+
```
|
51
|
+
|
52
|
+
## **Quick Start (Async)**
|
53
|
+
|
54
|
+
Below is a simple asynchronous example to fetch and execute an Ultra order.
|
55
|
+
|
56
|
+
```python
|
57
|
+
import asyncio
|
58
|
+
from dotenv import load_dotenv
|
59
|
+
from jup_python_sdk.clients.ultra_api_client import AsyncUltraApiClient
|
60
|
+
from jup_python_sdk.models.ultra_api.ultra_order_request_model import UltraOrderRequest
|
61
|
+
|
62
|
+
async def main():
|
63
|
+
load_dotenv()
|
64
|
+
# Note: For async client, methods are awaited.
|
65
|
+
client = AsyncUltraApiClient()
|
66
|
+
|
67
|
+
order_request = UltraOrderRequest(
|
68
|
+
input_mint="So11111111111111111111111111111111111111112", # WSOL
|
69
|
+
output_mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", # USDC
|
70
|
+
amount=10000000, # 0.01 WSOL
|
71
|
+
taker=await client.get_public_key(),
|
72
|
+
)
|
73
|
+
|
74
|
+
try:
|
75
|
+
client_response = await client.order_and_execute(order_request)
|
76
|
+
signature = str(client_response["signature"])
|
77
|
+
|
78
|
+
print("Order and Execute API Response:")
|
79
|
+
print(f" - Status: {client_response.get('status')}")
|
80
|
+
if client_response.get("status") == "Failed":
|
81
|
+
print(f" - Code: {client_response.get('code')}")
|
82
|
+
print(f" - Error: {client_response.get('error')}")
|
83
|
+
|
84
|
+
print(f" - Transaction Signature: {signature}")
|
85
|
+
print(f" - View on Solscan: https://solscan.io/tx/{signature}")
|
86
|
+
|
87
|
+
except Exception as e:
|
88
|
+
print("Error occurred while processing the swap:", str(e))
|
89
|
+
finally:
|
90
|
+
await client.close()
|
91
|
+
|
92
|
+
if __name__ == "__main__":
|
93
|
+
asyncio.run(main())
|
94
|
+
```
|
95
|
+
|
96
|
+
> **Note**: A synchronous client (`UltraApiClient`) is also available. See the [examples](./examples) folder for both sync and async usage.
|
97
|
+
|
98
|
+
## **Setup Instructions**
|
99
|
+
|
100
|
+
Before using the SDK, please ensure you have completed the following steps:
|
101
|
+
|
102
|
+
1. **Environment Variables**:
|
103
|
+
Set up your required environment variables.
|
104
|
+
The SDK supports both base58 string and uint8 array formats for your private key.
|
105
|
+
```sh
|
106
|
+
# Base58 format
|
107
|
+
export PRIVATE_KEY=your_base58_private_key_here
|
108
|
+
|
109
|
+
# OR as a uint8 array
|
110
|
+
export PRIVATE_KEY=[10,229,131,132,213,96,74,22,...]
|
111
|
+
```
|
112
|
+
|
113
|
+
> **Note**: `PRIVATE_KEY` can be either a base58-encoded string (default Solana format), or a uint8 array (e.g. `[181,99,240,...]`). The SDK will automatically detect and parse the format.
|
114
|
+
|
115
|
+
2. **Optional Configuration**:
|
116
|
+
Depending on your credentials and setup, you have a couple of options for initializing the `UltraApiClient`:
|
117
|
+
- **API Key**: Use an API key from [the Jupiter Portal](https://portal.jup.ag/onboard) for enhanced access. This will use the `https://api.jup.ag/` endpoint.
|
118
|
+
- **Custom Private Key Env Var**: Specify a different environment variable name for your private key.
|
119
|
+
|
120
|
+
```python
|
121
|
+
from jup_python_sdk.clients.ultra_api_client import AsyncUltraApiClient
|
122
|
+
|
123
|
+
client = AsyncUltraApiClient(
|
124
|
+
api_key="YOUR_API_KEY",
|
125
|
+
private_key_env_var="YOUR_CUSTOM_ENV_VAR"
|
126
|
+
)
|
127
|
+
```
|
128
|
+
|
129
|
+
## **Advanced Configuration (Proxies, Custom DNS)**
|
130
|
+
|
131
|
+
The SDK is built on `curl_cffi`, allowing you to pass any valid `curl_cffi` client parameter during initialization for advanced network control.
|
132
|
+
|
133
|
+
### Using a SOCKS5 Proxy
|
134
|
+
|
135
|
+
```python
|
136
|
+
from jup_python_sdk.clients.ultra_api_client import AsyncUltraApiClient
|
137
|
+
|
138
|
+
proxies = {"httpss": "socks5://user:pass@host:port"}
|
139
|
+
client = AsyncUltraApiClient(client_kwargs={"proxies": proxies, "impersonate": "chrome110"})
|
140
|
+
```
|
141
|
+
|
142
|
+
### Using Custom DNS Resolution
|
143
|
+
|
144
|
+
This is useful for bypassing local DNS caches or using a specialized DNS resolver.
|
145
|
+
|
146
|
+
```python
|
147
|
+
from jup_python_sdk.clients.ultra_api_client import AsyncUltraApiClient
|
148
|
+
|
149
|
+
# Tell the client to resolve jup.ag to a specific IP address
|
150
|
+
resolve_string = "jup.ag:443:1.2.3.4"
|
151
|
+
client = AsyncUltraApiClient(client_kwargs={"resolve": [resolve_string]})
|
152
|
+
```
|
153
|
+
|
154
|
+
## **Disclaimer**
|
155
|
+
|
156
|
+
🚨 **This project is actively worked on.**
|
157
|
+
While we don't expect breaking changes as the SDK evolves, we recommend you stay updated with the latest releases.
|
158
|
+
Any important updates will be announced in the [Discord server](https://discord.gg/jup).
|
@@ -0,0 +1,14 @@
|
|
1
|
+
jup_python_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
jup_python_sdk/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
jup_python_sdk/clients/jupiter_client.py,sha256=3zX4e9iEmLP5KqSzmHt2vrry4UVbAKLaKSir6HFLf-U,4607
|
4
|
+
jup_python_sdk/clients/ultra_api_client.py,sha256=jgNgf04bDSJxu8MY1oGRx3Bxemyy4B4y5eUuQBN61qA,6750
|
5
|
+
jup_python_sdk/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
jup_python_sdk/models/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
jup_python_sdk/models/common/dex_enum.py,sha256=javWWg5TTbPAVNhoBQJlaVEUlpTkwfin7SO4xGKToaI,1510
|
8
|
+
jup_python_sdk/models/ultra_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
jup_python_sdk/models/ultra_api/ultra_execute_request_model.py,sha256=jvoPgCa5QxUFuMmZ7brFPcAyQzU7WgxtnwXH1KgxIPM,403
|
10
|
+
jup_python_sdk/models/ultra_api/ultra_order_request_model.py,sha256=DSxQtLALHgHGwr5gw3Iu1fkg4LbydUUmEo-aHF55G4Y,534
|
11
|
+
solanab_jup_python_sdk-2.0.3.dist-info/METADATA,sha256=OoA0fmw4M3EEXukcMU_LcViHFLl-oa1_vxdc6U6fh2A,5992
|
12
|
+
solanab_jup_python_sdk-2.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
13
|
+
solanab_jup_python_sdk-2.0.3.dist-info/licenses/LICENSE,sha256=3va7FgUbc2istAEEchr1jkoUjBoSYPMkguY1BGuHt2U,1061
|
14
|
+
solanab_jup_python_sdk-2.0.3.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Fiji
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|