jupiter-python-sdk


Namejupiter-python-sdk JSON
Version 0.0.2.0 PyPI version JSON
download
home_page
SummaryJupiter Python SDK
upload_time2024-02-10 17:14:40
maintainer
docs_urlNone
authorTaoDev
requires_python
licenseLICENSE.txt
keywords python solana jupiter dex trading sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
<div align="center">
    <h1>🐍 JUPITER PYTHON SDK 🪐</h1>
    <img src="https://github.com/0xTaoDev/jupiter-python-sdk/blob/main/images/jupiter-python-sdk-banner.png?raw=true" width="75%" height="75%">
</div>

---

<p align="center">
    <img src="https://img.shields.io/github/stars/0xtaodev/jupiter-python-sdk">
    <img src="https://img.shields.io/github/forks/0xtaodev/jupiter-python-sdk">
    <br>
    <img src="https://img.shields.io/github/issues/0xtaodev/jupiter-python-sdk">
    <img src="https://img.shields.io/github/issues-closed/0xtaodev/jupiter-python-sdk">
    <br>
    <img src="https://img.shields.io/github/languages/top/0xtaodev/jupiter-python-sdk">
    <img src="https://img.shields.io/github/last-commit/0xtaodev/jupiter-python-sdk">
    <br>
</p>

# 📖 Introduction
**Jupiter Python SDK** is a Python library that allows you to use most of **[Jupiter](https://jup.ag/) features**.<br>
It enables executing swaps, limit orders, DCA, swap pairs, tokens prices, fetching wallet infos, stats, data and more!<br>
This library is using packages like: [solana-py](https://github.com/michaelhly/solana-py), [solders](https://github.com/kevinheavey/solders), [anchorpy](https://github.com/kevinheavey/anchorpy).<br>
There is documentation inside each function, however, you can access to the [official Jupiter API](https://docs.jup.ag/docs) for more information.

# ⚠️ Disclaimer
**Please note that I'm not responsible for any loss of funds, damages, or other libailities resulting from the use of this software or any associated services.<br>
This tool is provided for educational purposes only and should not be used as financial advice, it is still in expiremental phase so use it at your own risk.**

# ✨ Quickstart

### 🛠️ Installation

```sh
pip install jupiter-python-sdk
```

### 📃 General Usage
**Providing the private key and RPC client is not mandatory if you only intend to execute functions for retrieving data.<br>
Otherwise, this is required, for instance, to open a DCA account or to close one.**

If you encounter ```ImportError: cannot import name 'sync_native' from 'spl.token.instructions``` error when trying to import Jupiter, Jupiter_DCA from jupiter_python_sdk.jupiter, follow these steps:
1. Go to https://github.com/michaelhly/solana-py/tree/master/src/spl/token and download ```instructions.py```
2. In your packages folder, replace ```spl/token/instructions.py``` with the one you just downloaded.

### Here is a code snippet on how to use the SDK
```py
import base58
import base64
import json

from solders import message
from solders.pubkey import Pubkey
from solders.keypair import Keypair
from solders.transaction import VersionedTransaction

from solana.rpc.types import TxOpts
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Processed

from jupiter_python_sdk.jupiter import Jupiter, Jupiter_DCA


private_key = Keypair.from_bytes(base58.b58decode(os.getenv("PRIVATE-KEY"))) # Private key as string
async_client = AsyncClient("SOLANA-RPC-ENDPOINT-URL")
jupiter = Jupiter(async_client, private_key)


"""
EXECUTE A SWAP
"""
transaction_data = await jupiter.swap(
    input_mint="So11111111111111111111111111111111111111112",
    output_mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    amount=5_000_000,
    slippage_bps=1,
)
# Returns str: serialized transactions to execute the swap.

raw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data))
signature = private_key.sign_message(message.to_bytes_versioned(raw_transaction.message))
signed_txn = VersionedTransaction.populate(raw_transaction.message, [signature])
opts = TxOpts(skip_preflight=False, preflight_commitment=Processed)
result = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)
transaction_id = json.loads(result.to_json())['result']
print(f"Transaction sent: https://explorer.solana.com/tx/{transaction_id}")


"""
OPEN LIMIT ORDER
"""
transaction_data = await jupiter.open_order(
    input_mint=So11111111111111111111111111111111111111112",
    output_mint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    in_amount=5_000_000,
    out_amount=100_000,
)
# Returns dict: {'transaction_data': serialized transactions to create the limit order, 'signature2': signature of the account that will be opened}

raw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data['transaction_data']))
signature = private_key.sign_message(message.to_bytes_versioned(raw_transaction.message))
signed_txn = VersionedTransaction.populate(raw_transaction.message, [signature, transaction_data['signature2']])
opts = TxOpts(skip_preflight=False, preflight_commitment=Processed)
result = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)
transaction_id = json.loads(result.to_json())['result']
print(f"Transaction sent: https://explorer.solana.com/tx/{transaction_id}")


"""
CREATE DCA ACCOUNT
"""
create_dca_account = await jupiter.dca.create_dca(
    input_mint=Pubkey.from_string("So11111111111111111111111111111111111111112"),
    output_mint=Pubkey.from_string("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),
    total_in_amount=5_000_000,
    in_amount_per_cycle=100_000,
    cycle_frequency=60,
    min_out_amount_per_cycle=0,
    max_out_amount_per_cycle=0,
    start=0
)
# Returns DCA Account Pubkey and transaction hash.


"""
CLOSE DCA ACCOUNT
"""
close_dca_account = await jupiter.dca.close_dca(
    dca_pubkey=Pubkey.from_string("45iYdjmFUHSJCQHnNpWNFF9AjvzRcsQUP9FDBvJCiNS1")
)
# Returns transaction hash.
```

### 📜 All available features
```py
- quote
- swap
- open_order
- cancel_orders
- create_dca
- close_dca
- fetch_user_dca_accounts
- fetch_dca_account_fills_history
- get_available_dca_tokens
- fetch_dca_data
- query_open_orders
- query_orders_history
- query_trades_history
- get_jupiter_stats
- get_token_price
- get_indexed_route_map
- get_tokens_list
- get_all_tickers
- get_all_swap_pairs
- get_swap_pairs
- get_token_stats_by_date
- program_id_to_label
```

# 📝 TO-DO
- [ ] Bridge 🌉
- [ ] Perpetual 💸

# 🤝 Contributions
If you are interesting in contributing, fork the repository and submit a pull request in order to merge your improvements into the main repository.<br>
Contact me for any inquiry, I will reach you as soon as possible.<br>
[![Discord](https://img.shields.io/badge/Discord-%237289DA.svg?logo=discord&logoColor=white)](https://discord.gg/QxwPGcXDp7)
[![Twitter](https://img.shields.io/badge/Twitter-%231DA1F2.svg?logo=Twitter&logoColor=white)](https://twitter.com/_TaoDev_)

# 👑 Donations
This project doesn't include platform fees. If you find value in it and would like to support its development, your donations are greatly appreciated.<br>
**SOLANA ADDRESS**
```sh
AyWu89SjZBW1MzkxiREmgtyMKxSkS1zVy8Uo23RyLphX
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "jupiter-python-sdk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,solana,jupiter,dex,trading,sdk",
    "author": "TaoDev",
    "author_email": "taodev3@proton.me",
    "download_url": "https://files.pythonhosted.org/packages/a4/e1/71f95b23bca701642a6e0bf2ffca218ffad323265b53839c79ed147b1883/jupiter-python-sdk-0.0.2.0.tar.gz",
    "platform": null,
    "description": "\r\n<div align=\"center\">\r\n    <h1>\ud83d\udc0d JUPITER PYTHON SDK \ud83e\ude90</h1>\r\n    <img src=\"https://github.com/0xTaoDev/jupiter-python-sdk/blob/main/images/jupiter-python-sdk-banner.png?raw=true\" width=\"75%\" height=\"75%\">\r\n</div>\r\n\r\n---\r\n\r\n<p align=\"center\">\r\n    <img src=\"https://img.shields.io/github/stars/0xtaodev/jupiter-python-sdk\">\r\n    <img src=\"https://img.shields.io/github/forks/0xtaodev/jupiter-python-sdk\">\r\n    <br>\r\n    <img src=\"https://img.shields.io/github/issues/0xtaodev/jupiter-python-sdk\">\r\n    <img src=\"https://img.shields.io/github/issues-closed/0xtaodev/jupiter-python-sdk\">\r\n    <br>\r\n    <img src=\"https://img.shields.io/github/languages/top/0xtaodev/jupiter-python-sdk\">\r\n    <img src=\"https://img.shields.io/github/last-commit/0xtaodev/jupiter-python-sdk\">\r\n    <br>\r\n</p>\r\n\r\n# \ud83d\udcd6 Introduction\r\n**Jupiter Python SDK** is a Python library that allows you to use most of **[Jupiter](https://jup.ag/) features**.<br>\r\nIt enables executing swaps, limit orders, DCA, swap pairs, tokens prices, fetching wallet infos, stats, data and more!<br>\r\nThis library is using packages like: [solana-py](https://github.com/michaelhly/solana-py), [solders](https://github.com/kevinheavey/solders), [anchorpy](https://github.com/kevinheavey/anchorpy).<br>\r\nThere is documentation inside each function, however, you can access to the [official Jupiter API](https://docs.jup.ag/docs) for more information.\r\n\r\n# \u26a0\ufe0f Disclaimer\r\n**Please note that I'm not responsible for any loss of funds, damages, or other libailities resulting from the use of this software or any associated services.<br>\r\nThis tool is provided for educational purposes only and should not be used as financial advice, it is still in expiremental phase so use it at your own risk.**\r\n\r\n# \u2728 Quickstart\r\n\r\n### \ud83d\udee0\ufe0f Installation\r\n\r\n```sh\r\npip install jupiter-python-sdk\r\n```\r\n\r\n### \ud83d\udcc3 General Usage\r\n**Providing the private key and RPC client is not mandatory if you only intend to execute functions for retrieving data.<br>\r\nOtherwise, this is required, for instance, to open a DCA account or to close one.**\r\n\r\nIf you encounter ```ImportError: cannot import name 'sync_native' from 'spl.token.instructions``` error when trying to import Jupiter, Jupiter_DCA from jupiter_python_sdk.jupiter, follow these steps:\r\n1. Go to https://github.com/michaelhly/solana-py/tree/master/src/spl/token and download ```instructions.py```\r\n2. In your packages folder, replace ```spl/token/instructions.py``` with the one you just downloaded.\r\n\r\n### Here is a code snippet on how to use the SDK\r\n```py\r\nimport base58\r\nimport base64\r\nimport json\r\n\r\nfrom solders import message\r\nfrom solders.pubkey import Pubkey\r\nfrom solders.keypair import Keypair\r\nfrom solders.transaction import VersionedTransaction\r\n\r\nfrom solana.rpc.types import TxOpts\r\nfrom solana.rpc.async_api import AsyncClient\r\nfrom solana.rpc.commitment import Processed\r\n\r\nfrom jupiter_python_sdk.jupiter import Jupiter, Jupiter_DCA\r\n\r\n\r\nprivate_key = Keypair.from_bytes(base58.b58decode(os.getenv(\"PRIVATE-KEY\"))) # Private key as string\r\nasync_client = AsyncClient(\"SOLANA-RPC-ENDPOINT-URL\")\r\njupiter = Jupiter(async_client, private_key)\r\n\r\n\r\n\"\"\"\r\nEXECUTE A SWAP\r\n\"\"\"\r\ntransaction_data = await jupiter.swap(\r\n    input_mint=\"So11111111111111111111111111111111111111112\",\r\n    output_mint=\"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\r\n    amount=5_000_000,\r\n    slippage_bps=1,\r\n)\r\n# Returns str: serialized transactions to execute the swap.\r\n\r\nraw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data))\r\nsignature = private_key.sign_message(message.to_bytes_versioned(raw_transaction.message))\r\nsigned_txn = VersionedTransaction.populate(raw_transaction.message, [signature])\r\nopts = TxOpts(skip_preflight=False, preflight_commitment=Processed)\r\nresult = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)\r\ntransaction_id = json.loads(result.to_json())['result']\r\nprint(f\"Transaction sent: https://explorer.solana.com/tx/{transaction_id}\")\r\n\r\n\r\n\"\"\"\r\nOPEN LIMIT ORDER\r\n\"\"\"\r\ntransaction_data = await jupiter.open_order(\r\n    input_mint=So11111111111111111111111111111111111111112\",\r\n    output_mint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\r\n    in_amount=5_000_000,\r\n    out_amount=100_000,\r\n)\r\n# Returns dict: {'transaction_data': serialized transactions to create the limit order, 'signature2': signature of the account that will be opened}\r\n\r\nraw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data['transaction_data']))\r\nsignature = private_key.sign_message(message.to_bytes_versioned(raw_transaction.message))\r\nsigned_txn = VersionedTransaction.populate(raw_transaction.message, [signature, transaction_data['signature2']])\r\nopts = TxOpts(skip_preflight=False, preflight_commitment=Processed)\r\nresult = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)\r\ntransaction_id = json.loads(result.to_json())['result']\r\nprint(f\"Transaction sent: https://explorer.solana.com/tx/{transaction_id}\")\r\n\r\n\r\n\"\"\"\r\nCREATE DCA ACCOUNT\r\n\"\"\"\r\ncreate_dca_account = await jupiter.dca.create_dca(\r\n    input_mint=Pubkey.from_string(\"So11111111111111111111111111111111111111112\"),\r\n    output_mint=Pubkey.from_string(\"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\"),\r\n    total_in_amount=5_000_000,\r\n    in_amount_per_cycle=100_000,\r\n    cycle_frequency=60,\r\n    min_out_amount_per_cycle=0,\r\n    max_out_amount_per_cycle=0,\r\n    start=0\r\n)\r\n# Returns DCA Account Pubkey and transaction hash.\r\n\r\n\r\n\"\"\"\r\nCLOSE DCA ACCOUNT\r\n\"\"\"\r\nclose_dca_account = await jupiter.dca.close_dca(\r\n    dca_pubkey=Pubkey.from_string(\"45iYdjmFUHSJCQHnNpWNFF9AjvzRcsQUP9FDBvJCiNS1\")\r\n)\r\n# Returns transaction hash.\r\n```\r\n\r\n### \ud83d\udcdc All available features\r\n```py\r\n- quote\r\n- swap\r\n- open_order\r\n- cancel_orders\r\n- create_dca\r\n- close_dca\r\n- fetch_user_dca_accounts\r\n- fetch_dca_account_fills_history\r\n- get_available_dca_tokens\r\n- fetch_dca_data\r\n- query_open_orders\r\n- query_orders_history\r\n- query_trades_history\r\n- get_jupiter_stats\r\n- get_token_price\r\n- get_indexed_route_map\r\n- get_tokens_list\r\n- get_all_tickers\r\n- get_all_swap_pairs\r\n- get_swap_pairs\r\n- get_token_stats_by_date\r\n- program_id_to_label\r\n```\r\n\r\n# \ud83d\udcdd TO-DO\r\n- [ ] Bridge \ud83c\udf09\r\n- [ ] Perpetual \ud83d\udcb8\r\n\r\n# \ud83e\udd1d Contributions\r\nIf you are interesting in contributing, fork the repository and submit a pull request in order to merge your improvements into the main repository.<br>\r\nContact me for any inquiry, I will reach you as soon as possible.<br>\r\n[![Discord](https://img.shields.io/badge/Discord-%237289DA.svg?logo=discord&logoColor=white)](https://discord.gg/QxwPGcXDp7)\r\n[![Twitter](https://img.shields.io/badge/Twitter-%231DA1F2.svg?logo=Twitter&logoColor=white)](https://twitter.com/_TaoDev_)\r\n\r\n# \ud83d\udc51 Donations\r\nThis project doesn't include platform fees. If you find value in it and would like to support its development, your donations are greatly appreciated.<br>\r\n**SOLANA ADDRESS**\r\n```sh\r\nAyWu89SjZBW1MzkxiREmgtyMKxSkS1zVy8Uo23RyLphX\r\n```\r\n",
    "bugtrack_url": null,
    "license": "LICENSE.txt",
    "summary": "Jupiter Python SDK",
    "version": "0.0.2.0",
    "project_urls": null,
    "split_keywords": [
        "python",
        "solana",
        "jupiter",
        "dex",
        "trading",
        "sdk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "814807637b43b7ef65ab4ae03f8133853e29f54e368ab4e6f286bc925e112733",
                "md5": "82efd1cbc5fb438add694eeb78d34e66",
                "sha256": "a4fc7bd3cd663c9bb9f35a1710555e9392ebe48ca0417c16fe8a701b28777a00"
            },
            "downloads": -1,
            "filename": "jupiter_python_sdk-0.0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "82efd1cbc5fb438add694eeb78d34e66",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 19360,
            "upload_time": "2024-02-10T17:14:38",
            "upload_time_iso_8601": "2024-02-10T17:14:38.703965Z",
            "url": "https://files.pythonhosted.org/packages/81/48/07637b43b7ef65ab4ae03f8133853e29f54e368ab4e6f286bc925e112733/jupiter_python_sdk-0.0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4e171f95b23bca701642a6e0bf2ffca218ffad323265b53839c79ed147b1883",
                "md5": "5a860aa0e149905c79e65c3f80efb260",
                "sha256": "5e055106f62cdbe33e7867bbcfcab8b15486be92543555b40dc84113685551f6"
            },
            "downloads": -1,
            "filename": "jupiter-python-sdk-0.0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5a860aa0e149905c79e65c3f80efb260",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21793,
            "upload_time": "2024-02-10T17:14:40",
            "upload_time_iso_8601": "2024-02-10T17:14:40.443780Z",
            "url": "https://files.pythonhosted.org/packages/a4/e1/71f95b23bca701642a6e0bf2ffca218ffad323265b53839c79ed147b1883/jupiter-python-sdk-0.0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-10 17:14:40",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "jupiter-python-sdk"
}
        
Elapsed time: 0.52371s