feat: harden trading SDK examples

This commit is contained in:
0xfnzero
2026-07-12 14:35:58 +08:00
parent 47cef59d15
commit b09902c527
70 changed files with 1447 additions and 471 deletions
+16
View File
@@ -0,0 +1,16 @@
# Simple Trading API
[中文](README_CN.md)
This is the recommended starting point for `SimpleBuyParams`, `SimpleSellParams`, `BuyAmount`, `SellAmount`, account policies, recent blockhashes, and durable nonces.
The example constructs parameters but does not submit the commented buy/sell calls. Set `PRIVATE_KEY` and replace protocol-state placeholders before adapting it to a live integration.
```bash
export RPC_URL=https://your-rpc.example
cargo run --package simple_trading
```
`WithMaxInput` protects maximum quote cost and is generally appropriate when fill priority matters. `ExactInput` protects minimum output and may fail more often in active markets. `HotPathMinimal` requires all needed token accounts to exist; normal integrations should use `AccountPolicy::Auto`.
See [Trading Parameters](../../docs/TRADING_PARAMETERS.md) and [Low-Latency Bots](../../docs/LOW_LATENCY_BOTS.md).
+16
View File
@@ -0,0 +1,16 @@
# 简化交易 API
[English](README.md)
这是学习 `SimpleBuyParams``SimpleSellParams``BuyAmount``SellAmount`、账户策略、recent blockhash 和 durable nonce 的推荐入口。
示例只构造参数,买卖调用保持注释状态。用于真实集成前必须设置 `PRIVATE_KEY` 并替换协议状态占位值。
```bash
export RPC_URL=https://your-rpc.example
cargo run --package simple_trading
```
`WithMaxInput` 保护最大 quote 成本,适合优先成交;`ExactInput` 保护最小输出,在活跃市场更容易失败。`HotPathMinimal` 要求所需 token 账户均已存在,普通接入应使用 `AccountPolicy::Auto`
参见[交易参数说明](../../docs/TRADING_PARAMETERS_CN.md)和[低延迟 Bot 指南](../../docs/LOW_LATENCY_BOTS_CN.md)。
+2 -2
View File
@@ -18,11 +18,11 @@ use sol_trade_sdk::{
SolanaTrade, TradeTokenType,
};
use solana_commitment_config::CommitmentConfig;
use solana_sdk::{hash::Hash, pubkey::Pubkey, signature::Keypair, signer::Signer};
use solana_sdk::{hash::Hash, pubkey::Pubkey, signer::Signer};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let payer = Keypair::from_base58_string("use_your_payer_keypair_here");
let payer = sol_trade_sdk::common::keypair::load_keypair_from_env("PRIVATE_KEY")?;
let rpc_url = std::env::var("RPC_URL")
.unwrap_or_else(|_| "https://api.mainnet-beta.solana.com".to_string());
let commitment = CommitmentConfig::processed();