I'm currently on a project that makes me need to do a swap transaction between SOL and a specific token (specifying the token's address) through raydium, and we are using python to build this interface. Would it be possible to perform this swap operation using Python code? Do you have any example code, SDK or lib available for this?
2 Answers
Basic Steps:
- Import pool keys from here.
- Create instruction with imported pool keys and get Associated token accounts or the token account or create a wrapped solana account.
- Create close WSOL acocunt instructions
- Create a transaction e.g. txn = Transaction()
- Pass the instructions
- Sign the txn
- SendTransaction and confirm
More information about the swap can be found in raydium sdk which is in Typescript or you can read through my code for raydium swap but its not well organized or so called clean code.
Main issues with raydium swap from my experience, if you are trying to retrieve pool keys simultaneously in multiple threads for multiple coins, the api.raydium.io will rate limit you and it takes long time to get the keys due to which transaction execution time is to infinity and beyond.
-
Thanks friend! I will try your code! I noticed you are building a sniping bot, that looks interesting. Do you have any means of contact like Telegram that you can share? I'm also a programmer and I have some good contacts, I believe we can think about some degen things together Commented Dec 28, 2023 at 12:57
-
-
I went through the same struggle some time ago. I try to find the good method to perform with Raydium swap with only python package but I couldn't find it. So I implemented it with node.js and run command "node swap_raydium.js arg1 arg2" with python. Is this helpful with your issue?