Spaces:
Running
Running
| """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}%" | |