> For the complete documentation index, see [llms.txt](https://developers.lfj.gg/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.lfj.gg/guides/id-from-price.md).

# Bin Id From Price

As mentioned previously, it is possible to link a `bin` to a price. It is also possible to perform the conversion in the other direction and thus link a price to a `bin`. We provide examples to get the `binId` from a price.

#### Conversion Functions

As the previous example, it is necessary to know the `binStep` of the underlying pair. Here is the conversion logic.

{% tabs %}
{% tab title="Typescript" %}

```typescript
function getIdFromPrice(price: number, binStep: number): number {
  /**
   * Convert a price to the underlying binId.
   *
   * @param price - Price of the bin.
   * @param binStep - BinStep of the pair.
   * @return BinId of the underlying bin.
   */

  return Math.trunc(Math.log(price) / Math.log(1 + binStep / 10_000)) + 8388608;
}
```

{% endtab %}

{% tab title="Python" %}

```python
import math

def getIdFromPrice(price: float, binStep: int) -> int:
    """
    Convert a price to the underlying binId.

    :param price: Price of the bin.
    :param binStep: BinStep of the pair.
    :return: Id of the underlying bin.
    """

    return (
      math.trunc(math.log(price) / math.log(1 + binStep / 10_000)) + 8388608
    )
```

{% endtab %}
{% endtabs %}

#### Example

Here is an example to illustrate the conversion function with the [`sAVAX`/`AVAX`](https://lfj.gg/avalanche/pool/v21/0x2b2c81e08f1af8835a78bb2a90ae924ace0ea4be/AVAX/5) pair which has a `binStep` of 5. We choose here a price equal to 1.075, as both tokens have 18 decimals.

```python
getIdFromPrice(1.075, 5)
>>> 8388752
```

For second example, let's take [BTC.b/USDC](https://lfj.gg/avalanche/pool/v21/0x152b9d0fdc40c096757f570a51e494bd4b943e50/0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e/10) pair which has a `binStep` of 10. To choose price equal to 30000 USDC / BTC.b we need to adjust it

$$
priceAdjusted = price\cdot 10^{(\text{decimalsY} - \text{decimalsX})}
$$

$$
priceAdjusted = 30 000 \cdot 10^{(\text{6} - \text{8})} = 300
$$

```python
getIdFromPrice(300, 10)
>>> 8394314
```


---

# 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://developers.lfj.gg/guides/id-from-price.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.
