File size: 1,994 Bytes
20eee66
 
f104fee
20eee66
f104fee
20eee66
 
f104fee
20eee66
 
f104fee
 
20eee66
f104fee
 
 
 
 
 
20eee66
 
f104fee
 
 
20eee66
 
f104fee
 
 
20eee66
f104fee
20eee66
f104fee
 
20eee66
f104fee
 
 
 
 
20eee66
 
 
f104fee
 
20eee66
 
f104fee
 
 
20eee66
f104fee
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import plotly.graph_objects as go
from datetime import datetime
from typing import Dict, Any

def create_price_chart(data: Dict[str, Any], symbol: str) -> go.Figure:
    try:
        if not data or "prices" not in data:
            return _empty_chart(f"No price data for {symbol}")
        
        prices = data["prices"]
        timestamps = [datetime.fromtimestamp(p[0]/1000) for p in prices]
        values = [p[1] for p in prices]
        
        fig = go.Figure()
        fig.add_trace(go.Scatter(
            x=timestamps, y=values, mode='lines',
            name=f'{symbol.upper()} Price',
            line=dict(color='#00D4AA', width=2)
        ))
        
        fig.update_layout(
            title=f'{symbol.upper()} Price History',
            xaxis_title='Date', yaxis_title='Price (USD)',
            template='plotly_dark', height=400
        )
        
        return fig
    except Exception:
        return _empty_chart(f"Chart error for {symbol}")

def create_market_overview(data: Dict[str, Any]) -> go.Figure:
    try:
        if not data:
            return _empty_chart("No market data available")
        
        fig = go.Figure()
        fig.add_annotation(
            text="Market Overview\n" + str(data)[:200] + "...",
            x=0.5, y=0.5, font=dict(size=12, color="white"),
            showarrow=False, align="left"
        )
        
        fig.update_layout(
            title="Market Overview", template='plotly_dark', height=400,
            xaxis=dict(visible=False), yaxis=dict(visible=False)
        )
        
        return fig
    except Exception:
        return _empty_chart("Market overview error")

def _empty_chart(message: str) -> go.Figure:
    fig = go.Figure()
    fig.add_annotation(
        text=message, x=0.5, y=0.5,
        font=dict(size=16, color="white"), showarrow=False
    )
    fig.update_layout(
        template='plotly_dark', height=400,
        xaxis=dict(visible=False), yaxis=dict(visible=False)
    )
    return fig