Skip to content

Instantly share code, notes, and snippets.

@ries9112
Last active June 6, 2021 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ries9112/b3198514632157c644ad6b7beae6b5f6 to your computer and use it in GitHub Desktop.
Save ries9112/b3198514632157c644ad6b7beae6b5f6 to your computer and use it in GitHub Desktop.
An example of pulling data from the hic et nunc GraphQL endpoint by @marchingsquare into the R programming language for further manipulation
library(ghql)
library(jsonlite)
# Address to lookup:
address = "tz1c2iwyckUCcicx2qxqtwLEartYFEHg1pvB"
# connect to the endpoint
con <- GraphqlClient$new(
url = "https://api.hicdex.com/v1/graphql"
)
# initialize a new query
graphql_request <- Query$new()
# Define query
graphql_request$query('mydata', paste0('{
hic_et_nunc_swap(where: {status: {_in: [1]}, token: {swaps: {trades: {buyer: {address: {_eq: "',address,'"}}}}}}, order_by: {price: desc}) {
price
status
token {
title
mime
description
id
artifact_uri
}
timestamp
amount
amount_left
}
}'))
# Run query (pull data)
hen_data <- con$exec(graphql_request$queries$mydata)
# convert results to JSON
hen_data <- fromJSON(hen_data)
# extract dataframe
hen_data <- hen_data$data$hic_et_nunc_swap
# Add Tezos price
hen_data$price_tezos = hen_data$price/1000000
## Start analysis now
library(tidyverse)
# First unique the data
hen_data_new <- distinct(hen_data, token, .keep_all = TRUE)
# View data
View(hen_data_new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment