"""
=============================================================================
TRADING BOT SETTINGS
=============================================================================
Edit this file to configure your trading bot before running backtests
or live trading. All parameters are organized by category.
=============================================================================
"""

# =============================================================================
# TRADING PAIR
# =============================================================================
SYMBOL = "BTCUSD"                     # Trading pair (BTCUSD, BTCUSDT, etc.)


# =============================================================================
# ACCOUNT & RISK MANAGEMENT
# =============================================================================
INITIAL_BALANCE = 10000.0             # Starting balance for backtesting
RISK_PERCENT = 1.5                    # Percentage of balance to risk per trade
                                      # Higher = larger positions, more risk
                                      # 1% = conservative, 5% = moderate, 10% = aggressive

# =============================================================================
# STRATEGY PARAMETERS
# =============================================================================
BASE_MULTIPLIER = 4.0                 # Multiplier for TP/Entry distance based on spread
                                      # Higher = wider TP, fewer trades, more profit per trade
                                      # Lower = tighter TP, more trades, less profit per trade
                                      # Doubled from 2.0 to offset commission impact

AGGRESSION_LEVEL = 50                 # Lot size increase % per averaging level
                                      # Formula: lot_size(n) = base_lot * (1 + AGGRESSION/100)^n
                                      # 10 = 10% increase per level (conservative)
                                      # 20 = 20% increase per level (moderate)
                                      # 50 = 50% increase per level (aggressive martingale)

FIRST_DISTANCE_MULTIPLIER = 1.0       # Multiplier for first averaging distance
                                      # 1.0 = standard Fibonacci spacing
                                      # 1.5 = wider spacing (more conservative)
                                      # 0.5 = tighter spacing (more aggressive)

# =============================================================================
# BIDIRECTIONAL TRADING (Grid Style)
# =============================================================================
ENABLE_LONGS = True                   # Enable BUY positions (average DOWN on drops)
ENABLE_SHORTS = False                 # Enable SELL positions (average UP on rises)

GRID_SPACING = 500.0                  # Minimum distance between main orders ($)
                                      # Prevents clustering of threads at similar prices
                                      # $500 = new thread only if price moved $500+ from last

MAX_CONCURRENT_THREADS = 1            # Maximum threads running at same time
                                      # Higher = more capital used, more opportunities
                                      # Lower = less risk, fewer trades

# =============================================================================
# INDIVIDUAL TP MODE (Per-Position Take Profit)
# =============================================================================
INDIVIDUAL_TP_ENABLED = False         # True = each position has its own TP
                                      # False = unified TP for all positions (original)

INDIVIDUAL_TP_DISTANCE = 300.0        # TP distance from entry for each position ($)

# =============================================================================
# DRAWDOWN HEDGE (Anti-Martingale Lock)
# =============================================================================
HEDGE_ENABLED = False                 # Enable hedging when drawdown gets deep
HEDGE_TRIGGER_LEVEL = 5               # Open hedge when averaging reaches this level
                                      # Lower = earlier protection, more hedge trades
                                      # Higher = later protection, fewer hedges

HEDGE_CLOSE_PROFIT = 150.0            # Close hedge when it profits this much ($)
                                      # Higher = hold hedge longer for bigger profit

HEDGE_LOT_PERCENT = 50                # Hedge size as % of total main lots
                                      # 100 = full hedge, 50 = half hedge
                                      # BUY: TP = entry + distance
                                      # SELL: TP = entry - distance

# =============================================================================
# CUSTOM MARTINGALE LEVELS (Optional - from CustomMartingaleEA)
# =============================================================================
# Set to None to use Fibonacci distances, or provide custom values:
# Example: [1.3, 2.1, 3.4, 5.5, 8.9] = levels at 1.3x, 2.1x, 3.4x base distance
# =============================================================================
# MARTINGALE GRID CONFIGURATION (Based on UniqueMartingaleEA style)
# =============================================================================
# Fixed dollar distances from entry (similar to pip-based in forex)
# For BTC ~$100k: $100 ≈ 10 pips equivalent
CUSTOM_LEVELS = [
    0.5, 0.8, 1.3, 2.2, 3.7,          # Levels 1-5: Based on EA's 50,80,130,220,370 pips
    5.5, 8.0, 12.0, 18.0, 27.0,       # Levels 6-10: Extended
    40.0, 60.0, 90.0, 135.0, 200.0,   # Levels 11-15: Deep levels
    300.0, 450.0, 675.0, 1000.0, 1500.0  # Levels 16-20: Very deep recovery levels
]
                                      # Distance multipliers (multiply by base_distance)
                                      # e.g., base=$200, level 5 = $200 * 3.7 = $740 from entry

# CUMULATIVE multipliers (each level multiplies previous)
# Graduated approach: aggressive early, conservative deep
# This helps recover without explosive lot sizes at deep levels
CUSTOM_MULTIPLIERS = [
    1.5, 1.5, 1.5, 1.5, 1.5,          # Levels 1-5: 1.5x cumulative (up to 7.6x)
    1.5, 1.5, 1.5, 1.5, 1.5,          # Levels 6-10: 1.5x cumulative (up to 57.7x)
    1.4, 1.4, 1.4, 1.4, 1.4,          # Levels 11-15: 1.4x cumulative (slower growth)
    1.3, 1.3, 1.3, 1.3, 1.3           # Levels 16-20: 1.3x cumulative (conservative deep)
]
                                      # CUMULATIVE lot multipliers
                                      # Level N lot = base_lot * mult[0] * mult[1] * ... * mult[N]

# Use cumulative multiplication like the EA (True) or direct (False)
USE_CUMULATIVE_MULTIPLIERS = True

# Spread safety (from CustomMartingaleEA)
MAX_SPREAD = 100.0                    # Maximum allowed spread in dollars
                                      # Don't open new positions when spread > this


# =============================================================================
# AVERAGING CONFIGURATION
# =============================================================================
MAX_AVERAGING_LEVELS = 50             # Maximum averaging levels allowed
                                      # Set high for unlimited (golden ratio extends)
                                      # Set lower to cap exposure

# TP CASCADE (Re-entry behavior)
REENTRY_ENABLED = True                # Enable re-entry after averaging TP hit
                                      # True = reopen averaging orders when price returns
                                      # False = close and move on

TP_TOLERANCE_PIPS = 0.5               # Tolerance for price return detection (in pips)
                                      # Used for re-entry trigger detection


# =============================================================================
# LOT SIZE CONSTRAINTS
# =============================================================================
MIN_LOT_SIZE = 0.001                  # Minimum lot size per order
MAX_LOT_SIZE = 10.0                   # Maximum lot size per order
LOT_STEP = 0.001                      # Lot size increment/precision


# =============================================================================
# EXECUTION COSTS
# =============================================================================
COMMISSION_PERCENT = 0.05             # Commission per trade (percentage)
                                      # Binance Spot: 0.1% (0.075% with BNB)
                                      # Binance Futures: 0.02% maker, 0.05% taker
                                      # Using 0.05% (futures taker) for accurate backtesting

SLIPPAGE_PIPS = 0                     # Simulated slippage in pips
                                      # 0 = no slippage (ideal conditions)
                                      # 1-2 = realistic for liquid pairs


# =============================================================================
# BACKTESTING DATA
# =============================================================================
# Sample data generation (when no CSV/JSON provided)
SAMPLE_DATA_CANDLES = 5000            # Number of candles to generate
SAMPLE_START_PRICE = 50000.0          # Starting price for generated data
SAMPLE_VOLATILITY = 0.015             # Price volatility (0.01 = 1% std dev per candle)
                                      # 0.01 = low volatility
                                      # 0.02 = medium volatility
                                      # 0.05 = high volatility

# Data file paths (set to load your own data)
DATA_FILE_CSV = ""                    # Path to CSV file (leave empty to use generated data)
DATA_FILE_JSON = ""                   # Path to JSON file (leave empty to use generated data)

# CSV column mapping (customize if your CSV has different column names)
CSV_TIMESTAMP_COL = "timestamp"
CSV_OPEN_COL = "open"
CSV_HIGH_COL = "high"
CSV_LOW_COL = "low"
CSV_CLOSE_COL = "close"
CSV_VOLUME_COL = "volume"


# =============================================================================
# BACKTEST OPTIONS
# =============================================================================
USE_TICK_DATA = False                 # Generate ticks from candles for more precision
                                      # True = slower but more accurate
                                      # False = faster, candle-based simulation

TICKS_PER_CANDLE = 4                  # Ticks to generate per candle (if USE_TICK_DATA=True)
                                      # 4 = OHLC pattern
                                      # 10+ = smoother price action

# =============================================================================
# TICK DATA SETTINGS (for tick_backtest.py)
# =============================================================================
TICK_DATA_FILE = "BTCUSD (2).csv"     # Path to tick data CSV file
TICK_MAX_ROWS = None                  # Max ticks to load (None for all, start small for testing)
TICK_SKIP_ROWS = 0                    # Skip first N rows
TICK_REPORT_INTERVAL = 10000          # Print status every N ticks


# =============================================================================
# LIVE TRADING
# =============================================================================
EXCHANGE = "simulated"                # Exchange: "simulated", "binance" (future)
TESTNET = True                        # Use testnet/sandbox mode

POLL_INTERVAL = 1.0                   # Seconds between price checks (live trading)
                                      # 1.0 = check every second
                                      # 0.5 = check twice per second


# =============================================================================
# LOGGING
# =============================================================================
LOG_LEVEL = "INFO"                    # Logging level: DEBUG, INFO, WARNING, ERROR
LOG_FILE = "trading_bot.log"          # Log file name
LOG_TO_CONSOLE = True                 # Print logs to console
LOG_TO_FILE = True                    # Save logs to file
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"     # Timestamp format for logs


# =============================================================================
# MAGIC NUMBER (Thread ID Generation)
# =============================================================================
BASE_MAGIC = 100000                   # Base magic number for thread identification
                                      # Each thread gets a unique magic derived from this


# =============================================================================
# CRYPTO PAIR SPECIFICATIONS
# =============================================================================
# You can add or modify pairs here
# Format: "SYMBOL": {"pip_size", "min_lot", "max_lot", "lot_step", "decimals"}

CRYPTO_PAIRS = {
    "BTCUSD": {
        "pip_size": 0.1,              # Minimum price movement (for $100k BTC)
        "min_lot": 0.001,             # Minimum order size
        "max_lot": 100.0,             # Maximum order size
        "lot_step": 0.001,            # Order size precision
        "decimals": 1                 # Price decimal places
    },
    "BTCUSDT": {
        "pip_size": 0.01,             # Minimum price movement
        "min_lot": 0.001,             # Minimum order size
        "max_lot": 100.0,             # Maximum order size
        "lot_step": 0.001,            # Order size precision
        "decimals": 2                 # Price decimal places
    },
    "ETHUSDT": {
        "pip_size": 0.01,
        "min_lot": 0.01,
        "max_lot": 1000.0,
        "lot_step": 0.01,
        "decimals": 2
    },
    "BNBUSDT": {
        "pip_size": 0.01,
        "min_lot": 0.01,
        "max_lot": 10000.0,
        "lot_step": 0.01,
        "decimals": 2
    },
    "XRPUSDT": {
        "pip_size": 0.0001,
        "min_lot": 1.0,
        "max_lot": 1000000.0,
        "lot_step": 1.0,
        "decimals": 4
    },
    "SOLUSDT": {
        "pip_size": 0.01,
        "min_lot": 0.1,
        "max_lot": 100000.0,
        "lot_step": 0.1,
        "decimals": 2
    },
    "DOGEUSDT": {
        "pip_size": 0.00001,
        "min_lot": 1.0,
        "max_lot": 10000000.0,
        "lot_step": 1.0,
        "decimals": 5
    }
}

# Default config for pairs not listed above
DEFAULT_PAIR_CONFIG = {
    "pip_size": 0.01,
    "min_lot": 0.001,
    "max_lot": 100.0,
    "lot_step": 0.001,
    "decimals": 2
}


# =============================================================================
# QUICK PRESETS
# =============================================================================
# Uncomment one of these blocks to quickly apply a preset strategy

# --- CONSERVATIVE PRESET ---
# RISK_PERCENT = 0.5
# AGGRESSION_LEVEL = 5
# BASE_MULTIPLIER = 3.0
# FIRST_DISTANCE_MULTIPLIER = 1.5

# --- BALANCED PRESET ---
# RISK_PERCENT = 1.0
# AGGRESSION_LEVEL = 10
# BASE_MULTIPLIER = 2.0
# FIRST_DISTANCE_MULTIPLIER = 1.0

# --- AGGRESSIVE PRESET ---
# RISK_PERCENT = 2.0
# AGGRESSION_LEVEL = 20
# BASE_MULTIPLIER = 1.5
# FIRST_DISTANCE_MULTIPLIER = 0.8


# =============================================================================
# END OF SETTINGS
# =============================================================================
