Simple Paper Trading Engine
Build a paper trading engine that simulates order execution against live market data without risking real capital.
Paper Trading Engine
Overview
This notebook presents a self-contained paper trading engine designed for the simulation of order execution logic. The engine operates without real market interaction, providing a controlled environment for strategy evaluation.
Design Principles
- API Parity: The engine's API mirrors live execution classes, facilitating seamless transition from simulation to production.
- State Management: Comprehensive tracking of simulated P&L, account balance, and historical position data is maintained in-memory.
- Independence: The engine is implemented with minimal external dependencies, ensuring a lightweight and self-sufficient operational framework.
- Flexible Price Input: Supports various price sources, including historical datasets and live data feeds.
Applications
- Strategy Validation: Pre-deployment testing and validation of trading algorithms.
- Risk Parameter Optimization: Calibration and tuning of risk management parameters, such as Take-Profit (TP) and Stop-Loss (SL) levels.
- Educational Contexts: Utilized as a tool for teaching and demonstrating algorithmic trading concepts.
1. Module Imports
This section imports all necessary Python libraries for the paper trading engine. Each module serves a specific function within the simulation framework.
import time
import random
import datetime
import math
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from dataclasses import dataclass, field
from typing import Optional
# Confirm successful import of all required modules.
print("Required modules imported successfully.")Required modules imported successfully.
2. Configuration Parameters
This section defines the core parameters for the paper trading engine and the simulation. These parameters control strategy behavior, financial mechanics, and simulation settings.
# ── Strategy-Specific Configuration ───────────────────────────────────────
# Parameters dictating the trading strategy's characteristics.
config_strategy = {
"name": "btc_paper_1h", # Unique identifier for the strategy.
"symbol": "BTC", # Trading instrument symbol (e.g., 'BTC', 'ETH').
"time_horizon": "1h", # Timeframe of the strategy (e.g., '1h', '4h', '1d').
"live_tp_percent": 2.0, # Take-profit threshold as a percentage of entry price.
"live_sl_percent": 1.0, # Stop-loss threshold as a percentage of entry price.
}
# ── Engine-Specific Configuration ─────────────────────────────────────────
# Financial and operational parameters for the simulation engine.
INITIAL_BALANCE = 10_000.0 # Starting capital in USDT for the simulation.
ALLOCATION_PERCENT = 50 # Percentage of the total balance allocated per trade (e.g., 50 means 50% of capital).
MAKER_FEE = 0.0002 # Maker transaction fee rate (e.g., 0.0002 for 0.02%).
TAKER_FEE = 0.0004 # Taker transaction fee rate (e.g., 0.0004 for 0.04%).
# Output initial balance for verification.
print(f"Paper Trading Engine Initialized | Balance: ${INITIAL_BALANCE:,.2f} USDT")Paper Trading Engine Initialized | Balance: $10,000.00 USDT
3. Trade Record Structure
This section defines the structure for each completed trading operation within the simulation engine. Instead of a dedicated class, trade details are encapsulated in a dictionary format. Each dictionary instance serves as an immutable record, providing a comprehensive audit trail for performance analysis and post-mortem evaluation.
Trade Record Fields:
entry_time: Datetime of position open.exit_time: Datetime of position close.symbol: Asset traded.direction: 'long' | 'short'.entry_price: Fill price at open.exit_price: Fill price at close.quantity: Base asset quantity.pnl_usd: Realized P&L in USD.pnl_pct: Realized P&L as percentage of entry notional.reason: Close reason ('take_profit', 'stop_loss', 'direction_change', 'end_of_simulation').
# The 'Trade' dataclass has been removed as per the user's request.
# Trade records will now be represented as dictionaries with the structure detailed in the preceding markdown cell.4. Functional Trading Engine Core
This section redefines the core logic of the paper trading engine using a functional programming paradigm, replacing the previous class-based implementation. The engine's state is explicitly passed between functions, promoting modularity and testability. Each function performs a specific operation on the engine's state or related data, adhering to the principle of statelessness where applicable.
Core Components:
- State Initialization: Sets up the initial financial and positional parameters.
- Price Sourcing: Retrieves or simulates current market prices.
- Order Simulation: Handles trade execution, including slippage and fee calculations.
- Position Management: Functions for opening, closing, and monitoring trading positions.
- Performance Analytics: Calculates and summarizes key trading metrics.
- Simulation Orchestration: Manages the sequential execution of trading logic over time.
# The PaperTradingEngine class has been removed as per the user's request.
# Its functionalities are now being refactored into a set of modular functions.
# The engine state will be managed through dictionary structures passed between these functions.4.1. initialize_engine_state Function
This function initializes the state dictionary for the paper trading engine. It sets up the initial balance, allocation parameters, fee structures, and internal tracking variables for positions and trade history. This state dictionary will be passed as an argument to subsequent functions to maintain and update the simulation's status.
def initialize_engine_state(symbol: str, initial_balance: float, allocation_pct: float,
tp_percent: float, sl_percent: float,
taker_fee: float, maker_fee: float) -> dict:
"""
Initializes and returns the state dictionary for the paper trading engine.
Parameters:
- symbol (str): Base asset symbol (e.g., 'BTC').
- initial_balance (float): Starting paper balance in USDT.
- allocation_pct (float): Percentage of balance to allocate per trade.
- tp_percent (float): Take-profit trigger (%).
- sl_percent (float): Stop-loss trigger (%).
- taker_fee (float): Taker transaction fee rate.
- maker_fee (float): Maker transaction fee rate.
Returns:
- dict: A dictionary representing the initial state of the trading engine.
"""
engine_state = {
"symbol": symbol.upper(),
"balance": initial_balance,
"initial_balance": initial_balance,
"allocation": allocation_pct / 100,
"tp_percent": tp_percent,
"sl_percent": sl_percent,
"taker_fee": taker_fee,
"maker_fee": maker_fee,
"direction": 0, # +1 long | -1 short | 0 flat
"entry_price": 0.0,
"quantity": 0.0,
"entry_time": None,
"trades": [],
"balance_curve": [initial_balance],
"time_curve": [datetime.datetime.now(datetime.UTC)], # Use timezone-aware datetime
"_last_price": 50_000.0 # For random walk default price source
}
print(f"Paper Trading Engine Initialized | Balance: ${engine_state['balance']:,.2f} USDT")
return engine_state4.2. get_current_price Function
This function retrieves the current market price for the asset. It supports an external price_source callable or defaults to a simulated random walk for demonstration purposes. The function updates the _last_price in the engine_state if using the default random walk.
def get_current_price(engine_state: dict, price_source=None) -> float:
"""
Retrieves the current market price.
Parameters:
- engine_state (dict): The current state of the trading engine.
- price_source (Callable | None): A callable function that returns the current price.
If None, a random walk simulation is used.
Returns:
- float: The current market price.
"""
if price_source is not None:
return price_source()
# Default: random walk around last price (for standalone demo)
last_price = engine_state.get("_last_price", 50_000.0)
change = last_price * random.gauss(0, 0.002)
current_price = max(100, last_price + change)
engine_state["_last_price"] = current_price # Update last price in state
return round(current_price, 2)4.3. simulate_fill Function
This function simulates the execution of an order, accounting for transaction fees and potential slippage. Market orders incur a taker fee and simulated slippage, while limit orders incur a maker fee with no slippage. The fill price and fee cost are returned.
def simulate_fill(engine_state: dict, side: str, quantity: float,
price: float, order_type: str = "market") -> tuple[float, float]:
"""
Simulates an order fill, applying realistic slippage and fees.
Parameters:
- engine_state (dict): The current state of the trading engine.
- side (str): Order side ('buy' or 'sell').
- quantity (float): Quantity of the asset to trade.
- price (float): The requested execution price.
- order_type (str): Type of order ('market' or 'limit').
Returns:
- tuple[float, float]: A tuple containing the fill price after slippage and the calculated fee cost.
"""
fee_rate = engine_state["taker_fee"] if order_type == "market" else engine_state["maker_fee"]
# Slippage model: normally distributed, mean = 1 bps, std = 0.3 bps
if order_type == "market":
slippage_bps = abs(random.gauss(1.0, 0.3))
if side == "buy":
fill_price = price * (1 + slippage_bps / 10_000)
else:
fill_price = price * (1 - slippage_bps / 10_000)
else:
fill_price = price
fee_cost = quantity * fill_price * fee_rate
return round(fill_price, 2), round(fee_cost, 4)4.4. open_position Function
This function executes the opening of a simulated trading position based on a given prediction. It calculates the quantity to be traded based on allocation percentage, simulates the order fill (including fees), and updates the engine's state with the new position details. This function only proceeds if there is no current open position or if the new prediction differs from the current direction.
def open_position(engine_state: dict, prediction: int, current_price: Optional[float] = None) -> None:
"""
Opens a simulated trading position in the direction of the prediction.
Parameters:
- engine_state (dict): The current state of the trading engine.
- prediction (int): Trading signal: +1 for long, -1 for short. 0 implies no action.
- current_price (float | None): Optional. The current market price. If None, `get_current_price` is used.
"""
# If no prediction or direction matches current position, no action.
if prediction == 0 or engine_state["direction"] == prediction:
return
price = current_price if current_price is not None else get_current_price(engine_state)
# Calculate raw quantity based on allocated balance and price.
raw_qty = (engine_state["balance"] * engine_state["allocation"]) / price
quantity = round(raw_qty, 6)
# Simulate the order fill to get fill price and fees.
fill_price, fee = simulate_fill(
engine_state,
"buy" if prediction == 1 else "sell",
quantity,
price
)
# Update engine state after opening position.
engine_state["balance"] -= fee # Deduct opening fee from balance.
engine_state["direction"] = prediction
engine_state["entry_price"] = fill_price
engine_state["quantity"] = quantity
engine_state["entry_time"] = datetime.datetime.now(datetime.UTC) # Use timezone-aware datetime
print(f"[OPEN] {'LONG' if prediction==1 else 'SHORT'} | "
f"Qty: {quantity:.6f} {engine_state['symbol']} | Price: {fill_price:.2f} | "
f"Fee: ${fee:.4f}")4.5. close_open_position Function
This function is responsible for closing an active trading position. It simulates the fill for the closing order, calculates the realized Profit and Loss (PnL), updates the engine_state (including balance and trade history), and then resets the position-specific variables within the state. A trade record (dictionary) is generated and appended to the trades list in the engine_state.
def close_open_position(engine_state: dict, current_price: Optional[float] = None,
reason: str = "direction_change") -> Optional[dict]:
"""
Closes the current simulated position and records the trade.
Parameters:
- engine_state (dict): The current state of the trading engine.
- current_price (float | None): Optional. The current market price. If None, `get_current_price` is used.
- reason (str): The reason for closing the position (e.g., 'take_profit', 'stop_loss', 'direction_change').
Returns:
- dict | None: A dictionary representing the closed trade record, or None if no position was open.
"""
if engine_state["direction"] == 0:
return None
price = current_price if current_price is not None else get_current_price(engine_state)
close_side = "sell" if engine_state["direction"] == 1 else "buy"
fill_price, fee = simulate_fill(engine_state, close_side, engine_state["quantity"], price)
# ── Compute PnL ────────────────────────────────────────────────────
if engine_state["direction"] == 1: # Long
pnl_usd = (fill_price - engine_state["entry_price"]) * engine_state["quantity"]
pnl_pct = ((fill_price - engine_state["entry_price"]) / engine_state["entry_price"]) * 100
else: # Short
pnl_usd = (engine_state["entry_price"] - fill_price) * engine_state["quantity"]
pnl_pct = ((engine_state["entry_price"] - fill_price) / engine_state["entry_price"]) * 100
pnl_usd -= fee # Deduct closing fee
# ── Update balance ─────────────────────────────────────────────────
# The balance update should only add the realized PnL (which includes all fees).
# The notional value of the trade was never subtracted from the balance, only the initial fee.
engine_state["balance"] += pnl_usd
engine_state["balance_curve"].append(round(engine_state["balance"], 4))
engine_state["time_curve"].append(datetime.datetime.now(datetime.UTC))
trade = {
"entry_time": engine_state["entry_time"],
"exit_time": datetime.datetime.now(datetime.UTC),
"symbol": engine_state["symbol"],
"direction": "long" if engine_state["direction"] == 1 else "short",
"entry_price": engine_state["entry_price"],
"exit_price": fill_price,
"quantity": engine_state["quantity"],
"pnl_usd": round(pnl_usd, 4),
"pnl_pct": round(pnl_pct, 4),
"reason": reason,
}
engine_state["trades"].append(trade)
print(f"[CLOSE] {reason.upper()} | Price: {fill_price:.2f} | "
f"PnL: ${pnl_usd:.2f} ({pnl_pct:.2f}%) | Balance: ${engine_state['balance']:.2f}")
# Reset position state in the engine_state dictionary
engine_state["direction"] = 0
engine_state["entry_price"] = 0.0
engine_state["quantity"] = 0.0
engine_state["entry_time"] = None
return trade4.6. check_tp_sl Function
This function evaluates the current profit/loss (PnL) of an open position against predefined Take-Profit (TP) and Stop-Loss (SL) thresholds. If the PnL exceeds the TP or falls below the SL, the function triggers the close_open_position function, recording the trade and updating the engine_state. It returns True if the position was closed, False otherwise.
def check_tp_sl(engine_state: dict, current_price: Optional[float] = None) -> bool:
"""
Evaluates Take-Profit (TP) and Stop-Loss (SL) conditions for the current open position.
Parameters:
- engine_state (dict): The current state of the trading engine.
- current_price (float | None): Optional. The current market price. If None, `get_current_price` is used.
Returns:
- bool: True if the position was closed due to TP/SL, False otherwise.
"""
if engine_state["direction"] == 0:
return True # No open position, so no TP/SL to check
price = current_price if current_price is not None else get_current_price(engine_state)
if engine_state["direction"] == 1: # Long position
pnl_pct = ((price - engine_state["entry_price"]) / engine_state["entry_price"]) * 100
else: # Short position
pnl_pct = ((engine_state["entry_price"] - price) / engine_state["entry_price"]) * 100
print(f"[MONITOR] PnL: {pnl_pct:.2f}% | TP: +{engine_state['tp_percent']}% | SL: -{engine_state['sl_percent']}%")
if pnl_pct >= engine_state["tp_percent"]:
close_open_position(engine_state, price, "take_profit")
return True
if pnl_pct <= -engine_state["sl_percent"]:
close_open_position(engine_state, price, "stop_loss")
return True
return False4.7. _max_drawdown Function
This auxiliary function calculates the maximum drawdown percentage from the balance_curve stored in the engine_state. Maximum drawdown represents the largest peak-to-trough decline in the balance, indicating the largest historical loss from a peak. This metric is crucial for assessing the risk associated with the trading strategy.
def _max_drawdown(engine_state: dict) -> float:
"""
Computes the maximum drawdown percentage of the balance curve.
Parameters:
- engine_state (dict): The current state of the trading engine, containing the 'balance_curve'.
Returns:
- float: The maximum drawdown as a percentage.
"""
curve = np.array(engine_state["balance_curve"])
if len(curve) < 2:
return 0.0
peak = np.maximum.accumulate(curve)
drawdown = (curve - peak) / peak * 100
return abs(drawdown.min())4.8. _sharpe_ratio Function
This auxiliary function calculates the annualized Sharpe ratio based on the PnL percentages of completed trades. The Sharpe ratio measures the excess return per unit of risk, with a higher value indicating better risk-adjusted performance. A risk-free rate can be specified, though it defaults to 0.0 for simplicity.
def _sharpe_ratio(engine_state: dict, risk_free_rate: float = 0.0) -> float:
"""
Calculates the annualized Sharpe ratio from trade PnL percentages.
Parameters:
- engine_state (dict): The current state of the trading engine, containing 'trades'.
- risk_free_rate (float): The risk-free return rate (default is 0.0).
Returns:
- float: The annualized Sharpe ratio.
"""
pnls = [t["pnl_pct"] for t in engine_state["trades"]]
if len(pnls) < 2:
return 0.0
excess_returns = np.array(pnls) - risk_free_rate
if np.std(excess_returns) == 0:
return 0.0
# Assuming daily returns for annualization (sqrt(252 trading days))
return (np.mean(excess_returns) / np.std(excess_returns)) * math.sqrt(252)4.9. get_performance_summary Function
This function compiles key performance metrics from the engine_state's trade history and balance curve. It calculates metrics such as total return, win rate, average win/loss, profit factor, maximum drawdown, and Sharpe ratio. The results are returned as a Pandas DataFrame for clear presentation and analysis.
def get_performance_summary(engine_state: dict) -> pd.DataFrame:
"""
Computes and returns a summary of key performance metrics from the trade history.
Parameters:
- engine_state (dict): The current state of the trading engine, containing 'trades' and 'balance_curve'.
Returns:
- pd.DataFrame: A DataFrame summarizing the performance metrics.
"""
if not engine_state["trades"]:
return pd.DataFrame([{"Message": "No trades recorded."}])
pnls_usd = [t["pnl_usd"] for t in engine_state["trades"]]
pnls_pct = [t["pnl_pct"] for t in engine_state["trades"]]
wins = [p for p in pnls_pct if p > 0]
losses = [p for p in pnls_pct if p <= 0]
total_return = ((engine_state["balance"] - engine_state["initial_balance"]) / engine_state["initial_balance"]) * 100
# Calculate profit factor
total_wins = sum(p for p in pnls_usd if p > 0)
total_losses = abs(sum(p for p in pnls_usd if p < 0))
profit_factor = round(total_wins / total_losses, 2) if total_losses != 0 else float("inf")
summary = {
"Initial Balance ($)": engine_state["initial_balance"],
"Final Balance ($)": round(engine_state["balance"], 2),
"Total Return (%)": round(total_return, 2),
"Total Trades": len(engine_state["trades"]),
"Win Rate (%)": round(len(wins) / max(len(engine_state["trades"]), 1) * 100, 1),
"Avg Win (%)": round(np.mean(wins), 2) if wins else 0,
"Avg Loss (%)": round(np.mean(losses), 2) if losses else 0,
"Profit Factor": profit_factor,
"Max Drawdown (%)": round(_max_drawdown(engine_state), 2),
"Sharpe Ratio": round(_sharpe_ratio(engine_state), 2),
"Take Profit Hits": sum(1 for t in engine_state["trades"] if t["reason"] == "take_profit"),
"Stop Loss Hits": sum(1 for t in engine_state["trades"] if t["reason"] == "stop_loss"),
}
return pd.DataFrame([summary]).T.rename(columns={0: "Value"})4.10. run_simulation Function
This function serves as the primary orchestrator for the paper trading simulation. It iterates through a sequence of time-series predictions and corresponding market prices, applying the trading logic at each step. It handles position opening and closing based on signals and monitors for Take-Profit and Stop-Loss conditions. Finally, it generates a comprehensive performance summary upon completion.
def run_simulation(engine_state: dict, predictions: list[tuple], prices: list[float]) -> pd.DataFrame:
"""
Runs a batch simulation using a list of time-series predictions and corresponding prices.
Parameters:
- engine_state (dict): The initial state of the trading engine.
- predictions (list[tuple]): A list of (datetime, signal) tuples, where signal is +1 (long), -1 (short), or 0 (no action).
- prices (list[float]): A list of corresponding market prices for each prediction timestamp.
Returns:
- pd.DataFrame: A DataFrame summarizing the performance of the simulation.
"""
print(f"[SIM START] {len(predictions)} predictions.")
prev_signal = 0
for (dt, signal), price in zip(predictions, prices):
# Ensure consistent datetime in engine state time curve
engine_state["time_curve"][-1] = dt # Update the last datetime to current prediction time
# Check for TP/SL if a position is currently open
if engine_state["direction"] != 0:
check_tp_sl(engine_state, price)
# If the signal changes, re-evaluate position
if signal != prev_signal:
# Close existing position if any
if engine_state["direction"] != 0:
close_open_position(engine_state, price, "direction_change")
# Open new position if signal is not neutral
if signal != 0:
open_position(engine_state, signal, price)
prev_signal = signal
# Close any remaining position at the end of the simulation
if engine_state["direction"] != 0:
close_open_position(engine_state, prices[-1], "end_of_simulation")
print("[SIM END]")
return get_performance_summary(engine_state)5. Demo Simulation
This section demonstrates the functionality of the paper trading engine with synthetic data. It initializes the engine with predefined parameters, generates a series of simulated price movements and trading signals, and then executes the run_simulation function to process these events. Finally, it displays the performance summary and visualizes the results.
# ── Generate synthetic predictions and prices ─────────────────────────────
np.random.seed(42)
n_periods = 200
# Simulated price path (GBM-like)
returns = np.random.normal(0.0002, 0.015, n_periods)
prices = [50_000.0]
for r in returns:
prices.append(prices[-1] * (1 + r))
prices = prices[1:]
# Simulated prediction signals: +1, -1, 0 with realistic frequency
signals = np.random.choice([1, -1, 0], size=n_periods, p=[0.4, 0.4, 0.2])
base_dt = datetime.datetime(2025, 1, 1, 0, 0, 0, tzinfo=datetime.UTC)
predictions = [(base_dt + datetime.timedelta(hours=i), int(s)) for i, s in enumerate(signals)]
# ── Initialize paper trading engine state ────────────────────────────────
engine_state = initialize_engine_state(
symbol = config_strategy["symbol"],
initial_balance = INITIAL_BALANCE,
allocation_pct = ALLOCATION_PERCENT,
tp_percent = config_strategy["live_tp_percent"],
sl_percent = config_strategy["live_sl_percent"],
taker_fee = TAKER_FEE,
maker_fee = MAKER_FEE
)
# ── Run paper trading simulation ───────────────────────────────────────────
summary = run_simulation(engine_state, predictions, prices)
print("\n=== Performance Summary ===")
print(summary.to_string())Paper Trading Engine Initialized | Balance: $10,000.00 USDT
[SIM START] 200 predictions.
[OPEN] SHORT | Qty: 0.099427 BTC | Price: 50284.02 | Fee: $1.9998
[MONITOR] PnL: -1.00% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -3.33% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 51967.95 | PnL: $-169.49 (-3.35%) | Balance: $14828.09
[OPEN] LONG | Qty: 0.143170 BTC | Price: 51789.88 | Fee: $2.9659
[MONITOR] PnL: -0.34% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 2.04% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 52843.56 | PnL: $147.83 (2.03%) | Balance: $22387.71
[OPEN] SHORT | Qty: 0.210487 BTC | Price: 53174.95 | Fee: $4.4771
[MONITOR] PnL: 0.67% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.29% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 3.13% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 51514.71 | PnL: $345.12 (3.12%) | Balance: $33921.00
[OPEN] LONG | Qty: 0.344235 BTC | Price: 49273.79 | Fee: $6.7847
[MONITOR] PnL: -1.35% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 48605.18 | PnL: $-236.85 (-1.36%) | Balance: $50639.12
[OPEN] SHORT | Qty: 0.520501 BTC | Price: 48636.47 | Fee: $10.1261
[MONITOR] PnL: 0.30% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 48494.92 | PnL: $63.58 (0.29%) | Balance: $76007.91
[OPEN] LONG | Qty: 0.783756 BTC | Price: 48494.37 | Fee: $15.2031
[MONITOR] PnL: 0.11% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 48543.05 | PnL: $22.93 (0.10%) | Balance: $114023.39
[OPEN] SHORT | Qty: 1.174328 BTC | Price: 48540.75 | Fee: $22.8011
[MONITOR] PnL: 2.10% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 47526.41 | PnL: $1168.84 (2.09%) | Balance: $172172.20
[OPEN] LONG | Qty: 1.826102 BTC | Price: 47144.61 | Fee: $34.4363
[MONITOR] PnL: 0.18% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 47223.20 | PnL: $109.02 (0.17%) | Balance: $258337.65
[OPEN] SHORT | Qty: 2.734897 BTC | Price: 47226.13 | Fee: $51.6634
[MONITOR] PnL: 1.70% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 46428.30 | PnL: $2131.19 (1.69%) | Balance: $389575.78
[OPEN] LONG | Qty: 4.195855 BTC | Price: 46428.38 | Fee: $77.9227
[MONITOR] PnL: 0.57% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -0.31% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 46280.14 | PnL: $-699.67 (-0.32%) | Balance: $583604.94
[OPEN] LONG | Qty: 6.331120 BTC | Price: 46097.57 | Fee: $116.7397
[MONITOR] PnL: -0.90% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.87% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 46955.92 | PnL: $5315.40 (1.86%) | Balance: $880652.85
[OPEN] SHORT | Qty: 9.376264 BTC | Price: 46956.90 | Fee: $176.1121
[MONITOR] PnL: -0.01% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.56% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 46232.39 | PnL: $6619.80 (1.54%) | Balance: $1327376.83
[OPEN] LONG | Qty: 14.357465 BTC | Price: 46231.92 | Fee: $265.5092
[MONITOR] PnL: 1.24% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 46799.14 | PnL: $7875.07 (1.23%) | Balance: $1998759.57
[OPEN] SHORT | Qty: 21.351711 BTC | Price: 46802.23 | Fee: $399.7231
[MONITOR] PnL: 1.80% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 45960.87 | PnL: $17571.94 (1.80%) | Balance: $3015239.47
[OPEN] LONG | Qty: 32.804413 BTC | Price: 45962.38 | Fee: $603.1076
[MONITOR] PnL: 0.32% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -2.61% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 44760.81 | PnL: $-40004.14 (-2.61%) | Balance: $4482401.12
[OPEN] SHORT | Qty: 50.066142 BTC | Price: 44760.03 | Fee: $896.3848
[MONITOR] PnL: 1.96% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.65% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.54% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.27% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44644.51 | PnL: $4889.57 (0.26%) | Balance: $6727356.32
[OPEN] SHORT | Qty: 75.467008 BTC | Price: 44568.26 | Fee: $1345.3732
[MONITOR] PnL: 0.42% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44382.53 | PnL: $12676.72 (0.42%) | Balance: $10102120.90
[OPEN] LONG | Qty: 113.816173 BTC | Price: 44383.82 | Fee: $2020.6387
[MONITOR] PnL: -2.21% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43399.83 | PnL: $-113969.82 (-2.22%) | Balance: $15037726.98
[OPEN] SHORT | Qty: 173.230721 BTC | Price: 43399.90 | Fee: $3007.2784
[MONITOR] PnL: 1.05% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42946.50 | PnL: $75566.95 (1.04%) | Balance: $22628482.62
[OPEN] LONG | Qty: 263.466389 BTC | Price: 42949.17 | Fee: $4526.2649
[MONITOR] PnL: -0.68% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42652.39 | PnL: $-82686.54 (-0.69%) | Balance: $33856932.54
[OPEN] SHORT | Qty: 396.863491 BTC | Price: 42651.78 | Fee: $6770.7732
[MONITOR] PnL: -1.61% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43343.26 | PnL: $-281303.71 (-1.62%) | Balance: $50495792.37
[OPEN] LONG | Qty: 582.546678 BTC | Price: 43345.47 | Fee: $10100.3044
[MONITOR] PnL: 0.52% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -2.11% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 42423.89 | PnL: $-546748.92 (-2.13%) | Balance: $75189702.70
[OPEN] SHORT | Qty: 886.546087 BTC | Price: 42402.16 | Fee: $15036.5867
[MONITOR] PnL: 0.99% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.06% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42383.04 | PnL: $1920.95 (0.05%) | Balance: $112768056.09
[OPEN] LONG | Qty: 1330.518722 BTC | Price: 42380.79 | Fee: $22555.3730
[MONITOR] PnL: 1.56% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 3.00% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 43646.21 | PnL: $1660436.16 (2.99%) | Balance: $170794371.42
[OPEN] SHORT | Qty: 1980.894316 BTC | Price: 43104.71 | Fee: $34154.3522
[MONITOR] PnL: 0.43% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -0.08% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -1.57% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43785.50 | PnL: $-1383266.82 (-1.58%) | Balance: $254762825.28
[OPEN] LONG | Qty: 2909.523408 BTC | Price: 43785.80 | Fee: $50958.3183
[MONITOR] PnL: -0.71% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43466.67 | PnL: $-979103.12 (-0.73%) | Balance: $381128573.89
[OPEN] SHORT | Qty: 4394.674338 BTC | Price: 43357.44 | Fee: $76216.7322
[MONITOR] PnL: 1.63% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 3.37% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 41898.87 | PnL: $6336287.39 (3.36%) | Balance: $577930473.48
[OPEN] LONG | Qty: 6675.848512 BTC | Price: 43289.40 | Fee: $115597.3845
[MONITOR] PnL: -0.10% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.43% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43905.01 | PnL: $3992477.84 (1.42%) | Balance: $870800830.50
[OPEN] SHORT | Qty: 9916.487017 BTC | Price: 43903.02 | Fee: $174145.4741
[MONITOR] PnL: -0.57% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44155.10 | PnL: $-2674893.46 (-0.57%) | Balance: $1303315519.41
[OPEN] LONG | Qty: 14758.856727 BTC | Price: 44156.76 | Fee: $260681.2920
[MONITOR] PnL: -0.95% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -0.40% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.92% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.89% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44986.01 | PnL: $11973205.11 (1.88%) | Balance: $1966731337.59
[OPEN] SHORT | Qty: 21352.340005 BTC | Price: 46050.01 | Fee: $393310.1914
[MONITOR] PnL: 3.90% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 44259.56 | PnL: $37852279.06 (3.89%) | Balance: $2987465777.21
[OPEN] LONG | Qty: 33336.206955 BTC | Price: 44813.10 | Fee: $597559.4906
[MONITOR] PnL: 0.14% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44871.84 | PnL: $1359826.01 (0.13%) | Balance: $4482126819.63
[OPEN] SHORT | Qty: 49939.473249 BTC | Price: 44870.39 | Fee: $896321.5041
[MONITOR] PnL: 0.42% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.26% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44758.63 | PnL: $4687146.63 (0.25%) | Balance: $6726721285.84
[OPEN] LONG | Qty: 75152.626078 BTC | Price: 44758.01 | Fee: $1345472.9224
[MONITOR] PnL: -2.97% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43420.62 | PnL: $-101813639.94 (-2.99%) | Balance: $9987244162.50
[OPEN] SHORT | Qty: 114985.125559 BTC | Price: 43421.67 | Fee: $1997138.6046
[MONITOR] PnL: 0.29% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43298.85 | PnL: $12130983.65 (0.28%) | Balance: $14990224184.48
[OPEN] LONG | Qty: 173121.252002 BTC | Price: 43300.84 | Fee: $2998518.4313
[MONITOR] PnL: 0.54% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43527.27 | PnL: $36185646.66 (0.52%) | Balance: $22519706946.24
[OPEN] SHORT | Qty: 258641.631922 BTC | Price: 43528.78 | Fee: $4503341.4577
[MONITOR] PnL: -2.25% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 44514.59 | PnL: $-259576837.77 (-2.26%) | Balance: $33513981461.79
[OPEN] LONG | Qty: 379364.064689 BTC | Price: 44177.73 | Fee: $6703776.7307
[MONITOR] PnL: -1.21% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43641.47 | PnL: $-210060176.01 (-1.21%) | Balance: $50056660730.58
[OPEN] SHORT | Qty: 577692.452469 BTC | Price: 43321.67 | Fee: $10010641.7127
[MONITOR] PnL: -1.40% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43931.06 | PnL: $-362191461.03 (-1.41%) | Balance: $74711060415.20
[OPEN] SHORT | Qty: 852640.268962 BTC | Price: 43806.93 | Fee: $14940619.8341
[MONITOR] PnL: -0.80% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44162.44 | PnL: $-318184010.77 (-0.81%) | Balance: $111729488362.19
[OPEN] LONG | Qty: 1265120.024955 BTC | Price: 44162.57 | Fee: $22348379.3745
[MONITOR] PnL: 0.15% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.63% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44878.78 | PnL: $883380794.49 (1.62%) | Balance: $168461472437.79
[OPEN] SHORT | Qty: 1876702.720685 BTC | Price: 44877.71 | Fee: $33688846.9021
[MONITOR] PnL: 1.02% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44423.10 | PnL: $819820245.71 (1.01%) | Balance: $253469724291.71
[OPEN] LONG | Qty: 2853191.539578 BTC | Price: 44421.34 | Fee: $50697038.2186
[MONITOR] PnL: -0.48% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44206.22 | PnL: $-664230090.64 (-0.48%) | Balance: $379497388627.56
[OPEN] SHORT | Qty: 4292063.498858 BTC | Price: 44204.29 | Fee: $75891053.8321
[MONITOR] PnL: 0.56% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43962.17 | PnL: $963719040.34 (0.55%) | Balance: $570112836216.01
[OPEN] SHORT | Qty: 6628939.455526 BTC | Price: 42997.98 | Fee: $114012390.7076
[MONITOR] PnL: -0.47% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43205.09 | PnL: $-1487481218.49 (-0.48%) | Balance: $853542348736.73
[OPEN] LONG | Qty: 9878637.772389 BTC | Price: 43206.03 | Fee: $170726703.0101
[MONITOR] PnL: 0.40% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43373.89 | PnL: $1486838154.93 (0.39%) | Balance: $1281675180141.62
[OPEN] SHORT | Qty: 14772913.274068 BTC | Price: 43373.31 | Fee: $256300056.8750
[MONITOR] PnL: -0.04% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.29% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 2.39% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 42342.93 | PnL: $14971503016.58 (2.38%) | Balance: $1937140530140.59
[OPEN] LONG | Qty: 23017878.314382 BTC | Price: 42084.36 | Fee: $387477103.6078
[MONITOR] PnL: -0.51% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 41865.48 | PnL: $-5423614979.74 (-0.52%) | Balance: $2900022115475.89
[OPEN] LONG | Qty: 35122997.602091 BTC | Price: 41288.88 | Fee: $580075744.0802
[MONITOR] PnL: 0.61% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 3.48% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 42722.17 | PnL: $49741228971.18 (3.47%) | Balance: $4399372501936.01
[OPEN] SHORT | Qty: 51178083.948116 BTC | Price: 42977.76 | Fee: $879807722.7016
[MONITOR] PnL: 2.85% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 41758.67 | PnL: $61535838778.35 (2.84%) | Balance: $6659547942173.64
[OPEN] LONG | Qty: 79750184.526160 BTC | Price: 41757.68 | Fee: $1332072937.4475
[MONITOR] PnL: -0.03% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.08% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 41787.45 | PnL: $1041140212.49 (0.07%) | Balance: $9989439694833.03
[OPEN] LONG | Qty: 115237543.042289 BTC | Price: 43349.66 | Fee: $1998203500.8854
[MONITOR] PnL: -0.28% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43220.00 | PnL: $-16933926347.18 (-0.30%) | Balance: $14966015875103.56
[OPEN] LONG | Qty: 172298087.464514 BTC | Price: 43436.38 | Fee: $2993602421.4336
[MONITOR] PnL: -0.05% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -1.78% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 42660.37 | PnL: $-136645159209.82 (-1.79%) | Balance: $22310382313854.17
[OPEN] SHORT | Qty: 261464623.019399 BTC | Price: 42662.33 | Fee: $4461875934.4462
[MONITOR] PnL: -1.74% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43409.14 | PnL: $-199804376681.34 (-1.75%) | Balance: $33260806091817.58
[OPEN] SHORT | Qty: 374288163.353404 BTC | Price: 44429.31 | Fee: $6651745651.8842
[MONITOR] PnL: 1.34% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43838.67 | PnL: $214506242236.54 (1.33%) | Balance: $50098025427361.27
[OPEN] LONG | Qty: 559554193.266437 BTC | Price: 44771.05 | Fee: $10020732304.5771
[MONITOR] PnL: -2.09% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43828.88 | PnL: $-537005026875.11 (-2.10%) | Balance: $74602828432622.89
[OPEN] SHORT | Qty: 843383991.950426 BTC | Price: 44223.43 | Fee: $14918932239.1288
[MONITOR] PnL: -3.32% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 45694.75 | PnL: $-1256303022640.62 (-3.33%) | Balance: $110628939408883.38
[OPEN] SHORT | Qty: 1238924616.199954 BTC | Price: 44644.65 | Fee: $22124543973.1611
[MONITOR] PnL: -0.18% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44728.25 | PnL: $-125740072249.12 (-0.19%) | Balance: $165792430659292.38
[OPEN] LONG | Qty: 1853554778.791549 BTC | Price: 44723.38 | Fee: $33158894798.7351
[MONITOR] PnL: -0.74% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44391.49 | PnL: $-648089116729.86 (-0.74%) | Balance: $248008417370474.12
[OPEN] SHORT | Qty: 2793263682.246324 BTC | Price: 44391.39 | Fee: $49598744471.8352
[MONITOR] PnL: 2.30% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 43376.26 | PnL: $2787061231813.49 (2.29%) | Balance: $374742737349248.44
[OPEN] LONG | Qty: 4320269361.876224 BTC | Price: 43373.36 | Fee: $74953830707.3401
[MONITOR] PnL: 0.12% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43420.34 | PnL: $127931223143.04 (0.11%) | Balance: $562180313071311.88
[OPEN] SHORT | Qty: 6529009589.014138 BTC | Price: 43049.48 | Fee: $112428180619.0885
[MONITOR] PnL: 1.35% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -0.96% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.21% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42963.31 | PnL: $450401601169.71 (0.20%) | Balance: $843588754213934.88
[OPEN] LONG | Qty: 9818025208.673403 BTC | Price: 42963.48 | Fee: $168726625377.2895
[MONITOR] PnL: -0.47% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42756.29 | PnL: $-2202109565780.12 (-0.48%) | Balance: $1263034447715113.00
[OPEN] SHORT | Qty: 14587171621.996126 BTC | Price: 43290.09 | Fee: $252591984627.7969
[MONITOR] PnL: 1.82% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42507.58 | PnL: $11166581506571.97 (1.81%) | Balance: $1905428409598715.50
[OPEN] LONG | Qty: 22335082280.839554 BTC | Price: 42659.05 | Fee: $381117339206.9278
[MONITOR] PnL: 1.97% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43496.39 | PnL: $18313459608672.79 (1.96%) | Balance: $2876154143640630.00
[OPEN] LONG | Qty: 33868827836.315067 BTC | Price: 42465.25 | Fee: $575299253183.4922
[MONITOR] PnL: 0.29% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.70% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42758.50 | PnL: $9352761586137.56 (0.69%) | Balance: $4323179847249662.50
[OPEN] LONG | Qty: 49954894250.160194 BTC | Price: 43276.35 | Fee: $864746166198.6404
[MONITOR] PnL: -1.85% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 42470.29 | PnL: $-41115281679472.12 (-1.86%) | Balance: $6443065307186912.00
[OPEN] SHORT | Qty: 76387498760.234756 BTC | Price: 42168.88 | Fee: $1288470251846.4131
[MONITOR] PnL: -0.41% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -0.95% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.06% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42148.67 | PnL: $255938763741.37 (0.05%) | Balance: $9663208044419296.00
[OPEN] LONG | Qty: 114647161502.923172 BTC | Price: 42146.50 | Fee: $1932790668096.7776
[MONITOR] PnL: 0.36% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 0.82% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42489.61 | PnL: $37388062528884.27 (0.81%) | Balance: $14530639908563036.00
[OPEN] SHORT | Qty: 170977246319.201752 BTC | Price: 42490.99 | Fee: $2905997305861.7031
[MONITOR] PnL: 1.05% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -1.74% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43235.89 | PnL: $-130317892216260.00 (-1.75%) | Balance: $21662408482617652.00
[OPEN] LONG | Qty: 253197612190.729095 BTC | Price: 42781.03 | Fee: $4332821557891.8032
[MONITOR] PnL: 1.00% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43206.36 | PnL: $103316641750883.97 (0.99%) | Balance: $32593446945870592.00
[OPEN] SHORT | Qty: 377173362041.102051 BTC | Price: 43203.06 | Fee: $6518017218309.7344
[MONITOR] PnL: 1.43% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 42587.23 | PnL: $225849563513590.16 (1.43%) | Balance: $49107821882829328.00
[OPEN] LONG | Qty: 576593324624.063477 BTC | Price: 42590.18 | Fee: $9822884698644.6309
[MONITOR] PnL: 1.19% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 43092.71 | PnL: $279816657002965.97 (1.18%) | Balance: $73935029137670944.00
[OPEN] SHORT | Qty: 857799885068.462280 BTC | Price: 43089.44 | Fee: $14784846336939.8789
[MONITOR] PnL: -1.77% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 43857.46 | PnL: $-673855838710071.50 (-1.78%) | Balance: $110208505132288320.00
[OPEN] LONG | Qty: 1253596350162.830078 BTC | Price: 43962.07 | Fee: $22044274765903.2344
[MONITOR] PnL: 0.63% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.89% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 4.81% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 46070.94 | PnL: $2620569992163824.50 (4.80%) | Balance: $167917721347289088.00
[OPEN] SHORT | Qty: 1822197179545.731445 BTC | Price: 46071.73 | Fee: $33580713012490.2344
[MONITOR] PnL: 0.34% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.45% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 45410.97 | PnL: $1170935912850777.50 (1.43%) | Balance: $253006853009919872.00
[OPEN] LONG | Qty: 2786093828002.889160 BTC | Price: 45410.23 | Fee: $50606863186962.0859
[MONITOR] PnL: -1.32% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 44803.91 | PnL: $-1739195571361000.50 (-1.34%) | Balance: $377734212106563520.00
[OPEN] SHORT | Qty: 4266333602224.085938 BTC | Price: 44265.58 | Fee: $75540685109627.0625
[MONITOR] PnL: 0.09% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44232.71 | PnL: $64749780452253.70 (0.07%) | Balance: $566575152577844608.00
[OPEN] LONG | Qty: 6405331739211.813477 BTC | Price: 44232.29 | Fee: $113329008963307.8906
[MONITOR] PnL: 0.52% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 44458.18 | PnL: $1332992636289382.75 (0.51%) | Balance: $851117307240192000.00
[OPEN] SHORT | Qty: 9529829636951.261719 BTC | Price: 44652.31 | Fee: $170211547736057.5938
[MONITOR] PnL: -1.27% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 45223.37 | PnL: $-5614492922154864.00 (-1.28%) | Balance: $1270861509966636288.00
[OPEN] LONG | Qty: 14052470920218.607422 BTC | Price: 45222.05 | Fee: $254192643976849.4688
[MONITOR] PnL: 0.03% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 2.23% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 46228.32 | PnL: $13880731065552808.00 (2.23%) | Balance: $1919969590965883904.00
[OPEN] LONG | Qty: 20843250054056.800781 BTC | Price: 46060.94 | Fee: $384023865748630.3750
[MONITOR] PnL: 4.09% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 47941.27 | PnL: $38792487629527176.00 (4.08%) | Balance: $2918437744874569728.00
[OPEN] SHORT | Qty: 30795384090729.609375 BTC | Price: 47380.11 | Fee: $583635529075391.8750
[MONITOR] PnL: 0.31% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 47240.41 | PnL: $3720200490018178.50 (0.29%) | Balance: $4380662995546531840.00
[OPEN] LONG | Qty: 46370958029092.921875 BTC | Price: 47238.36 | Fee: $876195205188807.8750
[MONITOR] PnL: 1.08% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.82% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 48093.18 | PnL: $38746771673860800.00 (1.81%) | Balance: $6609021580938385408.00
[OPEN] SHORT | Qty: 68702522587644.320312 BTC | Price: 48092.24 | Fee: $1321623200844936.7500
[MONITOR] PnL: 0.08% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.32% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 3.55% | TP: +2.0% | SL: -1.0%
[CLOSE] TAKE_PROFIT | Price: 46390.97 | PnL: $115606669954477408.00 (3.54%) | Balance: $10027364832582430720.00
[OPEN] LONG | Qty: 108792328689564.625000 BTC | Price: 46086.66 | Fee: $2005550003613385.5000
[MONITOR] PnL: 1.30% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 46682.93 | PnL: $62838103962228960.00 (1.29%) | Balance: $15102072449465257984.00
[OPEN] SHORT | Qty: 161740524629837.468750 BTC | Price: 46682.76 | Fee: $3020197450278490.0000
[MONITOR] PnL: -0.35% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 46850.12 | PnL: $-30099919508236092.00 (-0.36%) | Balance: $22619446426075533312.00
[OPEN] LONG | Qty: 241426665806263.031250 BTC | Price: 46849.86 | Fee: $4524322110724387.0000
[MONITOR] PnL: -1.86% | TP: +2.0% | SL: -1.0%
[CLOSE] STOP_LOSS | Price: 45976.18 | PnL: $-215369600022042080.00 (-1.86%) | Balance: $33710357997232971776.00
[OPEN] SHORT | Qty: 366581181620693.000000 BTC | Price: 45978.00 | Fee: $6741868078253318.0000
[MONITOR] PnL: -0.28% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 46111.61 | PnL: $-55740371736095648.00 (-0.29%) | Balance: $50502545325974847488.00
[OPEN] LONG | Qty: 547654592593676.750000 BTC | Price: 46112.94 | Fee: $10101585814167216.0000
[MONITOR] PnL: 0.59% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -0.73% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: -0.48% | TP: +2.0% | SL: -1.0%
[CLOSE] DIRECTION_CHANGE | Price: 45887.17 | PnL: $-133696104180156448.00 (-0.49%) | Balance: $75612711004977184768.00
[OPEN] SHORT | Qty: 823797394478226.625000 BTC | Price: 45889.28 | Fee: $15121386209027572.0000
[MONITOR] PnL: -0.11% | TP: +2.0% | SL: -1.0%
[MONITOR] PnL: 1.58% | TP: +2.0% | SL: -1.0%
[CLOSE] END_OF_SIMULATION | Price: 45165.51 | PnL: $581356949346992512.00 (1.58%) | Balance: $113982415866596933632.00
[SIM END]
=== Performance Summary ===
Value
Initial Balance ($) 1.000000e+04
Final Balance ($) 1.139824e+20
Total Return (%) 1.139824e+18
Total Trades 9.100000e+01
Win Rate (%) 6.040000e+01
Avg Win (%) 1.440000e+00
Avg Loss (%) -1.360000e+00
Profit Factor 1.940000e+00
Max Drawdown (%) 0.000000e+00
Sharpe Ratio 3.030000e+00
Take Profit Hits 1.400000e+01
Stop Loss Hits 2.100000e+01
6. Performance Visualisation
This section visualizes the simulation results. It generates two plots:
- Equity Curve: Displays the evolution of the trading account balance over the course of the simulation.
- Per-Trade PnL Distribution: Illustrates the profit and loss percentage for each individual trade executed by the engine.
These visualizations provide a clear graphical representation of the strategy's performance and risk characteristics.
fig, axes = plt.subplots(1, 2, figsize=(14, 5))
fig.suptitle("Paper Trading Engine — Simulation Results", fontsize=13, fontweight="bold")
# ── Equity Curve ──────────────────────────────────────────────────────────
axes[0].plot(range(len(engine_state["balance_curve"])), engine_state["balance_curve"],
color="#2ecc71", linewidth=2)
axes[0].axhline(INITIAL_BALANCE, linestyle="--", color="#bdc3c7", label="Initial Balance")
axes[0].set_xlabel("Trade Number")
axes[0].set_ylabel("Balance (USDT)")
axes[0].set_title("Equity Curve")
axes[0].legend()
axes[0].grid(True, alpha=0.3)
# ── Per-Trade PnL Distribution ────────────────────────────────────────────
if engine_state["trades"]:
pnls = [t["pnl_pct"] for t in engine_state["trades"]]
colors = ["#2ecc71" if p > 0 else "#e74c3c" for p in pnls]
axes[1].bar(range(len(pnls)), pnls, color=colors, alpha=0.8, edgecolor="black", linewidth=0.3)
axes[1].axhline(0, color="#333", linewidth=1)
axes[1].set_xlabel("Trade #")
axes[1].set_ylabel("PnL (%)")
axes[1].set_title("Per-Trade PnL")
axes[1].grid(True, alpha=0.3, axis="y")
plt.tight_layout()
plt.show()