Skip to content

Instantly share code, notes, and snippets.

@sparrowDom
Created January 25, 2025 00:43
Show Gist options
  • Select an option

  • Save sparrowDom/6ad191ff59703eaa61c684ba67191c37 to your computer and use it in GitHub Desktop.

Select an option

Save sparrowDom/6ad191ff59703eaa61c684ba67191c37 to your computer and use it in GitHub Desktop.
# import matplotlib.animation
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
import json
plt.rcParams["animation.html"] = "jshtml"
plt.rcParams['figure.dpi'] = 150
plt.ioff()
fig, ax = plt.subplots()
with open('ichiVault_27SnapshotTimeline.json', 'r') as file:
data = json.load(file)
numpy_array = np.array(data)
dataLength = len(numpy_array)
x= np.linspace(-30,30,60)
# Arbitrary decision: totalAmount of 2 positions 10 ticks wide is tall 10 units
def printLiquidity(lowerTick, upperTick, totalPositionAmount, totalAmounts, color):
width = (upperTick - lowerTick)
if (width == 0):
return
amountPerSquareUnit = totalAmounts / 100 # 10 ticks wide and 10 units tall
height = totalPositionAmount / width / amountPerSquareUnit
height = height if height > 0.2 else 0.2
ax.add_patch(Rectangle((lowerTick, 0), width, height, facecolor = color))
def animate(t):
data = numpy_array[t]
plt.cla()
printLiquidity(int(data['baseLower']), int(data['baseUpper']), int(data['totalBaseAmount']), int(data['totalAmounts']), 'lightsteelblue')
printLiquidity(int(data['limitLower']), int(data['limitUpper']), int(data['totalLimitAmount']), int(data['totalAmounts']), 'cornflowerblue')
plt.plot()
plt.xlim(-30,30)
plt.ylim(0,10)
matplotlib.animation.FuncAnimation(fig, animate, frames=dataLength)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment