Skip to content

Instantly share code, notes, and snippets.

@rodrigosobrero
Last active December 3, 2020 13:46
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 rodrigosobrero/9c00bba87513d2fb7de052921e38dea2 to your computer and use it in GitHub Desktop.
Save rodrigosobrero/9c00bba87513d2fb7de052921e38dea2 to your computer and use it in GitHub Desktop.
Obtener precio de un token con el Subgraph oficial de Balancer.
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
transport = AIOHTTPTransport(url="https://api.thegraph.com/subgraphs/name/balancer-labs/balancer")
client = Client(transport=transport, fetch_schema_from_transport=True)
# DAI
tokenAddress = "0x6b175474e89094c44da98b954eedeac495271d0f"
query = gql(
"""
query getPrice($id: ID!) {
tokenPrice(id: $id) {
price
}
}
"""
)
params = {"id", tokenAddress}
result = client.execute(query, variable_values=params)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment