Created
January 30, 2023 18:25
-
-
Save Evan-Kim2028/6207e537161c9396ab8bf9b14eeed5d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from datastreams.datastream import Streamer\n", | |
"\n", | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pd.set_option('display.max_columns', None)\n", | |
"pd.set_option('display.expand_frame_repr', False)\n", | |
"pd.set_option('max_colwidth', None)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# select subgraph endpoint\n", | |
"endpoint = 'https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# https://info.uniswap.org/#/pools/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\n", | |
"# https://etherscan.io/address/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640\n", | |
"\n", | |
"# USDC/WETH \n", | |
"lp_name = '0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# load Streamer class\n", | |
"ds = Streamer(endpoint)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"dict_keys(['tokens', 'rewardTokens', 'liquidityPoolFees', 'dexAmmProtocols', 'usageMetricsDailySnapshots', 'usageMetricsHourlySnapshots', 'financialsDailySnapshots', 'liquidityPools', 'liquidityPoolDailySnapshots', 'liquidityPoolHourlySnapshots', 'deposits', 'withdraws', 'swaps', 'accounts', 'activeAccounts', 'liquidityPoolAmounts', 'helperStores', 'tokenWhitelists', 'protocols', 'events'])" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# check available query fields via the query dictionary.\n", | |
"ds.queryDict.keys()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"FIELD - liquidityPoolAmounts\n" | |
] | |
}, | |
{ | |
"ename": "PaginationError", | |
"evalue": "Expecting value: line 1 column 1 (char 0)", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mJSONDecodeError\u001b[0m Traceback (most recent call last)", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/requests/models.py:971\u001b[0m, in \u001b[0;36mResponse.json\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 970\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 971\u001b[0m \u001b[39mreturn\u001b[39;00m complexjson\u001b[39m.\u001b[39;49mloads(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtext, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 972\u001b[0m \u001b[39mexcept\u001b[39;00m JSONDecodeError \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 973\u001b[0m \u001b[39m# Catch JSON-related errors and raise as requests.JSONDecodeError\u001b[39;00m\n\u001b[1;32m 974\u001b[0m \u001b[39m# This aliases json.JSONDecodeError and simplejson.JSONDecodeError\u001b[39;00m\n", | |
"File \u001b[0;32m/usr/lib/python3.10/json/__init__.py:346\u001b[0m, in \u001b[0;36mloads\u001b[0;34m(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[1;32m 343\u001b[0m \u001b[39mif\u001b[39;00m (\u001b[39mcls\u001b[39m \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m object_hook \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m\n\u001b[1;32m 344\u001b[0m parse_int \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m parse_float \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m\n\u001b[1;32m 345\u001b[0m parse_constant \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m object_pairs_hook \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m kw):\n\u001b[0;32m--> 346\u001b[0m \u001b[39mreturn\u001b[39;00m _default_decoder\u001b[39m.\u001b[39;49mdecode(s)\n\u001b[1;32m 347\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mcls\u001b[39m \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n", | |
"File \u001b[0;32m/usr/lib/python3.10/json/decoder.py:337\u001b[0m, in \u001b[0;36mJSONDecoder.decode\u001b[0;34m(self, s, _w)\u001b[0m\n\u001b[1;32m 333\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Return the Python representation of ``s`` (a ``str`` instance\u001b[39;00m\n\u001b[1;32m 334\u001b[0m \u001b[39mcontaining a JSON document).\u001b[39;00m\n\u001b[1;32m 335\u001b[0m \n\u001b[1;32m 336\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m--> 337\u001b[0m obj, end \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mraw_decode(s, idx\u001b[39m=\u001b[39;49m_w(s, \u001b[39m0\u001b[39;49m)\u001b[39m.\u001b[39;49mend())\n\u001b[1;32m 338\u001b[0m end \u001b[39m=\u001b[39m _w(s, end)\u001b[39m.\u001b[39mend()\n", | |
"File \u001b[0;32m/usr/lib/python3.10/json/decoder.py:355\u001b[0m, in \u001b[0;36mJSONDecoder.raw_decode\u001b[0;34m(self, s, idx)\u001b[0m\n\u001b[1;32m 354\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mStopIteration\u001b[39;00m \u001b[39mas\u001b[39;00m err:\n\u001b[0;32m--> 355\u001b[0m \u001b[39mraise\u001b[39;00m JSONDecodeError(\u001b[39m\"\u001b[39m\u001b[39mExpecting value\u001b[39m\u001b[39m\"\u001b[39m, s, err\u001b[39m.\u001b[39mvalue) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39m\n\u001b[1;32m 356\u001b[0m \u001b[39mreturn\u001b[39;00m obj, end\n", | |
"\u001b[0;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)", | |
"\nDuring handling of the above exception, another exception occurred:\n", | |
"\u001b[0;31mJSONDecodeError\u001b[0m Traceback (most recent call last)", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/pagination/pagination.py:79\u001b[0m, in \u001b[0;36mpaginate\u001b[0;34m(schema, doc, pagination_strategy)\u001b[0m\n\u001b[1;32m 78\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 79\u001b[0m page_data \u001b[39m=\u001b[39m client\u001b[39m.\u001b[39;49mquery(\n\u001b[1;32m 80\u001b[0m url\u001b[39m=\u001b[39;49mdoc\u001b[39m.\u001b[39;49murl,\n\u001b[1;32m 81\u001b[0m query_str\u001b[39m=\u001b[39;49mdoc\u001b[39m.\u001b[39;49mgraphql,\n\u001b[1;32m 82\u001b[0m variables\u001b[39m=\u001b[39;49mdoc\u001b[39m.\u001b[39;49mvariables \u001b[39m|\u001b[39;49m args\n\u001b[1;32m 83\u001b[0m )\n\u001b[1;32m 84\u001b[0m data \u001b[39m=\u001b[39m merge(data, page_data)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/client.py:162\u001b[0m, in \u001b[0;36mquery\u001b[0;34m(url, query_str, variables)\u001b[0m\n\u001b[1;32m 151\u001b[0m logger\u001b[39m.\u001b[39minfo(\n\u001b[1;32m 152\u001b[0m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mclient.query: url = \u001b[39m\u001b[39m{\u001b[39;00murl\u001b[39m}\u001b[39;00m\u001b[39m, variables = \u001b[39m\u001b[39m{\u001b[39;00mvariables\u001b[39m}\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39m{\u001b[39;00mquery_str\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m\n\u001b[1;32m 153\u001b[0m )\n\u001b[1;32m 154\u001b[0m resp \u001b[39m=\u001b[39m requests\u001b[39m.\u001b[39;49mpost(\n\u001b[1;32m 155\u001b[0m url,\n\u001b[1;32m 156\u001b[0m json\u001b[39m=\u001b[39;49m(\n\u001b[1;32m 157\u001b[0m {\u001b[39m'\u001b[39;49m\u001b[39mquery\u001b[39;49m\u001b[39m'\u001b[39;49m: query_str}\n\u001b[1;32m 158\u001b[0m \u001b[39mif\u001b[39;49;00m variables \u001b[39m==\u001b[39;49m {}\n\u001b[1;32m 159\u001b[0m \u001b[39melse\u001b[39;49;00m {\u001b[39m'\u001b[39;49m\u001b[39mquery\u001b[39;49m\u001b[39m'\u001b[39;49m: query_str, \u001b[39m'\u001b[39;49m\u001b[39mvariables\u001b[39;49m\u001b[39m'\u001b[39;49m: variables}\n\u001b[1;32m 160\u001b[0m ),\n\u001b[1;32m 161\u001b[0m headers\u001b[39m=\u001b[39;49m{\u001b[39m'\u001b[39;49m\u001b[39mContent-Type\u001b[39;49m\u001b[39m'\u001b[39;49m: \u001b[39m'\u001b[39;49m\u001b[39mapplication/json\u001b[39;49m\u001b[39m'\u001b[39;49m}\n\u001b[0;32m--> 162\u001b[0m )\u001b[39m.\u001b[39;49mjson()\n\u001b[1;32m 164\u001b[0m \u001b[39mtry\u001b[39;00m:\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/requests/models.py:975\u001b[0m, in \u001b[0;36mResponse.json\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 972\u001b[0m \u001b[39mexcept\u001b[39;00m JSONDecodeError \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 973\u001b[0m \u001b[39m# Catch JSON-related errors and raise as requests.JSONDecodeError\u001b[39;00m\n\u001b[1;32m 974\u001b[0m \u001b[39m# This aliases json.JSONDecodeError and simplejson.JSONDecodeError\u001b[39;00m\n\u001b[0;32m--> 975\u001b[0m \u001b[39mraise\u001b[39;00m RequestsJSONDecodeError(e\u001b[39m.\u001b[39mmsg, e\u001b[39m.\u001b[39mdoc, e\u001b[39m.\u001b[39mpos)\n", | |
"\u001b[0;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)", | |
"\nDuring handling of the above exception, another exception occurred:\n", | |
"\u001b[0;31mPaginationError\u001b[0m Traceback (most recent call last)", | |
"Cell \u001b[0;32mIn[22], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m df \u001b[39m=\u001b[39m ds\u001b[39m.\u001b[39;49mrunQuery(ds\u001b[39m.\u001b[39;49mqueryDict\u001b[39m.\u001b[39;49mget(\u001b[39m'\u001b[39;49m\u001b[39mliquidityPoolAmounts\u001b[39;49m\u001b[39m'\u001b[39;49m), query_size\u001b[39m=\u001b[39;49m\u001b[39m1500\u001b[39;49m)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/src/datastreams/streamer.py:159\u001b[0m, in \u001b[0;36mStreamer.runQuery\u001b[0;34m(self, query_field, query_size, where)\u001b[0m\n\u001b[1;32m 157\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mFIELD - \u001b[39m\u001b[39m{\u001b[39;00mquery_field\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m)\n\u001b[1;32m 158\u001b[0m \u001b[39mif\u001b[39;00m where \u001b[39m==\u001b[39m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m--> 159\u001b[0m df \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msub\u001b[39m.\u001b[39;49mquery_df(query_field(first\u001b[39m=\u001b[39;49mquery_size))\n\u001b[1;32m 160\u001b[0m \u001b[39m# add endpoint column to df\u001b[39;00m\n\u001b[1;32m 161\u001b[0m df[\u001b[39m'\u001b[39m\u001b[39mendpoint\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mendpoint\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:380\u001b[0m, in \u001b[0;36mSubgrounds.query_df\u001b[0;34m(self, fpaths, columns, concat, pagination_strategy)\u001b[0m\n\u001b[1;32m 309\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Same as :func:`Subgrounds.query` but formats the response data into a\u001b[39;00m\n\u001b[1;32m 310\u001b[0m \u001b[39mPandas DataFrame. If the response data cannot be flattened to a single query\u001b[39;00m\n\u001b[1;32m 311\u001b[0m \u001b[39m(e.g.: when querying multiple list fields that return different entities),\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 372\u001b[0m \u001b[39m 9 1643213196 2610.686563\u001b[39;00m\n\u001b[1;32m 373\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 374\u001b[0m fpaths \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\n\u001b[1;32m 375\u001b[0m [fpaths]\n\u001b[1;32m 376\u001b[0m \u001b[39m|\u001b[39m traverse\n\u001b[1;32m 377\u001b[0m \u001b[39m|\u001b[39m \u001b[39mmap\u001b[39m(FieldPath\u001b[39m.\u001b[39m_auto_select)\n\u001b[1;32m 378\u001b[0m \u001b[39m|\u001b[39m traverse\n\u001b[1;32m 379\u001b[0m )\n\u001b[0;32m--> 380\u001b[0m json_data \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mquery_json(fpaths, pagination_strategy\u001b[39m=\u001b[39;49mpagination_strategy)\n\u001b[1;32m 381\u001b[0m \u001b[39mreturn\u001b[39;00m df_of_json(json_data, fpaths, columns, concat)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:274\u001b[0m, in \u001b[0;36mSubgrounds.query_json\u001b[0;34m(self, fpaths, pagination_strategy)\u001b[0m\n\u001b[1;32m 267\u001b[0m fpaths \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\n\u001b[1;32m 268\u001b[0m [fpaths]\n\u001b[1;32m 269\u001b[0m \u001b[39m|\u001b[39m traverse\n\u001b[1;32m 270\u001b[0m \u001b[39m|\u001b[39m \u001b[39mmap\u001b[39m(FieldPath\u001b[39m.\u001b[39m_auto_select)\n\u001b[1;32m 271\u001b[0m \u001b[39m|\u001b[39m traverse\n\u001b[1;32m 272\u001b[0m )\n\u001b[1;32m 273\u001b[0m req \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmk_request(fpaths)\n\u001b[0;32m--> 274\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mexecute(req, pagination_strategy\u001b[39m=\u001b[39;49mpagination_strategy)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:199\u001b[0m, in \u001b[0;36mSubgrounds.execute\u001b[0;34m(self, req, pagination_strategy)\u001b[0m\n\u001b[1;32m 195\u001b[0m \u001b[39mreturn\u001b[39;00m transform\u001b[39m.\u001b[39mtransform_response(req, data)\n\u001b[1;32m 197\u001b[0m \u001b[39massert\u001b[39;00m \u001b[39mFalse\u001b[39;00m \u001b[39m# Suppress mypy missing return statement warning\u001b[39;00m\n\u001b[0;32m--> 199\u001b[0m \u001b[39mreturn\u001b[39;00m transform_req(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mglobal_transforms, req)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:191\u001b[0m, in \u001b[0;36mSubgrounds.execute.<locals>.transform_req\u001b[0;34m(transforms, req)\u001b[0m\n\u001b[1;32m 189\u001b[0m \u001b[39mmatch\u001b[39;00m transforms:\n\u001b[1;32m 190\u001b[0m \u001b[39mcase\u001b[39;00m []:\n\u001b[0;32m--> 191\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mlist\u001b[39;49m(req\u001b[39m.\u001b[39;49mdocuments \u001b[39m|\u001b[39;49m \u001b[39mmap\u001b[39;49m(\u001b[39mlambda\u001b[39;49;00m doc: transform_doc(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msubgraphs[doc\u001b[39m.\u001b[39;49murl]\u001b[39m.\u001b[39;49m_transforms, doc)))\n\u001b[1;32m 192\u001b[0m \u001b[39mcase\u001b[39;00m [transform, \u001b[39m*\u001b[39mrest]:\n\u001b[1;32m 193\u001b[0m new_req \u001b[39m=\u001b[39m transform\u001b[39m.\u001b[39mtransform_request(req)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:191\u001b[0m, in \u001b[0;36mSubgrounds.execute.<locals>.transform_req.<locals>.<lambda>\u001b[0;34m(doc)\u001b[0m\n\u001b[1;32m 189\u001b[0m \u001b[39mmatch\u001b[39;00m transforms:\n\u001b[1;32m 190\u001b[0m \u001b[39mcase\u001b[39;00m []:\n\u001b[0;32m--> 191\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mlist\u001b[39m(req\u001b[39m.\u001b[39mdocuments \u001b[39m|\u001b[39m \u001b[39mmap\u001b[39m(\u001b[39mlambda\u001b[39;00m doc: transform_doc(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msubgraphs[doc\u001b[39m.\u001b[39;49murl]\u001b[39m.\u001b[39;49m_transforms, doc)))\n\u001b[1;32m 192\u001b[0m \u001b[39mcase\u001b[39;00m [transform, \u001b[39m*\u001b[39mrest]:\n\u001b[1;32m 193\u001b[0m new_req \u001b[39m=\u001b[39m transform\u001b[39m.\u001b[39mtransform_request(req)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:183\u001b[0m, in \u001b[0;36mSubgrounds.execute.<locals>.transform_doc\u001b[0;34m(transforms, doc)\u001b[0m\n\u001b[1;32m 181\u001b[0m \u001b[39mcase\u001b[39;00m [transform, \u001b[39m*\u001b[39mrest]:\n\u001b[1;32m 182\u001b[0m new_doc \u001b[39m=\u001b[39m transform\u001b[39m.\u001b[39mtransform_document(doc)\n\u001b[0;32m--> 183\u001b[0m data \u001b[39m=\u001b[39m transform_doc(rest, new_doc)\n\u001b[1;32m 184\u001b[0m \u001b[39mreturn\u001b[39;00m transform\u001b[39m.\u001b[39mtransform_response(doc, data)\n\u001b[1;32m 186\u001b[0m \u001b[39massert\u001b[39;00m \u001b[39mFalse\u001b[39;00m\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:183\u001b[0m, in \u001b[0;36mSubgrounds.execute.<locals>.transform_doc\u001b[0;34m(transforms, doc)\u001b[0m\n\u001b[1;32m 181\u001b[0m \u001b[39mcase\u001b[39;00m [transform, \u001b[39m*\u001b[39mrest]:\n\u001b[1;32m 182\u001b[0m new_doc \u001b[39m=\u001b[39m transform\u001b[39m.\u001b[39mtransform_document(doc)\n\u001b[0;32m--> 183\u001b[0m data \u001b[39m=\u001b[39m transform_doc(rest, new_doc)\n\u001b[1;32m 184\u001b[0m \u001b[39mreturn\u001b[39;00m transform\u001b[39m.\u001b[39mtransform_response(doc, data)\n\u001b[1;32m 186\u001b[0m \u001b[39massert\u001b[39;00m \u001b[39mFalse\u001b[39;00m\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:180\u001b[0m, in \u001b[0;36mSubgrounds.execute.<locals>.transform_doc\u001b[0;34m(transforms, doc)\u001b[0m\n\u001b[1;32m 178\u001b[0m \u001b[39mmatch\u001b[39;00m transforms:\n\u001b[1;32m 179\u001b[0m \u001b[39mcase\u001b[39;00m []:\n\u001b[0;32m--> 180\u001b[0m \u001b[39mreturn\u001b[39;00m execute_document(doc)\n\u001b[1;32m 181\u001b[0m \u001b[39mcase\u001b[39;00m [transform, \u001b[39m*\u001b[39mrest]:\n\u001b[1;32m 182\u001b[0m new_doc \u001b[39m=\u001b[39m transform\u001b[39m.\u001b[39mtransform_document(doc)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/subgrounds.py:172\u001b[0m, in \u001b[0;36mSubgrounds.execute.<locals>.execute_document\u001b[0;34m(doc)\u001b[0m\n\u001b[1;32m 167\u001b[0m subgraph: Subgraph \u001b[39m=\u001b[39m \u001b[39mnext\u001b[39m(\n\u001b[1;32m 168\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msubgraphs\u001b[39m.\u001b[39mvalues()\n\u001b[1;32m 169\u001b[0m \u001b[39m|\u001b[39m where(\u001b[39mlambda\u001b[39;00m sg: sg\u001b[39m.\u001b[39m_url \u001b[39m==\u001b[39m doc\u001b[39m.\u001b[39murl)\n\u001b[1;32m 170\u001b[0m )\n\u001b[1;32m 171\u001b[0m \u001b[39mif\u001b[39;00m pagination_strategy \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m subgraph\u001b[39m.\u001b[39m_is_subgraph:\n\u001b[0;32m--> 172\u001b[0m \u001b[39mreturn\u001b[39;00m paginate(subgraph\u001b[39m.\u001b[39;49m_schema, doc, pagination_strategy\u001b[39m=\u001b[39;49mpagination_strategy)\n\u001b[1;32m 173\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 174\u001b[0m \u001b[39mreturn\u001b[39;00m client\u001b[39m.\u001b[39mquery(doc\u001b[39m.\u001b[39murl, doc\u001b[39m.\u001b[39mgraphql, variables\u001b[39m=\u001b[39mdoc\u001b[39m.\u001b[39mvariables)\n", | |
"File \u001b[0;32m~/Documents/github/DataStreams/ds/lib/python3.10/site-packages/subgrounds/pagination/pagination.py:89\u001b[0m, in \u001b[0;36mpaginate\u001b[0;34m(schema, doc, pagination_strategy)\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[39mbreak\u001b[39;00m\n\u001b[1;32m 88\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m exn:\n\u001b[0;32m---> 89\u001b[0m \u001b[39mraise\u001b[39;00m PaginationError(exn\u001b[39m.\u001b[39margs[\u001b[39m0\u001b[39m], strategy)\n\u001b[1;32m 91\u001b[0m \u001b[39mreturn\u001b[39;00m data\n\u001b[1;32m 93\u001b[0m \u001b[39mexcept\u001b[39;00m SkipPagination:\n", | |
"\u001b[0;31mPaginationError\u001b[0m: Expecting value: line 1 column 1 (char 0)" | |
] | |
} | |
], | |
"source": [ | |
"df = ds.runQuery(ds.queryDict.get('liquidityPoolAmounts'), query_size=1500)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>liquidityPoolAmounts_id</th>\n", | |
" <th>endpoint</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0x0001fcbba8eb491c3ccfeddc5a5caba1a98c4c28</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>0x0002e63328169d7feea121f1e32e4f620abf0352</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>0x0003c9d75e102b8a9fe77280ca410e9135beb150</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>0x000ea4a83acefdd62b1b43e9ccc281f442651520</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>0x000f0c0b0b791e855dcc5ad6501c7529dea882e0</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>145</th>\n", | |
" <td>0x03a86d1488dd6ae052214cac0d845d6ac0153d7a</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>146</th>\n", | |
" <td>0x03a86da24f980cfeace0898883db181c74be9c13</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>147</th>\n", | |
" <td>0x03a90943380f7eb21fde74b94d945aa3e8508740</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>148</th>\n", | |
" <td>0x03aba5d772d2bc81e416295b6d5f914bbc12dcb7</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>149</th>\n", | |
" <td>0x03bb7a155816480fccce7d349f185427707d2711</td>\n", | |
" <td>https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>150 rows × 2 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" liquidityPoolAmounts_id endpoint\n", | |
"0 0x0001fcbba8eb491c3ccfeddc5a5caba1a98c4c28 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"1 0x0002e63328169d7feea121f1e32e4f620abf0352 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"2 0x0003c9d75e102b8a9fe77280ca410e9135beb150 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"3 0x000ea4a83acefdd62b1b43e9ccc281f442651520 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"4 0x000f0c0b0b791e855dcc5ad6501c7529dea882e0 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
".. ... ...\n", | |
"145 0x03a86d1488dd6ae052214cac0d845d6ac0153d7a https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"146 0x03a86da24f980cfeace0898883db181c74be9c13 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"147 0x03a90943380f7eb21fde74b94d945aa3e8508740 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"148 0x03aba5d772d2bc81e416295b6d5f914bbc12dcb7 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"149 0x03bb7a155816480fccce7d349f185427707d2711 https://api.thegraph.com/subgraphs/name/messari/uniswap-v3-ethereum\n", | |
"\n", | |
"[150 rows x 2 columns]" | |
] | |
}, | |
"execution_count": 21, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>liquidityPools_id</th>\n", | |
" <th>liquidityPools_protocol_id</th>\n", | |
" <th>liquidityPools_name</th>\n", | |
" <th>liquidityPools_symbol</th>\n", | |
" <th>liquidityPools_outputToken_id</th>\n", | |
" <th>liquidityPools_isSingleSided</th>\n", | |
" <th>liquidityPools_createdTimestamp</th>\n", | |
" <th>liquidityPools_createdBlockNumber</th>\n", | |
" <th>liquidityPools_totalValueLockedUSD</th>\n", | |
" <th>liquidityPools_cumulativeSupplySideRevenueUSD</th>\n", | |
" <th>liquidityPools_cumulativeProtocolSideRevenueUSD</th>\n", | |
" <th>liquidityPools_cumulativeTotalRevenueUSD</th>\n", | |
" <th>liquidityPools_cumulativeVolumeUSD</th>\n", | |
" <th>liquidityPools_outputTokenSupply</th>\n", | |
" <th>liquidityPools_outputTokenPriceUSD</th>\n", | |
" <th>liquidityPools_stakedOutputTokenAmount</th>\n", | |
" <th>endpoint</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
"Empty DataFrame\n", | |
"Columns: [liquidityPools_id, liquidityPools_protocol_id, liquidityPools_name, liquidityPools_symbol, liquidityPools_outputToken_id, liquidityPools_isSingleSided, liquidityPools_createdTimestamp, liquidityPools_createdBlockNumber, liquidityPools_totalValueLockedUSD, liquidityPools_cumulativeSupplySideRevenueUSD, liquidityPools_cumulativeProtocolSideRevenueUSD, liquidityPools_cumulativeTotalRevenueUSD, liquidityPools_cumulativeVolumeUSD, liquidityPools_outputTokenSupply, liquidityPools_outputTokenPriceUSD, liquidityPools_stakedOutputTokenAmount, endpoint]\n", | |
"Index: []" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# search df where liquidityPools_id = lp_name\n", | |
"df[df['liquidityPools_id'] == lp_name]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "ds", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.10.6" | |
}, | |
"orig_nbformat": 4, | |
"vscode": { | |
"interpreter": { | |
"hash": "6e4771a491a32973a3d91a7498ed105fbed006d0c3342348d97c77c956876e4a" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment