sol-trade-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. sol_trade_sdk-0.1.0/.gitignore +55 -0
  2. sol_trade_sdk-0.1.0/PKG-INFO +434 -0
  3. sol_trade_sdk-0.1.0/README.md +394 -0
  4. sol_trade_sdk-0.1.0/README_CN.md +394 -0
  5. sol_trade_sdk-0.1.0/examples/README.md +48 -0
  6. sol_trade_sdk-0.1.0/examples/address_lookup.py +70 -0
  7. sol_trade_sdk-0.1.0/examples/bonk_copy_trading.py +165 -0
  8. sol_trade_sdk-0.1.0/examples/bonk_sniper_trading.py +158 -0
  9. sol_trade_sdk-0.1.0/examples/complete_example.py +287 -0
  10. sol_trade_sdk-0.1.0/examples/complete_migration_test.py +309 -0
  11. sol_trade_sdk-0.1.0/examples/gas_fee_strategy.py +48 -0
  12. sol_trade_sdk-0.1.0/examples/hot_path_trading.py +348 -0
  13. sol_trade_sdk-0.1.0/examples/meteora_damm_v2_trading.py +83 -0
  14. sol_trade_sdk-0.1.0/examples/middleware_system.py +39 -0
  15. sol_trade_sdk-0.1.0/examples/nonce_cache.py +138 -0
  16. sol_trade_sdk-0.1.0/examples/pumpfun_copy_trading.py +163 -0
  17. sol_trade_sdk-0.1.0/examples/pumpfun_sniper_trading.py +153 -0
  18. sol_trade_sdk-0.1.0/examples/pumpfun_trading.py +79 -0
  19. sol_trade_sdk-0.1.0/examples/pumpswap_direct_trading.py +138 -0
  20. sol_trade_sdk-0.1.0/examples/pumpswap_trading.py +149 -0
  21. sol_trade_sdk-0.1.0/examples/raydium_amm_v4_trading.py +146 -0
  22. sol_trade_sdk-0.1.0/examples/raydium_cpmm_trading.py +81 -0
  23. sol_trade_sdk-0.1.0/examples/seed_trading.py +143 -0
  24. sol_trade_sdk-0.1.0/examples/shared_infrastructure.py +57 -0
  25. sol_trade_sdk-0.1.0/examples/trading.py +130 -0
  26. sol_trade_sdk-0.1.0/examples/trading_client.py +138 -0
  27. sol_trade_sdk-0.1.0/examples/wsol_wrapper.py +104 -0
  28. sol_trade_sdk-0.1.0/pyproject.toml +92 -0
  29. sol_trade_sdk-0.1.0/sol_trade_sdk/__init__.py +17 -0
  30. sol_trade_sdk-0.1.0/src/__init__.py +1083 -0
  31. sol_trade_sdk-0.1.0/src/address_lookup.py +105 -0
  32. sol_trade_sdk-0.1.0/src/cache/__init__.py +27 -0
  33. sol_trade_sdk-0.1.0/src/cache/cache.py +331 -0
  34. sol_trade_sdk-0.1.0/src/calc/__init__.py +996 -0
  35. sol_trade_sdk-0.1.0/src/calc/bonk.py +157 -0
  36. sol_trade_sdk-0.1.0/src/calc/meteora_damm_v2.py +75 -0
  37. sol_trade_sdk-0.1.0/src/calc/pumpfun.py +332 -0
  38. sol_trade_sdk-0.1.0/src/calc/pumpswap.py +305 -0
  39. sol_trade_sdk-0.1.0/src/calc/raydium_amm_v4.py +66 -0
  40. sol_trade_sdk-0.1.0/src/calc/raydium_cpmm.py +75 -0
  41. sol_trade_sdk-0.1.0/src/clock.py +103 -0
  42. sol_trade_sdk-0.1.0/src/common/__init__.py +224 -0
  43. sol_trade_sdk-0.1.0/src/common/bonding_curve.py +276 -0
  44. sol_trade_sdk-0.1.0/src/common/fast_fn.py +83 -0
  45. sol_trade_sdk-0.1.0/src/common/fast_timing.py +278 -0
  46. sol_trade_sdk-0.1.0/src/common/gas_fee_strategy.py +19 -0
  47. sol_trade_sdk-0.1.0/src/common/sdk_log.py +189 -0
  48. sol_trade_sdk-0.1.0/src/common/seed.py +283 -0
  49. sol_trade_sdk-0.1.0/src/common/spl_token.py +348 -0
  50. sol_trade_sdk-0.1.0/src/common/subscription_handle.py +423 -0
  51. sol_trade_sdk-0.1.0/src/common/trading_utils.py +260 -0
  52. sol_trade_sdk-0.1.0/src/common/types.py +414 -0
  53. sol_trade_sdk-0.1.0/src/common/wsol_manager.py +280 -0
  54. sol_trade_sdk-0.1.0/src/compute/__init__.py +49 -0
  55. sol_trade_sdk-0.1.0/src/compute/compute_budget_manager.py +185 -0
  56. sol_trade_sdk-0.1.0/src/execution/__init__.py +75 -0
  57. sol_trade_sdk-0.1.0/src/execution/execution.py +378 -0
  58. sol_trade_sdk-0.1.0/src/hotpath/__init__.py +57 -0
  59. sol_trade_sdk-0.1.0/src/hotpath/executor.py +461 -0
  60. sol_trade_sdk-0.1.0/src/hotpath/state.py +402 -0
  61. sol_trade_sdk-0.1.0/src/instruction/__init__.py +517 -0
  62. sol_trade_sdk-0.1.0/src/instruction/bonk.py +158 -0
  63. sol_trade_sdk-0.1.0/src/instruction/bonk_builder.py +763 -0
  64. sol_trade_sdk-0.1.0/src/instruction/common.py +295 -0
  65. sol_trade_sdk-0.1.0/src/instruction/meteora_damm_v2.py +136 -0
  66. sol_trade_sdk-0.1.0/src/instruction/meteora_damm_v2_builder.py +731 -0
  67. sol_trade_sdk-0.1.0/src/instruction/pumpfun_builder.py +1036 -0
  68. sol_trade_sdk-0.1.0/src/instruction/pumpswap_builder.py +949 -0
  69. sol_trade_sdk-0.1.0/src/instruction/raydium_amm_v4.py +181 -0
  70. sol_trade_sdk-0.1.0/src/instruction/raydium_amm_v4_builder.py +665 -0
  71. sol_trade_sdk-0.1.0/src/instruction/raydium_cpmm.py +178 -0
  72. sol_trade_sdk-0.1.0/src/instruction/raydium_cpmm_builder.py +651 -0
  73. sol_trade_sdk-0.1.0/src/middleware/__init__.py +13 -0
  74. sol_trade_sdk-0.1.0/src/middleware/builtin.py +52 -0
  75. sol_trade_sdk-0.1.0/src/middleware/traits.py +106 -0
  76. sol_trade_sdk-0.1.0/src/nonce_cache.py +138 -0
  77. sol_trade_sdk-0.1.0/src/perf/__init__.py +160 -0
  78. sol_trade_sdk-0.1.0/src/perf/compiler_optimization.py +538 -0
  79. sol_trade_sdk-0.1.0/src/perf/hardware_optimizations.py +320 -0
  80. sol_trade_sdk-0.1.0/src/perf/kernel_bypass.py +570 -0
  81. sol_trade_sdk-0.1.0/src/perf/protocol_optimization.py +486 -0
  82. sol_trade_sdk-0.1.0/src/perf/realtime_tuning.py +282 -0
  83. sol_trade_sdk-0.1.0/src/perf/simd.py +427 -0
  84. sol_trade_sdk-0.1.0/src/perf/syscall_bypass.py +287 -0
  85. sol_trade_sdk-0.1.0/src/perf/ultra_low_latency.py +318 -0
  86. sol_trade_sdk-0.1.0/src/perf/zero_copy_io.py +242 -0
  87. sol_trade_sdk-0.1.0/src/pool/__init__.py +23 -0
  88. sol_trade_sdk-0.1.0/src/pool/pool.py +343 -0
  89. sol_trade_sdk-0.1.0/src/py.typed +1 -0
  90. sol_trade_sdk-0.1.0/src/rpc/__init__.py +23 -0
  91. sol_trade_sdk-0.1.0/src/rpc/client.py +454 -0
  92. sol_trade_sdk-0.1.0/src/security/__init__.py +22 -0
  93. sol_trade_sdk-0.1.0/src/security/secure_key.py +428 -0
  94. sol_trade_sdk-0.1.0/src/security/validators.py +290 -0
  95. sol_trade_sdk-0.1.0/src/seed/__init__.py +59 -0
  96. sol_trade_sdk-0.1.0/src/seed/pda.py +262 -0
  97. sol_trade_sdk-0.1.0/src/serialization/__init__.py +56 -0
  98. sol_trade_sdk-0.1.0/src/serialization/serialization.py +232 -0
  99. sol_trade_sdk-0.1.0/src/spl_token/__init__.py +55 -0
  100. sol_trade_sdk-0.1.0/src/spl_token/token.py +518 -0
  101. sol_trade_sdk-0.1.0/src/swqos/__init__.py +139 -0
  102. sol_trade_sdk-0.1.0/src/swqos/advanced_clients.py +663 -0
  103. sol_trade_sdk-0.1.0/src/swqos/clients.py +2131 -0
  104. sol_trade_sdk-0.1.0/src/swqos/providers.py +1145 -0
  105. sol_trade_sdk-0.1.0/src/trading/__init__.py +101 -0
  106. sol_trade_sdk-0.1.0/src/trading/core/__init__.py +74 -0
  107. sol_trade_sdk-0.1.0/src/trading/core/async_executor.py +463 -0
  108. sol_trade_sdk-0.1.0/src/trading/core/confirmation_monitor.py +484 -0
  109. sol_trade_sdk-0.1.0/src/trading/core/retry_handler.py +492 -0
  110. sol_trade_sdk-0.1.0/src/trading/core/transaction_pool.py +418 -0
  111. sol_trade_sdk-0.1.0/src/trading/executor.py +450 -0
  112. sol_trade_sdk-0.1.0/src/trading/factory.py +402 -0
  113. sol_trade_sdk-0.1.0/src/trading/high_perf_executor.py +425 -0
  114. sol_trade_sdk-0.1.0/src/trading/params.py +423 -0
  115. sol_trade_sdk-0.1.0/src/utils/__init__.py +93 -0
  116. sol_trade_sdk-0.1.0/tests/conftest.py +22 -0
  117. sol_trade_sdk-0.1.0/tests/test_complete_integration.py +335 -0
  118. sol_trade_sdk-0.1.0/tests/test_complete_sdk.py +426 -0
  119. sol_trade_sdk-0.1.0/tests/test_hotpath.py +444 -0
  120. sol_trade_sdk-0.1.0/tests/test_migration_final.py +279 -0
  121. sol_trade_sdk-0.1.0/tests/test_migration_simple.py +359 -0
  122. sol_trade_sdk-0.1.0/tests/test_sdk.py +298 -0
@@ -0,0 +1,55 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual environments
24
+ venv/
25
+ env/
26
+ ENV/
27
+ .venv
28
+
29
+ # IDE
30
+ .vscode/
31
+ .idea/
32
+ *.swp
33
+ *.swo
34
+ *~
35
+
36
+ # Testing
37
+ .pytest_cache/
38
+ .coverage
39
+ htmlcov/
40
+ .tox/
41
+
42
+ # MyPy
43
+ .mypy_cache/
44
+ .dmypy.json
45
+ dmypy.json
46
+
47
+ # Environment variables
48
+ .env
49
+ .env.local
50
+
51
+ # Jupyter Notebook
52
+ .ipynb_checkpoints
53
+
54
+ # macOS
55
+ .DS_Store
@@ -0,0 +1,434 @@
1
+ Metadata-Version: 2.4
2
+ Name: sol-trade-sdk
3
+ Version: 0.1.0
4
+ Summary: High-performance Solana trading SDK with multi-protocol support
5
+ Project-URL: Homepage, https://github.com/0xfnzero/sol-trade-sdk-python
6
+ Project-URL: Documentation, https://github.com/0xfnzero/sol-trade-sdk-python#readme
7
+ Project-URL: Repository, https://github.com/0xfnzero/sol-trade-sdk-python
8
+ Author: Sol Trade SDK Team
9
+ License-Expression: MIT
10
+ Keywords: blockchain,defi,dex,meteora,pumpfun,raydium,solana,trading
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Office/Business :: Financial
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.9
22
+ Requires-Dist: aiohttp>=3.9.0
23
+ Requires-Dist: anchorpy>=0.18.0
24
+ Requires-Dist: base58>=2.1.1
25
+ Requires-Dist: solana>=0.30.0
26
+ Requires-Dist: solders>=0.18.0
27
+ Requires-Dist: typing-extensions>=4.0.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: black>=23.0.0; extra == 'dev'
30
+ Requires-Dist: isort>=5.12.0; extra == 'dev'
31
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
32
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
33
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
34
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
35
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
36
+ Provides-Extra: quic
37
+ Requires-Dist: aioquic>=1.0.0; extra == 'quic'
38
+ Requires-Dist: cryptography>=41.0.0; extra == 'quic'
39
+ Description-Content-Type: text/markdown
40
+
41
+ <div align="center">
42
+ <h1>πŸš€ Sol Trade SDK for Python</h1>
43
+ <h3><em>A comprehensive Python SDK for seamless Solana DEX trading</em></h3>
44
+ </div>
45
+
46
+ <p align="center">
47
+ <strong>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.</strong>
48
+ </p>
49
+
50
+ <p align="center">
51
+ <a href="https://pypi.org/project/sol-trade-sdk">
52
+ <img src="https://img.shields.io/pypi/v/sol-trade-sdk.svg" alt="PyPI">
53
+ </a>
54
+ <a href="https://pypi.org/project/sol-trade-sdk">
55
+ <img src="https://img.shields.io/pypi/pyversions/sol-trade-sdk.svg" alt="Python Versions">
56
+ </a>
57
+ <a href="LICENSE">
58
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
59
+ </a>
60
+ </p>
61
+
62
+ <p align="center">
63
+ <img src="https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python">
64
+ <img src="https://img.shields.io/badge/Solana-9945FF?style=for-the-badge&logo=solana&logoColor=white" alt="Solana">
65
+ <img src="https://img.shields.io/badge/DEX-4B8BBE?style=for-the-badge&logo=bitcoin&logoColor=white" alt="DEX Trading">
66
+ </p>
67
+
68
+ <p align="center">
69
+ <a href="https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/README_CN.md">δΈ­ζ–‡</a> |
70
+ <a href="https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/README.md">English</a> |
71
+ <a href="https://fnzero.dev/">Website</a> |
72
+ <a href="https://t.me/fnzero_group">Telegram</a> |
73
+ <a href="https://discord.gg/vuazbGkqQE">Discord</a>
74
+ </p>
75
+
76
+ > β˜• **Support This Project**
77
+ >
78
+ > This SDK is completely free and open source. However, maintaining and continuously updating it requires significant AI computing resources and token consumption. If this SDK helps with your development, consider making a monthly SOL donation β€” any amount is appreciated and helps keep this project alive!
79
+ >
80
+ > **Donation Wallet:** `6oW7AXz1yRb57pYSxysuXnMs2aR1ha5rzGzReZ1MjPV8`
81
+
82
+ ## πŸ“‹ Table of Contents
83
+
84
+ - [✨ Features](#-features)
85
+ - [πŸ“¦ Installation](#-installation)
86
+ - [πŸ› οΈ Usage Examples](#️-usage-examples)
87
+ - [πŸ“‹ Example Usage](#-example-usage)
88
+ - [⚑ Trading Parameters](#-trading-parameters)
89
+ - [πŸ“Š Usage Examples Summary Table](#-usage-examples-summary-table)
90
+ - [βš™οΈ SWQoS Service Configuration](#️-swqos-service-configuration)
91
+ - [πŸ”§ Middleware System](#-middleware-system)
92
+ - [πŸ” Address Lookup Tables](#-address-lookup-tables)
93
+ - [πŸ” Nonce Cache](#-nonce-cache)
94
+ - [πŸ’° Cashback Support (PumpFun / PumpSwap)](#-cashback-support-pumpfun--pumpswap)
95
+ - [πŸ›‘οΈ MEV Protection Services](#️-mev-protection-services)
96
+ - [πŸ“ Project Structure](#-project-structure)
97
+ - [πŸ“„ License](#-license)
98
+ - [πŸ’¬ Contact](#-contact)
99
+ - [⚠️ Important Notes](#️-important-notes)
100
+
101
+ ---
102
+
103
+ ## πŸ“¦ SDK Versions
104
+
105
+ This SDK is available in multiple languages:
106
+
107
+ | Language | Repository | Description |
108
+ |----------|------------|-------------|
109
+ | **Rust** | [sol-trade-sdk](https://github.com/0xfnzero/sol-trade-sdk) | Ultra-low latency with zero-copy optimization |
110
+ | **Node.js** | [sol-trade-sdk-nodejs](https://github.com/0xfnzero/sol-trade-sdk-nodejs) | TypeScript/JavaScript for Node.js |
111
+ | **Python** | [sol-trade-sdk-python](https://github.com/0xfnzero/sol-trade-sdk-python) | Async/await native support |
112
+ | **Go** | [sol-trade-sdk-golang](https://github.com/0xfnzero/sol-trade-sdk-golang) | Concurrent-safe with goroutine support |
113
+
114
+ ## ✨ Features
115
+
116
+ 1. **PumpFun Trading**: Support for `buy` and `sell` operations
117
+ 2. **PumpSwap Trading**: Support for PumpSwap pool trading operations
118
+ 3. **Bonk Trading**: Support for Bonk trading operations
119
+ 4. **Raydium CPMM Trading**: Support for Raydium CPMM (Concentrated Pool Market Maker) trading operations
120
+ 5. **Raydium AMM V4 Trading**: Support for Raydium AMM V4 (Automated Market Maker) trading operations
121
+ 6. **Meteora DAMM V2 Trading**: Support for Meteora DAMM V2 (Dynamic AMM) trading operations
122
+ 7. **Multiple MEV Protection**: Support for Jito, Nextblock, ZeroSlot, Temporal, Bloxroute, FlashBlock, BlockRazor, Node1, Astralane and other services
123
+ 8. **Concurrent Trading**: Send transactions using multiple MEV services simultaneously; the fastest succeeds while others fail
124
+ 9. **Unified Trading Interface**: Use unified trading protocol types for trading operations
125
+ 10. **Middleware System**: Support for custom instruction middleware to modify, add, or remove instructions before transaction execution
126
+ 11. **Shared Infrastructure**: Share expensive RPC and SWQoS clients across multiple wallets for reduced resource usage
127
+
128
+ ## πŸ“¦ Installation
129
+
130
+ ### Direct Clone (Recommended)
131
+
132
+ Clone this project to your project directory:
133
+
134
+ ```bash
135
+ cd your_project_root_directory
136
+ git clone https://github.com/0xfnzero/sol-trade-sdk-python
137
+ ```
138
+
139
+ Install dependencies:
140
+
141
+ ```bash
142
+ cd sol-trade-sdk-python
143
+ pip install -e .
144
+ ```
145
+
146
+ Or add to your `requirements.txt`:
147
+
148
+ ```
149
+ sol-trade-sdk @ ./sol-trade-sdk-python
150
+ ```
151
+
152
+ Or add to your `pyproject.toml`:
153
+
154
+ ```toml
155
+ [project]
156
+ dependencies = [
157
+ "sol-trade-sdk @ ./sol-trade-sdk-python",
158
+ ]
159
+ ```
160
+
161
+ ### Use PyPI
162
+
163
+ ```bash
164
+ pip install sol-trade-sdk
165
+ ```
166
+
167
+ ## πŸ› οΈ Usage Examples
168
+
169
+ ### πŸ“‹ Example Usage
170
+
171
+ #### 1. Create TradingClient Instance
172
+
173
+ You can refer to [Example: Create TradingClient Instance](examples/trading_client.py).
174
+
175
+ **Method 1: Simple (single wallet)**
176
+ ```python
177
+ import asyncio
178
+ from sol_trade_sdk import TradingClient, TradeConfig, SwqosConfig, SwqosRegion
179
+
180
+ async def main():
181
+ # Wallet
182
+ payer = Keypair.from_secret_key(/* your keypair */)
183
+
184
+ # RPC URL
185
+ rpc_url = "https://mainnet.helius-rpc.com/?api-key=xxxxxx"
186
+
187
+ # Multiple SWQoS services can be configured
188
+ swqos_configs = [
189
+ SwqosConfig(type="Default", rpc_url=rpc_url),
190
+ SwqosConfig(type="Jito", uuid="your_uuid", region=SwqosRegion.FRANKFURT),
191
+ SwqosConfig(type="Bloxroute", api_token="your_api_token", region=SwqosRegion.FRANKFURT),
192
+ SwqosConfig(type="Astralane", api_key="your_api_key", region=SwqosRegion.FRANKFURT),
193
+ ]
194
+
195
+ # Create TradeConfig instance
196
+ trade_config = TradeConfig(rpc_url, swqos_configs)
197
+
198
+ # Create TradingClient
199
+ client = TradingClient(payer, trade_config)
200
+
201
+ asyncio.run(main())
202
+ ```
203
+
204
+ **Method 2: Shared infrastructure (multiple wallets)**
205
+
206
+ For multi-wallet scenarios, create the infrastructure once and share it across wallets.
207
+ See [Example: Shared Infrastructure](examples/shared_infrastructure.py).
208
+
209
+ ```python
210
+ from sol_trade_sdk import TradingInfrastructure, InfrastructureConfig
211
+
212
+ # Create infrastructure once (expensive)
213
+ infra_config = InfrastructureConfig(rpc_url, swqos_configs)
214
+ infrastructure = TradingInfrastructure(infra_config)
215
+
216
+ # Create multiple clients sharing the same infrastructure (fast)
217
+ client1 = TradingClient.from_infrastructure(payer1, infrastructure)
218
+ client2 = TradingClient.from_infrastructure(payer2, infrastructure)
219
+ ```
220
+
221
+ #### 2. Configure Gas Fee Strategy
222
+
223
+ ```python
224
+ from sol_trade_sdk import GasFeeStrategy
225
+
226
+ # Create GasFeeStrategy instance
227
+ gas_fee_strategy = GasFeeStrategy()
228
+ # Set global strategy
229
+ gas_fee_strategy.set_global_fee_strategy(150000, 150000, 500000, 500000, 0.001, 0.001)
230
+ ```
231
+
232
+ #### 3. Build Trading Parameters
233
+
234
+ ```python
235
+ from sol_trade_sdk import TradeBuyParams, DexType, TradeTokenType
236
+
237
+ buy_params = TradeBuyParams(
238
+ dex_type=DexType.PUMPSWAP,
239
+ input_token_type=TradeTokenType.WSOL,
240
+ mint=mint_pubkey,
241
+ input_token_amount=buy_sol_amount,
242
+ slippage_basis_points=500,
243
+ recent_blockhash=recent_blockhash,
244
+ # Use extension_params for protocol-specific parameters
245
+ extension_params={"type": "PumpSwap", "params": pumpswap_params},
246
+ address_lookup_table_account=None,
247
+ wait_transaction_confirmed=True,
248
+ create_input_token_ata=True,
249
+ close_input_token_ata=True,
250
+ create_mint_ata=True,
251
+ durable_nonce=None,
252
+ fixed_output_token_amount=None,
253
+ gas_fee_strategy=gas_fee_strategy,
254
+ simulate=False,
255
+ )
256
+ ```
257
+
258
+ #### 4. Execute Trading
259
+
260
+ ```python
261
+ result = await client.buy(buy_params)
262
+ print(f"Transaction signature: {result.signature}")
263
+ ```
264
+
265
+ ### ⚑ Trading Parameters
266
+
267
+ For comprehensive information about all trading parameters including `TradeBuyParams` and `TradeSellParams`, see the Trading Parameters documentation.
268
+
269
+ #### About ShredStream
270
+
271
+ When using shred to subscribe to events, due to the nature of shreds, you cannot get complete information about transaction events.
272
+ Please ensure that the parameters your trading logic depends on are available in shreds when using them.
273
+
274
+ ### πŸ“Š Usage Examples Summary Table
275
+
276
+ | Description | Run Command | Source Code |
277
+ |-------------|-------------|-------------|
278
+ | Create and configure TradingClient instance | `python examples/trading_client.py` | [examples/trading_client.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/trading_client.py) |
279
+ | Share infrastructure across multiple wallets | `python examples/shared_infrastructure.py` | [examples/shared_infrastructure.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/shared_infrastructure.py) |
280
+ | PumpFun token sniping trading | `python examples/pumpfun_sniper_trading.py` | [examples/pumpfun_sniper_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/pumpfun_sniper_trading.py) |
281
+ | PumpFun token copy trading | `python examples/pumpfun_copy_trading.py` | [examples/pumpfun_copy_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/pumpfun_copy_trading.py) |
282
+ | PumpSwap trading operations | `python examples/pumpswap_trading.py` | [examples/pumpswap_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/pumpswap_trading.py) |
283
+ | PumpSwap direct trading (via RPC) | `python examples/pumpswap_direct_trading.py` | [examples/pumpswap_direct_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/pumpswap_direct_trading.py) |
284
+ | Raydium CPMM trading operations | `python examples/raydium_cpmm_trading.py` | [examples/raydium_cpmm_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/raydium_cpmm_trading.py) |
285
+ | Raydium AMM V4 trading operations | `python examples/raydium_amm_v4_trading.py` | [examples/raydium_amm_v4_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/raydium_amm_v4_trading.py) |
286
+ | Meteora DAMM V2 trading operations | `python examples/meteora_damm_v2_trading.py` | [examples/meteora_damm_v2_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/meteora_damm_v2_trading.py) |
287
+ | Bonk token sniping trading | `python examples/bonk_sniper_trading.py` | [examples/bonk_sniper_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/bonk_sniper_trading.py) |
288
+ | Bonk token copy trading | `python examples/bonk_copy_trading.py` | [examples/bonk_copy_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/bonk_copy_trading.py) |
289
+ | Custom instruction middleware example | `python examples/middleware_system.py` | [examples/middleware_system.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/middleware_system.py) |
290
+ | Address lookup table example | `python examples/address_lookup.py` | [examples/address_lookup.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/address_lookup.py) |
291
+ | Nonce cache (durable nonce) example | `python examples/nonce_cache.py` | [examples/nonce_cache.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/nonce_cache.py) |
292
+ | Wrap/unwrap SOL to/from WSOL example | `python examples/wsol_wrapper.py` | [examples/wsol_wrapper.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/wsol_wrapper.py) |
293
+ | Seed trading example | `python examples/seed_trading.py` | [examples/seed_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/seed_trading.py) |
294
+ | Gas fee strategy example | `python examples/gas_fee_strategy.py` | [examples/gas_fee_strategy.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/gas_fee_strategy.py) |
295
+ | Hot path trading (zero-RPC) | `python examples/hot_path_trading.py` | [examples/hot_path_trading.py](https://github.com/0xfnzero/sol-trade-sdk-python/blob/main/examples/hot_path_trading.py) |
296
+
297
+ ### βš™οΈ SWQoS Service Configuration
298
+
299
+ When configuring SWQoS services, note the different parameter requirements for each service:
300
+
301
+ - **Jito**: The first parameter is UUID (if no UUID, pass an empty string `""`)
302
+ - **Other MEV services**: The first parameter is the API Token
303
+
304
+ #### Custom URL Support
305
+
306
+ Each SWQoS service supports an optional custom URL parameter:
307
+
308
+ ```python
309
+ # Using custom URL
310
+ jito_config = SwqosConfig(
311
+ type="Jito",
312
+ uuid="your_uuid",
313
+ region=SwqosRegion.FRANKFURT,
314
+ custom_url="https://custom-jito-endpoint.com"
315
+ )
316
+
317
+ # Using default regional endpoint
318
+ bloxroute_config = SwqosConfig(
319
+ type="Bloxroute",
320
+ api_token="your_api_token",
321
+ region=SwqosRegion.NEW_YORK
322
+ )
323
+ ```
324
+
325
+ **URL Priority Logic**:
326
+ - If a custom URL is provided, it will be used instead of the regional endpoint
327
+ - If no custom URL is provided, the system will use the default endpoint for the specified region
328
+ - This allows for maximum flexibility while maintaining backward compatibility
329
+
330
+ 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.
331
+
332
+ ---
333
+
334
+ ### πŸ”§ Middleware System
335
+
336
+ 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:
337
+
338
+ ```python
339
+ from sol_trade_sdk import MiddlewareManager
340
+
341
+ manager = MiddlewareManager() \
342
+ .add_middleware(FirstMiddleware()) \
343
+ .add_middleware(SecondMiddleware()) \
344
+ .add_middleware(ThirdMiddleware())
345
+ ```
346
+
347
+ ### πŸ” Address Lookup Tables
348
+
349
+ Address Lookup Tables (ALT) allow you to optimize transaction size and reduce fees by storing frequently used addresses in a compact table format.
350
+
351
+ ```python
352
+ from sol_trade_sdk import fetch_address_lookup_table_account, AddressLookupTableCache
353
+
354
+ # Fetch ALT from chain
355
+ alt = await fetch_address_lookup_table_account(rpc, alt_address)
356
+ print(f"ALT contains {len(alt.addresses)} addresses")
357
+
358
+ # Use cache for performance
359
+ cache = AddressLookupTableCache(rpc)
360
+ await cache.prefetch([alt_address1, alt_address2, alt_address3])
361
+ cached = cache.get(alt_address1)
362
+ ```
363
+
364
+ ### πŸ” Durable Nonce
365
+
366
+ Use Durable Nonce to implement transaction replay protection and optimize transaction processing.
367
+
368
+ ```python
369
+ from sol_trade_sdk import fetch_nonce_info, NonceCache
370
+
371
+ # Fetch nonce info
372
+ nonce_info = await fetch_nonce_info(rpc, nonce_account)
373
+ ```
374
+
375
+ ## πŸ’° Cashback Support (PumpFun / PumpSwap)
376
+
377
+ 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.
378
+
379
+ - **When params come from RPC**: If you use `PumpFunParams.from_mint_by_rpc` or `PumpSwapParams.from_pool_address_by_rpc`, the SDK reads `is_cashback_coin` from chainβ€”no extra step.
380
+ - **When params come from event/parser**: If you build params from trade events (e.g. [sol-parser-sdk](https://github.com/0xfnzero/sol-parser-sdk)), you **must** pass the cashback flag into the SDK:
381
+ - **PumpFun**: Set `is_cashback_coin` when building params from parsed events.
382
+ - **PumpSwap**: Set `is_cashback_coin` field when constructing params manually.
383
+
384
+ ## πŸ›‘οΈ MEV Protection Services
385
+
386
+ You can apply for a key through the official website: [Community Website](https://fnzero.dev/swqos)
387
+
388
+ - **Jito**: High-performance block space
389
+ - **ZeroSlot**: Zero-latency transactions
390
+ - **Temporal**: Time-sensitive transactions
391
+ - **Bloxroute**: Blockchain network acceleration
392
+ - **FlashBlock**: High-speed transaction execution with API key authentication
393
+ - **BlockRazor**: High-speed transaction execution with API key authentication
394
+ - **Node1**: High-speed transaction execution with API key authentication
395
+ - **Astralane**: Blockchain network acceleration
396
+
397
+ ## πŸ“ Project Structure
398
+
399
+ ```
400
+ src/
401
+ β”œβ”€β”€ common/ # Common functionality and tools
402
+ β”œβ”€β”€ constants/ # Constant definitions
403
+ β”œβ”€β”€ instruction/ # Instruction building
404
+ β”‚ └── utils/ # Instruction utilities
405
+ β”œβ”€β”€ swqos/ # MEV service clients
406
+ β”œβ”€β”€ trading/ # Unified trading engine
407
+ β”‚ β”œβ”€β”€ common/ # Common trading tools
408
+ β”‚ β”œβ”€β”€ core/ # Core trading engine
409
+ β”‚ β”œβ”€β”€ middleware/ # Middleware system
410
+ β”‚ └── factory.py # Trading factory
411
+ β”œβ”€β”€ utils/ # Utility functions
412
+ β”‚ β”œβ”€β”€ calc/ # Amount calculation utilities
413
+ β”‚ └── price/ # Price calculation utilities
414
+ └── __init__.py # Main library file
415
+ ```
416
+
417
+ ## πŸ“„ License
418
+
419
+ MIT License
420
+
421
+ ## πŸ’¬ Contact
422
+
423
+ - Official Website: https://fnzero.dev/
424
+ - Project Repository: https://github.com/0xfnzero/sol-trade-sdk-python
425
+ - Telegram Group: https://t.me/fnzero_group
426
+ - Discord: https://discord.gg/vuazbGkqQE
427
+
428
+ ## ⚠️ Important Notes
429
+
430
+ 1. Test thoroughly before using on mainnet
431
+ 2. Properly configure private keys and API tokens
432
+ 3. Pay attention to slippage settings to avoid transaction failures
433
+ 4. Monitor balances and transaction fees
434
+ 5. Comply with relevant laws and regulations