
fragment CandlestickOHLC on TimestampedOhlc {
  id
  timestamp
  open {
    id
    value
  }
  high {
    id
    value
  }
  low {
    id
    value
  }
  close {
    id
    value
  }
}

fragment PriceHistoryFallback on TimestampedAmount {
  id
  value
  timestamp
}

query TokenPrice($chain: Chain!, $address: String = null, $duration: HistoryDuration!, $fallback: Boolean = false) {
  token(chain: $chain, address: $address) {
    id
    address
    chain
    market(currency: USD) {
      id
      price {
        id
        value
      }
      ohlc(duration: $duration) @skip(if: $fallback) {
        ...CandlestickOHLC
      }
      priceHistory(duration: $duration) @include(if: $fallback) {
        ...PriceHistoryFallback
      }
    }
  }
}

query TokenHistoricalVolumes($chain: Chain!, $address: String = null, $duration: HistoryDuration!) {
  token(chain: $chain, address: $address) {
    id
    address
    chain
    market(currency: USD) {
      id
      historicalVolume(duration: $duration) {
        id
        timestamp
        value
      }
    }
  }
}

query TokenHistoricalTvls($chain: Chain!, $address: String = null, $duration: HistoryDuration!) {
  token(chain: $chain, address: $address) {
    id
    address
    chain
    market(currency: USD) {
      id
      historicalTvl(duration: $duration) {
        id
        timestamp
        value
      }
      totalValueLocked {
        id
        value
        currency
      }
    }
  }
}
