Skip to content

Instantly share code, notes, and snippets.

@wangshouh
Last active April 16, 2025 13:13
Show Gist options
  • Save wangshouh/93300fff4b7548b0822c83a209db5b5e to your computer and use it in GitHub Desktop.
Save wangshouh/93300fff4b7548b0822c83a209db5b5e to your computer and use it in GitHub Desktop.
import marimo
__generated_with = "0.11.12"
app = marimo.App(width="medium")
@app.cell
def _():
import altair as alt
return (alt,)
@app.cell
def _():
import marimo as mo
return (mo,)
@app.cell
def _():
import pandas as pd
return (pd,)
@app.cell
def _():
import requests
return (requests,)
@app.cell
def _():
import json
return (json,)
@app.cell
def _():
skip = 0
query = f"""query {{
ticks(
first: 1000,
skip: {skip},
where: {{
poolAddress: "0x324963c267c354c7660ce8ca3f5f167e05649970"
}}
orderBy: tickIdx
) {{
tickIdx
liquidityNet
price0
}}
}}"""
return query, skip
@app.cell
def _(json, query, requests):
url = 'https://sonicv2.kingdomsubgraph.com/subgraphs/name/core'
r = requests.post(url, json={'query': query})
json_data = json.loads(r.text)
return json_data, r, url
@app.cell
def _(json_data, pd):
data = pd.DataFrame(json_data["data"]["ticks"])
data = data.set_index("tickIdx")
data['price0'] = pd.to_numeric(data['price0'], errors='coerce') * 1e12
data['liquidityNet'] = pd.to_numeric(data['liquidityNet'], errors='coerce')
return (data,)
@app.cell
def _(data):
data["liquidity"] = data["liquidityNet"].cumsum() / 1e18
return
@app.cell
def _(alt, data, mo):
interval = alt.selection_interval()
chart = mo.ui.altair_chart(alt.Chart(data["-306100":]).mark_bar().encode(
x='price0',
y='liquidity',
).transform_filter((alt.datum.price0 > 0.1) & (alt.datum.price0 < 2)).interactive(bind_y=False))
return chart, interval
@app.cell
def _(chart, mo):
mo.vstack([chart, chart.value])
return
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment