QAway-to commited on
Commit
7b9c77c
·
1 Parent(s): 343fdcb
Files changed (2) hide show
  1. core/multi_charts.py +0 -56
  2. core/visual_comparison.py +0 -94
core/multi_charts.py CHANGED
@@ -1,56 +0,0 @@
1
- """
2
- Multi Visualization Demo — ECharts + Highcharts (pure HTML/JS)
3
- Никаких внешних питон-зависимостей, всё через CDN-скрипты.
4
- """
5
- import json
6
- import numpy as np
7
-
8
- def build_echarts_html():
9
- # сгенерируем 90 точек псевдо-цены
10
- prices = (np.cumsum(np.random.randn(90)) * 100 + 42000).tolist()
11
- xcats = list(range(1, 91))
12
- return f"""
13
- <div id="echarts_btc" style="height:360px;"></div>
14
- <script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
15
- <script>
16
- var chart = echarts.init(document.getElementById('echarts_btc'), null, {{renderer:'canvas'}});
17
- var option = {{
18
- backgroundColor: '#0d1117',
19
- title: {{ text: 'ECharts: BTC/USD (Simulated)', textStyle: {{ color:'#f0f6fc' }} }},
20
- tooltip: {{ trigger: 'axis' }},
21
- grid: {{ left: 30, right: 20, top: 40, bottom: 20 }},
22
- xAxis: {{ type: 'category', data: {json.dumps(xcats)}, axisLine: {{ lineStyle: {{ color:'#30363d' }} }} }},
23
- yAxis: {{ type: 'value', axisLine: {{ lineStyle: {{ color:'#30363d' }} }} }},
24
- series: [{{
25
- name: 'BTC/USD',
26
- type: 'line',
27
- smooth: true,
28
- data: {json.dumps(prices)},
29
- lineStyle: {{ width: 2, color: '#4f46e5' }},
30
- areaStyle: {{ color: 'rgba(99,102,241,0.15)' }},
31
- showSymbol: false
32
- }}]
33
- }};
34
- chart.setOption(option);
35
- window.addEventListener('resize', () => chart.resize());
36
- </script>
37
- """
38
-
39
- def build_highcharts_html():
40
- prices = (np.cumsum(np.random.randn(90)) * 10 + 2300).tolist()
41
- xcats = list(range(1, 91))
42
- return f"""
43
- <div id="highcharts_eth" style="height:360px;"></div>
44
- <script src="https://code.highcharts.com/highcharts.js"></script>
45
- <script>
46
- Highcharts.chart('highcharts_eth', {{
47
- chart: {{ backgroundColor: '#0d1117', style: {{ fontFamily: 'Inter' }} }},
48
- title: {{ text: 'Highcharts: ETH/USD (Simulated)', style: {{ color: '#f0f6fc' }} }},
49
- xAxis: {{ categories: {json.dumps(xcats)}, labels: {{ style: {{ color: '#9da5b4' }} }} }},
50
- yAxis: {{ title: {{ text: 'Price (USD)', style: {{ color: '#9da5b4' }} }} }},
51
- tooltip: {{ backgroundColor:'#161b22', borderColor:'#30363d', style: {{ color:'#f0f6fc' }} }},
52
- credits: {{ enabled: false }},
53
- series: [{{ name: 'ETH/USD', data: {json.dumps(prices)}, color: '#10b981' }}]
54
- }});
55
- </script>
56
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
core/visual_comparison.py CHANGED
@@ -1,94 +0,0 @@
1
- """
2
- Module: visual_comparison.py
3
- Purpose: Interactive crypto pair comparison (Plotly + CoinGecko)
4
- """
5
-
6
- import requests
7
- import pandas as pd
8
- import plotly.graph_objects as go
9
-
10
- COINGECKO_API = "https://api.coingecko.com/api/v3"
11
-
12
-
13
- def get_coin_history(coin_id: str, days: int = 180):
14
- """Fetch historical market data for given coin from CoinGecko API."""
15
- url = f"{COINGECKO_API}/coins/{coin_id}/market_chart?vs_currency=usd&days={days}"
16
- r = requests.get(url)
17
- r.raise_for_status()
18
- data = r.json()
19
- df = pd.DataFrame(data["prices"], columns=["timestamp", "price"])
20
- df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms")
21
- return df
22
-
23
-
24
- def build_price_chart(pair: tuple[str, str], days: int = 180):
25
- """Build comparative price chart for selected pair."""
26
- coin_a, coin_b = pair
27
-
28
- df_a = get_coin_history(coin_a, days)
29
- df_b = get_coin_history(coin_b, days)
30
-
31
- fig = go.Figure()
32
- fig.add_trace(go.Scatter(
33
- x=df_a["timestamp"],
34
- y=df_a["price"],
35
- name=f"{coin_a.capitalize()} / USD",
36
- line=dict(width=2),
37
- ))
38
- fig.add_trace(go.Scatter(
39
- x=df_b["timestamp"],
40
- y=df_b["price"],
41
- name=f"{coin_b.capitalize()} / USD",
42
- line=dict(width=2),
43
- ))
44
-
45
- fig.update_layout(
46
- template="plotly_dark",
47
- height=480,
48
- margin=dict(l=40, r=20, t=30, b=40),
49
- xaxis_title="Date",
50
- yaxis_title="Price (USD)",
51
- legend_title="Asset",
52
- hovermode="x unified",
53
- )
54
-
55
- return fig
56
-
57
-
58
- def build_volatility_chart(pair: tuple[str, str], days: int = 180):
59
- """Build comparative volatility chart for selected pair."""
60
- coin_a, coin_b = pair
61
-
62
- df_a = get_coin_history(coin_a, days)
63
- df_b = get_coin_history(coin_b, days)
64
-
65
- df_a["returns"] = df_a["price"].pct_change() * 100
66
- df_b["returns"] = df_b["price"].pct_change() * 100
67
-
68
- fig = go.Figure()
69
- fig.add_trace(go.Scatter(
70
- x=df_a["timestamp"],
71
- y=df_a["returns"],
72
- name=f"{coin_a.upper()} Daily Change (%)",
73
- mode="lines",
74
- line=dict(width=1.6),
75
- ))
76
- fig.add_trace(go.Scatter(
77
- x=df_b["timestamp"],
78
- y=df_b["returns"],
79
- name=f"{coin_b.upper()} Daily Change (%)",
80
- mode="lines",
81
- line=dict(width=1.6),
82
- ))
83
-
84
- fig.update_layout(
85
- template="plotly_dark",
86
- height=400,
87
- margin=dict(l=40, r=20, t=30, b=40),
88
- xaxis_title="Date",
89
- yaxis_title="Daily Change (%)",
90
- legend_title="Volatility",
91
- hovermode="x unified",
92
- )
93
-
94
- return fig