Files
maxbot/config.py
T

181 lines
8.4 KiB
Python
Raw Normal View History

2026-05-27 07:02:58 +01:00
"""
config.py — All bot settings in one place.
==========================================
This is the ONLY file you need to edit for day-to-day configuration.
All other files import from here.
STRATEGY SUMMARY:
-----------------
This bot trades TSLA CFDs on Capital.com using a grid/mean-reversion strategy.
It places limit buy orders at regular intervals BELOW the current price.
Each order has a take profit set to generate a fixed GBP profit.
As equity grows, the grid tightens (more orders = more frequent fills = more profit).
SURVIVAL RULE:
--------------
The bot simulates a full 60% drop from the highest open position to check
whether the account would survive (margin level stays above 50%).
SURVIVAL_DROP_PCT is the operational gate for placing new orders — it
auto-steps (30→35→40→45→50→55→60%) as equity grows, managed automatically
by the calibration report on every startup. Do not edit it manually.
2026-05-27 07:02:58 +01:00
SIZE RULE:
----------
0.2 shares for all orders (more profit per fill, faster recovery at lower prices).
0.1 shares only within top 5% of highest open price (expensive to hold overnight).
threshold = highest_open * 0.95
PROFIT TARGETS:
---------------
0.2 shares → £1.00 profit per position (same price travel as 0.1)
0.1 shares → £0.50 profit per position (half size = half profit, same distance)
Take profit distance = profit_gbp * gbpusd / size
QUEUE MANAGEMENT:
-----------------
Bot maintains exactly QUEUE_DEPTH pending orders covering the grid window.
Window = from just below lowest open position down to survival floor.
On each loop, bot scans for gaps in the grid and fills them.
It does NOT just add to the bottom — it fills gaps anywhere in the window.
MARGIN STAGES (Capital.com UK retail):
---------------------------------------
> 100% → Normal operation
= 100% → Warning 1: bot stops placing new orders
= 75% → Warning 2: urgent alert
= 50% → Auto closeout: Capital.com closes positions automatically
MODES:
------
dryrun → connects, reads everything, prints what it would do. ZERO actions.
confirm → asks y/n before every single action. Start here.
live → fully autonomous. Only use after confirming behaviour in other modes.
"""
import os
# ─────────────────────────────────────────────
# CREDENTIALS
# Set these as environment variables, not hardcoded.
# export CAPITAL_API_KEY="your_key"
# export CAPITAL_IDENTIFIER="your@email.com"
# export CAPITAL_PASSWORD="your_password"
# ─────────────────────────────────────────────
API_KEY = os.environ.get("CAPITAL_API_KEY", "YOUR_API_KEY_HERE")
IDENTIFIER = os.environ.get("CAPITAL_IDENTIFIER", "your@email.com")
PASSWORD = os.environ.get("CAPITAL_PASSWORD", "YOUR_PASSWORD_HERE")
# ─────────────────────────────────────────────
# API ENDPOINTS
# ─────────────────────────────────────────────
BASE_URL = "https://api-capital.backend-capital.com"
DEMO_URL = "https://demo-api-capital.backend-capital.com"
USE_DEMO = False # Set True to point at demo account for testing
# ─────────────────────────────────────────────
# INSTRUMENT
# ─────────────────────────────────────────────
EPIC = "TSLA" # Capital.com epic for Tesla Inc CFD
# ─────────────────────────────────────────────
# GRID STRATEGY
# ─────────────────────────────────────────────
# % spacing between grid levels. Tightens automatically as equity grows.
# At 1.5%: $414.99 → $408.77 → $402.63 → $396.59 etc.
BASE_SPACING_PCT = 1.5
# Number of pending orders to maintain in the grid window at all times.
# Grows with equity — see QUEUE_TIERS below.
QUEUE_DEPTH = 10
# Bot will not place orders if simulated X% drop from highest open position
# would result in margin closeout. Increase this as equity grows.
# Current safe value for £640 equity = 30%. Target = 60%.
SURVIVAL_DROP_PCT = 35.0
2026-05-27 07:02:58 +01:00
# Capital.com retail margin rate for shares CFDs (5:1 leverage = 20% margin)
MARGIN_RATE = 0.20
# Stop placing NEW orders if current margin level drops below this %.
# Capital.com warning stage 1 = 100%. We stop here before it gets worse.
MARGIN_STOP_PCT = 100.0
# Alert and pause if price moves more than this % between loops.
# Protects against gap-down opens (e.g. Monday open after weekend news).
GAP_ALERT_PCT = 20.0
# Size threshold: orders within top 5% of highest open price use 0.1 shares.
# Everything else uses 0.2 shares.
# Example: highest open = $450 → threshold = $427.50 → above = 0.1, below = 0.2
SIZE_SMALL_THRESHOLD_PCT = 0.95 # top 5% = 0.1 shares
# ─────────────────────────────────────────────
# PROFIT TARGETS (GBP)
# ─────────────────────────────────────────────
TP_PROFIT_LARGE = 1.00 # £1.00 target for 0.2 share positions
TP_PROFIT_SMALL = 0.50 # £0.50 target for 0.1 share positions
# Both use the same price travel distance. 0.1 shares just earns half as much.
# ─────────────────────────────────────────────
# GBP/USD
# ─────────────────────────────────────────────
# Bot fetches live GBP/USD rate each loop. Falls back to this if fetch fails.
GBPUSD_FALLBACK = 1.27
# ─────────────────────────────────────────────
# EQUITY GROWTH TIERS
# IMPORTANT — ORDER OF OPERATIONS:
# 1. Survival check first (always)
# 2. Spacing tightens second (more frequent fills)
# 3. Queue depth increases third (only after spacing already tightened)
# Never both spacing and depth upgrade in the same calibration run.
#
# Each tier upgrade is SURVIVAL-GATED:
# Before applying an upgrade, the full grid is simulated at the new
# settings. Only if survival check still passes does the upgrade apply.
# ─────────────────────────────────────────────
# Grid spacing tightens with equity.
# Each tier is only applied if survival check passes at new spacing.
# Spacing must tighten BEFORE queue depth can increase.
SPACING_TIERS = [
(600, 1.5), # base — current
(800, 1.2), # tightens at £800 IF survival passes
(1100, 1.0), # tightens at £1100 IF survival passes
(1500, 0.8), # tightens at £1500 IF survival passes
]
# Queue depth increases with equity.
# Each tier is only applied if:
# a) Spacing has already tightened to the corresponding level
# b) Survival check passes at new depth
# Depth at tier N requires spacing to be at tier N-1 already.
QUEUE_TIERS = [
(600, 10, 1.5), # 10 orders at 1.5% spacing — base
(900, 12, 1.2), # 12 orders — requires spacing already at 1.2%
(1200, 15, 1.0), # 15 orders — requires spacing already at 1.0%
(1500, 18, 0.8), # 18 orders — requires spacing already at 0.8%
]
# Queue tier format: (equity_threshold, depth, required_spacing)
# ─────────────────────────────────────────────
# DEPOSITS
# Set your planned weekly deposit amount here.
# Used by calibration report for milestone projections.
# Set to 0 if not making regular deposits.
# ─────────────────────────────────────────────
WEEKLY_DEPOSIT_GBP = 0.0 # £ per week — update when you start depositing
# Capital.com session tokens expire after 10 minutes. Refresh at 9 minutes.
SESSION_REFRESH_SECS = 540
# How often the main monitoring loop runs.
LOOP_INTERVAL_SECS = 60