Spaces:
Runtime error
Runtime error
File size: 2,282 Bytes
f36cf39 7630a4f f36cf39 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # -*- coding: utf-8 -*-
from pymongo import MongoClient
import pandas as pd
import requests
import json
import urllib.parse
import gradio as gr
import datetime
import os
client = MongoClient(os.getenv('MONGO_DB_URI'))
db = client["HYPER_balances"]
collection = db["balance_data"]
def load_from_mongo():
latest = collection.find_one(sort=[("timestamp", -1)])
if latest:
df0 = pd.DataFrame(latest["df0"]).T
df1 = pd.DataFrame(latest["df1"]).T
df2 = pd.DataFrame(latest["df2"]).T
df3 = pd.DataFrame(latest["df3"]).T
df4 = pd.DataFrame(latest["df4"]).T
return (
df0, latest["total0"],
df1, latest["total1"],
df2, latest["total2"],
df3, latest["total3"],
df4, latest["total4"],
f"PNL : {latest['pnl']:,.2f}",
f"LP Rewards : {latest['rewards']:,.2f}"
)
else:
empty_df = pd.DataFrame()
return empty_df, 0, empty_df, 0, empty_df, 0, empty_df, 0, empty_df, 0,"PNL : 0.00","LP Rewards : 0.00"
if __name__ == "__main__":
with gr.Blocks() as demo:
gr.Markdown("## HYPER Balances and PnL")
df0_out = gr.Dataframe(label="Starting Balances")
txt0_out = gr.Textbox(label="Starting Value Total")
df2_out = gr.Dataframe(label="Wallet Balances")
txt2_out = gr.Textbox(label="Wallet Value Total")
df3_out = gr.Dataframe(label="JUP Limit Balances")
txt3_out = gr.Textbox(label="JUP Limit Value Total")
df4_out = gr.Dataframe(label="LP Balances")
txt4_out = gr.Textbox(label="LP Balances Value Total")
reward_out = gr.Textbox(label="LP Rewards")
df1_out = gr.Dataframe(label="Total Balances")
txt1_out = gr.Textbox(label="Current Value Total")
pnl_out = gr.Textbox(label="PNL (AUM Model)")
# Load from MongoDB on app load (sync function)
demo.load(
fn=load_from_mongo,
inputs=[],
outputs=[
df0_out, txt0_out,
df1_out, txt1_out,
df2_out, txt2_out,
df3_out, txt3_out,
df4_out, txt4_out,
pnl_out,reward_out
]
)
demo.launch(debug=True, share=True) |