ArcheanVision commited on
Commit
169bcfa
·
verified ·
1 Parent(s): 1e6c5ea

Create app.py

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