Interaction¶
cyhole.jupiter.Jupiter
¶
Jupiter(headers: Any | None = None)
Bases: Interaction
Class used to connect Jupiter API, one of them most popular Solana DEX. To have access Jupiter API is not required an API key.
Check https://station.jup.ag/docs/api for all the details on the available endpoints.
Example
import asyncio
from cyhole.jupiter import Jupiter
from cyhole.core.token.solana import JUP
jupiter = Jupiter()
# Get current price of JUP on Solana
# synchronous
response = jupiter.client.get_price([JUP.address])
print("Current JUP/USDC:", response.data[JUP.address].price)
# asynchronous
async def main() -> None:
async with jupiter.async_client as client:
response = await client.get_price([JUP.address])
print("Current JUP/USDC:", response.data[JUP.address].price)
asyncio.run(main())
Source code in src/cyhole/jupiter/interaction.py
66 67 68 69 70 71 72 73 74 75 76 77 78 | |
_get_price
¶
_get_price(
sync: Literal[True],
address: list[str],
extra_info: bool = False,
vs_address: str | None = None,
) -> GetPriceResponse
_get_price(
sync: Literal[False],
address: list[str],
extra_info: bool = False,
vs_address: str | None = None,
) -> Coroutine[None, None, GetPriceResponse]
_get_price(
sync: bool,
address: list[str],
extra_info: bool = False,
vs_address: str | None = None,
) -> (
GetPriceResponse
| Coroutine[None, None, GetPriceResponse]
)
This function refers to the GET Price API endpoint, and it is used to get the current price of a list of tokens on Solana chain with respect to another token taken from Jupiter Swap.
The API returns the unit buy price for the tokens; by default, the price is provided according to
the value of USDC token. It is also possible to provide another comparison token in the request.
Info
Observe that when the token address or comparison token address are not found,
the response provided will have a data object with the token address as key and
the value will be None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
list[str]
|
list of tokens addresses to get the price.
For example, |
required |
extra_info
|
bool
|
flag to include extra information in the response
that could be useful fot analysis (e.g., last swap, current quote price).
More important, if activated, then |
False
|
vs_address
|
str | None
|
comparison token address.
Default Value: |
None
|
Returns:
| Type | Description |
|---|---|
GetPriceResponse | Coroutine[None, None, GetPriceResponse]
|
tokens' prices. |
Source code in src/cyhole/jupiter/interaction.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
_get_quote
¶
_get_quote(
sync: Literal[True], input: GetQuoteInput
) -> GetQuoteResponse
_get_quote(
sync: Literal[False], input: GetQuoteInput
) -> Coroutine[None, None, GetQuoteResponse]
_get_quote(
sync: bool, input: GetQuoteInput
) -> (
GetQuoteResponse
| Coroutine[None, None, GetQuoteResponse]
)
This function refers to the GET Quote API endpoint,
and it is used to get a quote for swapping a specific amount of tokens.
The function can be combined with the post_swap enpdpoint to implement a payment mechanism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
GetQuoteInput
|
an input schema used to describe the request. More details in the object definition. |
required |
Returns:
| Type | Description |
|---|---|
GetQuoteResponse | Coroutine[None, None, GetQuoteResponse]
|
Quote found by Jupiter API. |
Source code in src/cyhole/jupiter/interaction.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
_get_quote_tokens
¶
_get_quote_tokens(
sync: Literal[True],
) -> GetQuoteTokensResponse
_get_quote_tokens(
sync: Literal[False],
) -> Coroutine[None, None, GetQuoteTokensResponse]
_get_quote_tokens(
sync: bool,
) -> (
GetQuoteTokensResponse
| Coroutine[None, None, GetQuoteTokensResponse]
)
This function refers to the GET Quote Tokens API endpoint, and it is used to get the list of the current supported tradable tokens.
Returns:
| Type | Description |
|---|---|
GetQuoteTokensResponse | Coroutine[None, None, GetQuoteTokensResponse]
|
List of tradable tokens. |
Source code in src/cyhole/jupiter/interaction.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
_get_quote_program_id_label
¶
_get_quote_program_id_label(
sync: Literal[True],
) -> GetQuoteProgramIdLabelResponse
_get_quote_program_id_label(
sync: Literal[False],
) -> Coroutine[None, None, GetQuoteProgramIdLabelResponse]
_get_quote_program_id_label(
sync: bool,
) -> (
GetQuoteProgramIdLabelResponse
| Coroutine[None, None, GetQuoteProgramIdLabelResponse]
)
This function refers to the GET Quote Program ID to Label API endpoint, and it is used to get the list of supported DEXes to use in quote endpoint.
Returns:
| Type | Description |
|---|---|
GetQuoteProgramIdLabelResponse | Coroutine[None, None, GetQuoteProgramIdLabelResponse]
|
List of DEXs addresses and labels. |
Source code in src/cyhole/jupiter/interaction.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
_post_swap
¶
_post_swap(
sync: Literal[True], body: PostSwapBody
) -> PostSwapResponse
_post_swap(
sync: Literal[False], body: PostSwapBody
) -> Coroutine[None, None, PostSwapResponse]
_post_swap(
sync: bool, body: PostSwapBody
) -> (
PostSwapResponse
| Coroutine[None, None, PostSwapResponse]
)
This function refers to the POST Swap API endpoint,
and it is used to recive the transaction to perform the swap initialised from get_quote
endopoint for the desired pair.
The function should be combined with the get_quote endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
PostSwapBody
|
the body to sent to Jupiter API that describe the swap. More details in the object definition. |
required |
Returns:
| Type | Description |
|---|---|
PostSwapResponse | Coroutine[None, None, PostSwapResponse]
|
Transaction found by Jupiter API. |
Source code in src/cyhole/jupiter/interaction.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
_get_token_info
¶
_get_token_info(
sync: Literal[True], address: str
) -> GetTokenInfoResponse
_get_token_info(
sync: Literal[False], address: str
) -> Coroutine[None, None, GetTokenInfoResponse]
_get_token_info(
sync: bool, address: str
) -> (
GetTokenInfoResponse
| Coroutine[None, None, GetTokenInfoResponse]
)
This function refers to the GET Token API endpoint, with a specific focus on retrieving the information of a token given its address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
address of the token to check.
For example, |
required |
Returns:
| Type | Description |
|---|---|
GetTokenInfoResponse | Coroutine[None, None, GetTokenInfoResponse]
|
Information of the token. |
Source code in src/cyhole/jupiter/interaction.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
_get_token_market_mints
¶
_get_token_market_mints(
sync: Literal[True], address: str
) -> GetTokenMarketMintsResponse
_get_token_market_mints(
sync: Literal[False], address: str
) -> Coroutine[None, None, GetTokenMarketMintsResponse]
_get_token_market_mints(
sync: bool, address: str
) -> (
GetTokenMarketMintsResponse
| Coroutine[None, None, GetTokenMarketMintsResponse]
)
This function refers to the GET Token Market Mints API endpoint, and can be used to retrieve the list of token addresses that belong to a market/pool address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
address of the market/pool to check. |
required |
Returns:
| Type | Description |
|---|---|
GetTokenMarketMintsResponse | Coroutine[None, None, GetTokenMarketMintsResponse]
|
List of token addresses. |
Source code in src/cyhole/jupiter/interaction.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
_get_token_tagged
¶
_get_token_tagged(
sync: Literal[True], tag: str | JupiterTokenTagType
) -> GetTokenTaggedResponse
_get_token_tagged(
sync: Literal[False], tag: str | JupiterTokenTagType
) -> Coroutine[None, None, GetTokenTaggedResponse]
_get_token_tagged(
sync: bool, tag: str | JupiterTokenTagType
) -> (
GetTokenTaggedResponse
| Coroutine[None, None, GetTokenTaggedResponse]
)
This function refers to the GET Tagged Token API endpoint,
and it is used to retrieved the list of tokens eligible for trading, managed by Jupiter.
Choose the tokens list according to tag field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str | JupiterTokenTagType
|
Jupiter manages the tradable tokens through a set of tags in order to guarantee its
core values and provide a secure service. The supported tages are available on |
required |
Returns:
| Type | Description |
|---|---|
GetTokenTaggedResponse | Coroutine[None, None, GetTokenTaggedResponse]
|
List of Jupiter's tokens list. |
Source code in src/cyhole/jupiter/interaction.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
_get_token_new
¶
_get_token_new(
sync: Literal[True],
limit: int = 10,
offset: int | None = None,
) -> GetTokenNewResponse
_get_token_new(
sync: Literal[False],
limit: int = 10,
offset: int | None = None,
) -> Coroutine[None, None, GetTokenNewResponse]
_get_token_new(
sync: bool, limit: int = 10, offset: int | None = None
) -> (
GetTokenNewResponse
| Coroutine[None, None, GetTokenNewResponse]
)
This function refers to the GET New Token API endpoint, and it is used to retrieved the list of new tokens managed by Jupiter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
number of tokens to retrieve. |
10
|
offset
|
int | None
|
number of tokens to skip. |
None
|
Returns:
| Type | Description |
|---|---|
GetTokenNewResponse | Coroutine[None, None, GetTokenNewResponse]
|
List of Jupiter's tokens list. |
Source code in src/cyhole/jupiter/interaction.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
_post_limit_order_create
¶
_post_limit_order_create(
sync: Literal[True], body: PostLimitOrderCreateBody
) -> PostLimitOrderCreateResponse
_post_limit_order_create(
sync: Literal[False], body: PostLimitOrderCreateBody
) -> Coroutine[None, None, PostLimitOrderCreateResponse]
_post_limit_order_create(
sync: bool, body: PostLimitOrderCreateBody
) -> (
PostLimitOrderCreateResponse
| Coroutine[None, None, PostLimitOrderCreateResponse]
)
This function refers to the POST Limit Order - Create API endpoint, and it is used to receive the transaction to perform the creation of a Limit Order via Jupiter API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
PostLimitOrderCreateBody
|
the body to sent to Jupiter API that describe the swap. More details in the object definition. |
required |
Returns:
| Type | Description |
|---|---|
PostLimitOrderCreateResponse | Coroutine[None, None, PostLimitOrderCreateResponse]
|
Transaction created by Jupiter API. |
Source code in src/cyhole/jupiter/interaction.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
_post_limit_order_cancel
¶
_post_limit_order_cancel(
sync: Literal[True], body: PostLimitOrderCancelBody
) -> PostLimitOrderCancelResponse
_post_limit_order_cancel(
sync: Literal[False], body: PostLimitOrderCancelBody
) -> Coroutine[None, None, PostLimitOrderCancelResponse]
_post_limit_order_cancel(
sync: bool, body: PostLimitOrderCancelBody
) -> (
PostLimitOrderCancelResponse
| Coroutine[None, None, PostLimitOrderCancelResponse]
)
This function refers to the POST Limit Order - Cancel API endpoint, and it is used to receive the transaction to perform the cancellation of a Limit Order previously opened via Jupiter API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
PostLimitOrderCancelBody
|
the body to sent to Jupiter API that describe the limit order to cancel. More details in the object definition. |
required |
Returns:
| Type | Description |
|---|---|
PostLimitOrderCancelResponse | Coroutine[None, None, PostLimitOrderCancelResponse]
|
Transaction created by Jupiter API. |
Source code in src/cyhole/jupiter/interaction.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
_get_limit_order_open
¶
_get_limit_order_open(
sync: Literal[True],
wallet: str | None = None,
input_token: str | None = None,
output_token: str | None = None,
) -> GetLimitOrderOpenResponse
_get_limit_order_open(
sync: Literal[False],
wallet: str | None = None,
input_token: str | None = None,
output_token: str | None = None,
) -> Coroutine[None, None, GetLimitOrderOpenResponse]
_get_limit_order_open(
sync: bool,
wallet: str | None = None,
input_token: str | None = None,
output_token: str | None = None,
) -> (
GetLimitOrderOpenResponse
| Coroutine[None, None, GetLimitOrderOpenResponse]
)
This function refers to the GET Limit Order - Open API endpoint, and it is used to receive the current open limit orders related to a wallet, input token or output token via Jupiter API.
Observe that all the input parameters are optional; if for example, only the input_token is provided,
then all the limit orders having that input token address are returned (if available).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wallet
|
str | None
|
address of the wallet to check. |
None
|
input_token
|
str | None
|
address of the input token associated to the limit order. |
None
|
output_token
|
str | None
|
address of the output token associated to the limit order. |
None
|
Returns:
| Type | Description |
|---|---|
GetLimitOrderOpenResponse | Coroutine[None, None, GetLimitOrderOpenResponse]
|
Open limit orders created by Jupiter API. |
Source code in src/cyhole/jupiter/interaction.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
_get_limit_order_history
¶
_get_limit_order_history(
sync: Literal[True],
wallet: str,
cursor: int | None = None,
skip: int | None = None,
take: int | None = None,
) -> GetLimitOrderHistoryResponse
_get_limit_order_history(
sync: Literal[False],
wallet: str,
cursor: int | None = None,
skip: int | None = None,
take: int | None = None,
) -> Coroutine[None, None, GetLimitOrderHistoryResponse]
_get_limit_order_history(
sync: bool,
wallet: str,
cursor: int | None = None,
skip: int | None = None,
take: int | None = None,
) -> (
GetLimitOrderHistoryResponse
| Coroutine[None, None, GetLimitOrderHistoryResponse]
)
This function refers to the GET Limit Order - History API endpoint, and it is used to retrieve the history of Limit Orders associated to a wallet via Jupiter API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wallet
|
str
|
address of the wallet to check. |
required |
cursor
|
int | None
|
specify which 'page' of orders to return. |
None
|
skip
|
int | None
|
specify the number of order to skip (from the top). |
None
|
take
|
int | None
|
specify the number of orders to return. |
None
|
Returns:
| Type | Description |
|---|---|
GetLimitOrderHistoryResponse | Coroutine[None, None, GetLimitOrderHistoryResponse]
|
History of limit orders associated to the input wallet. |
Source code in src/cyhole/jupiter/interaction.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |
_get_limit_order_trade_history
¶
_get_limit_order_trade_history(
sync: Literal[True],
wallet: str | None = None,
input_token: str | None = None,
output_token: str | None = None,
cursor: int | None = None,
skip: int | None = None,
take: int | None = None,
) -> GetLimitOrderTradeHistoryResponse
_get_limit_order_trade_history(
sync: Literal[False],
wallet: str | None = None,
input_token: str | None = None,
output_token: str | None = None,
cursor: int | None = None,
skip: int | None = None,
take: int | None = None,
) -> Coroutine[
None, None, GetLimitOrderTradeHistoryResponse
]
_get_limit_order_trade_history(
sync: bool,
wallet: str | None = None,
input_token: str | None = None,
output_token: str | None = None,
cursor: int | None = None,
skip: int | None = None,
take: int | None = None,
) -> (
GetLimitOrderTradeHistoryResponse
| Coroutine[
None, None, GetLimitOrderTradeHistoryResponse
]
)
This function refers to the GET Limit Order - Trade History API endpoint, and it is used to retrieve the trades history related to Limit Orders extracted with specific requirements via Jupiter API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wallet
|
str | None
|
address of the wallet to check. |
None
|
input_token
|
str | None
|
address of the input token associated to the limit order. |
None
|
output_token
|
str | None
|
address of the output token associated to the limit order. |
None
|
cursor
|
int | None
|
specify which 'page' of orders to return. |
None
|
skip
|
int | None
|
specify the number of order to skip (from the top). |
None
|
take
|
int | None
|
specify the number of orders to return. |
None
|
Returns:
| Type | Description |
|---|---|
GetLimitOrderTradeHistoryResponse | Coroutine[None, None, GetLimitOrderTradeHistoryResponse]
|
Hostory of limit orders associated to the input wallet. |
Source code in src/cyhole/jupiter/interaction.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
_raise
¶
_raise(exception: HTTPError) -> JupiterException
Internal function used to raise the correct Jupiter exception according to the error code provided by the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exception
|
HTTPError
|
the HTTP error returned from Jupiter API. |
required |
Raises:
| Type | Description |
|---|---|
JupiterNoRouteFoundError
|
for error code |
JupiterInvalidRequest
|
for error code |
JupiterException
|
general exception raised when an unknown error code is found or a different error is found. |
Source code in src/cyhole/jupiter/interaction.py
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 | |