leq6c / soldexpy

Experimental Python toolkit to work with Raydium by using RPC only.
34 stars 16 forks source link

Token Address instead of Pool Address? #1

Closed Allen-Taylor closed 5 months ago

Allen-Taylor commented 5 months ago

First, THANK YOU for this.

I was trading via Jupiter Quote/Swap API, but it doesn't handle low liquidity tokens.

One suggestion - it would be good to include a "helper" function that fetches the pool address based on the token address.

This is how I was doing it. I don't know if you can make another method via the RPCs that you use.

People usually trade by the token addresses.

Also, how did you figure how to construct the swaps instructions?

Thanks.

import requests

def get_pool_address(token_address):
    url = f"https://api.dexscreener.com/latest/dex/search?q={token_address}"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0",
        "Accept": "*/*",
        "Accept-Language": "en-US,en;q=0.5",
        "Accept-Encoding": "gzip, deflate, br",
        "Connection": "keep-alive",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "cross-site"
    }

    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        return response.json()['pairs'][0]['pairAddress']
    else:
        return None

pair_address = get_pool_address("some_token_address")
print(pair_address)
leq6c commented 5 months ago

@Allen-Taylor Most of uses may want that kind of things but this project aims to exclude any 3rd party api dependencies and I think it's difficult to get a proper pool instantly by using the token address with Solana mainnet RPC.

Thanks for the suggestion though.