Production Verified Architecture Reference

Institutional Enhancements & Risk Guardrails

Complete technical specification, forensic justification, and verification manifest for the 4 core algorithmic guardrails deployed to AWS EC2.

๐Ÿ›ก๏ธ 1. Chop Cooldown Filter
Risk Engine Gate

Core Mandate: Enforce a mandatory 20-minute cooldown on any specific option strike if 2 consecutive stop-outs occur on that strike while the market is classified in RANGE or CHOPPY regime.

Consecutive Stop-Outs
2 Trades
Regime Target
RANGE / CHOPPY
Strike Lockout
20.0 Minutes

Forensic Problem Solved: During sideways compression or auction chop, repetitive re-entries on the exact same ATM strike (e.g., 25100 CE) suffer continuous theta decay and whip whipsaws. Other non-cooldown strikes remain tradeable if directional momentum emerges.

Trade Closed (Loss) on Strike S in RANGE Regime โ”‚ โ”œโ”€โ”€> Consecutive Stop-Outs[S] = Consecutive Stop-Outs[S] + 1 โ”‚ โ”œโ”€โ”€> If Consecutive Stop-Outs[S] >= 2: โ”‚ โ”œโ”€โ”€ Lockout Strike S until (ExitTime + 20 minutes) โ”‚ โ””โ”€โ”€ RiskManager.evaluate_order() rejects signal: โ”‚ [CHOP_COOLDOWN_ACTIVE] (e.g. 17.5 mins remaining) โ”‚ โ””โ”€โ”€> If Trade Closed (Profit) on Strike S: โ””โ”€โ”€ Reset Consecutive Stop-Outs[S] = 0

Key Verification: Tested in test_chop_cooldown_and_displacement.py: 1 loss does not trigger lockout; 2 consecutive losses locks the strike for 20m; trades on other strikes are allowed; profit resets the streak.

๐Ÿ“ 2. Strike Re-Entry Displacement
Execution Gate

Core Mandate: Prohibit re-entering the exact same option strike within 45 minutes unless NIFTY underlying spot has displaced at least 25.0 index points from the previous entry level.

Re-Entry Window
45.0 Minutes
Min Displacement
โ‰ฅ 25.0 Points
Action on Breach
Order Rejection

Forensic Problem Solved: Prevents "churning" at the same price consolidation shelf. If spot has only moved 8โ€“12 points, market structure has not fundamentally reset; re-entering the same contract results in overlapping risk without edge.

Incoming Signal on Strike S at Spot P_current โ”‚ โ”œโ”€โ”€> Check Strike History: Previous Entry (P_prev, T_prev) โ”‚ โ”œโ”€โ”€> If (T_current - T_prev) < 45 Minutes: โ”‚ โ”œโ”€โ”€ Displacement = |P_current - P_prev| โ”‚ โ”œโ”€โ”€ If Displacement < 25.0 Points: โ”‚ โ”‚ โ””โ”€โ”€ REJECT ORDER: [STRIKE_REENTRY_DISPLACEMENT_UNMET] โ”‚ โ””โ”€โ”€ If Displacement >= 25.0 Points: โ”‚ โ””โ”€โ”€ ALLOW ORDER (Auction has broken consolidation) โ”‚ โ””โ”€โ”€> If (T_current - T_prev) >= 45 Minutes: โ””โ”€โ”€ ALLOW ORDER (Window elapsed, structure refreshed)

Key Verification: Tested in test_chop_cooldown_and_displacement.py: Sub-25pt re-entry in 15m is blocked; 28pt re-entry is approved; 50m elapsed re-entry is approved.

๐Ÿ” 3. Persistent Cryptographic Token Vault
Security & Broker

Core Mandate: Protect active FYERS session tokens with authenticated encryption, tamper-resistant HMAC-SHA256 signatures, CSPRNG nonces, and automatic integrity verification with seamless auto-reconnect on startup.

Key Derivation
PBKDF2-100k
Integrity Tag
HMAC-SHA256
Dependencies
0 Ext (StdLib)

Architecture Details:

  • Keystream Cipher: Uses CSPRNG 16-byte random nonces and counter-mode HMAC-SHA256 keystream expansion.
  • Tamper Detection: Computes independent HMAC tag over nonce + ciphertext and SHA-256 payload checksum. Any bit flip raises TokenVaultIntegrityError.
  • Zero Third-Party Dependencies: Standard Python 3.12 library only (hashlib, hmac, os, json).
  • Auto-Migration: Detects legacy plaintext tokens/account_1.json and transparently upgrades it to encrypted tokens/token_vault.enc on first boot.

Key Verification: Tested in test_token_vault.py: 100% test pass on round-trip encryption, HMAC tamper detection, checksum validation, and legacy migration.

๐Ÿ“Š 4. Volume Profile POC Confluence
FVG Strategy Filter

Core Mandate: Mandate high volume node alignment (Point of Control / POC) on all mid-morning (10:00 - 11:30 IST) Fair Value Gap retest entries. Retests lacking POC confluence are strictly rejected.

Mid-Morning Window
10:00 - 11:30 IST
Tolerance Distance
โ‰ค 15.0 Points
Conviction Bonus
+0.10 Entry / +0.08 Run

Forensic Problem Solved: Mid-morning (10:00 - 11:30 IST) is the European open preparation and institutional rebalancing period. Low-volume FVGs formed in vacuum moves frequently fail without institutional auction consensus. Requiring POC alignment guarantees high-volume acceptance.

FVG Retest Detected at Timestamp T_eval โ”‚ โ”œโ”€โ”€> Compute VolumeProfileIndicator across session candles -> POC โ”‚ โ”œโ”€โ”€> If (10:00 <= T_eval <= 11:30 IST): [Mid-Morning Auction] โ”‚ โ”œโ”€โ”€ Check POC in/near FVG Zone: โ”‚ โ”‚ Distance = min(|POC - FVG_low|, |POC - FVG_high|) โ”‚ โ”œโ”€โ”€ If Distance > 15.0 Points: โ”‚ โ”‚ โ””โ”€โ”€ REJECT SIGNAL: [Mid-morning FVG retest rejected: POC alignment mandated] โ”‚ โ””โ”€โ”€ If Distance <= 15.0 Points: โ”‚ โ””โ”€โ”€ APPROVE + Grant High Conviction Bonus (+0.10 Entry, +0.08 Runner) โ”‚ โ””โ”€โ”€> If Outside 10:00 - 11:30 IST: โ””โ”€โ”€ Normal Evaluation (POC confluence adds +0.05 bonus if present)

Key Verification: Tested in test_fvg_poc_confluence.py: Mid-morning retest without POC rejected; aligned retest approved with +0.10 bonus; early/afternoon trades permitted.

๐Ÿงช Multi-Layer Test & Deployment Verification Manifest
44 / 44 Tests Passed
Test Suite Module Coverage Target Test Cases Local Status AWS EC2 Status
test_token_vault.py Persistent Encrypted Token Vault & Auth Integration 4 Tests PASSED (100%) PASSED (100%)
test_chop_cooldown_and_displacement.py Chop Cooldown (20m) & Strike Re-Entry Displacement (45m / 25pts) 4 Tests PASSED (100%) PASSED (100%)
test_fvg_poc_confluence.py Mid-Morning Volume Profile POC Confluence (10:00 - 11:30 IST) 3 Tests PASSED (100%) PASSED (100%)
test_risk_manager.py Full Risk Engine Circuit Breakers & Invariant Gating 22 Tests PASSED (100%) PASSED (100%)
test_fyers_auth.py FYERS OAuth2 Flow, Header Signing & File Caching 7 Tests PASSED (100%) PASSED (100%)
test_fvg_retest_strategy.py Core Fair Value Gap Retest Price Action & Invalidation 4 Tests PASSED (100%) PASSED (100%)

Live Production Deployment Confirmed: All files uploaded to ubuntu@13.207.146.76:/home/ubuntu/AntigravityTradeSetup/. Service nifty-runner.service restarted successfully (Main PID: 323389). Automated EOD forensics archiver executed clean end-of-market audit, and dashboard REST API is healthy.