GithubHelp home page GithubHelp logo

thevolumegrid / jupiter-python-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 0xtaodev/jupiter-python-sdk

0.0 0.0 0.0 4.08 MB

Jupiter Python SDK is a Python library that allows you to use most of Jupiter features.

Home Page: https://pypi.org/project/jupiter-python-sdk/

jupiter-python-sdk's Introduction

๐Ÿ JUPITER PYTHON SDK ๐Ÿช





๐Ÿ“– Introduction

Jupiter Python SDK is a Python library that allows you to use most of Jupiter features.
It enables executing swaps, limit orders, DCA, swap pairs, tokens prices, fetching wallet infos, stats, data and more!
This library is using packages like: solana-py, solders, anchorpy.
There is documentation inside each function, however, you can access to the official Jupiter API 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.
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

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.
Otherwise, this is required, for instance, to open a DCA account or to close one.

You can set custom URLs for any self-hosted Jupiter APIs. Like the V6 Swap API or QuickNode's Metis API.

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

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=async_client,
    keypair=private_key,
    quote_api_url="https://quote-api.jup.ag/v6/quote?",
    swap_api_url="https://quote-api.jup.ag/v6/swap",
    open_order_api_url="https://jup.ag/api/limit/v1/createOrder",
    cancel_orders_api_url="https://jup.ag/api/limit/v1/cancelOrders",
    query_open_orders_api_url="https://jup.ag/api/limit/v1/openOrders?wallet=",
    query_order_history_api_url="https://jup.ag/api/limit/v1/orderHistory",
    query_trade_history_api_url="https://jup.ag/api/limit/v1/tradeHistory"
)


"""
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

- 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 ๐Ÿ’ธ
  • Price API
  • Wallet Transactions History

๐Ÿค 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.
Contact me for any inquiry, I will reach you as soon as possible.
Discord Twitter

๐Ÿ‘‘ 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.
SOLANA ADDRESS

AyWu89SjZBW1MzkxiREmgtyMKxSkS1zVy8Uo23RyLphX

jupiter-python-sdk's People

Contributors

0xtaodev avatar thomasvanderlinden avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.