beta_load_subgraph

Fetch data from a single subgraph

beta_load_subgraph(
    url,     
    query, 
    progressCallback=None, 
    useBigDecimal=False)

Parameters

  • url (str)

    The endpoint of a subgraph. Explore the existing subgraphs here.

  • query (str)

    The subgraph query to get desired data from a subgraph. You can play / test your query at the graph explorer or the graph studio.

    • pass in bypassPagination: true in each entity when you need to fetch large data set.

  • progressCallback (callback function)

    Optional. A callback function is triggered when items are retrieved from the graph. It can be used to track the progress of retrieving large amount of data from a subgraph. The argument is defined as {<Entity_name>: <Number_of_items_loaded>}

  • useBigDecimal (Boolean)

    Optional. Default is False. And the numbers are treated as float64 type. If the value is True, the numbers are treated as decimal128. We only recommend doing so when you absolutely need the accuracy, for example when displaying account balance, since decimal128 is not natively supported in pandas or numpy, you will have to create your own methods to process the data down the pipeline.

Return

The subgraph data returned in a DataFrame type. If you have not familiar with pandas.DataFrame, please check out these tutorials.

{
    <Entity_name>: <DataFrame_of_items_from_the_graph>
}

Examples

From 2021-01-01 to 2021-01-10, fetch all deposits and earliest 3 flash loans from the AAVE v2 subgraph.

url = 'https://api.thegraph.com/subgraphs/name/aave/protocol-v2'
query = """
{
    deposits(
        where:{timestamp_gt:1609459200, timestamp_lt:1610236800}
        orderBy: timestamp
        orderDirection: desc
        bypassPagination: true 
    ) {
        amount
        timestamp
    }
    flashLoans(
        orderBy: timestamp
        orderDirection: asc
        first:3
    ){
        amount
         timestamp
     }
}
"""

data = bubbletea.beta_load_subgraph(url, query)

df_deposits = data['deposits']
df_flashloans = data['flashLoans']

print(df_deposits) 
print(df_deposits.dtypes) #Print column types.
print(df_flashloans)
print(df_flashloans.dtypes)

Last updated

Was this helpful?