Taskmaster track · Google "All Things Agentic" hackathon
VIGIL watches gold (COMEX proxy for MCX), FX, NIFTY, and crypto around the clock. Every few minutes it fetches fresh candles from keyless public APIs, runs a deterministic rule engine — volume confirmation, last-15-candle trend check, RSI guard, lot-size compliance — and decides. When a setup looks tempting but fails the rules, VIGIL refuses and tells you exactly why. Every decision is journaled to Firestore and Google Sheets, graded at expiry, and reported over Telegram. A weekly self-review proposes rule tweaks; a human approves or rejects them, and approved changes go live immediately.
VIGIL is paper-only by design. It never touches real money — it decides, sizes, checks compliance, and journals; the human pulls the trigger in their own broker. It was built because 91% of individual F&O traders in India lost money in FY25 (≈₹1.06 lakh crore in aggregate, SEBI July 2025 study) — most of it to undisciplined, manual decision-making. VIGIL is the discipline layer: rules, evidence, and a complete audit trail for every call.
Cloud Scheduler (every 5 min)
│ Pub/Sub (vigil-scans)
▼
Cloud Run ── ADK 2.7 Workflow "vigil_scan" (function nodes, autonomous routing)
│
├─ init_run parse payload, seed run state
├─ fetch_all keyless OHLCV: Binance API (crypto) + Yahoo chart API (gold/FX/NIFTY)
├─ grade_expired grade open paper positions at expiry (WIN/LOSS/FLAT)
├─ decide_all deterministic rule engine per symbol (Gemini never decides)
├─ risk_gate sizing + lot-size compliance → route
│ ├─ signals ──► execute_signals paper ledger, one signal/symbol/day
│ └─ refusals ─► journal the discipline moment
├─ journal Firestore (state) + Google Sheets (audit mirror)
└─ notify Telegram alerts + digest + Gemini narrative
│
▼
HUMAN (pulls the trigger, approves weekly review)
Gemini 3.5 Flash provides the human-facing narrative (one call per cycle, keyless fallback). The model reports; the rules decide. The weekly review uses a human-in-the-loop gate: proposal → Telegram → approve/reject → live threshold change.
| Rule | Check | Outcome |
|---|---|---|
| Data sufficiency | ≥ 60 candles | else REFUSE |
| Trend confirmation | price vs 20-EMA on the same side as EMA slope, ≥ 12 of last 15 candles | trend confirmed → direction |
| Volume gate | last volume ≥ 1.5× 20-candle average | REFUSE: "volume confirmation failed (no push behind the move)" — the demo moment |
| RSI guard | RSI(14) in (30, 70) | REFUSE when extreme |
| Lot compliance | notional ≤ lot × max_lots × price | REFUSE when it doesn't fit |
| Discipline | one signal per symbol per day | no doubles |
Thresholds are tunable at runtime (Firestore active_rules), so an approved
self-review tweak changes live behavior.
vigil/
config.py env-driven config (VIGIL_* vars)
data/ keyless kline fetchers (binance, yahoo) + router
ta/ indicators + deterministic rule engine
risk/ sizing + lot compliance
core/ Signal/Refusal/Trade models + grader
state/ FirestoreStore/NullStore, SheetsJournal/NullJournal
notify/ TelegramNotifier/NullNotifier
narrative.py Gemini narrative layer (keyless fallback)
orchestrator.py ADK 2.7 Workflows: scan + weekly review
main.py FastAPI entry (dashboard, /scan, /review)
dashboard.py server-rendered status page
scripts/run_scan.py local demo driver
deploy/ cloud_run_deploy.sh, scheduler_setup.sh
docs/ CONTRACTS.md (interfaces), architecture.md, demo-script.md
tests/ 146 tests — run offline, no credentials required
uv venv .venv --python 3.11
uv pip install -r requirements.txt --python .venv/Scripts/python.exe
cp .env.example .env # edit if you have keys; defaults work bare
.venv/Scripts/python.exe scripts/run_scan.py
.venv/Scripts/python.exe -m pytestEverything degrades gracefully without credentials: NullStore /
NullJournal / NullNotifier stand in for Firestore / Sheets / Telegram,
and the Gemini narrative falls back to deterministic text. One command, live
market data, a full decision cycle with an audit trail.
The agent can watch markets continuously and keep its history across restarts (local JSON store — the same journal the cloud deployment writes to Firestore):
export VIGIL_STORE=file VIGIL_DATA_DIR=vigil-data
.venv/Scripts/python.exe scripts/watch.py # foreground, every 5 min
# or one cycle at a time (cron-friendly):
bash scripts/soak_tick.sh| Variable | Default | Meaning |
|---|---|---|
VIGIL_WATCHLIST |
MCXGOLD,BTCUSDT,^NSEI,USDINR=X |
symbols to scan (MCXGOLD = synthetic MCX gold proxy) |
VIGIL_INTERVAL |
1h |
candle interval (15m/1h/1d) |
VIGIL_ACCOUNT_SIZE / VIGIL_MAX_RISK_PCT |
100000 / 1.0 |
paper risk budget |
VIGIL_LOT_RULES |
{} |
JSON {"SYM": {"lot": 0.001, "max_lots": 3}} |
VIGIL_VOLUME_MULTIPLIER / VIGIL_RSI_HIGH / VIGIL_RSI_LOW |
1.5 / 70 / 30 |
tunable thresholds |
VIGIL_TELEGRAM_BOT_TOKEN / VIGIL_TELEGRAM_CHAT_ID |
— | alerts |
VIGIL_GCP_PROJECT / VIGIL_GCP_CREDENTIALS / VIGIL_FIRESTORE_DB |
— | Firestore state |
VIGIL_SPREADSHEET_ID / VIGIL_SHEETS_CREDENTIALS |
— | Sheets audit mirror |
VIGIL_GEMINI_API_KEY / VIGIL_MODEL |
— / gemini-3.5-flash |
narrative layer |
VIGIL_STORE / VIGIL_DATA_DIR |
file / vigil-data |
soak mode: persistent local state |
VIGIL_WEBHOOK_TOKEN |
— | auth for /scan, /review* |
VIGIL_DRY_RUN |
1 |
paper-only (keep it 1) |
export PROJECT_ID=your-project
bash deploy/cloud_run_deploy.sh # enables APIs, deploys Cloud Run (scale-to-zero, dry-run forced)
bash deploy/scheduler_setup.sh # Firestore db, Pub/Sub topic + push sub (OIDC SA), Cloud Scheduler every 5 minThen hit the .run URL: / is the live dashboard, /healthz is the probe,
POST /scan accepts the Pub/Sub push (or a plain JSON body), /status
shows journal + active rules, /review starts the weekly self-review and
/review/approve applies the human's decision. gcloud run services logs tail vigil --region asia-south1 shows the per-decision structured log lines
(the Cloud Logging proof).
| Method | Path | Description |
|---|---|---|
| GET | / |
dashboard (hosted project URL) |
| GET | /healthz |
liveness |
| POST | /scan |
one scan cycle (Pub/Sub push or JSON) |
| GET | /status |
journal, active rules, pending review |
| POST | /review |
start weekly self-review |
| POST | /review/approve |
`{"approve": true |
All mutating endpoints require X-Vigil-Token when VIGIL_WEBHOOK_TOKEN is
set.
Scale-to-zero Cloud Run + free-tier Firestore + negligible Pub/Sub/Scheduler
put a full demo period around $0.35; Gemini 3.5 Flash runs (narrative +
review) fit thousands of cycles inside the $150 hackathon credits. Cost
controls: scale-to-zero (--min-instances 0), a 120s run timeout, and the
/cost endpoint for real usage + projections. Budget alerts can be added
with gcloud billing budgets create once a billing account is linked
(no budget command is baked into the deploy scripts).
Paper-only. VIGIL_DRY_RUN=1 is forced at deploy. No broker connection, no
order routing, no real-money path anywhere in the codebase. VIGIL is an
education and discipline tool for people who want to stop losing money to
undisciplined manual trading — it shows you when not to trade.
146 tests, zero network, zero credentials (conftest forces the keyless
path): indicators, rule engine, sizing, grading (target/stop-aware),
orchestrator routing, dedupe, review lifecycle, threshold overlay,
idempotency, narrative tiers + rotation pool, news sentiment, multiframe
alignment, resampler, MCX proxy, correlation, memory lessons, dashboard
charts, persistence, cost estimator. pytest in the repo root.