After completing the authentication process and loading the required packages, you can directly access BigQuery from the Co-lab IDE. Below are some examples:
Sample Code To Track All Trades for a Token
# Example 3: SQL query moved to colab
result_3 = client.query("""
SELECT
token_address,
DATE(block_timestamp) as date,
SUM(CAST(value AS FLOAT64)) AS sum_value
FROM
`bigquery-public-data.crypto_ethereum.token_transfers`
WHERE
token_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
GROUP BY
date, token_address
ORDER BY
date ASC
""").result()
Note that you have to specify a token address.
The result can then be loaded into a pandas dataframe for additional processing.
# Example 3: Moving the query data to a pandas.DataFrame
df_3 = result_3.to_dataframe()
df_3['date'] = pandas.to_datetime(df_3['date'])
df_3.head()
We can then create visualizations with the following code.
# Example 3: Visualising token transfer gross value for a specific token, in a line chart
rolling_period = 15
fig = plt.figure()
plt.plot(df_3['date'] ,df_3['sum_value'].rolling(rolling_period).sum() ,'r')
plt.legend((['Gross USDC transfer value, in # of tokens, 15-day rolling period']))
plt.show()