AJAY KASU commited on
Commit ·
502f466
1
Parent(s): 19c8e7e
Add Supabase integration for remote trade logging
Browse files- app.py +39 -0
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -2,8 +2,21 @@ import streamlit as st
|
|
| 2 |
import asyncio
|
| 3 |
import pandas as pd
|
| 4 |
from datetime import datetime, timezone
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
from src.strategies.arbitrage import CrossPlatformArbitrage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# We would import the live clients here, but for the dashboard
|
| 8 |
# we can instantiate the scanner and populate it directly for testing.
|
| 9 |
|
|
@@ -73,6 +86,32 @@ if st.session_state.opps is not None:
|
|
| 73 |
if o.market_id_pm not in st.session_state.positions:
|
| 74 |
st.session_state.positions.append(o.market_id_pm)
|
| 75 |
st.session_state.trades.append(o)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
st.session_state.opps = None
|
| 78 |
st.rerun()
|
|
|
|
| 2 |
import asyncio
|
| 3 |
import pandas as pd
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
from supabase import create_client
|
| 8 |
|
| 9 |
from src.strategies.arbitrage import CrossPlatformArbitrage
|
| 10 |
+
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def init_supabase():
|
| 13 |
+
url = st.secrets.get("SUPABASE_URL") or os.environ.get("SUPABASE_URL")
|
| 14 |
+
key = st.secrets.get("SUPABASE_KEY") or os.environ.get("SUPABASE_KEY")
|
| 15 |
+
if url and key:
|
| 16 |
+
return create_client(url, key)
|
| 17 |
+
return None
|
| 18 |
+
|
| 19 |
+
supabase = init_supabase()
|
| 20 |
# We would import the live clients here, but for the dashboard
|
| 21 |
# we can instantiate the scanner and populate it directly for testing.
|
| 22 |
|
|
|
|
| 86 |
if o.market_id_pm not in st.session_state.positions:
|
| 87 |
st.session_state.positions.append(o.market_id_pm)
|
| 88 |
st.session_state.trades.append(o)
|
| 89 |
+
|
| 90 |
+
if supabase:
|
| 91 |
+
try:
|
| 92 |
+
supabase.table("trades").insert({
|
| 93 |
+
"event_id": o.event_name,
|
| 94 |
+
"buy_platform": o.buy_platform,
|
| 95 |
+
"sell_platform": o.sell_platform,
|
| 96 |
+
"buy_price": o.buy_price,
|
| 97 |
+
"sell_price": o.sell_price,
|
| 98 |
+
"size": o.buy_size,
|
| 99 |
+
"net_edge": o.expected_profit_margin,
|
| 100 |
+
"pnl": profit
|
| 101 |
+
}).execute()
|
| 102 |
+
except Exception as e:
|
| 103 |
+
st.error(f"Failed to write trade to Supabase: {e}")
|
| 104 |
+
|
| 105 |
+
if supabase:
|
| 106 |
+
try:
|
| 107 |
+
supabase.table("portfolio").insert({
|
| 108 |
+
"capital": st.session_state.capital,
|
| 109 |
+
"pnl": st.session_state.pnl,
|
| 110 |
+
"active_positions": len(st.session_state.positions),
|
| 111 |
+
"market_regime": "Stable"
|
| 112 |
+
}).execute()
|
| 113 |
+
except Exception as e:
|
| 114 |
+
st.error(f"Failed to write portfolio snapshot to Supabase: {e}")
|
| 115 |
|
| 116 |
st.session_state.opps = None
|
| 117 |
st.rerun()
|
requirements.txt
CHANGED
|
@@ -20,3 +20,4 @@ torch
|
|
| 20 |
streamlit
|
| 21 |
plotly
|
| 22 |
web3
|
|
|
|
|
|
| 20 |
streamlit
|
| 21 |
plotly
|
| 22 |
web3
|
| 23 |
+
supabase
|