# Is this the correct query to get OHLC price data for a given token in USD for Solana?

**URL:** <https://community.bitquery.io/t/is-this-the-correct-query-to-get-ohlc-price-data-for-a-given-token-in-usd-for-solana/1901>\
**Category:** GraphQL API\
**Created:** [April 30, 2024, 5:50pm UTC](https://community.bitquery.io/t/is-this-the-correct-query-to-get-ohlc-price-data-for-a-given-token-in-usd-for-solana/1901 "2024-04-30T17:50:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![duotang](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@duotang](https://community.bitquery.io/u/duotang)\
**Post date:** [April 30, 2024, 5:50pm UTC](https://community.bitquery.io/t/is-this-the-correct-query-to-get-ohlc-price-data-for-a-given-token-in-usd-for-solana/1901/1 "2024-04-30T17:50:36Z")

</div>

I’m mainly wondering about the section below. Should I be using something like “median(of: )” in order to get the midpoint of buys and sells for each of high, low, open, close?

```auto
Trade {
                    high: PriceInUSD(maximum: Trade_PriceInUSD)
                    low: PriceInUSD(minimum: Trade_PriceInUSD)
                    open: PriceInUSD(minimum: Block_Height)
                    close: PriceInUSD(maximum: Block_Height)
                  }

```

FULL QUERY BELOW:

```auto
query {
              Solana {
                Archive: DEXTradeByTokens(
                  orderBy: {ascendingByField: "Block_Time"}
                  where: {
                    Trade: {
                      Currency: {MintAddress: {is: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"}},
                      Side: {Currency: {MintAddress: {is: "So11111111111111111111111111111111111111112"}}},
                      PriceAsymmetry: {lt: 0.01},
                      AmountInUSD: {gt: "0.000000000001"}
                    }
                  }
                ) 
                {
                  Block {
                    Time(interval: {in: minutes, count: 5})
                  }
                  Trade {
                    high: PriceInUSD(maximum: Trade_PriceInUSD)
                    low: PriceInUSD(minimum: Trade_PriceInUSD)
                    open: PriceInUSD(minimum: Block_Height)
                    close: PriceInUSD(maximum: Block_Height)
                  }
                }
              }
            }

```

---

<div class="post-metadata">

**Author:** ![duotang](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@duotang](https://community.bitquery.io/u/duotang)\
**Post date:** [May 1, 2024, 8:37pm UTC](https://community.bitquery.io/t/is-this-the-correct-query-to-get-ohlc-price-data-for-a-given-token-in-usd-for-solana/1901/2 "2024-05-01T20:37:13Z")

</div>

I’ve tried modifying the query several times but can’t seem to get accurate USD prices for Solana tokens using DexTradeByTokens.

Would be helpful to know more about PriceInUSD vs Trade\_PriceInUSD and how that relates to this snippet:

```auto
Trade {
  high: PriceInUSD(maximum: Trade_PriceInUSD)
  low: PriceInUSD(minimum: Trade_PriceInUSD)
  open: PriceInUSD(minimum: Block_Height)
  close: PriceInUSD(maximum: Block_Height)
}

```

Would also be nice to know more about the Solana\_DEXTradeByToken\_Cube object in general.

---

<div class="post-metadata">

**Author:** ![Divya](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@Divya](https://community.bitquery.io/u/Divya)\
**Post date:** [May 2, 2024, 11:37am UTC](https://community.bitquery.io/t/is-this-the-correct-query-to-get-ohlc-price-data-for-a-given-token-in-usd-for-solana/1901/3 "2024-05-02T11:37:46Z")

</div>

Hello,

The query is correct. Few things

- wrt EAP, it has only real-time info that goes back a few hours
- It might be closer to the coinmarketcap value if the data was over longer periods which is currently not possible with EAP
- We have 3 mint candle based on token trading volume on centralized exchanges, so we refresh USD price in every 3 mint.

---

<div class="post-metadata">

**Author:** ![duotang](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@duotang](https://community.bitquery.io/u/duotang)\
**Post date:** [May 3, 2024, 10:54pm UTC](https://community.bitquery.io/t/is-this-the-correct-query-to-get-ohlc-price-data-for-a-given-token-in-usd-for-solana/1901/4 "2024-05-03T22:54:27Z")

</div>

Thanks @Divya. Have now found a query that’s fairly consistent for getting the historical ohlc data.

Now for the live subscription data I’m having trouble getting accurate USD prices for Solana tokens.

Take for example the query below:

```auto
subscription ($token: String) {
              Solana {
                Live: DEXTradeByTokens(
                  orderBy: {descendingByField: "Block_Time"}
                  where: {
                    Trade: {
                      Currency: {MintAddress: {is: $token}},
                      Side: {Currency: {MintAddress: {is: "So11111111111111111111111111111111111111112"}}},
                      PriceAsymmetry: {le: 0.01}, 
                      Price: {gt: 0}}}
                ) {
                  Block {
                    Time
                  }
                  Trade {
                    price: PriceInUSD
                  }
                }
              }
            }

```

Say we set $token = “25hAyBQfoDhfWx9ay6rarbgvWGwDdNqcHsXS3jQ3mTDJ” for MANEKI token. using:

```auto
{
  "token": "25hAyBQfoDhfWx9ay6rarbgvWGwDdNqcHsXS3jQ3mTDJ"
}

```

The output provided by the API is wrong in terms of both magnitude and value. At time of writing it outputs a USD price of $0.00000105… whereas the current USD price is $0.01233.

I was thinking the value issue is maybe a midpoint problem and the magnitude issue I can sort out later, so I try getting price as follows:

```auto
{
                  Block {
                    Time
                  }
                  price: median(of: Trade_PriceInUSD)
                }
              }
            }

```

But this still outputs the same $0.00000105.

That said, using Trade {Price} does seem to output the correct price in SOL, so it seems to only be a USD issue.

---

<div class="post-metadata">

**Author:** ![duotang](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@duotang](https://community.bitquery.io/u/duotang)\
**Post date:** [May 8, 2024, 9:23pm UTC](https://community.bitquery.io/t/is-this-the-correct-query-to-get-ohlc-price-data-for-a-given-token-in-usd-for-solana/1901/5 "2024-05-08T21:23:08Z")

</div>

@gaurav @Divya any thoughts? I feel like I’m doing something wrong.

---

<div class="post-metadata">

**Author:** ![akshat.bitquery](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@akshat.bitquery](https://community.bitquery.io/u/akshat.bitquery)\
**Post date:** [May 13, 2024, 9:04am UTC](https://community.bitquery.io/t/is-this-the-correct-query-to-get-ohlc-price-data-for-a-given-token-in-usd-for-solana/1901/6 "2024-05-13T09:04:44Z")

</div>

Now, it will give you correct priceInUSD. The issue was resolved. Try again and let us know if you face any problems.
