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

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?

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

FULL QUERY BELOW:

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)
                  }
                }
              }
            }

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:

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.

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.

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:

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:

{
  "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:

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

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

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