Skip to content

Instantly share code, notes, and snippets.

@mattebb
Forked from mariuswatz/TezTok-getSaleStats.ql
Last active June 12, 2023 06:52
Show Gist options
  • Save mattebb/4b7b50e34992b5e522b4767d156853ad to your computer and use it in GitHub Desktop.
Save mattebb/4b7b50e34992b5e522b4767d156853ad 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": "tz2LxoshyxpJ1oyfN3WReb3cA38doAUxZt1H",
# "date1": "2021-07-01",
# "date2": "2022-06-30"
# }
#
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: {timestamp: asc}) {
aggregate {
min {
price
timestamp
}
max {
price
timestamp
}
count(columns: timestamp)
}
nodes {
timestamp
price
seller_address
seller_profile {
alias
twitter
}
token {
name
fa2_address
token_id
}
price_in_usd
}
}
sales: events_aggregate(where: {implements: {_eq: "SALE"}, seller_address: {_eq: $wallet}, timestamp: {_gte: $date1, _lt: $date2}}, order_by: {price: asc}) {
aggregate {
min {
price
timestamp
}
max {
price
timestamp
}
count(columns: timestamp)
}
nodes {
timestamp
price
seller_address
seller_profile {
alias
twitter
}
token {
name
fa2_address
token_id
}
price_in_usd
}
}
events(where: {implements: {_eq: "SALE"}, _or: [{seller_address: {_eq: $wallet}}, {buyer_address: {_eq: $wallet}}], timestamp: {_gte: $date1, _lt: $date2}}, order_by: {timestamp: 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
artist_profile {
alias
}
}
price_in_usd
token_name
artist_profile {
alias
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment