# Hugging Face Spaces — Initial Setup Guide (CRE v1.0) Step-by-step to deploy and operate CRE on Hugging Face. Do these in order. ## 1. Create the Space 1. Go to **huggingface.co → your profile → New → Space**. 2. **Owner:** your account (or an org). 3. **Space name:** e.g. `confluence-reversal-engine` (this becomes the URL slug: `huggingface.co/spaces//confluence-reversal-engine`). 4. **License:** MIT (matches the README front-matter). 5. **SDK:** select **Gradio**. 6. **Hardware:** `CPU basic` is enough (CRE is I/O-bound, not compute-bound). 7. **Visibility:** Public or Private — your call. Private still runs the workers. 8. Click **Create Space**. ## 2. Upload the project files Either drag-drop in the Space's **Files** tab, or push via git: ``` git clone https://huggingface.co/spaces//confluence-reversal-engine # copy all files from this build into the clone, then: git add . && git commit -m "CRE v1.0" && git push ``` Required files (all in this build): `README.md`, `requirements.txt`, `app.py`, `config.py`, `workers.py`, `engine/`, `exchange/`, `store/`, `alerts/`, `ui/`. > The YAML block at the top of `README.md` configures the Space — do not edit it > (there's a tamper-protection note right below it). ## 3. Persistence — HF Storage Bucket (recommended) CRE keeps its database on a **Storage Bucket** so state survives restart/sleep: on boot it restores the DB from the bucket; it then syncs back periodically and on shutdown. After a reboot the dashboard reloads the last state and continues — open trades and full history are recalled. > **Why not mount the bucket and put SQLite on it directly?** Object storage doesn't > safely support SQLite's file locking under constant writes (corruption risk). CRE > instead runs SQLite on the Space's fast local disk and snapshots it to the bucket > (restore-on-boot + periodic + on-shutdown sync) — robust and the same pattern HF's > own tools use. The DB is only megabytes, so bucket cost is minimal. **Setup:** 1. Create a bucket at **huggingface.co/new-bucket** (set it **private**). Note its id as `owner/bucket-name`. 2. Create a write token: **Settings → Access Tokens → New token** (role: *Write*). 3. In the Space, add: - **Secret** `HF_TOKEN` = the write token. - **Variable** `CRE_BUCKET` = `owner/bucket-name`. 4. That's it — CRE auto-restores on boot and syncs thereafter. **No bucket?** CRE still runs fully with ephemeral `DB_PATH=./cre.db`; history just resets on restart. Fine for evaluation, not for a long-running track record. ## 4. Secrets & Variables Space → **Settings → Variables and secrets**. **Secrets** (encrypted — use for tokens): | Name | Value | |------|-------| | `TELEGRAM_BOT_TOKEN` | from @BotFather (see step 5) | | `TELEGRAM_CHAT_ID` | your chat/channel id (see step 5) | | `COINGLASS_API_KEY` | *(optional)* Coinglass key for cross-exchange enrichment | **Variables** (plain — non-secret config): | Name | Suggested value | Purpose | |------|-----------------|---------| | `DB_PATH` | `/data/cre.db` (or leave unset) | persist DB (requires step 3) | | `TV_EXCHANGE` | `BYBIT` | where the per-signal TV link points (`BYBIT`/`BINANCE`/`MEXC`/`OKX`) | | `WATCHLIST` | *(leave unset for the dynamic whole-market scan)* | pin a fixed comma-separated list | | `UNIVERSE_MAX` | `80` | max coins kept after the liquidity funnel | | `UNIVERSE_MIN_TURNOVER_USD` | `20000000` | min 24h USD turnover to qualify | | `POLL_INTERVAL_SEC` | `60` | market poll cadence | > **Data source:** OKX (public, no key) is built in — no `EXCHANGE` variable needed. > Binance/Bybit are geo-blocked on free hosts and were removed; `TV_EXCHANGE` above > only controls where the *chart link* sends you, not where data comes from. ## 5. Telegram bot (for alerts) 1. In Telegram, message **@BotFather → `/newbot`**, follow prompts → copy the **bot token** → put it in `TELEGRAM_BOT_TOKEN`. 2. Create a channel/group, add your bot as an admin (or just DM the bot once). 3. Get the chat id: message the bot, then open `https://api.telegram.org/bot/getUpdates` and read `chat.id` → put it in `TELEGRAM_CHAT_ID`. 4. Alerts are optional — without these two, CRE still runs and logs; it just won't push (dashboard still shows everything). ## 6. First boot & verification 1. After upload + secrets, the Space builds automatically (watch the **Logs** tab). 2. On success you'll see the Gradio dashboard. Check **Tab 4 — Settings & Health**: - websocket: connected - per-symbol last poll times advancing - liquidation baseline coverage starting to climb (0 → 7 days over the first week) 3. Cold start is normal: for the first ~7 days the engine is **WATCH-only** until each symbol has enough self-collected liquidation history (spec §15.3). ## 7. Keeping it awake (free tier) Free Spaces sleep after ~48h of no UI traffic; a sleeping Space can't poll or alert. Options: upgrade to persistent hardware, or accept monitoring gaps (CRE catches up on wake and marks gap buckets incomplete so baselines stay clean).