curl --request GET \
--url https://swap-v2.solanatracker.io/swapimport requests
url = "https://swap-v2.solanatracker.io/swap"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://swap-v2.solanatracker.io/swap', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://swap-v2.solanatracker.io/swap",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://swap-v2.solanatracker.io/swap"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://swap-v2.solanatracker.io/swap")
.asString();require 'uri'
require 'net/http'
url = URI("https://swap-v2.solanatracker.io/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"txn": "BASE64_TX",
"rate": {
"amountIn": 1,
"amountOut": 81.631985,
"minAmountOut": 73.4687865,
"currentPrice": 0.012219167460548153,
"executionPrice": 0.010997250714493338,
"priceImpact": 0.002517,
"fee": 0.000005,
"baseCurrency": {
"mint": "<string>",
"decimals": 123
},
"quoteCurrency": {
"mint": "<string>",
"decimals": 123
},
"platformFee": 9000000,
"platformFeeUI": 0.009
},
"timeTaken": 0.016,
"type": "legacy"
}{
"error": "An internal error occurred",
"details": "Unable to fetch pools for token"
}{
"error": "An internal error occurred",
"details": "Unable to fetch pools for token"
}Solana 兑换交易构建:Swap API
用 GET /swap 构建序列化的 Solana 兑换交易,然后从钱包签名并广播。包含滑点和优先费选项。
curl --request GET \
--url https://swap-v2.solanatracker.io/swapimport requests
url = "https://swap-v2.solanatracker.io/swap"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://swap-v2.solanatracker.io/swap', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://swap-v2.solanatracker.io/swap",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://swap-v2.solanatracker.io/swap"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://swap-v2.solanatracker.io/swap")
.asString();require 'uri'
require 'net/http'
url = URI("https://swap-v2.solanatracker.io/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"txn": "BASE64_TX",
"rate": {
"amountIn": 1,
"amountOut": 81.631985,
"minAmountOut": 73.4687865,
"currentPrice": 0.012219167460548153,
"executionPrice": 0.010997250714493338,
"priceImpact": 0.002517,
"fee": 0.000005,
"baseCurrency": {
"mint": "<string>",
"decimals": 123
},
"quoteCurrency": {
"mint": "<string>",
"decimals": 123
},
"platformFee": 9000000,
"platformFeeUI": 0.009
},
"timeTaken": 0.016,
"type": "legacy"
}{
"error": "An internal error occurred",
"details": "Unable to fetch pools for token"
}{
"error": "An internal error occurred",
"details": "Unable to fetch pools for token"
}swap-v2.solanatracker.io)。它仍在运行,每笔兑换收取平台费。Raptor 是另一款独立的兑换 API(raptor.solanatracker.io),目前免费,无需 API 密钥。概览
swap 端点在 Solana 上构建代币兑换交易。您会收到一个序列化交易,您需要使用钱包签名并广播。支持的平台
- Pump.fun - 上线平台代币
- PumpSwap - Pump.fun 流动性池
- Orca - 集中流动性
- Meteora - 动态池
- Moonshot - 新上线
- Raydium - V4 AMM、CPMM、Launchpad
- Jupiter - 聚合路由
SDK 示例
import { SolanaTracker } from 'solana-swap';
const tracker = new SolanaTracker('YOUR_API_KEY', 'YOUR_PRIVATE_KEY');
// Basic swap
const swap = await tracker.swap({
from: 'So11111111111111111111111111111111111111112', // SOL
to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
fromAmount: 0.1,
slippage: 10,
payer: 'YOUR_WALLET_ADDRESS',
priorityFee: 0.000005,
txVersion: 'v0'
});
console.log('Transaction:', swap.txn);
slippage: 10 表示 10%。from solana_swap import SolanaTracker
tracker = SolanaTracker('YOUR_API_KEY', 'YOUR_PRIVATE_KEY')
# Basic swap
swap = tracker.swap(
from_token='So11111111111111111111111111111111111111112',
to_token='4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
from_amount=0.1,
slippage=10,
payer='YOUR_WALLET_ADDRESS',
priority_fee=0.000005,
tx_version='v0'
)
print('Transaction:', swap['txn'])
curl -X GET "https://swap-v2.solanatracker.io/swap?from=So11111111111111111111111111111111111111112&to=4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R&fromAmount=0.1&slippage=10&payer=YOUR_WALLET_ADDRESS&priorityFee=0.000005&txVersion=v0"
关键参数
金额格式
fromAmount 参数接受:
- 数值:
1、0.5- 精确金额 - 自动:
"auto"- 整个钱包余额 - 百分比:
"50%"、"25%"- 余额的百分比
优先费
// Manual fee
{ priorityFee: 0.000005 }
// Automatic with level
{
priorityFee: "auto",
priorityFeeLevel: "high" // min, low, medium, high, veryHigh, unsafeMax
}
合作伙伴 / 推荐费
添加您自己的合作伙伴或推荐费用以实现盈利:{
fee: "YOUR_WALLET:0.1", // 0.1% to your wallet
feeType: "add" // or "deduct" (SOL only)
}
示例
使用自动金额的兑换
// Swap entire balance
const swap = await tracker.swap({
from: 'So11111111111111111111111111111111111111112',
to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
fromAmount: "auto",
slippage: 15,
payer: 'YOUR_WALLET_ADDRESS'
});
使用百分比的兑换
// Swap 50% of balance
const swap = await tracker.swap({
from: 'TOKEN_ADDRESS',
to: 'So11111111111111111111111111111111111111112',
fromAmount: "50%",
slippage: 10,
payer: 'YOUR_WALLET_ADDRESS'
});
自定义费用的兑换
// Add 0.1% fee
const swap = await tracker.swap({
from: 'So11111111111111111111111111111111111111112',
to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
fromAmount: 1,
slippage: 10,
payer: 'YOUR_WALLET_ADDRESS',
fee: 'YOUR_FEE_WALLET:0.1',
feeType: 'add'
});
响应结构
{
"txn": "BASE64_ENCODED_TRANSACTION",
"rate": {
"amountIn": 0.1,
"amountOut": 81.631985,
"minAmountOut": 73.4687865,
"currentPrice": 0.012219167460548153,
"executionPrice": 0.010997250714493338,
"priceImpact": 0.002517,
"fee": 0.000005,
"platformFee": 9000000,
"platformFeeUI": 0.009
},
"timeTaken": 0.016,
"type": "v0"
}
Solana Tracker 平台费
标准费用:交易金额的 0.5%- 从输出中扣除
- 在
platformFee(lamports)和platformFeeUI(SOL)中显示 - 提供成交量折扣
常见错误
| 错误 | 解决方案 |
|---|---|
| 无效代币地址 | 验证地址是否有效 |
| 无效金额 | 使用数字、“auto” 或百分比 |
| 无效滑点 | 设为 0-100 之间 |
| 代币没有池 | 代币可能已下架 |
| 流动性不足 | 尝试较小金额 |
下一步
Rate 端点
JavaScript SDK
查询参数
The base token address
"So11111111111111111111111111111111111111112"
The quote token address
"4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"
The amount of the base token to swap. Accepts numeric value, 'auto' for full wallet balance, or percentage like '50%'
1
Maximum acceptable slippage percentage or 'auto' for dynamic slippage (Beta)
0 <= x <= 10010
Public key of the wallet sending the transaction
"arsc4jbDnzaqcCLByyGo7fg7S2SmcFsWUzQuDtLZh2y"
Amount in SOL to increase transaction priority or 'auto'
0.000005
Priority level when priorityFee is set to 'auto'
min, low, medium, high, veryHigh, unsafeMax Transaction version
v0, legacy Custom fee for your users in format 'WALLET_ADDRESS:PERCENTAGE'
^[a-zA-Z0-9]+:[0-9]+(\.[0-9]+)?$"arsc4jbDnzaqcCLByyGo7fg7S2SmcFsWUzQuDtLZh2y:0.1"
Custom tip for Jito or similar services in format 'WALLET_ADDRESS:SOL_AMOUNT'
^[a-zA-Z0-9]+:[0-9]+(\.[0-9]+)?$Fee application type. 'deduct' option is only used when the from address is SOL
add, deduct Disable multi-hop swaps
此页面对您有帮助吗?