Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Example query to grab token price on a certain date? #71

Open
classicrob opened this issue Sep 12, 2021 · 2 comments
Open

Example query to grab token price on a certain date? #71

classicrob opened this issue Sep 12, 2021 · 2 comments

Comments

@classicrob
Copy link

Hi! I was wondering if someone could write an example query to grab a specific token's price on a certain day? I'm struggling to figure it out by looking through the schema and I'm not yet super familiar with GraphQL. Thank you!

I recognize that token price fluctuates a lot throughout the day, so maybe an average price, or a price at a specific time stamp?

@jiro-ono
Copy link
Contributor

@classicrob try this:

{ 
  token(id: "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2") {
    dayData(where: {date: 1632096000}) {
      date
      priceUSD
    }
  }
}

Where id is the token address (in lowercase), and the date timestamp is the start of any day 00:00 UTC

Also you can do something like this to get multiple days in one query:

{ 
  token(id: "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2") {
    dayData(where: {date_in: [1632096000, 1634688000, 1618876800]}) {
      date
      priceUSD
    }
  }
}

And if you want to only grab the prices for each day in a certain range do such:

{ 
  token(id: "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2") {
    dayData(where: {date_gte: 1618876800, date_lt: 1619308800}) {
      date
      priceUSD
    }
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants