curl --request GET \
--url https://swap-v2.solanatracker.io/rateimport requests
url = "https://swap-v2.solanatracker.io/rate"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://swap-v2.solanatracker.io/rate', 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/rate",
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/rate"
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/rate")
.asString();require 'uri'
require 'net/http'
url = URI("https://swap-v2.solanatracker.io/rate")
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{
"amountIn": 1,
"amountOut": 9181.330823048,
"minAmountOut": 9089.517514818,
"currentPrice": 9181.330823048,
"executionPrice": 9089.517514818,
"priceImpact": 0.0334641736518774,
"fee": 0.01,
"baseCurrency": {
"decimals": 9,
"mint": "So11111111111111111111111111111111111111112"
},
"quoteCurrency": {
"decimals": 9,
"mint": "4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"
},
"platformFee": 9000000,
"platformFeeUI": 0.009
}{
"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 /rate 获取 Solana 代币兑换报价,返回预期输出数量和价格影响。请在兑换前使用,不要当作价格 API。
curl --request GET \
--url https://swap-v2.solanatracker.io/rateimport requests
url = "https://swap-v2.solanatracker.io/rate"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://swap-v2.solanatracker.io/rate', 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/rate",
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/rate"
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/rate")
.asString();require 'uri'
require 'net/http'
url = URI("https://swap-v2.solanatracker.io/rate")
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{
"amountIn": 1,
"amountOut": 9181.330823048,
"minAmountOut": 9089.517514818,
"currentPrice": 9181.330823048,
"executionPrice": 9089.517514818,
"priceImpact": 0.0334641736518774,
"fee": 0.01,
"baseCurrency": {
"decimals": 9,
"mint": "So11111111111111111111111111111111111111112"
},
"quoteCurrency": {
"decimals": 9,
"mint": "4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"
},
"platformFee": 9000000,
"platformFeeUI": 0.009
}{
"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 密钥。概览
rate 端点为代币兑换提供执行交易前的价格报价。用它在用户即将兑换时向其显示预期输出量和价格影响。用例
- 兑换前报价:在执行兑换前获取准确定价
- 滑点计算:向用户显示最低保证输出
- 价格影响检查:验证交易规模是否可接受
SDK 示例
import { SolanaTracker } from 'solana-swap';
const tracker = new SolanaTracker('YOUR_API_KEY');
// Get rate quote before swap
const quote = await tracker.getRate({
from: 'So11111111111111111111111111111111111111112', // SOL
to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
amount: 1,
slippage: 10
});
console.log(`Expected: ${quote.amountOut} tokens`);
console.log(`Minimum: ${quote.minAmountOut} tokens`);
console.log(`Price impact: ${(quote.priceImpact * 100).toFixed(2)}%`);
slippage: 10 表示 10%。from solana_swap import SolanaTracker
tracker = SolanaTracker('YOUR_API_KEY')
# Get rate quote before swap
quote = tracker.get_rate(
from_token='So11111111111111111111111111111111111111112',
to_token='4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
amount=1,
slippage=10
)
print(f"Expected: {quote['amountOut']} tokens")
print(f"Minimum: {quote['minAmountOut']} tokens")
print(f"Price impact: {quote['priceImpact'] * 100:.2f}%")
curl -X GET "https://swap-v2.solanatracker.io/rate?from=So11111111111111111111111111111111111111112&to=4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R&amount=1&slippage=10"
响应字段
| 字段 | 类型 | 描述 |
|---|---|---|
amountIn | number | 输入代币数量 |
amountOut | number | 预期输出代币数量 |
minAmountOut | number | 滑点后最低输出 |
currentPrice | number | 当前市场价格 |
executionPrice | number | 实际执行价格 |
priceImpact | number | 价格影响(小数,0.05 = 5%) |
fee | number | 交易费用 |
platformFee | number | 平台费(lamports) |
platformFeeUI | number | 平台费(SOL) |
示例响应
{
"amountIn": 1,
"amountOut": 9181.330823048,
"minAmountOut": 9089.517514818,
"currentPrice": 9181.330823048,
"executionPrice": 9089.517514818,
"priceImpact": 0.0334641736518774,
"fee": 0.01,
"baseCurrency": {
"decimals": 9,
"mint": "So11111111111111111111111111111111111111112"
},
"quoteCurrency": {
"decimals": 9,
"mint": "4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"
},
"platformFee": 9000000,
"platformFeeUI": 0.009
}
理解价格影响
价格影响显示您的交易使市场价格变动多少:- < 1% - 流动性极好,可放心交易
- 1-5% - 大多数交易可接受
- > 5% - 考虑较小的交易、不同的路径或等待更多流动性
在兑换前验证
// Check rate before executing swap
async function validateAndSwap(swapParams) {
// Get quote first
const quote = await tracker.getRate({
from: swapParams.from,
to: swapParams.to,
amount: swapParams.amount,
slippage: swapParams.slippage
});
// Check price impact
if (quote.priceImpact > 0.05) {
throw new Error('Price impact too high');
}
// Execute swap
return await tracker.swap(swapParams);
}
常见错误
| 错误 | 描述 | 解决方案 |
|---|---|---|
Invalid or missing token address | 代币地址无效 | 验证代币地址 |
Invalid amount | 金额无效 | 确保金额为正数 |
Invalid slippage tolerance | 滑点不在 0-100 之间 | 将滑点设为 0-100 |
Unable to fetch pools | 找不到流动性 | 代币可能缺少活跃池 |
下一步
Swap 端点
JavaScript SDK
查询参数
The base token address
"So11111111111111111111111111111111111111112"
The quote token address
"4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"
The amount of the base token to convert (in native units, not lamports)
1
The maximum acceptable slippage percentage
0 <= x <= 10010
响应
Successful rate quote
The amount of the source token used for the conversion
1
The amount of the destination token that would be received
9181.330823048
The minimum amount of the destination token after applying slippage
9089.517514818
The current market price for the token pair
9181.330823048
The actual price at which the trade would be executed
9089.517514818
The difference between market price and execution price as a fraction
0.0334641736518774
The trading fee charged for the transaction
0.01
Show child attributes
Show child attributes
Show child attributes
Show child attributes
The fee charged by the platform in lamports
9000000
The platform fee in SOL
0.009
此页面对您有帮助吗?