# trade1 — bot core + separate rule files

Created 2026-09-26 from `screener/trade`. The core has **no entry or exit
strategy**. Every buy/sell decision comes from these three files:

| File | Job | Now |
|---|---|---|
| `breakout_rules.py` | when to buy a breakout | empty (never buys) |
| `reversal_rules.py` | when to buy a reversal | empty (never buys) |
| `exit_rules.py` | when to sell an open position | empty (always holds) |

`rules_api.py` is the contract: what the core gives a rule
(`MarketView`: price, 1-min bars, 5-s bars, quote, buy/sell imbalance,
levels, scanner data, slots free, last trade...) and what it expects back
(`EntryDecision` / `ExitDecision`).

## Core files (don't need touching for strategy work)

`monitor.py` (daily loop, calls the rule files), `stream.py` (live data),
`scanner.py` / `universe.py` / `symbol_filters.py` (9:28 scan + rescans),
`position_manager.py` (orders, 1% risk sizing, 19% notional cap),
`alpaca_client.py`, `data_store.py`, `config_loader.py`, `logger_setup.py`,
`market_time.py`, `indicators.py`, `volatility.py`, `run_scanner.py`.

## What the core still does on its own

- scans at 9:28 and rescans (scanner.* settings)
- max 5 positions, position sizing
- sells everything at 15:55 (end of day)
- safety net: if `exit_rules.py` fails to load or crashes, sells a position
  only when price falls to its entry stop
- a crashing rule file is logged and skipped; it can't stop the bot

## config.json

- `rules.entry_modules`: which entry files, in order (first BUY wins)
- `rules.exit_module`: the exit file
- `rules.hot_reload`: `true` = an edited rule file is reloaded while
  the bot runs (no restart, so no liquidation)
- each rule file's own settings go in a section with its name
  (`breakout_rules`, `reversal_rules`, `exit_rules`), passed in as `view.cfg`

## Warning

Uses the **same Alpaca paper account** as `screener/trade`. Never run the
two bots at the same time. There is no cron entry for this bot.
The previous contents of this folder (the August bot) are archived at
`/root/backups/trade1_old_2026-09-26.tar.gz`.

## Simulator (simulate.py)

Replays saved trade-by-trade data through the **real** `monitor.py` code
with a replay clock and a simulated broker, so it tests exactly what would
trade live — same rule files, same sizing, same 5 slots, same 15:55 exit.

    python3 simulate.py --days all                    # all 21 saved days (8/27-9/25), ~1 hour
    python3 simulate.py --date 2026-09-22             # one day, ~3 min
    python3 simulate.py --days all --entry breakout_rules --exit exit_rules
    python3 simulate.py --days all --rules-dir /path --entry my_variant   # try a copy without touching the real files

Stock lists: `sim/candidates/<date>.json`. Tick data: `simulator.cache_dir`
(shared with screener/trade). Results: `data/simulations/<name>.json`, rule
decisions per day in `data/simulations/<name>/`, log in `logs/sim_*.log`.
Simplifications: fills at last trade price, fixed equity, no rescans.
