# Trading212 "Touch & Turn" Scalping Bot This project implements the "Touch & Turn" scalping strategy (Opening Range Liquidity Reversal) in Python for the Trading212 API. It is specifically designed to trade US Equities at the 09:30 EST market open. ## ⚠️ Disclaimer **This software is for educational purposes only.** Trading in financial markets involves a high degree of risk. Always use the practice/demo environment (`demo.trading212.com`) to test strategies before using real money. --- ## Strategy Overview The strategy capitalizes on the initial liquidity and volatility of the US market open. 1. **The Setup:** Captures the high and low of the first 15-minute candle (09:30 - 09:45 EST). 2. **The Filter:** The range of this opening candle must be at least **25%** of the stock's 14-day Average True Range (ATR). 3. **The Trigger (ISA Optimized):** - **LONG (Bearish candle):** Bot places an immediate **Market BUY** order for the stock. - **SHORT (Bullish candle):** Since standard shorting is restricted in UK ISAs, the bot automatically substitutes this with a **Market BUY** order for a **3x Inverse ETP** (e.g., buying `3SLA` if `TSLA` gives a short signal). 4. **The Targets:** - Brackets are placed **immediately** after the market order is filled, using the **Actual Fill Price** from your portfolio. - **Take Profit (TP):** The 38.2% Fibonacci retracement level. - **Stop Loss (SL):** Placed to ensure a Risk:Reward ratio of 1:2. 5. **Time Exit:** All open positions are forcefully closed via Market Order at **11:00 EST**. --- ## Installation & Setup 1. **Clone the repository and set up a virtual environment:** ```bash python3 -m venv venv source venv/bin/activate pip install -r requirements.txt ``` 2. **Configure Environment Variables:** Create a `.env` file in the root directory: ```ini TRADING212_API_KEY_ID=your_key_id_here TRADING212_API_KEY=your_api_key_here TRADING212_BASE_URL=https://demo.trading212.com/api/v0/ ISA_MODE=True ``` --- ## Risk Management & Position Sizing The bot uses dynamic **Risk-Based Position Sizing** to ensure consistent exposure. - **5% Risk Rule:** By default, the bot risks **5% of your account balance** per trade. - **Virtual Balance simulation:** If you are testing on a demo account with a large balance (e.g., £5,000) but plan to trade live with £250, the bot can maintain perspective. It automatically calculates a "Virtual Balance" by subtracting £4,750 from your actual total, ensuring your risk amount is exactly what it will be in the real world. (e.g. £12.50 risk on a £250 virtual balance). - **Leverage Adjusted:** For Inverse ETPs (3x leverage), the bot adjusts the quantity and bracket percentages to ensure the monetary risk remains identical to a standard 1x stock trade. --- ## Automation Workflow The bot is designed to be triggered once per day (e.g., via a **systemd timer** or cron) at exactly **09:30 EST**. 1. **Scan:** Runs the ISA candidate filter to find the most volatile US stocks. 2. **Backtest:** Runs a 60-day historical backtest on the top 10 candidates. 3. **Select:** Picks the **Top 3** tickers that showed a positive historical return (Net PnL > 0 R). 4. **Execute:** Spawns parallel threads to monitor and trade the selected assets. 5. **Clean:** Shuts down automatically after the 11:00 EST exit and cleanup. --- ## Monitoring - **Logs:** All activity is recorded in `logs/bot_YYYY-MM-DD.log`. - **PnL Tracking:** A permanent ledger of every trade (including ETP substitutions) is kept in `pnl_tracking.csv` for graphing and analysis. ## Architecture * **`src/api/client.py`:** REST API wrapper with Basic Auth. * **`src/strategy/touch_turn.py`:** Logic engine and Fibonacci calculator. * **`src/strategy/inverse_mapping.py`:** Map of US stocks to 3x Short Inverse ETPs. * **`src/execution/manager.py`:** Handles market entries, actual fill-based bracketing, and ISA substitutions. * **`main.py`:** The morning orchestrator.