File size: 3,649 Bytes
2e658e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f8cf56
2e658e7
 
 
 
 
 
 
 
 
 
 
 
 
1f8cf56
2e658e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Security and Safety

## Non-negotiable invariants

Do not change or weaken:

- deterministic `LONG`, `SHORT`, and `NO_TRADE` decisions;
- Datasource 4 authority;
- `noTradeGuard`;
- Futures verification;
- provider timestamp and freshness checks;
- risk approval;
- Stop Loss and Take Profit rules;
- leverage caps and volatility haircut;
- quantity/sizing logic;
- Paper execution validation;
- Telegram webhook-only isolation;
- single FastAPI application and port 7860 architecture.

## Browser trust model

The browser is untrusted for execution. It may display and calculate convenience diagnostics, but the server ignores browser-derived authorization.

Server-side Paper checks include plan reference, symbol/risk identity, expiry, executed flag, direction, DS4 verification, readiness, guard state, risk approval, executable flag, Paper mode, and fresh re-analysis.

## Secret handling

Never expose or commit:

```text
HF_TOKEN
HERMES_ADMIN_PASSWORD
FUTURES_API_KEY
FUTURES_API_SECRET
FUTURES_API_PASSPHRASE
OPENROUTER_API_KEY
GOOGLE_API_KEY
TELEGRAM_BOT_TOKEN
TELEGRAM_WEBHOOK_SECRET
TELEGRAM_BOOTSTRAP_SECRET
TELEGRAM_RELAY_SECRET
cookies or Authorization headers
```

Diagnostics redact keys and text matching authorization, cookie, token, secret, password, or API key patterns. Continue to sanitize new error fields before they reach API responses or UI.

## Market-data integrity

- No fabricated production candles, prices, funding, Open Interest, or order-book levels.
- Missing values are `null`/`Unavailable`, not zero.
- HTTP success is not data freshness.
- Provider errors in main UI are concise; detailed errors remain sanitized under Technical Diagnostics.
- Binance regional restriction must not be bypassed with raw IP, DNS override, or disabled TLS.

## External AI boundary

External AI (Hermes auxiliary task `futures_advisory`) may return market bias, confidence, summary, supporting points, and warnings. Implementation uses `agent.auxiliary_client.async_call_llm` with a strict JSON schema (`external_ai/advisory_schema.py`). It must never modify:

```text
decision
risk approval
noTradeGuard
Entry
Stop Loss
Take Profit
leverage
quantity
execution availability
```

Bulk scans must not use advisory AI. The dashboard labels this lane **Optional AI context** (violet / informational); the deterministic engine lane (emerald) remains authoritative.

## Telegram boundary

- Webhook secret-token validation is mandatory.
- Request size is bounded.
- Owner bootstrap is one-time, secret-checked, and private-chat only.
- Users are authorized by configured IDs or persisted owner.
- Commands are rate-limited.
- Callback nonces expire and are user-bound.
- Telegram performs analysis only and contains no order path.
- Polling remains disabled.

## Development safety

During ordinary development and deployment verification:

- do not call Paper Execute;
- do not run Testnet or Live execution;
- use the read-only audit script;
- use Paper account endpoints only for display verification;
- do not add an execution keyboard shortcut;
- do not allow a UI feature to write plan or risk state directly.

## Review checklist for security-sensitive changes

- Does the change alter a deterministic threshold or formula?
- Can fallback data override DS4 safety?
- Can a missing timestamp be treated as fresh?
- Can the browser enable execution without server state?
- Can a raw error include a secret?
- Can a Telegram request bypass authorization or webhook validation?
- Does the change introduce a second network service or port?
- Does it add an exchange credential requirement?
- Are failure states blocked by default?