Update app.py
Browse files
app.py
CHANGED
|
@@ -1,204 +1,10 @@
|
|
| 1 |
-
import
|
| 2 |
-
import logging
|
| 3 |
-
|
| 4 |
-
# Suppress deprecation warnings about experimental query params functions
|
| 5 |
-
warnings.filterwarnings(
|
| 6 |
-
"ignore",
|
| 7 |
-
message="Please replace `st.experimental_get_query_params` with `st.query_params`"
|
| 8 |
-
)
|
| 9 |
-
warnings.filterwarnings(
|
| 10 |
-
"ignore",
|
| 11 |
-
message="Please replace `st.experimental_set_query_params` with `st.query_params`"
|
| 12 |
-
)
|
| 13 |
-
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
| 14 |
-
|
| 15 |
-
# Adjust the Streamlit loggers to only show errors
|
| 16 |
-
logging.getLogger("streamlit.deprecation").setLevel(logging.ERROR)
|
| 17 |
-
logging.getLogger("streamlit.runtime.scriptrunner").setLevel(logging.ERROR)
|
| 18 |
-
|
| 19 |
-
import streamlit as st
|
| 20 |
-
import pandas as pd
|
| 21 |
-
import plotly.express as px
|
| 22 |
-
from archeanvision import ArcheanVisionAPI
|
| 23 |
import os
|
| 24 |
-
from dotenv import load_dotenv
|
| 25 |
-
load_dotenv()
|
| 26 |
-
# ---------------------------- #
|
| 27 |
-
# AUTO-REFRESH #
|
| 28 |
-
# ---------------------------- #
|
| 29 |
-
st.set_page_config(
|
| 30 |
-
page_title="Dashboard Auto-Refresh",
|
| 31 |
-
layout="wide"
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
REFRESH_INTERVAL = 260 # 160 seconds
|
| 35 |
-
st.markdown(f"<meta http-equiv='refresh' content='{REFRESH_INTERVAL}'>", unsafe_allow_html=True)
|
| 36 |
-
# ---------------------------- #
|
| 37 |
|
| 38 |
-
LOGO_IMAGE_URL = "https://archeanvision.com/assets/archeanvision.png"
|
| 39 |
-
st.sidebar.image(LOGO_IMAGE_URL, use_container_width=True, caption="ArcheanVision")
|
| 40 |
-
|
| 41 |
-
# Replace with your API key
|
| 42 |
API_KEY = os.getenv("API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
def get_selected_market(market_list):
|
| 45 |
-
"""
|
| 46 |
-
Returns the selected market from the URL query params or defaults to the first item.
|
| 47 |
-
Also updates the query param if the user picks a different market from the dropdown.
|
| 48 |
-
|
| 49 |
-
Using experimental_* methods for compatibility with older Streamlit versions (<1.25).
|
| 50 |
-
"""
|
| 51 |
-
# 1. Read current query parameters (EXPERIMENTAL)
|
| 52 |
-
params = st.experimental_get_query_params()
|
| 53 |
-
|
| 54 |
-
# 2. Check if 'market' param is set; otherwise default to the first market
|
| 55 |
-
if "market" in params:
|
| 56 |
-
default_market = params["market"]
|
| 57 |
-
# If it's a list, pick the first element
|
| 58 |
-
if isinstance(default_market, list):
|
| 59 |
-
default_market = default_market[0]
|
| 60 |
-
else:
|
| 61 |
-
default_market = market_list[0]
|
| 62 |
-
|
| 63 |
-
# 3. Determine the index to use in the selectbox
|
| 64 |
-
if default_market in market_list:
|
| 65 |
-
default_index = market_list.index(default_market)
|
| 66 |
-
else:
|
| 67 |
-
default_index = 0
|
| 68 |
-
|
| 69 |
-
# 4. Create the dropdown
|
| 70 |
-
selected = st.selectbox("Select a market:", market_list, index=default_index)
|
| 71 |
-
|
| 72 |
-
# 5. If user picks a new market, update URL param (EXPERIMENTAL)
|
| 73 |
-
if selected != default_market:
|
| 74 |
-
params["market"] = selected
|
| 75 |
-
st.experimental_set_query_params(**params)
|
| 76 |
-
|
| 77 |
-
return selected
|
| 78 |
-
|
| 79 |
-
def main():
|
| 80 |
-
st.title("Active AI Crypto Markets - ArcheanVision")
|
| 81 |
-
|
| 82 |
-
st.markdown("""
|
| 83 |
-
### What is ArcheanVision?
|
| 84 |
-
|
| 85 |
-
**ArcheanVision** is an autonomous multi-market trading agent.
|
| 86 |
-
It operates simultaneously on multiple crypto assets, monitoring price movements
|
| 87 |
-
in real time and delivering **data** as well as **signals** (BUY, SELL, etc.)
|
| 88 |
-
to automate and optimize decision-making.
|
| 89 |
-
|
| 90 |
-
- **AI Agent**: Continuously analyzes crypto markets.
|
| 91 |
-
- **Multi-Market**: Manages multiple assets at once.
|
| 92 |
-
- **Live Data**: Access to streaming data feeds (SSE).
|
| 93 |
-
- **Buy/Sell Signals**: Generated in real-time to seize market opportunities.
|
| 94 |
-
|
| 95 |
-
Below is a dashboard showcasing the active markets, their 24h data
|
| 96 |
-
(1,440 most recent data points), and their associated signals.
|
| 97 |
-
|
| 98 |
-
---
|
| 99 |
-
**Join our Discord as a beta tester** to help improve the agent and the system.
|
| 100 |
-
- Official platform: [https://archeanvision.com](https://archeanvision.com)
|
| 101 |
-
- Discord link: [https://discord.gg/k9xHuM7Jr8](https://discord.gg/k9xHuM7Jr8)
|
| 102 |
-
""")
|
| 103 |
-
|
| 104 |
-
# 1. Initialize the API
|
| 105 |
-
api = ArcheanVisionAPI(api_key=API_KEY)
|
| 106 |
-
|
| 107 |
-
# 2. Retrieve active markets
|
| 108 |
-
active_markets = api.get_active_markets()
|
| 109 |
-
if not active_markets:
|
| 110 |
-
st.error("No active markets found through the API.")
|
| 111 |
-
return
|
| 112 |
-
|
| 113 |
-
# 3. Build a list of markets
|
| 114 |
-
market_list = []
|
| 115 |
-
if isinstance(active_markets, list):
|
| 116 |
-
for item in active_markets:
|
| 117 |
-
if isinstance(item, dict) and "market" in item:
|
| 118 |
-
market_list.append(item["market"])
|
| 119 |
-
elif isinstance(item, str):
|
| 120 |
-
market_list.append(item)
|
| 121 |
-
else:
|
| 122 |
-
st.warning(f"Item missing 'market' key: {item}")
|
| 123 |
-
else:
|
| 124 |
-
st.error("The structure of 'active_markets' is not a list as expected.")
|
| 125 |
-
return
|
| 126 |
-
|
| 127 |
-
if not market_list:
|
| 128 |
-
st.error("The market list is empty or 'market' keys not found.")
|
| 129 |
-
return
|
| 130 |
-
|
| 131 |
-
# 4. Get the selected market from (experimental) query params or default
|
| 132 |
-
selected_market = get_selected_market(market_list)
|
| 133 |
-
|
| 134 |
-
if selected_market:
|
| 135 |
-
st.subheader(f"Selected Market: {selected_market}")
|
| 136 |
-
st.write(f"Fetching data for **{selected_market}** ...")
|
| 137 |
-
|
| 138 |
-
# 5. Retrieve market data (1,440 points ~24h)
|
| 139 |
-
market_data = api.get_market_data(selected_market)
|
| 140 |
-
if not market_data:
|
| 141 |
-
st.error(f"No data found for market {selected_market}.")
|
| 142 |
-
return
|
| 143 |
-
|
| 144 |
-
# 6. Convert to DataFrame & parse 'close_time'
|
| 145 |
-
df = pd.DataFrame(market_data)
|
| 146 |
-
if "close_time" in df.columns:
|
| 147 |
-
df['close_time'] = pd.to_datetime(df['close_time'], unit='ms', errors='coerce')
|
| 148 |
-
else:
|
| 149 |
-
st.error("The 'close_time' column is missing from the retrieved data.")
|
| 150 |
-
return
|
| 151 |
-
|
| 152 |
-
st.write("### Market Data Overview")
|
| 153 |
-
st.dataframe(df.head())
|
| 154 |
-
|
| 155 |
-
# 7. Check columns before plotting
|
| 156 |
-
required_cols = {"close", "last_predict_15m", "last_predict_1h"}
|
| 157 |
-
if not required_cols.issubset(df.columns):
|
| 158 |
-
st.error(
|
| 159 |
-
f"The required columns {required_cols} are not all present. "
|
| 160 |
-
f"Available columns: {list(df.columns)}"
|
| 161 |
-
)
|
| 162 |
-
return
|
| 163 |
-
|
| 164 |
-
# 8. Create a Plotly line chart
|
| 165 |
-
fig = px.line(
|
| 166 |
-
df,
|
| 167 |
-
x='close_time',
|
| 168 |
-
y=['close', 'last_predict_15m', 'last_predict_1h'],
|
| 169 |
-
title=f"{selected_market} : Close Price & Predictions",
|
| 170 |
-
labels={
|
| 171 |
-
'close_time': 'Time',
|
| 172 |
-
'value': 'Price',
|
| 173 |
-
'variable': 'Metric'
|
| 174 |
-
}
|
| 175 |
-
)
|
| 176 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 177 |
-
|
| 178 |
-
# 9. Retrieve & display signals for the selected market
|
| 179 |
-
st.write(f"### Signals for {selected_market}")
|
| 180 |
-
signals = api.get_market_signals(selected_market)
|
| 181 |
-
if not signals:
|
| 182 |
-
st.warning(f"No signals found for market {selected_market}.")
|
| 183 |
-
else:
|
| 184 |
-
df_signals = pd.DataFrame(signals)
|
| 185 |
-
|
| 186 |
-
# Convert 'date' if present
|
| 187 |
-
if 'date' in df_signals.columns:
|
| 188 |
-
df_signals['date'] = pd.to_datetime(df_signals['date'], unit='ms', errors='coerce')
|
| 189 |
-
|
| 190 |
-
# Fix Arrow errors for dict columns
|
| 191 |
-
for col in df_signals.columns:
|
| 192 |
-
if df_signals[col].apply(lambda x: isinstance(x, dict)).any():
|
| 193 |
-
df_signals[col] = df_signals[col].apply(lambda x: str(x) if isinstance(x, dict) else x)
|
| 194 |
-
|
| 195 |
-
# Sort signals by date descending if desired
|
| 196 |
-
if 'date' in df_signals.columns:
|
| 197 |
-
df_signals = df_signals.sort_values('date', ascending=False)
|
| 198 |
-
|
| 199 |
-
st.write("Total number of signals:", len(df_signals))
|
| 200 |
-
st.write("Preview of the last 4 signals:")
|
| 201 |
-
st.dataframe(df_signals.head(4))
|
| 202 |
-
|
| 203 |
-
if __name__ == "__main__":
|
| 204 |
-
main()
|
|
|
|
| 1 |
+
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
API_KEY = os.getenv("API_KEY")
|
| 5 |
+
headers = {"Authorization": f"Bearer {API_KEY}"}
|
| 6 |
+
url = "https://archeanvision.com/api/signals/available"
|
| 7 |
+
response = requests.get(url, headers=headers)
|
| 8 |
+
print(response.status_code)
|
| 9 |
+
print(response.text)
|
| 10 |
|
|
|
|
|
|
|
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