| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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
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 |
sol-trade-sdk-python brings the FnZero Solana trading SDK to Python. It is built for async trading bots, copy-trading pipelines, sniper bots, research automation, and backend services that need low-latency Solana DEX trade construction with Rust SDK behavior parity.
| Area | Coverage |
|---|---|
| DEX protocols | PumpFun, PumpSwap, Bonk, Meteora DAMM v2, Raydium AMM v4, Raydium CPMM |
| Submit lanes | Default Solana RPC plus Jito, ZeroSlot, Temporal, Bloxroute, FlashBlock, BlockRazor, Node1, Astralane, Stellium, Lightspeed, Soyas, Speedlanding, Helius, and Solami; NextBlock remains Rust-blacklisted by default |
| Trading workflows | buy_simple / sell_simple, legacy buy/sell params, copy trading, sniper trading, address lookup tables, durable nonce, middleware, shared infrastructure |
| Runtime | Python 3.9+, async services, research scripts, and latency-sensitive bot infrastructure |
PyPI package: sol-trade-sdk==0.1.5
This release refreshes PumpFun V2 and USDC quote-pool handling, keeps the default RPC submit lane active alongside SWQoS lanes, and aligns Raydium CPMM fixed-output swaps with the on-chain swap_base_out instruction. Trade execution requires a caller-supplied recent_blockhash or durable nonce; hot-path execution does not query RPC for blockhash, account, or balance data.
This SDK now tracks the Rust SDK v4.0.21 public behavior for high-level trade intent APIs and SWQoS provider coverage. New code can use buy_simple / sell_simple with AccountPolicy, BuyAmount, and SellAmount; these convert to the existing buy / sell params without removing the legacy API. SWQoS coverage includes the Rust Solami type and defaults (beam.solami.dev:11000, min tip 0.0001 SOL); live Solami submit uses the main QUIC client path and requires the same base58 Solana keypair api token model as Rust. Explicit SWQoS routes still keep the default RPC lane appended. NextBlock is still filtered by the Rust parity blacklist unless Rust changes that behavior. Legacy extended provider classes such as Triton, QuickNode, Syndica, Figment, and Alchemy are kept only for source compatibility and are not part of Rust v4.0.21 trading provider parity.
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-sdk==0.1.5For the high-level intent API, see Simple Trading. It shows SimpleBuyParams.new, BuyAmount.with_max_input, AccountPolicy.AUTO, and the conversion to legacy TradeBuyParams.
You 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())Temporal uses HTTP/3 QUIC first and Binary Batch HTTP as its default fallback. BlockRazor uses gRPC SendBinaryTransaction first and JSON HTTP as fallback. Astralane uses persistent QUIC first and Binary HTTP as fallback. Explicit transport settings force one protocol; a custom URL without a transport remains an explicit HTTP route.
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 (
AccountPolicy,
BuyAmount,
DexType,
SimpleBuyParams,
TradeTokenType,
simple_buy_params_to_trade_buy_params,
)
simple = (
SimpleBuyParams.new(
DexType.PUMPSWAP,
TradeTokenType.WSOL,
mint_pubkey,
BuyAmount.with_max_input(buy_sol_amount),
{"type": "PumpSwap", "params": pumpswap_params},
recent_blockhash,
gas_fee_strategy,
)
.set_slippage_basis_points(500)
.set_account_policy(AccountPolicy.AUTO)
)
buy_params = simple_buy_params_to_trade_buy_params(simple)
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:
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:
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.
You can apply for a key through the official website: Community Website
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
| Back | FazBrowse Home | New Git URL |