Get Swap Quote
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"
}Legacy Swap API
Get a Solana Swap Quote with the Swap API
Get a price quote for a Solana token swap with GET /rate: expected output amount and price impact. Use it before a swap, not as a pricing API.
GET
/
rate
Get Swap Quote
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"
}This page covers the older Solana Tracker Swap API at
swap-v2.solanatracker.io. It is still live and charges a platform fee on each swap. Raptor is a separate swap API at raptor.solanatracker.io, currently free with no API key.Overview
The rate endpoint provides price quotes for token swaps before executing a transaction. Use this to show users the expected output amount and price impact when they’re ready to swap.This endpoint is for pre-swap quotes only. Do not use it as a free pricing or market data API. Excessive requests for non-swap purposes may result in rate limiting.
Use Cases
- Pre-Swap Quotes: Get accurate pricing before executing a swap
- Slippage Calculation: Show users the minimum guaranteed output
- Price Impact Check: Validate that trade size is acceptable
SDK Examples
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)}%`);
In these SDK examples,
slippage: 10 means 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"
Response Fields
| Field | Type | Description |
|---|---|---|
amountIn | number | Input token amount |
amountOut | number | Expected output token amount |
minAmountOut | number | Minimum output after slippage |
currentPrice | number | Current market price |
executionPrice | number | Actual execution price |
priceImpact | number | Price impact as decimal (0.05 = 5%) |
fee | number | Trading fee |
platformFee | number | Platform fee in lamports |
platformFeeUI | number | Platform fee in SOL |
Example Response
{
"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
}
Understanding Price Impact
Price impact shows how much your trade moves the market price:- < 1% - Excellent liquidity, proceed with confidence
- 1-5% - Acceptable for most trades
- > 5% - Consider a smaller trade, a different route, or waiting for more liquidity
Validate Before Swap
// 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);
}
Common Errors
| Error | Description | Solution |
|---|---|---|
Invalid or missing token address | Token address is invalid | Verify token addresses |
Invalid amount | Amount is not valid | Ensure amount is positive |
Invalid slippage tolerance | Slippage not between 0-100 | Set slippage 0-100 |
Unable to fetch pools | Cannot find liquidity | Token may lack active pools |
Next Steps
Swap Endpoint
Execute the swap transaction
JavaScript SDK
Install the SDK
Query Parameters
Response
Successful rate quote
Was this page helpful?