deanpowers commited on
Commit
a339418
Β·
1 Parent(s): 1db0bad

docs: add DEPLOY.md self-hosting guide (Bybit keys, Telegram, GCP deploy)

Browse files
Files changed (1) hide show
  1. DEPLOY.md +196 -0
DEPLOY.md ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Blind Monkeys β€” Self-Hosting / Deployment Guide
2
+
3
+ This guide explains how to run the complete Blind Monkeys application
4
+ (rising-coin scanner, Bybit grid bots, combo futures, Telegram alerts)
5
+ on your own Google Cloud account with your own Bybit and Telegram
6
+ credentials. No coding knowledge is required beyond copying commands.
7
+
8
+ ---
9
+
10
+ ## 1. What you need before starting
11
+
12
+ | Service | Purpose |
13
+ |---|---|
14
+ | **Bybit account** | Trading (futures grid bots + combo futures) |
15
+ | **Telegram account** | Alert bot + notification channels |
16
+ | **Google Cloud account** | Hosting (free tier is enough to start) |
17
+ | **A domain** (optional) | Nice URLs like `scan.yourdomain.com` |
18
+
19
+ Estimated setup time: **30–45 minutes**.
20
+
21
+ ---
22
+
23
+ ## 2. Generate the Bybit API keys
24
+
25
+ 1. Log in to Bybit β†’ **API Management** (`bybit.com/en/user/api-management`)
26
+ 2. Click **Create New API Key** β†’ choose **System-generated API keys**
27
+ 3. Set permissions:
28
+ - βœ… **Account** β†’ *Wallet balance*, *Account transfer*
29
+ - βœ… **Trade** β†’ *Futures* (covers grid bots and combo futures)
30
+ - ❌ Do **not** enable withdrawal permissions β€” the app never needs them
31
+ 4. IP restriction: Bybit cannot restrict to dynamic Cloud Run IPs, so most
32
+ self-hosters leave it unrestricted. This is acceptable because the key
33
+ has **no withdrawal rights**. If you prefer, restrict to your own home
34
+ IP and only run the scanner from there.
35
+ 5. Complete 2FA. Bybit shows the **API key** and **API secret** once β€”
36
+ **save the secret immediately** (it is never shown again).
37
+ 6. Fund the account:
38
+ - Transfer USDT into the **Funding account** β€” grid bots draw from it
39
+ - Keep margin in **Unified Trading** for combo futures
40
+
41
+ > ⚠️ **Security rules**
42
+ > - The API secret goes into a secret manager only β€” never into code,
43
+ > config files, or chat messages.
44
+ > - If a key ever leaks: delete it in Bybit and create a new one (~1 min).
45
+ > - The app's trader service is IAM-locked (below) so the open internet
46
+ > cannot invoke the trading endpoints directly.
47
+
48
+ ---
49
+
50
+ ## 3. Create the Telegram bot and channels
51
+
52
+ 1. Message **@BotFather** in Telegram β†’ `/newbot` β†’ follow the prompts.
53
+ You receive a **bot token** like `123456789:AAxxxxxxxxxxxxxxxxxxxx`.
54
+ 2. Create the notification channels you want, then add your bot as an
55
+ **Administrator** in each (it must be an admin to post).
56
+ 3. Get each channel's ID: post one message inside the channel, then open
57
+ `https://api.telegram.org/bot<TOKEN>/getUpdates` in a browser β€” each
58
+ channel appears with its `id` (format `-100xxxxxxxxxx`) and title.
59
+ 4. Get your personal chat ID by messaging **@userinfobot** (used for
60
+ admin notifications).
61
+
62
+ Typical channel layout:
63
+
64
+ | Channel | Events |
65
+ |---|---|
66
+ | Blind Monkey | daily / hourly riser scans |
67
+ | Grid New | new grid bot opened |
68
+ | Grid Profit | every grid profit event |
69
+ | Grid Closures | TP / SL / manual closes |
70
+ | Futures New | combo futures opened |
71
+ | Futures Funding | funding fees paid/received |
72
+ | Futures Close | futures TP / SL closures |
73
+
74
+ ---
75
+
76
+ ## 4. Google Cloud setup
77
+
78
+ Install the `gcloud` CLI (https://cloud.google.com/sdk/docs/install), then:
79
+
80
+ ```bash
81
+ gcloud auth login
82
+ gcloud config set project YOUR-PROJECT-ID
83
+ gcloud services enable run cloudbuild.googleapis.com secretmanager.googleapis.com \
84
+ cloudscheduler.googleapis.com storage.googleapis.com
85
+ ```
86
+
87
+ ### Create the secrets
88
+
89
+ ```bash
90
+ printf 'YOUR_BYBIT_API_KEY' | gcloud secrets create bybit-api-key --data-file=-
91
+ printf 'YOUR_BYBIT_SECRET' | gcloud secrets create bybit-api-secret --data-file=-
92
+ printf 'YOUR_TELEGRAM_TOKEN' | gcloud secrets create telegram-bot-token --data-file=-
93
+ printf 'SOME_RANDOM_STRING' | gcloud secrets create flask-secret --data-file=-
94
+ ```
95
+
96
+ ---
97
+
98
+ ## 5. Deploy the services
99
+
100
+ ### 5.1 Trader (IAM-restricted β€” only the scanner may call it)
101
+
102
+ ```bash
103
+ gcloud run deploy bm-trader --region europe-west1 --source trader-service \
104
+ --set-env-vars "TELEGRAM_CHAT_ID=YOUR_CHAT_ID" \
105
+ --set-secrets "BYBIT_API_KEY=bybit-api-key:latest,BYBIT_API_SECRET=bybit-api-secret:latest,TELEGRAM_BOT_TOKEN=telegram-bot-token:latest" \
106
+ --no-allow-unauthenticated
107
+ ```
108
+
109
+ Note the **trader URL** that gcloud prints β€” you need it in the next step.
110
+
111
+ ### 5.2 Scanner (public)
112
+
113
+ ```bash
114
+ gcloud run deploy bm-scanner --region europe-west1 --source scanner-service \
115
+ --set-env-vars "TRADER_URL=<TRADER_URL_FROM_STEP_5.1>,TELEGRAM_CHAT_ID=YOUR_CHAT_ID" \
116
+ --set-secrets "TELEGRAM_BOT_TOKEN=telegram-bot-token:latest,FLASK_SECRET=flask-secret:latest" \
117
+ --allow-unauthenticated
118
+ ```
119
+
120
+ ### 5.3 Scheduler jobs (automation)
121
+
122
+ ```bash
123
+ # Hourly rising-coin scan (runs at :15 past each hour)
124
+ gcloud scheduler jobs create http hourly-scan --location europe-west1 \
125
+ --schedule "15 * * * *" --uri "<SCANNER_URL>/run" --http-method GET
126
+
127
+ # Daily summary to Telegram
128
+ gcloud scheduler jobs create http daily-summary --location europe-west1 \
129
+ --schedule "0 8 * * *" --uri "<SCANNER_URL>/summary" --http-method GET
130
+ ```
131
+
132
+ The scanner also detects bot closures, grid-profit events, and funding fees
133
+ automatically whenever the grid page is open (90-second event-check cycle).
134
+
135
+ ### 5.4 Main website (optional)
136
+
137
+ The main site (home page, financials, settings) deploys the same way from the
138
+ `blind-monkeys/` directory:
139
+
140
+ ```bash
141
+ gcloud run deploy bm-site --region us-central1 --source blind-monkeys \
142
+ --set-env-vars "FLASK_ENV=production" \
143
+ --set-secrets "FLASK_SECRET=flask-secret:latest,TELEGRAM_BOT_TOKEN=telegram-bot-token:latest,TELEGRAM_CHAT_ID=YOUR_CHAT_ID" \
144
+ --allow-unauthenticated
145
+ ```
146
+
147
+ ---
148
+
149
+ ## 6. Custom domain (optional)
150
+
151
+ ```bash
152
+ gcloud beta run domain-mappings create --domain scan.yourdomain.com \
153
+ --service bm-scanner --region europe-west1
154
+ ```
155
+
156
+ Then add the **CNAME record** shown in the command output
157
+ (`ghs.googlehosted.com`) to your DNS provider. Certificate provisioning
158
+ starts as soon as the DNS record resolves (usually minutes).
159
+
160
+ ---
161
+
162
+ ## 7. Verify the installation
163
+
164
+ | Check | Expected |
165
+ |---|---|
166
+ | Open `<SCANNER_URL>/healthz` | `ok` |
167
+ | Open the scanner home page | Rising-coins table loads (~30–60 s first scan) |
168
+ | Open `<SCANNER_URL>/grid` | Grid tables + balance panel load |
169
+ | Balance panel shows your USDT | Funding / Unified / Grid values match Bybit |
170
+ | Post a test message via the bot to a channel | Message arrives |
171
+
172
+ ---
173
+
174
+ ## 8. Operating notes
175
+
176
+ - **Grid settings** (leverage, range, amount, TP/SL, auto-open score) are
177
+ configured on the scanner's `/grid` page β€” admin only.
178
+ - **Risk controls**: every grid bot carries a TP and SL; there is a daily
179
+ investment cap; completed bots are archived (releasing funds) and
180
+ tracked for win rate.
181
+ - **The score-weight feedback loop** refines coin selection automatically
182
+ from realized grid returns β€” no configuration needed.
183
+ - **Costs**: two Cloud Run services on the free tier plus a few scheduler
184
+ jobs β‰ˆ $0–2/month. Cloud Build minutes are free up to the daily quota.
185
+
186
+ ---
187
+
188
+ ## 9. Troubleshooting
189
+
190
+ | Symptom | Fix |
191
+ |---|---|
192
+ | Balance shows $0 | Check the API key has *Wallet balance* permission; check USDT is in the Funding account |
193
+ | Telegram silent | Bot must be an **admin** of each channel; check channel IDs via `getUpdates` |
194
+ | 403 on trader URLs | Expected β€” the trader is IAM-internal; only the scanner (with OIDC) may call it |
195
+ | 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` |
196
+ | Certificate pending on custom domain | DNS CNAME not propagated yet β€” wait, then re-check |