Skip to content

fix(frontend): Issue with small cap coins precision#240

Merged
lwaekfjlk merged 3 commits intomainfrom
fix/sht-coin-precision
Nov 21, 2025
Merged

fix(frontend): Issue with small cap coins precision#240
lwaekfjlk merged 3 commits intomainfrom
fix/sht-coin-precision

Conversation

@andrewBatutin
Copy link
Collaborator

@andrewBatutin andrewBatutin commented Nov 17, 2025


Fix: Micro-cap Token Price Formatting and Backtest Parametrization

Problem

Micro-cap cryptocurrency tokens (PEPE, BONK, SHIB, FLOKI, etc.) were displaying as $0.00 in both LLM
prompts and frontend charts due to fixed 2-decimal place formatting. This caused:

  • LLM agents receiving incorrect price data ($0.00 instead of actual prices like $0.00001234)
  • Poor trading decisions for meme coins and micro-cap tokens
  • Inefficient token usage in LLM prompts
  • Potential display issues in charts when these assets are shown

Example Issue:
PEPEUSDT: Current price is $0.00 ❌ (actual price: $0.00001234)

Solution

Implemented adaptive price formatting with scientific notation for small-value assets:

New Formatting Logic:

  • Prices ≥ $1.00: Standard format with 4 decimals ($43,250.6700)
  • Prices < $1.00: Scientific notation ($1.23e-05)

Benefits:

  • ✅ Token-efficient (saves tokens in LLM prompts)
  • ✅ LLM-friendly for mathematical operations
  • ✅ No precision loss
  • ✅ Works for any price magnitude

Changes Made

  1. Backend: LLM Prompt Formatting

Files:

  • live_trade_bench/agents/bitmex_agent.py (lines 35-45)
  • live_trade_bench/agents/base_agent.py (lines 179-189)

Current Price Display:
if price >= 1.0:
# Standard formatting for larger prices
analysis_parts.append(f"{symbol}: Current price is ${price:,.4f}")
else:
# Scientific notation for micro-cap tokens (PEPE, BONK, etc.)
analysis_parts.append(f"{symbol}: Current price is ${price:.2e}")

Historical Price Display:
if hist_price >= 1.0:
price_str = f"{hist_price:.4f}"
else:
price_str = f"{hist_price:.2e}"

  1. Frontend: Chart Tooltip Formatting

File: frontend/src/components/charts/AreaChart.tsx (lines 45-61, 175-183, 213-215)

Added formatPrice() utility function:

const formatPrice = (value: number): string => {
  if (value >= 1.0) {
    return value.toLocaleString(undefined, {
      minimumFractionDigits: 2,
      maximumFractionDigits: 4
    });
  } else if (value >= 0.0001) {
    return value.toFixed(8).replace(/\.?0+$/, '');
  } else if (value > 0) {
    return value.toExponential(2);  // Scientific notation
  }
  return '0';
};

Applied to:

  • Tooltip labels
  • Tooltip footer (total value)
  • Y-axis tick labels
Screenshot 2025-11-18 at 22 00 58
  1. Backtest Script Parametrization

File: examples/backtest_demo.py

  Added CLI argument parser with full parametrization support:

  New CLI Arguments:
  --start-date, --end-date          # Time period (YYYY-MM-DD)
  --exchanges                       # Comma-separated: stock,polymarket,bitmex
  --bitmex-symbols                  # Custom BitMEX symbols (e.g., XBTUSDT,PEPEUSDT)
  --stocks                          # Custom stock symbols (e.g., AAPL,TSLA)
  --bitmex-count, --stock-count     # Number of trending assets to fetch
  --initial-cash-bitmex             # Initial capital per exchange
  --threshold                       # Polymarket volume filter

  Example Usage:
  # 1-week backtest for BTC + PEPE
  python examples/backtest_demo.py \
    --start-date 2025-11-10 \
    --end-date 2025-11-17 \
    --exchanges bitmex \
    --bitmex-symbols XBTUSDT,PEPEUSDT \
    --initial-cash-bitmex 1000

  # Multi-exchange with custom assets
  python examples/backtest_demo.py \
    --start-date 2025-11-01 \
    --end-date 2025-11-30 \
    --exchanges stock,bitmex \
    --stocks AAPL,TSLA,NVDA \
    --bitmex-symbols XBTUSDT,ETHUSDT,PEPEUSDT

@andrewBatutin andrewBatutin marked this pull request as ready for review November 18, 2025 21:08
@lwaekfjlk lwaekfjlk changed the title (fix) Issue with small cap coins precision fix(frontend): Issue with small cap coins precision Nov 21, 2025
@lwaekfjlk lwaekfjlk merged commit ee1d75c into main Nov 21, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants