> For the complete documentation index, see [llms.txt](https://docs.heyhal.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.heyhal.xyz/api-documentation/get-reserves.md).

# Get Reserves

**Endpoint:** <mark style="color:yellow;">`GET /api/v1/coin/reserves`</mark><br>

**Description**

This endpoint retrieves the current reserves (token and SOL amounts) for a specific token's bonding curve pool. This information is crucial for calculating prices and understanding the liquidity depth of a token.

**Authentication Required:** No

**Type:** None

<br>

## **Request**&#x20;

**Headers**

Content-Type: application/json

**Query Parameters**<br>

| Parameter | Type   | Required | Description                   |
| --------- | ------ | -------- | ----------------------------- |
| token     | string | Yes      | The mint address of the token |

<br>

**Example Request:**

GET /api/v1/coin/reserves?token=TokenMintAddress123…

<br>

### Response

**Success Response**

Status Code: 200 OK

Content-Type: application/json

interface ReservesResponse {

&#x20; reserveOne: string;        // Token reserve amount (in base units)

&#x20; reserveTwo: string;        // SOL reserve amount (in lamports)

&#x20; reserveOneBN: string;      // Token reserve as BigNumber string

&#x20; reserveTwoBN: string;      // SOL reserve as BigNumber string

&#x20; reserveOneDecimal: string; // Token reserve in decimal format

&#x20; reserveTwoDecimal: string; // SOL reserve in decimal format

}

**Example Response:**

{

&#x20; "reserveOne": "1000000000000",

&#x20; "reserveTwo": "5000000000",

&#x20; "reserveOneBN": "1000000000000",

&#x20; "reserveTwoBN": "5000000000",

&#x20; "reserveOneDecimal": "1000.0",

&#x20; "reserveTwoDecimal": "5.0"

}

<br>

**Error Response**

Status Code: 500 Internal Server Error

{

&#x20; "error": "An internal error occurred. Please try again later."

}<br>

### Example Usage

async function getTokenReserves(tokenMintAddress: string) {

&#x20; try {

&#x20;   const response = await fetch(

&#x20;     \`<https://api.heyhal.xyz/api/v1/coin/reserves?token=${tokenMintAddress}\\`>

&#x20;   );

&#x20;  &#x20;

&#x20;   if (!response.ok) {

&#x20;     throw new Error(\`HTTP error! status: ${response.status}\`);

&#x20;   }

&#x20;  &#x20;

&#x20;   const reserves = await response.json();

&#x20;   return reserves;

&#x20; } catch (error) {

&#x20;   console.error('Error fetching reserves:', error);

&#x20;   throw error;

&#x20; }

}

**// Example usage with price calculation**

async function calculateTokenPrice(tokenMintAddress: string) {

&#x20; try {

&#x20;   const reserves = await getTokenReserves(tokenMintAddress);

&#x20;  &#x20;

&#x20; **// Calculate price (SOL per token)**

&#x20;   const price = Number(reserves.reserveTwoDecimal) /&#x20;

&#x20;                Number(reserves.reserveOneDecimal);

&#x20;  &#x20;

&#x20;   console.log(\`

&#x20;     Current Pool Status:

&#x20;     Token Reserve: ${reserves.reserveOneDecimal}

&#x20;     SOL Reserve: ${reserves.reserveTwoDecimal} SOL

&#x20;     Current Price: ${price.toFixed(6)} SOL/token

&#x20;   \`);

&#x20;  &#x20;

&#x20;   return price;

&#x20; } catch (error) {

&#x20;   console.error('Error calculating price:', error);

&#x20;   throw error;

&#x20; }

}

<br>

**// Example usage with liquidity analysis**

async function analyzeLiquidity(tokenMintAddress: string) {

&#x20; try {

&#x20;   const reserves = await getTokenReserves(tokenMintAddress);

&#x20;  &#x20;

&#x20;   return {

&#x20;     totalLiquiditySOL: Number(reserves.reserveTwoDecimal),

&#x20;     totalLiquidityTokens: Number(reserves.reserveOneDecimal),

&#x20;     liquidityDepth: {

&#x20;       sol: Number(reserves.reserveTwoDecimal),

&#x20;       tokens: Number(reserves.reserveOneDecimal)

&#x20;     }

&#x20;   };

&#x20; } catch (error) {

&#x20;   console.error('Error analyzing liquidity:', error);

&#x20;   throw error;

&#x20; }

}

<br>

### Implementation Notes

**Number Formats**

reserveOne and reserveTwo are provided in base units (smallest denomination)

reserveOneBN and reserveTwoBN are provided as BigNumber strings for precise calculations

reserveOneDecimal and reserveTwoDecimal are provided in human-readable decimal format

**Precision Handling**

Use the BigNumber (BN) versions for calculations to avoid floating-point precision issues

The decimal versions are provided for display purposes

SOL amounts are in lamports (1 SOL = 1,000,000,000 lamports)

**Common Calculations**

// Price calculation

const price = Number(reserves.reserveTwoDecimal) / Number(reserves.reserveOneDecimal);

// Impact of buying tokens

function calculateBuyImpact(buyAmount: number, reserves: ReservesResponse) {

&#x20; const k = Number(reserves.reserveOneDecimal) \* Number(reserves.reserveTwoDecimal);

&#x20; const newTokenReserve = Number(reserves.reserveOneDecimal) - buyAmount;

&#x20; const newSolReserve = k / newTokenReserve;

&#x20; const solNeeded = newSolReserve - Number(reserves.reserveTwoDecimal);

&#x20; return solNeeded;

}

<br>

**Error Handling**

Always check if the token exists before attempting to get reserves

Handle network errors appropriately

Consider implementing retry logic for temporary failures

## **Best Practices**

**Caching**

Consider caching the reserves data for short periods (e.g., 5-10 seconds)

Implement cache invalidation on relevant transactions

**Rate Limiting**

Implement reasonable rate limiting when polling for reserve updates

Consider using WebSocket connections for real-time updates instead of polling

**Price Impact**

Use reserves data to calculate price impact before executing trades

Consider slippage tolerance in calculations

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.heyhal.xyz/api-documentation/get-reserves.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
