# Blind Monkeys — Self-Hosting / Deployment Guide This guide explains how to run the complete Blind Monkeys application (rising-coin scanner, Bybit grid bots, combo futures, Telegram alerts) on your own Google Cloud account with your own Bybit and Telegram credentials. No coding knowledge is required beyond copying commands. --- ## 1. What you need before starting | Service | Purpose | |---|---| | **Bybit account** | Trading (futures grid bots + combo futures) | | **Telegram account** | Alert bot + notification channels | | **Google Cloud account** | Hosting (free tier is enough to start) | | **A domain** (optional) | Nice URLs like `scan.yourdomain.com` | Estimated setup time: **30–45 minutes**. --- ## 2. Generate the Bybit API keys 1. Log in to Bybit → **API Management** (`bybit.com/en/user/api-management`) 2. Click **Create New API Key** → choose **System-generated API keys** 3. Set permissions: - ✅ **Account** → *Wallet balance*, *Account transfer* - ✅ **Trade** → *Futures* (covers grid bots and combo futures) - ❌ Do **not** enable withdrawal permissions — the app never needs them 4. IP restriction: Bybit cannot restrict to dynamic Cloud Run IPs, so most self-hosters leave it unrestricted. This is acceptable because the key has **no withdrawal rights**. If you prefer, restrict to your own home IP and only run the scanner from there. 5. Complete 2FA. Bybit shows the **API key** and **API secret** once — **save the secret immediately** (it is never shown again). 6. Fund the account: - Transfer USDT into the **Funding account** — grid bots draw from it - Keep margin in **Unified Trading** for combo futures > ⚠️ **Security rules** > - The API secret goes into a secret manager only — never into code, > config files, or chat messages. > - If a key ever leaks: delete it in Bybit and create a new one (~1 min). > - The app's trader service is IAM-locked (below) so the open internet > cannot invoke the trading endpoints directly. --- ## 3. Create the Telegram bot and channels 1. Message **@BotFather** in Telegram → `/newbot` → follow the prompts. You receive a **bot token** like `123456789:AAxxxxxxxxxxxxxxxxxxxx`. 2. Create the notification channels you want, then add your bot as an **Administrator** in each (it must be an admin to post). 3. Get each channel's ID: post one message inside the channel, then open `https://api.telegram.org/bot/getUpdates` in a browser — each channel appears with its `id` (format `-100xxxxxxxxxx`) and title. 4. Get your personal chat ID by messaging **@userinfobot** (used for admin notifications). Typical channel layout: | Channel | Events | |---|---| | Blind Monkey | daily / hourly riser scans | | Grid New | new grid bot opened | | Grid Profit | every grid profit event | | Grid Closures | TP / SL / manual closes | | Futures New | combo futures opened | | Futures Funding | funding fees paid/received | | Futures Close | futures TP / SL closures | --- ## 4. Google Cloud setup Install the `gcloud` CLI (https://cloud.google.com/sdk/docs/install), then: ```bash gcloud auth login gcloud config set project YOUR-PROJECT-ID gcloud services enable run cloudbuild.googleapis.com secretmanager.googleapis.com \ cloudscheduler.googleapis.com storage.googleapis.com ``` ### Create the secrets ```bash printf 'YOUR_BYBIT_API_KEY' | gcloud secrets create bybit-api-key --data-file=- printf 'YOUR_BYBIT_SECRET' | gcloud secrets create bybit-api-secret --data-file=- printf 'YOUR_TELEGRAM_TOKEN' | gcloud secrets create telegram-bot-token --data-file=- printf 'SOME_RANDOM_STRING' | gcloud secrets create flask-secret --data-file=- ``` --- ## 5. Deploy the services ### 5.1 Trader (IAM-restricted — only the scanner may call it) ```bash gcloud run deploy bm-trader --region europe-west1 --source trader-service \ --set-env-vars "TELEGRAM_CHAT_ID=YOUR_CHAT_ID" \ --set-secrets "BYBIT_API_KEY=bybit-api-key:latest,BYBIT_API_SECRET=bybit-api-secret:latest,TELEGRAM_BOT_TOKEN=telegram-bot-token:latest" \ --no-allow-unauthenticated ``` Note the **trader URL** that gcloud prints — you need it in the next step. ### 5.2 Scanner (public) ```bash gcloud run deploy bm-scanner --region europe-west1 --source scanner-service \ --set-env-vars "TRADER_URL=,TELEGRAM_CHAT_ID=YOUR_CHAT_ID" \ --set-secrets "TELEGRAM_BOT_TOKEN=telegram-bot-token:latest,FLASK_SECRET=flask-secret:latest" \ --allow-unauthenticated ``` ### 5.3 Scheduler jobs (automation) ```bash # Hourly rising-coin scan (runs at :15 past each hour) gcloud scheduler jobs create http hourly-scan --location europe-west1 \ --schedule "15 * * * *" --uri "/run" --http-method GET # Daily summary to Telegram gcloud scheduler jobs create http daily-summary --location europe-west1 \ --schedule "0 8 * * *" --uri "/summary" --http-method GET ``` The scanner also detects bot closures, grid-profit events, and funding fees automatically whenever the grid page is open (90-second event-check cycle). ### 5.4 Main website (optional) The main site (home page, financials, settings) deploys the same way from the `blind-monkeys/` directory: ```bash gcloud run deploy bm-site --region us-central1 --source blind-monkeys \ --set-env-vars "FLASK_ENV=production" \ --set-secrets "FLASK_SECRET=flask-secret:latest,TELEGRAM_BOT_TOKEN=telegram-bot-token:latest,TELEGRAM_CHAT_ID=YOUR_CHAT_ID" \ --allow-unauthenticated ``` --- ## 6. Custom domain (optional) ```bash gcloud beta run domain-mappings create --domain scan.yourdomain.com \ --service bm-scanner --region europe-west1 ``` Then add the **CNAME record** shown in the command output (`ghs.googlehosted.com`) to your DNS provider. Certificate provisioning starts as soon as the DNS record resolves (usually minutes). --- ## 7. Verify the installation | Check | Expected | |---|---| | Open `/healthz` | `ok` | | Open the scanner home page | Rising-coins table loads (~30–60 s first scan) | | Open `/grid` | Grid tables + balance panel load | | Balance panel shows your USDT | Funding / Unified / Grid values match Bybit | | Post a test message via the bot to a channel | Message arrives | --- ## 8. Operating notes - **Grid settings** (leverage, range, amount, TP/SL, auto-open score) are configured on the scanner's `/grid` page — admin only. - **Risk controls**: every grid bot carries a TP and SL; there is a daily investment cap; completed bots are archived (releasing funds) and tracked for win rate. - **The score-weight feedback loop** refines coin selection automatically from realized grid returns — no configuration needed. - **Costs**: two Cloud Run services on the free tier plus a few scheduler jobs ≈ $0–2/month. Cloud Build minutes are free up to the daily quota. --- ## 9. Troubleshooting | Symptom | Fix | |---|---| | Balance shows $0 | Check the API key has *Wallet balance* permission; check USDT is in the Funding account | | Telegram silent | Bot must be an **admin** of each channel; check channel IDs via `getUpdates` | | 403 on trader URLs | Expected — the trader is IAM-internal; only the scanner (with OIDC) may call it | | Grid page stuck on "Loading…" | Bybit API latency — allow ~10 s; check the trader logs: `gcloud run services logs read bm-trader --region europe-west1 --limit 50` | | Certificate pending on custom domain | DNS CNAME not propagated yet — wait, then re-check |