Commit ee1d75c
authored
fix(crypto): Issue with small cap coins precision (#240)
---
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}"
2. 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
<img width="545" height="467" alt="Screenshot 2025-11-18 at 22 00 58" src="https://github.com/user-attachments/assets/79f9ed09-3f67-4616-9b05-d803489c6766" />
3. 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
```1 parent 1b1b13b commit ee1d75c
File tree
5 files changed
+303
-36
lines changed- examples
- frontend/src/components/charts
- live_trade_bench/agents
- tests
5 files changed
+303
-36
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
21 | 38 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
26 | 47 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
31 | 52 | | |
32 | 53 | | |
33 | 54 | | |
| |||
58 | 79 | | |
59 | 80 | | |
60 | 81 | | |
| 82 | + | |
| 83 | + | |
61 | 84 | | |
62 | 85 | | |
63 | 86 | | |
| |||
70 | 93 | | |
71 | 94 | | |
72 | 95 | | |
73 | | - | |
74 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
75 | 102 | | |
76 | | - | |
| 103 | + | |
77 | 104 | | |
78 | 105 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
85 | 116 | | |
86 | 117 | | |
87 | 118 | | |
| |||
277 | 308 | | |
278 | 309 | | |
279 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
280 | 411 | | |
| 412 | + | |
281 | 413 | | |
282 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
283 | 430 | | |
284 | 431 | | |
285 | 432 | | |
| |||
291 | 438 | | |
292 | 439 | | |
293 | 440 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | 441 | | |
299 | 442 | | |
300 | 443 | | |
| |||
317 | 460 | | |
318 | 461 | | |
319 | 462 | | |
320 | | - | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
321 | 466 | | |
322 | 467 | | |
323 | 468 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
45 | 63 | | |
46 | 64 | | |
47 | 65 | | |
| |||
157 | 175 | | |
158 | 176 | | |
159 | 177 | | |
160 | | - | |
| 178 | + | |
161 | 179 | | |
162 | 180 | | |
163 | 181 | | |
164 | | - | |
| 182 | + | |
165 | 183 | | |
166 | 184 | | |
167 | 185 | | |
| |||
193 | 211 | | |
194 | 212 | | |
195 | 213 | | |
196 | | - | |
| 214 | + | |
197 | 215 | | |
198 | 216 | | |
199 | 217 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
| |||
192 | 196 | | |
193 | 197 | | |
194 | 198 | | |
195 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
196 | 204 | | |
197 | 205 | | |
198 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| |||
0 commit comments