如果你计划使用退出智能流追踪此买入,你必须在提交买入交易之前连接流。流通过实时观察链上代币到达来检测新仓位。如果买入落地时流未连接,仓位将不会被追踪,也不会为其生成退出信号。
POST https://api.lasersell.io/v1/buy
请求头
| Header | 必需 | 说明 |
|---|
Content-Type | 是 | 必须为 application/json |
x-api-key | 是 | 你的 LaserSell API 密钥 |
请求体:BuildBuyTxRequest
| 字段 | 类型 | 必需 | 说明 |
|---|
mint | string | 是 | 要买入的代币地址(base58)。 |
user_pubkey | string | 是 | 你的钱包公钥(base58)。 |
amount | number | 否* | 人类可读的花费金额(例如 0.1 表示 0.1 SOL,10.0 表示 10 USD1)。与 amount_in_total 互斥。 |
amount_in_total | number | 否* | 以输入资产原子单位计的花费金额(例如 SOL 的 lamports)。与 amount 互斥。 |
slippage_bps | number | 是 | 最大滑点容忍度(基点,例如 2000 = 20%)。 |
input | string | 否 | 输入资产:"SOL"(默认)或 "USD1"。 |
mode | string | 否 | 路由模式提示。有效值:"fast"、"secure"。默认 "fast"。 |
send_mode | string | 否 | 交易发送模式:"helius_sender"、"astralane" 或 "rpc"。 |
tip_lamports | number | 否 | 可选的优先费小费(lamports)。 |
partner_fee_recipient | string | 否 | 合作伙伴费用接收钱包(base58 公钥)。 |
partner_fee_bps | number | 否 | 合作伙伴费用(基点,最大 50 = 0.5%)。与 partner_fee_lamports 互斥。 |
partner_fee_lamports | number | 否 | 合作伙伴费用(固定 SOL lamports,最大 50,000,000)。与 partner_fee_bps 互斥。 |
* 必须提供 amount 或 amount_in_total 中的一个。amount 根据 input 资产自动转换为原子单位(SOL: 10^9, USD1: 10^6)。
响应:BuildTxResponse
| 字段 | 类型 | 说明 |
|---|
tx | string | Base64 编码的未签名 Solana VersionedTransaction。 |
route | object | 可选的路由元数据。 |
debug | object | 可选的调试信息。 |
curl 示例
使用人类可读的 amount:
curl -X POST https://api.lasersell.io/v1/buy \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"mint": "TOKEN_MINT_ADDRESS",
"user_pubkey": "YOUR_WALLET_PUBKEY",
"amount": 0.1,
"slippage_bps": 2000,
"input": "SOL"
}'
使用原子单位 amount_in_total:
curl -X POST https://api.lasersell.io/v1/buy \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"mint": "TOKEN_MINT_ADDRESS",
"user_pubkey": "YOUR_WALLET_PUBKEY",
"amount_in_total": 100000000,
"slippage_bps": 2000,
"input": "SOL"
}'
SDK 示例
import { ExitApiClient, type BuildBuyTxRequest } from "@lasersell/lasersell-sdk";
const client = ExitApiClient.withApiKey("YOUR_API_KEY");
const request: BuildBuyTxRequest = {
mint: "TOKEN_MINT_ADDRESS",
user_pubkey: "YOUR_WALLET_PUBKEY",
amount: 0.1, // 0.1 SOL
slippage_bps: 2_000,
};
const response = await client.buildBuyTx(request);
console.log("Unsigned tx (base64):", response.tx);
错误响应
参见错误处理了解完整的错误信封规范和可重试错误逻辑。