Skip to content

Instantly share code, notes, and snippets.

@mariuswatz
Last active June 12, 2023 06:47
Show Gist options
  • Save mariuswatz/7bc47cdecc431eab84855bb47a628df0 to your computer and use it in GitHub Desktop.
Save mariuswatz/7bc47cdecc431eab84855bb47a628df0 to your computer and use it in GitHub Desktop.
GraphQL query that will get buy and sell activities for a specified Tezos wallet for a given date range, including sale / buy sum totals and number of events.
# Copy the following GraphQL query into the TezTok API Explorer at
# https://graphiql.teztok.com/
# Fill out the wallet, date1 and date2 parameters with the Tezos address
# and date range you're interested in. The output combines events() and
# events_aggregate() query to give you a quick overview over sales and buys
# over the time period.
#
# Example:
#
# {
# "wallet": "tz2NY3Fgt5QufrYGP1JKdvLKcWWt86sLsqrS",
# "date1": "2023-06-01",
# "date2": "2023-07-01"
# }
#
query getSaleStats($wallet: String!, $date1: timestamptz!, $date2: timestamptz!) {
buys: events_aggregate(where: {implements: {_eq: "SALE"}, buyer_address: {_eq: $wallet}, timestamp: {_gte: $date1, _lt: $date2}}, order_by: {price: asc}) {
aggregate {
sum {
price
}
count(columns: timestamp)
max {
price
timestamp
}
min {
price
timestamp
}
}
nodes {
timestamp
price
seller_address
seller_profile {
alias
twitter
}
token {
name
fa2_address
token_id
}
}
}
sales: events_aggregate(where: {implements: {_eq: "SALE"}, seller_address: {_eq: $wallet}, timestamp: {_gte: $date1, _lt: $date2}}, order_by: {price: asc}) {
aggregate {
sum {
price
}
count(columns: timestamp)
max {
price
timestamp
}
min {
price
timestamp
}
}
nodes {
timestamp
price
buyer_address
buyer_profile {
alias
twitter
}
token {
name
fa2_address
token_id
}
}
}
events(where: {implements: {_eq: "SALE"}, _or: [{seller_address: {_eq: $wallet}}, {buyer_address: {_eq: $wallet}}], timestamp: {_gte: $date1, _lt: $date2}}, order_by: {price: asc}) {
timestamp
type
token_id
price
buyer_address
buyer_profile {
alias
twitter
}
seller_address
seller_profile {
alias
twitter
}
token {
artist_address
name
fa2_address
token_id
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment