0xPlaygrounds / subgrounds

An intuitive Python library for interfacing with subgraphs and GraphQL
http://docs.playgrounds.network
Apache License 2.0
50 stars 8 forks source link

feat: custom subgrounds client for polars #43

Closed Evan-Kim2028 closed 12 months ago

Evan-Kim2028 commented 1 year ago

Related to this issue - https://github.com/0xPlaygrounds/subgrounds/issues/29

from polars_client import SubgroundsPolars
from subgrounds.subgraph import FieldPath, Subgraph

# from polars_utils.py import *

import polars as pl

sg = SubgroundsPolars()

snx_endpoint = "https://api.thegraph.com/subgraphs/name/synthetix-perps/perps"

snx = sg.load_subgraph(
    url=snx_endpoint,
)

trades_json = sg.query_json(
    [
        # set the first parameter to a larger size to query more rows.
        snx.Query.futuresTrades(
            first=2500,
            orderBy="timestamp",
            orderDirection="desc",
            # where=[{"timestamp_lte": "1694131200"}],  # 1694131200 = 9/8/23
        )
    ]
)

Features

TODO

Evan-Kim2028 commented 1 year ago