0vergeared commited on
Commit
b188ed5
·
verified ·
1 Parent(s): f145832

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -21
app.py CHANGED
@@ -1,33 +1,85 @@
1
- from dash import Dash, dcc, html
 
2
  import plotly.graph_objs as go
3
- import pandas as pd
4
  import ccxt
 
 
 
 
 
 
 
 
5
 
6
- app = Dash(__name__)
7
- symbol = "BTC/USDT"
8
- timeframe = "1h"
9
 
10
- def fetch_data(symbol, timeframe):
11
- binance = ccxt.binance()
12
- ohlcv = binance.fetch_ohlcv(symbol, timeframe=timeframe)
 
 
 
 
13
  df = pd.DataFrame(ohlcv, columns=["timestamp", "open", "high", "low", "close", "volume"])
14
  df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms")
15
  return df
16
 
17
- df = fetch_data(symbol, timeframe)
18
-
19
- fig = go.Figure(data=[go.Candlestick(
20
- x=df["timestamp"],
21
- open=df["open"],
22
- high=df["high"],
23
- low=df["low"],
24
- close=df["close"]
25
- )])
26
-
27
  app.layout = html.Div([
28
- html.H2("Crypto Signal Generator (Docker Dash)"),
29
- dcc.Graph(id="candlestick-chart", figure=fig)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ])
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  if __name__ == "__main__":
33
- app.run_server(debug=False, host="0.0.0.0", port=7860)
 
1
+ import dash
2
+ from dash import dcc, html, Input, Output
3
  import plotly.graph_objs as go
 
4
  import ccxt
5
+ import pandas as pd
6
+
7
+ # Initialize Dash app
8
+ app = dash.Dash(__name__)
9
+ server = app.server
10
+
11
+ # Setup MEXC exchange
12
+ exchange = ccxt.mexc()
13
 
14
+ # Supported trading pairs and timeframes
15
+ symbols = ["BTC/USDT", "ETH/USDT", "BNB/USDT", "SOL/USDT"]
16
+ timeframes = ["1m", "5m", "15m", "1h", "4h", "1d"]
17
 
18
+ # Default values
19
+ default_symbol = "BTC/USDT"
20
+ default_timeframe = "1h"
21
+
22
+ # Helper to fetch OHLCV
23
+ def fetch_ohlcv(symbol, timeframe):
24
+ ohlcv = exchange.fetch_ohlcv(symbol, timeframe)
25
  df = pd.DataFrame(ohlcv, columns=["timestamp", "open", "high", "low", "close", "volume"])
26
  df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms")
27
  return df
28
 
29
+ # Layout
 
 
 
 
 
 
 
 
 
30
  app.layout = html.Div([
31
+ html.H1("📊 TraderX AI - MEXC Crypto Dashboard"),
32
+ html.Div([
33
+ html.Label("Symbol:"),
34
+ dcc.Dropdown(
35
+ id="symbol-dropdown",
36
+ options=[{"label": s, "value": s} for s in symbols],
37
+ value=default_symbol,
38
+ style={"width": "200px"}
39
+ ),
40
+ html.Label("Timeframe:", style={"marginLeft": "20px"}),
41
+ dcc.Dropdown(
42
+ id="timeframe-dropdown",
43
+ options=[{"label": tf, "value": tf} for tf in timeframes],
44
+ value=default_timeframe,
45
+ style={"width": "120px"}
46
+ ),
47
+ ], style={"display": "flex", "alignItems": "center", "marginBottom": "20px"}),
48
+
49
+ dcc.Graph(id="price-chart")
50
  ])
51
 
52
+ # Callback
53
+ @app.callback(
54
+ Output("price-chart", "figure"),
55
+ Input("symbol-dropdown", "value"),
56
+ Input("timeframe-dropdown", "value")
57
+ )
58
+ def update_chart(symbol, timeframe):
59
+ try:
60
+ df = fetch_ohlcv(symbol, timeframe)
61
+
62
+ candle = go.Candlestick(
63
+ x=df["timestamp"],
64
+ open=df["open"],
65
+ high=df["high"],
66
+ low=df["low"],
67
+ close=df["close"],
68
+ name="Price"
69
+ )
70
+
71
+ layout = go.Layout(
72
+ title=f"{symbol} - {timeframe} Chart (MEXC)",
73
+ xaxis={"title": "Time", "rangeslider": {"visible": True}},
74
+ yaxis={"title": "Price (USDT)"},
75
+ height=600
76
+ )
77
+
78
+ return {"data": [candle], "layout": layout}
79
+
80
+ except Exception as e:
81
+ return {"data": [], "layout": go.Layout(title=f"Error: {str(e)}")}
82
+
83
+ # Run app
84
  if __name__ == "__main__":
85
+ app.run_server(host="0.0.0.0", port=7860)