跳转到主要内容
如果你计划使用退出智能流追踪此买入,你必须在提交买入交易之前连接流。流通过实时观察链上代币到达来检测新仓位。如果买入落地时流未连接,仓位将不会被追踪,也不会为其生成退出信号。

端点

POST https://api.lasersell.io/v1/buy

请求头

Header必需说明
Content-Type必须为 application/json
x-api-key你的 LaserSell API 密钥

请求体:BuildBuyTxRequest

字段类型必需说明
mintstring要买入的代币地址(base58)。
user_pubkeystring你的钱包公钥(base58)。
amountnumber否*人类可读的花费金额(例如 0.1 表示 0.1 SOL,10.0 表示 10 USD1)。与 amount_in_total 互斥。
amount_in_totalnumber否*以输入资产原子单位计的花费金额(例如 SOL 的 lamports)。与 amount 互斥。
slippage_bpsnumber最大滑点容忍度(基点,例如 2000 = 20%)。
inputstring输入资产:"SOL"(默认)或 "USD1"
modestring路由模式提示。有效值:"fast""secure"。默认 "fast"
send_modestring交易发送模式:"helius_sender""astralane""rpc"
tip_lamportsnumber可选的优先费小费(lamports)。
partner_fee_recipientstring合作伙伴费用接收钱包(base58 公钥)。
partner_fee_bpsnumber合作伙伴费用(基点,最大 50 = 0.5%)。与 partner_fee_lamports 互斥。
partner_fee_lamportsnumber合作伙伴费用(固定 SOL lamports,最大 50,000,000)。与 partner_fee_bps 互斥。
* 必须提供 amountamount_in_total 中的一个。amount 根据 input 资产自动转换为原子单位(SOL: 10^9, USD1: 10^6)。

响应:BuildTxResponse

字段类型说明
txstringBase64 编码的未签名 Solana VersionedTransaction
routeobject可选的路由元数据。
debugobject可选的调试信息。

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);

错误响应

参见错误处理了解完整的错误信封规范和可重试错误逻辑。