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"
}Rate
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"
}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.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)}%`);
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
JavaScript SDK
Query Parameters
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
Response
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
Was this page helpful?