> ## Documentation Index
> Fetch the complete documentation index at: https://docs.solanatracker.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Rate

## 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.

<Warning>
  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.
</Warning>

## 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

<CodeGroup>
  ```javascript JavaScript theme={null}
  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%.

  ```python Python theme={null}
  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}%")
  ```

  ```bash cURL theme={null}
  curl -X GET "https://swap-v2.solanatracker.io/rate?from=So11111111111111111111111111111111111111112&to=4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R&amount=1&slippage=10"
  ```
</CodeGroup>

## 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

```json theme={null}
{
  "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

```javascript theme={null}
// 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

<CardGroup cols={2}>
  <Card title="Swap Endpoint" icon="arrow-right-arrow-left" href="/swap-api/swap">
    Execute the swap transaction
  </Card>

  <Card title="JavaScript SDK" icon="js" href="https://github.com/YZYLAB/solana-swap">
    Install the SDK
  </Card>
</CardGroup>


## OpenAPI

````yaml openapi.json GET /rate
openapi: 3.1.0
info:
  title: Solana Tracker - Swap API
  description: >-
    The Solana Tracker Swap API offers seamless, zero-delay access to Solana's
    dynamic token marketplace. Trade tokens the moment they launch with our
    high-performance infrastructure. Supports Pump.fun, PumpSwap, Moonshot,
    Boop, Orca, Meteora, Raydium, and any pool supported by Jupiter.
  version: 2.0.0
  contact:
    name: Solana Tracker Support
    email: swap-api@solanatracker.io
    url: https://discord.com/invite/JH2e9rR9fc
  x-fees:
    standard: 0.5%
    highVolume: 0-0.5%
servers:
  - url: https://swap-v2.solanatracker.io
    description: Production server
security: []
tags:
  - name: Swap
    description: Token swap operations
  - name: Rate
    description: Rate and price quote operations
externalDocs:
  description: Full API Documentation
  url: https://docs.solanatracker.io/swap-api
paths:
  /rate:
    get:
      summary: Get Swap Quote
      description: Get live swap rates for any Solana token.
      operationId: getRate
      parameters:
        - name: from
          in: query
          required: true
          description: The base token address
          schema:
            type: string
            example: So11111111111111111111111111111111111111112
        - name: to
          in: query
          required: true
          description: The quote token address
          schema:
            type: string
            example: 4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R
        - name: amount
          in: query
          required: true
          description: >-
            The amount of the base token to convert (in native units, not
            lamports)
          schema:
            type: number
            example: 1
        - name: slippage
          in: query
          required: true
          description: The maximum acceptable slippage percentage
          schema:
            type: number
            minimum: 0
            maximum: 100
            example: 10
      responses:
        '200':
          description: Successful rate quote
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    RateResponse:
      type: object
      properties:
        amountIn:
          type: number
          description: The amount of the source token used for the conversion
          example: 1
        amountOut:
          type: number
          description: The amount of the destination token that would be received
          example: 9181.330823048
        minAmountOut:
          type: number
          description: The minimum amount of the destination token after applying slippage
          example: 9089.517514818
        currentPrice:
          type: number
          description: The current market price for the token pair
          example: 9181.330823048
        executionPrice:
          type: number
          description: The actual price at which the trade would be executed
          example: 9089.517514818
        priceImpact:
          type: number
          description: >-
            The difference between market price and execution price as a
            fraction
          example: 0.0334641736518774
        fee:
          type: number
          description: The trading fee charged for the transaction
          example: 0.01
        baseCurrency:
          type: object
          properties:
            decimals:
              type: integer
              description: Base token decimals
              example: 9
            mint:
              type: string
              description: Base token mint address
              example: So11111111111111111111111111111111111111112
        quoteCurrency:
          type: object
          properties:
            decimals:
              type: integer
              description: Quote token decimals
              example: 9
            mint:
              type: string
              description: Quote token mint address
              example: 4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R
        platformFee:
          type: integer
          description: The fee charged by the platform in lamports
          example: 9000000
        platformFeeUI:
          type: number
          description: The platform fee in SOL
          example: 0.009
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Error message
          examples:
            - An internal error occurred
            - Invalid or missing 'from' or 'to' token address
            - Invalid amount
            - Invalid slippage tolerance (should be between 0 and 100%)
        details:
          type: string
          description: Additional error details
          examples:
            - Unable to fetch pools for token
            - Token has no pools
            - No pools with liquidity found

````