Skip to content

[BUG] Incorrect P&L calculation in TON Trading Bot reportΒ #129

Description

@labtgbot

πŸ› Bug Description

The TON Trading Bot report shows incorrect P&L calculations when closing positions in simulation mode.

Current (Wrong) Behavior:

  • Position 28: Shows 10 TON β†’ 16.24 USDT with +13,310% profit
  • Position 29: Shows 50 TON β†’ 16.28 USDT with -73.53% loss
  • Total reported: +$1.247 net profit

Expected (Correct) Behavior:

Based on entry/exit prices:

  • Position 28 (Entry $1.240, Exit $1.249):
    10 TON Γ— $1.240 = $12.40 β†’ 10 TON Γ— $1.249 = $12.49
    Actual P&L: ~+$0.09 (not +$16.24!)

  • Position 29 (Entry $1.252, Exit $1.251):
    50 TON Γ— $1.252 = $62.60 β†’ 50 TON Γ— $1.251 = $62.55
    Actual P&L: ~-$0.05 (not -$45.22!)

Root Cause:

The ton_trading_record_trade tool (or report generator) is using incorrect formula for P&L calculation. It appears to:

  1. Use wrong amount_in/amount_out values in the report
  2. OR calculate PnL percentage based on incorrect base amounts

Affected Components:

  • TON Trading Bot plugin (likely in plugins/ton-trading or similar)
  • The recordTrade / calculatePnL function
  • Report generation in HEARTBEAT.md workflow

Steps to Reproduce:

  1. Open a simulated trade (e.g., 10 TON/USDT at $1.240)
  2. Close the trade at a slightly higher price ($1.249)
  3. Check the generated report β€” shows incorrect USDT amounts and P&L%

Expected Fix:

P&L should be calculated as:

pnl_usd = (amount_in Γ— exit_price_usd) - (amount_in Γ— entry_price_usd)
pnl_pct = ((exit_price - entry_price) / entry_price) Γ— 100

Report should show:

  • Correct USDT amounts based on actual TON amount Γ— price
  • Accurate P&L percentages

Priority: High πŸ”΄

This breaks trading performance tracking and could lead to wrong decisions in YOLO mode.


Date: 2026-04-09
Reporter: Tony ID (@labtgbot)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions