File size: 1,531 Bytes
7b8993a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
"""Utility functions for data formatting."""


def format_funding_rate(rate: float) -> str:
    """
    Format funding rate as percentage string.
    
    Args:
        rate: Raw funding rate (e.g., 0.0001)
    
    Returns:
        Formatted string (e.g., "+0.01%" or "-0.05%")
    """
    percentage = rate * 100
    sign = "+" if percentage >= 0 else ""
    return f"{sign}{percentage:.4f}%"


def format_volume(volume: float) -> str:
    """
    Format volume to human-readable format.
    
    Args:
        volume: Volume in USDT
    
    Returns:
        Formatted string (e.g., "$1.5M", "$500K")
    """
    if volume >= 1_000_000_000:
        return f"${volume / 1_000_000_000:.2f}B"
    elif volume >= 1_000_000:
        return f"${volume / 1_000_000:.2f}M"
    elif volume >= 1_000:
        return f"${volume / 1_000:.2f}K"
    return f"${volume:.2f}"


def format_price(price: float) -> str:
    """
    Format price based on value.
    
    Args:
        price: Price in USDT
    
    Returns:
        Formatted price string
    """
    if price >= 1000:
        return f"${price:,.2f}"
    elif price >= 1:
        return f"${price:.4f}"
    elif price >= 0.0001:
        return f"${price:.6f}"
    return f"${price:.8f}"


def format_percentage(value: float) -> str:
    """
    Format a percentage value.
    
    Args:
        value: Percentage value (e.g., 5.25)
    
    Returns:
        Formatted string (e.g., "+5.25%" or "-3.10%")
    """
    sign = "+" if value >= 0 else ""
    return f"{sign}{value:.2f}%"