A high-performance Python SDK for low-latency Solana DEX trading bots. Built for speed and efficiency, it enables seamless, high-throughput interaction with PumpFun, Pump AMM (PumpSwap), Bonk, Meteora DAMM v2, Raydium AMM v4, and Raydium CPMM for latency-critical trading strategies.
δΈζ | English | Website | Telegram | Discord
- β¨ Features
- π¦ Installation
- π οΈ Usage Examples
- π° Cashback Support (PumpFun / PumpSwap)
- π‘οΈ MEV Protection Services
- π Project Structure
- π License
- π¬ Contact
β οΈ Important Notes
This SDK is available in multiple languages:
| Language | Repository | Description |
|---|---|---|
| Rust | sol-trade-sdk | Ultra-low latency with zero-copy optimization |
| Node.js | sol-trade-sdk-nodejs | TypeScript/JavaScript for Node.js |
| Python | sol-trade-sdk-python | Async/await native support |
| Go | sol-trade-sdk-golang | Concurrent-safe with goroutine support |
- PumpFun Trading: Support for
buyandselloperations - PumpSwap Trading: Support for PumpSwap pool trading operations
- Bonk Trading: Support for Bonk trading operations
- Raydium CPMM Trading: Support for Raydium CPMM (Concentrated Pool Market Maker) trading operations
- Raydium AMM V4 Trading: Support for Raydium AMM V4 (Automated Market Maker) trading operations
- Meteora DAMM V2 Trading: Support for Meteora DAMM V2 (Dynamic AMM) trading operations
- Multiple MEV Protection: Support for Jito, Nextblock, ZeroSlot, Temporal, Bloxroute, FlashBlock, BlockRazor, Node1, Astralane and other services
- Concurrent Trading: Send transactions using multiple MEV services simultaneously; the fastest succeeds while others fail
- Unified Trading Interface: Use unified trading protocol types for trading operations
- Middleware System: Support for custom instruction middleware to modify, add, or remove instructions before transaction execution
- Shared Infrastructure: Share expensive RPC and SWQoS clients across multiple wallets for reduced resource usage
Clone this project to your project directory:
cd your_project_root_directory
git clone https://github.com/0xfnzero/sol-trade-sdk-pythonInstall dependencies:
cd sol-trade-sdk-python
pip install -e .Or add to your requirements.txt:
sol-trade-sdk @ ./sol-trade-sdk-python
Or add to your pyproject.toml:
[project]
dependencies = [
"sol-trade-sdk @ ./sol-trade-sdk-python",
]pip install sol-trade-sdkYou can refer to Example: Create TradingClient Instance.
Method 1: Simple (single wallet)
import asyncio
from sol_trade_sdk import TradingClient, TradeConfig, SwqosConfig, SwqosRegion
async def main():
# Wallet
payer = Keypair.from_secret_key(/* your keypair */)
# RPC URL
rpc_url = "https://mainnet.helius-rpc.com/?api-key=xxxxxx"
# Multiple SWQoS services can be configured
swqos_configs = [
SwqosConfig(type="Default", rpc_url=rpc_url),
SwqosConfig(type="Jito", uuid="your_uuid", region=SwqosRegion.FRANKFURT),
SwqosConfig(type="Bloxroute", api_token="your_api_token", region=SwqosRegion.FRANKFURT),
SwqosConfig(type="Astralane", api_key="your_api_key", region=SwqosRegion.FRANKFURT),
]
# Create TradeConfig instance
trade_config = TradeConfig(rpc_url, swqos_configs)
# Create TradingClient
client = TradingClient(payer, trade_config)
asyncio.run(main())Method 2: Shared infrastructure (multiple wallets)
For multi-wallet scenarios, create the infrastructure once and share it across wallets. See Example: Shared Infrastructure.
from sol_trade_sdk import TradingInfrastructure, InfrastructureConfig
# Create infrastructure once (expensive)
infra_config = InfrastructureConfig(rpc_url, swqos_configs)
infrastructure = TradingInfrastructure(infra_config)
# Create multiple clients sharing the same infrastructure (fast)
client1 = TradingClient.from_infrastructure(payer1, infrastructure)
client2 = TradingClient.from_infrastructure(payer2, infrastructure)from sol_trade_sdk import GasFeeStrategy
# Create GasFeeStrategy instance
gas_fee_strategy = GasFeeStrategy()
# Set global strategy
gas_fee_strategy.set_global_fee_strategy(150000, 150000, 500000, 500000, 0.001, 0.001)from sol_trade_sdk import TradeBuyParams, DexType, TradeTokenType
buy_params = TradeBuyParams(
dex_type=DexType.PUMPSWAP,
input_token_type=TradeTokenType.WSOL,
mint=mint_pubkey,
input_token_amount=buy_sol_amount,
slippage_basis_points=500,
recent_blockhash=recent_blockhash,
# Use extension_params for protocol-specific parameters
extension_params={"type": "PumpSwap", "params": pumpswap_params},
address_lookup_table_account=None,
wait_transaction_confirmed=True,
create_input_token_ata=True,
close_input_token_ata=True,
create_mint_ata=True,
durable_nonce=None,
fixed_output_token_amount=None,
gas_fee_strategy=gas_fee_strategy,
simulate=False,
)result = await client.buy(buy_params)
print(f"Transaction signature: {result.signature}")For comprehensive information about all trading parameters including TradeBuyParams and TradeSellParams, see the Trading Parameters documentation.
When using shred to subscribe to events, due to the nature of shreds, you cannot get complete information about transaction events. Please ensure that the parameters your trading logic depends on are available in shreds when using them.
| Description | Run Command | Source Code |
|---|---|---|
| Create and configure TradingClient instance | python examples/trading_client.py |
examples/trading_client.py |
| Share infrastructure across multiple wallets | python examples/shared_infrastructure.py |
examples/shared_infrastructure.py |
| PumpFun token sniping trading | python examples/pumpfun_sniper_trading.py |
examples/pumpfun_sniper_trading.py |
| PumpFun token copy trading | python examples/pumpfun_copy_trading.py |
examples/pumpfun_copy_trading.py |
| PumpSwap trading operations | python examples/pumpswap_trading.py |
examples/pumpswap_trading.py |
| PumpSwap direct trading (via RPC) | python examples/pumpswap_direct_trading.py |
examples/pumpswap_direct_trading.py |
| Raydium CPMM trading operations | python examples/raydium_cpmm_trading.py |
examples/raydium_cpmm_trading.py |
| Raydium AMM V4 trading operations | python examples/raydium_amm_v4_trading.py |
examples/raydium_amm_v4_trading.py |
| Meteora DAMM V2 trading operations | python examples/meteora_damm_v2_trading.py |
examples/meteora_damm_v2_trading.py |
| Bonk token sniping trading | python examples/bonk_sniper_trading.py |
examples/bonk_sniper_trading.py |
| Bonk token copy trading | python examples/bonk_copy_trading.py |
examples/bonk_copy_trading.py |
| Custom instruction middleware example | python examples/middleware_system.py |
examples/middleware_system.py |
| Address lookup table example | python examples/address_lookup.py |
examples/address_lookup.py |
| Nonce cache (durable nonce) example | python examples/nonce_cache.py |
examples/nonce_cache.py |
| Wrap/unwrap SOL to/from WSOL example | python examples/wsol_wrapper.py |
examples/wsol_wrapper.py |
| Seed trading example | python examples/seed_trading.py |
examples/seed_trading.py |
| Gas fee strategy example | python examples/gas_fee_strategy.py |
examples/gas_fee_strategy.py |
| Hot path trading (zero-RPC) | python examples/hot_path_trading.py |
examples/hot_path_trading.py |
When configuring SWQoS services, note the different parameter requirements for each service:
- Jito: The first parameter is UUID (if no UUID, pass an empty string
"") - Other MEV services: The first parameter is the API Token
Each SWQoS service supports an optional custom URL parameter:
# Using custom URL
jito_config = SwqosConfig(
type="Jito",
uuid="your_uuid",
region=SwqosRegion.FRANKFURT,
custom_url="https://custom-jito-endpoint.com"
)
# Using default regional endpoint
bloxroute_config = SwqosConfig(
type="Bloxroute",
api_token="your_api_token",
region=SwqosRegion.NEW_YORK
)URL Priority Logic:
- If a custom URL is provided, it will be used instead of the regional endpoint
- If no custom URL is provided, the system will use the default endpoint for the specified region
- This allows for maximum flexibility while maintaining backward compatibility
When using multiple MEV services, you need to use Durable Nonce. You need to use the fetch_nonce_info function to get the latest nonce value, and use it as the durable_nonce when trading.
The SDK provides a powerful middleware system that allows you to modify, add, or remove instructions before transaction execution. Middleware executes in the order they are added:
from sol_trade_sdk import MiddlewareManager
manager = MiddlewareManager() \
.add_middleware(FirstMiddleware()) \
.add_middleware(SecondMiddleware()) \
.add_middleware(ThirdMiddleware())Address Lookup Tables (ALT) allow you to optimize transaction size and reduce fees by storing frequently used addresses in a compact table format.
from sol_trade_sdk import fetch_address_lookup_table_account, AddressLookupTableCache
# Fetch ALT from chain
alt = await fetch_address_lookup_table_account(rpc, alt_address)
print(f"ALT contains {len(alt.addresses)} addresses")
# Use cache for performance
cache = AddressLookupTableCache(rpc)
await cache.prefetch([alt_address1, alt_address2, alt_address3])
cached = cache.get(alt_address1)Use Durable Nonce to implement transaction replay protection and optimize transaction processing.
from sol_trade_sdk import fetch_nonce_info, NonceCache
# Fetch nonce info
nonce_info = await fetch_nonce_info(rpc, nonce_account)PumpFun and PumpSwap support cashback for eligible tokens: part of the trading fee can be returned to the user. The SDK must know whether the token has cashback enabled so that buy/sell instructions include the correct accounts.
- When params come from RPC: If you use
PumpFunParams.from_mint_by_rpcorPumpSwapParams.from_pool_address_by_rpc, the SDK readsis_cashback_coinfrom chainβno extra step. - When params come from event/parser: If you build params from trade events (e.g. sol-parser-sdk), you must pass the cashback flag into the SDK:
- PumpFun: Set
is_cashback_coinwhen building params from parsed events. - PumpSwap: Set
is_cashback_coinfield when constructing params manually.
- PumpFun: Set
You can apply for a key through the official website: Community Website
- Jito: High-performance block space
- ZeroSlot: Zero-latency transactions
- Temporal: Time-sensitive transactions
- Bloxroute: Blockchain network acceleration
- FlashBlock: High-speed transaction execution with API key authentication
- BlockRazor: High-speed transaction execution with API key authentication
- Node1: High-speed transaction execution with API key authentication
- Astralane: Blockchain network acceleration
src/
βββ common/ # Common functionality and tools
βββ constants/ # Constant definitions
βββ instruction/ # Instruction building
β βββ utils/ # Instruction utilities
βββ swqos/ # MEV service clients
βββ trading/ # Unified trading engine
β βββ common/ # Common trading tools
β βββ core/ # Core trading engine
β βββ middleware/ # Middleware system
β βββ factory.py # Trading factory
βββ utils/ # Utility functions
β βββ calc/ # Amount calculation utilities
β βββ price/ # Price calculation utilities
βββ __init__.py # Main library file
MIT License
- Official Website: https://fnzero.dev/
- Project Repository: https://github.com/0xfnzero/sol-trade-sdk-python
- Telegram Group: https://t.me/fnzero_group
- Discord: https://discord.gg/vuazbGkqQE
- Test thoroughly before using on mainnet
- Properly configure private keys and API tokens
- Pay attention to slippage settings to avoid transaction failures
- Monitor balances and transaction fees
- Comply with relevant laws and regulations