clearfills 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clearfills-0.5.0/.github/workflows/ci.yml +36 -0
- clearfills-0.5.0/.github/workflows/publish-pypi.yml +28 -0
- clearfills-0.5.0/.gitignore +10 -0
- clearfills-0.5.0/LICENSE +91 -0
- clearfills-0.5.0/PKG-INFO +208 -0
- clearfills-0.5.0/README.md +167 -0
- clearfills-0.5.0/docs/AGENT_INTEGRATION.md +62 -0
- clearfills-0.5.0/docs/QUICKSTART.md +78 -0
- clearfills-0.5.0/examples/ai_hedge_fund_safe_execution.py +205 -0
- clearfills-0.5.0/examples/claude_mcp_setup.md +115 -0
- clearfills-0.5.0/examples/tradingagents_safe_execution.py +161 -0
- clearfills-0.5.0/packages/clearfills-desk/README.md +49 -0
- clearfills-0.5.0/packages/clearfills-desk/config/desk_rules.example.yaml +21 -0
- clearfills-0.5.0/packages/clearfills-desk/config/desk_rules.live.example.yaml +30 -0
- clearfills-0.5.0/packages/clearfills-desk/pyproject.toml +39 -0
- clearfills-0.5.0/packages/clearfills-desk/src/clearfills_desk/__init__.py +42 -0
- clearfills-0.5.0/packages/clearfills-desk/src/clearfills_desk/cli.py +187 -0
- clearfills-0.5.0/packages/clearfills-desk/src/clearfills_desk/ibkr.py +682 -0
- clearfills-0.5.0/packages/clearfills-desk/src/clearfills_desk/mcp_server.py +705 -0
- clearfills-0.5.0/packages/clearfills-desk/src/clearfills_desk/runtime.py +91 -0
- clearfills-0.5.0/packages/clearfills-desk/src/clearfills_desk/sync.py +236 -0
- clearfills-0.5.0/packages/clearfills-desk/src/clearfills_desk/telemetry.py +80 -0
- clearfills-0.5.0/packages/clearfills-desk/src/clearfills_desk/worker.py +449 -0
- clearfills-0.5.0/packages/clearfills-desk/tests/test_approval_worker.py +503 -0
- clearfills-0.5.0/packages/clearfills-desk/tests/test_broker_mcp.py +555 -0
- clearfills-0.5.0/packages/clearfills-desk/tests/test_desk_os.py +51 -0
- clearfills-0.5.0/packages/clearfills-desk/tests/test_ibkr_live.py +193 -0
- clearfills-0.5.0/packages/clearfills-desk/tests/test_sync.py +78 -0
- clearfills-0.5.0/packages/risk-firewall/README.md +47 -0
- clearfills-0.5.0/packages/risk-firewall/pyproject.toml +68 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/__init__.py +52 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/_locks.py +28 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/adapters.py +196 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/attestation.py +286 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/killswitch.py +186 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/ledger.py +181 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/mcp_server.py +536 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/models.py +231 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/policy.py +409 -0
- clearfills-0.5.0/packages/risk-firewall/src/clearfills_firewall/server.py +298 -0
- clearfills-0.5.0/packages/risk-firewall/tests/test_adapters_and_interfaces.py +261 -0
- clearfills-0.5.0/packages/risk-firewall/tests/test_desk_rules_v02.py +104 -0
- clearfills-0.5.0/packages/risk-firewall/tests/test_firewall_core.py +317 -0
- clearfills-0.5.0/packages/risk-firewall/tests/test_sleeves.py +154 -0
- clearfills-0.5.0/packages/risk-firewall/tests/test_v03_hardening_and_cloud_mcp.py +139 -0
- clearfills-0.5.0/packages/risk-firewall/uv.lock +666 -0
- clearfills-0.5.0/pyproject.toml +94 -0
- clearfills-0.5.0/server.json +22 -0
- clearfills-0.5.0/src/clearfills/__init__.py +58 -0
- clearfills-0.5.0/src/clearfills/cli.py +790 -0
- clearfills-0.5.0/tests/test_clearfills_cli.py +112 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.11", "3.12"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: astral-sh/setup-uv@v4
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- name: Run unified clearfills tests
|
|
20
|
+
run: |
|
|
21
|
+
uv sync --extra dev
|
|
22
|
+
uv run pytest -v
|
|
23
|
+
- name: Run clearfills-firewall tests
|
|
24
|
+
working-directory: packages/risk-firewall
|
|
25
|
+
run: |
|
|
26
|
+
uv sync --extra dev
|
|
27
|
+
uv run pytest -v
|
|
28
|
+
- name: Run clearfills-desk tests
|
|
29
|
+
working-directory: packages/clearfills-desk
|
|
30
|
+
run: |
|
|
31
|
+
uv sync --extra dev
|
|
32
|
+
uv run pytest -v
|
|
33
|
+
- name: Build & verify unified clearfills wheel
|
|
34
|
+
run: |
|
|
35
|
+
uv build
|
|
36
|
+
uvx twine check dist/*
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Publish clearfills to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish-clearfills:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment:
|
|
12
|
+
name: pypi
|
|
13
|
+
url: https://pypi.org/p/clearfills
|
|
14
|
+
permissions:
|
|
15
|
+
id-token: write
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: astral-sh/setup-uv@v4
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
- name: Build clearfills distribution
|
|
22
|
+
run: |
|
|
23
|
+
uv build
|
|
24
|
+
uvx twine check dist/*
|
|
25
|
+
- name: Publish clearfills to PyPI via Trusted Publishing (OIDC)
|
|
26
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
27
|
+
with:
|
|
28
|
+
packages-dir: dist/
|
clearfills-0.5.0/LICENSE
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including
|
|
45
|
+
the original version of the Work and any modifications or additions
|
|
46
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
47
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
48
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
49
|
+
the copyright owner.
|
|
50
|
+
|
|
51
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
52
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
53
|
+
subsequently incorporated within the Work.
|
|
54
|
+
|
|
55
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
56
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
57
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
58
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
59
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
60
|
+
Work and such Derivative Works in Source or Object form.
|
|
61
|
+
|
|
62
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
63
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
64
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
65
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
66
|
+
and otherwise transfer the Work.
|
|
67
|
+
|
|
68
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
69
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
70
|
+
modifications, and in Source or Object form, provided that You
|
|
71
|
+
retain all copyright, patent, trademark, and attribution notices.
|
|
72
|
+
|
|
73
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
74
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
75
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
76
|
+
this License, without any additional terms or conditions.
|
|
77
|
+
|
|
78
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
79
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
80
|
+
|
|
81
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
82
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
83
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
84
|
+
|
|
85
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
86
|
+
any Contributor be liable to You for damages, including any direct,
|
|
87
|
+
indirect, special, incidental, or consequential damages of any character
|
|
88
|
+
arising as a result of this License or out of the use or inability to use
|
|
89
|
+
the Work.
|
|
90
|
+
|
|
91
|
+
Copyright 2026 MLDSAI Inc. (ClearFills)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: clearfills
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Deterministic Ed25519 pre-trade risk firewall, MCP server, and IBKR execution guard for AI trading agents (clearfills.com)
|
|
5
|
+
Project-URL: Homepage, https://clearfills.com
|
|
6
|
+
Project-URL: Documentation, https://clearfills.com/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/clearfills/clearfills
|
|
8
|
+
Project-URL: Issues, https://github.com/clearfills/clearfills/issues
|
|
9
|
+
Author-email: "ClearFills / MLDSAI Inc." <desk@mldsai.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai-trading,alpaca,ed25519,ibkr,kalshi,mcp,polymarket,quant,risk-firewall,trading-agents
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
21
|
+
Classifier: Topic :: Security :: Cryptography
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: cryptography>=42.0.0
|
|
24
|
+
Requires-Dist: pydantic>=2.0.0
|
|
25
|
+
Requires-Dist: pyyaml>=6.0.0
|
|
26
|
+
Provides-Extra: all
|
|
27
|
+
Requires-Dist: fastapi>=0.111.0; extra == 'all'
|
|
28
|
+
Requires-Dist: ib-async>=1.0.0; extra == 'all'
|
|
29
|
+
Requires-Dist: uvicorn>=0.30.0; extra == 'all'
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: fastapi>=0.111.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: httpx>=0.27.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: uvicorn>=0.30.0; extra == 'dev'
|
|
35
|
+
Provides-Extra: ibkr
|
|
36
|
+
Requires-Dist: ib-async>=1.0.0; extra == 'ibkr'
|
|
37
|
+
Provides-Extra: server
|
|
38
|
+
Requires-Dist: fastapi>=0.111.0; extra == 'server'
|
|
39
|
+
Requires-Dist: uvicorn>=0.30.0; extra == 'server'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# ClearFills
|
|
43
|
+
|
|
44
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
45
|
+
[](https://pypi.org/project/clearfills/)
|
|
46
|
+
[](https://www.python.org/downloads/)
|
|
47
|
+
[](https://clearfills.com)
|
|
48
|
+
[](https://glama.ai/mcp/servers/clearfills/clearfills)
|
|
49
|
+
|
|
50
|
+
**Let AI manage your portfolio. Never give it your broker password.**
|
|
51
|
+
|
|
52
|
+
ClearFills is an open-core execution firewall and MCP server for AI trading agents. Connect Claude, Claude Code, Cursor, Codex, `TradingAgents`, or `ai-hedge-fund` to Interactive Brokers (IBKR), Alpaca, and multi-account portfolios with deterministic Ed25519 pre-trade risk rules and 1-tap human approval.
|
|
53
|
+
|
|
54
|
+
- **Install:** `pip install clearfills` (add `pip install 'clearfills[ibkr]'` for IBKR Gateway execution)
|
|
55
|
+
- **Live Sandbox ($0, 60 seconds):** [https://clearfills.com/console](https://clearfills.com/console)
|
|
56
|
+
- **Hosted Remote MCP (OAuth 2.1 + Bearer):** `https://clearfills-api.fly.dev/mcp`
|
|
57
|
+
- **Documentation:** [clearfills.com/docs](https://clearfills.com/docs) · [docs/QUICKSTART.md](docs/QUICKSTART.md) · [docs/AGENT_INTEGRATION.md](docs/AGENT_INTEGRATION.md)
|
|
58
|
+
- **Machine-Readable Docs:** [llms.txt](https://clearfills.com/llms.txt) · [agents.txt](https://clearfills.com/agents.txt)
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Install & Unified CLI
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Core firewall, Python SDK, MCP server, and CLI (zero broker libs)
|
|
66
|
+
pip install clearfills
|
|
67
|
+
|
|
68
|
+
# With IBKR Gateway execution (watch / sync ibkr / mcp --ibkr)
|
|
69
|
+
pip install 'clearfills[ibkr]'
|
|
70
|
+
|
|
71
|
+
# With local FastAPI HTTP firewall server (`clearfills serve`)
|
|
72
|
+
pip install 'clearfills[server]'
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Run the unified `clearfills` CLI right from your terminal:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# 1. Verify the firewall in 3 seconds (rogue market order, missing stop, single-use replay)
|
|
79
|
+
clearfills redteam --local
|
|
80
|
+
|
|
81
|
+
# 2. Generate a safe, commented .clearfills.yaml (paper defaults + per-sleeve caps)
|
|
82
|
+
clearfills init
|
|
83
|
+
|
|
84
|
+
# 3. Run 6 diagnostic checks (Python, config, IBKR extra, IB Gateway TCP, Cloud auth, SHA-256 audit)
|
|
85
|
+
clearfills doctor
|
|
86
|
+
|
|
87
|
+
# 4. Run the local stdio MCP server (or add --ibkr for IBKR execution tools)
|
|
88
|
+
clearfills mcp
|
|
89
|
+
|
|
90
|
+
# 5. Watch ClearFills Cloud for 1-Tap Inbox approvals (add --dry-run to test safely)
|
|
91
|
+
CLEARFILLS_API_KEY="cf_sk_..." clearfills watch --dry-run
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## How It Works (3 Steps)
|
|
97
|
+
|
|
98
|
+
1. **Connect read-only:** Sync your balances and holdings from IBKR, SnapTrade, EVM wallets, or statements without handing brokerage passwords to an LLM.
|
|
99
|
+
2. **Enforce hard math:** Every AI trade proposal passes through a deterministic, zero-LLM risk firewall (`clearfills`) that enforces per-sleeve notional caps, mandatory stop-losses, daily loss limits, and a fail-closed kill-switch before minting a single-use 120-second Ed25519 attestation.
|
|
100
|
+
3. **Approve in one tap:** Review attested orders in your ClearFills Inbox and tap **Approve**. Your local `clearfills watch` worker atomically claims the order, checks a fresh live quote (50 bps slippage guard), re-attests, and routes to IBKR or Alpaca.
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
Claude / Codex / Cursor / TradingAgents / ai-hedge-fund
|
|
104
|
+
| (MCP or Python SDK, zero broker passwords)
|
|
105
|
+
v
|
|
106
|
+
ClearFills Cloud & Risk Firewall
|
|
107
|
+
+-------------------------------------+
|
|
108
|
+
| 1. Connect read-only (multi-entity) |
|
|
109
|
+
| 2. Enforce hard math (Ed25519) |
|
|
110
|
+
| 3. Approve in one tap (Inbox) |
|
|
111
|
+
+------------------+------------------+
|
|
112
|
+
| (human clicks Approve)
|
|
113
|
+
v
|
|
114
|
+
clearfills watch (local)
|
|
115
|
+
+-------------------------------------+
|
|
116
|
+
| * Atomic claim + 50 bps guard |
|
|
117
|
+
| * Fresh Ed25519 re-attestation |
|
|
118
|
+
| * IBKR Gateway (loopback/Tailscale) |
|
|
119
|
+
+-------------------------------------+
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 60-Second Quickstart
|
|
125
|
+
|
|
126
|
+
### 1. Try the Live Sandbox ($0)
|
|
127
|
+
1. Sign in at [clearfills.com/console](https://clearfills.com/console) (GitHub or Google).
|
|
128
|
+
2. Click **Launch 60-Second Sandbox Demo** on `Portfolio` to load a sample Personal + Corporate balance sheet and queue an `SGOV` T-bill sweep.
|
|
129
|
+
3. Open `Inbox` and tap **Approve & Execute** to inspect an Ed25519-signed execution receipt and SHA-256 audit trail. Click **Clear Sandbox Data** anytime to connect real accounts.
|
|
130
|
+
|
|
131
|
+
### 2. Connect Your AI Agent via MCP (No `pip install` Required)
|
|
132
|
+
Connect **Claude.ai** (OAuth 2.1), **Claude Code**, **Cursor**, or **Codex** to `https://clearfills-api.fly.dev/mcp`. See the full copy-paste guide in [`examples/claude_mcp_setup.md`](examples/claude_mcp_setup.md).
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Claude Code (Hosted Remote MCP)
|
|
136
|
+
claude mcp add --transport http clearfills https://clearfills-api.fly.dev/mcp \
|
|
137
|
+
--header "Authorization: Bearer cf_sk_..."
|
|
138
|
+
|
|
139
|
+
# Claude Code (Local offline firewall MCP via uvx)
|
|
140
|
+
claude mcp add clearfills -- uvx clearfills mcp
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 3. Python SDK
|
|
144
|
+
```python
|
|
145
|
+
from clearfills import FirewallService, PortfolioSnapshot, RiskPolicy, TradeProposal
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 4. Connect Live or Paper IBKR
|
|
149
|
+
```bash
|
|
150
|
+
# Generate paper or live config
|
|
151
|
+
clearfills init --mode paper
|
|
152
|
+
|
|
153
|
+
# Validate fail-closed config (Paper: port 4002 + DU* | Live: port 4001 + two-key opt-in)
|
|
154
|
+
CLEARFILLS_ALLOW_LIVE=1 clearfills validate --config .clearfills.yaml
|
|
155
|
+
|
|
156
|
+
# Run the local execution daemon for 1-tap Inbox approvals (add --dry-run to test safely)
|
|
157
|
+
CLEARFILLS_ALLOW_LIVE=1 CLEARFILLS_API_KEY="cf_sk_..." \
|
|
158
|
+
clearfills watch --config .clearfills.yaml --dry-run
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Runnable Examples
|
|
164
|
+
|
|
165
|
+
| Example | What It Shows |
|
|
166
|
+
| :--- | :--- |
|
|
167
|
+
| [`examples/tradingagents_safe_execution.py`](examples/tradingagents_safe_execution.py) | Wrap `TauricResearch/TradingAgents` debate output with `FirewallService`, enforce limit orders + hard stops, issue a 120s Ed25519 attestation, and verify single-use replay protection. |
|
|
168
|
+
| [`examples/ai_hedge_fund_safe_execution.py`](examples/ai_hedge_fund_safe_execution.py) | Route `virattt/ai-hedge-fund` multi-analyst portfolio decisions through per-sleeve risk rules (`active_trading` vs. `cash_equivalent`) with optional ClearFills Cloud 1-Tap Approval Inbox queuing. |
|
|
169
|
+
| [`examples/claude_mcp_setup.md`](examples/claude_mcp_setup.md) | Copy-paste setup for Claude.ai (OAuth 2.1 Remote MCP), Claude Code (`claude mcp add`), Cursor, and OpenAI Codex CLI. |
|
|
170
|
+
|
|
171
|
+
Run any Python example locally with zero broker credentials:
|
|
172
|
+
```bash
|
|
173
|
+
pip install clearfills
|
|
174
|
+
python examples/tradingagents_safe_execution.py
|
|
175
|
+
python examples/ai_hedge_fund_safe_execution.py
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Per-Sleeve Deterministic Risk Firewall
|
|
181
|
+
|
|
182
|
+
Zero LLM in the approval path. Every `TradeProposal` is routed to a sleeve and evaluated deterministically before a single-use Ed25519 attestation (120s TTL) is signed:
|
|
183
|
+
|
|
184
|
+
| Sleeve | Example Symbols | Stop-Loss | Max Notional | Global Kill-Switch & Daily Loss |
|
|
185
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
186
|
+
| `cash_equivalent` | `SGOV`, `BIL`, `CBIL`, `SHV` | Exempt | $500,000 | Fail-closed enforced |
|
|
187
|
+
| `core_index` | `VT`, `VTI`, `VOO`, `SPY`, `VEQT` | Exempt | $500,000 | Fail-closed enforced |
|
|
188
|
+
| `active_trading` | All other equities / swing | **Required** | $50,000 | Fail-closed enforced |
|
|
189
|
+
|
|
190
|
+
Every decision (`PROPOSAL_APPROVED`, `PROPOSAL_VETOED`, `DISPATCH_ALLOWED`, `DISPATCH_REJECTED`, `KILL_SWITCH_TRIPPED`) appends to a **SHA-256 hash-chained audit ledger**.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Repository Layout
|
|
195
|
+
|
|
196
|
+
- [`src/clearfills`](src/clearfills/): Unified `clearfills` Python package & CLI (`init`, `doctor`, `mcp`, `watch`, `sync`, `validate`, `redteam`, `serve`).
|
|
197
|
+
- [`packages/risk-firewall`](packages/risk-firewall/): Apache-2.0 `clearfills_firewall`, deterministic policy engine, per-sleeve rules, Ed25519 attestation authority, SHA-256 audit ledger, MCP stdio and FastAPI server.
|
|
198
|
+
- [`packages/clearfills-desk`](packages/clearfills-desk/): Apache-2.0 `clearfills_desk`, IBKR execution adapter (`whatIf` previews, delayed-quote metadata, multi-agent `clientId` retry), `clearfills-desk-mcp`, `clearfills sync`, and `clearfills watch`.
|
|
199
|
+
- [`examples/`](examples/): Runnable integration examples for `TradingAgents`, `ai-hedge-fund`, Claude, Cursor, and Codex.
|
|
200
|
+
- [`docs/QUICKSTART.md`](docs/QUICKSTART.md): Concise operator guide covering Portfolio, Inbox, Rules, Lab, and live IBKR setup.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Security & Non-Custodial Guarantee
|
|
205
|
+
|
|
206
|
+
- **Zero credential custody:** AI agents never receive brokerage or banking passwords.
|
|
207
|
+
- **Fail-closed live execution:** Live IBKR requires both `ibkr.allow_live: true` in config and `CLEARFILLS_ALLOW_LIVE=1` in the execution environment, loopback/Tailscale-only transport, and a 50 bps fresh-quote slippage guard on `clearfills watch`.
|
|
208
|
+
- **Software only:** ClearFills is self-directed risk engineering and execution software, not an investment advisor, custodian, or broker-dealer.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# ClearFills
|
|
2
|
+
|
|
3
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
4
|
+
[](https://pypi.org/project/clearfills/)
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](https://clearfills.com)
|
|
7
|
+
[](https://glama.ai/mcp/servers/clearfills/clearfills)
|
|
8
|
+
|
|
9
|
+
**Let AI manage your portfolio. Never give it your broker password.**
|
|
10
|
+
|
|
11
|
+
ClearFills is an open-core execution firewall and MCP server for AI trading agents. Connect Claude, Claude Code, Cursor, Codex, `TradingAgents`, or `ai-hedge-fund` to Interactive Brokers (IBKR), Alpaca, and multi-account portfolios with deterministic Ed25519 pre-trade risk rules and 1-tap human approval.
|
|
12
|
+
|
|
13
|
+
- **Install:** `pip install clearfills` (add `pip install 'clearfills[ibkr]'` for IBKR Gateway execution)
|
|
14
|
+
- **Live Sandbox ($0, 60 seconds):** [https://clearfills.com/console](https://clearfills.com/console)
|
|
15
|
+
- **Hosted Remote MCP (OAuth 2.1 + Bearer):** `https://clearfills-api.fly.dev/mcp`
|
|
16
|
+
- **Documentation:** [clearfills.com/docs](https://clearfills.com/docs) · [docs/QUICKSTART.md](docs/QUICKSTART.md) · [docs/AGENT_INTEGRATION.md](docs/AGENT_INTEGRATION.md)
|
|
17
|
+
- **Machine-Readable Docs:** [llms.txt](https://clearfills.com/llms.txt) · [agents.txt](https://clearfills.com/agents.txt)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Install & Unified CLI
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Core firewall, Python SDK, MCP server, and CLI (zero broker libs)
|
|
25
|
+
pip install clearfills
|
|
26
|
+
|
|
27
|
+
# With IBKR Gateway execution (watch / sync ibkr / mcp --ibkr)
|
|
28
|
+
pip install 'clearfills[ibkr]'
|
|
29
|
+
|
|
30
|
+
# With local FastAPI HTTP firewall server (`clearfills serve`)
|
|
31
|
+
pip install 'clearfills[server]'
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Run the unified `clearfills` CLI right from your terminal:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 1. Verify the firewall in 3 seconds (rogue market order, missing stop, single-use replay)
|
|
38
|
+
clearfills redteam --local
|
|
39
|
+
|
|
40
|
+
# 2. Generate a safe, commented .clearfills.yaml (paper defaults + per-sleeve caps)
|
|
41
|
+
clearfills init
|
|
42
|
+
|
|
43
|
+
# 3. Run 6 diagnostic checks (Python, config, IBKR extra, IB Gateway TCP, Cloud auth, SHA-256 audit)
|
|
44
|
+
clearfills doctor
|
|
45
|
+
|
|
46
|
+
# 4. Run the local stdio MCP server (or add --ibkr for IBKR execution tools)
|
|
47
|
+
clearfills mcp
|
|
48
|
+
|
|
49
|
+
# 5. Watch ClearFills Cloud for 1-Tap Inbox approvals (add --dry-run to test safely)
|
|
50
|
+
CLEARFILLS_API_KEY="cf_sk_..." clearfills watch --dry-run
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## How It Works (3 Steps)
|
|
56
|
+
|
|
57
|
+
1. **Connect read-only:** Sync your balances and holdings from IBKR, SnapTrade, EVM wallets, or statements without handing brokerage passwords to an LLM.
|
|
58
|
+
2. **Enforce hard math:** Every AI trade proposal passes through a deterministic, zero-LLM risk firewall (`clearfills`) that enforces per-sleeve notional caps, mandatory stop-losses, daily loss limits, and a fail-closed kill-switch before minting a single-use 120-second Ed25519 attestation.
|
|
59
|
+
3. **Approve in one tap:** Review attested orders in your ClearFills Inbox and tap **Approve**. Your local `clearfills watch` worker atomically claims the order, checks a fresh live quote (50 bps slippage guard), re-attests, and routes to IBKR or Alpaca.
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
Claude / Codex / Cursor / TradingAgents / ai-hedge-fund
|
|
63
|
+
| (MCP or Python SDK, zero broker passwords)
|
|
64
|
+
v
|
|
65
|
+
ClearFills Cloud & Risk Firewall
|
|
66
|
+
+-------------------------------------+
|
|
67
|
+
| 1. Connect read-only (multi-entity) |
|
|
68
|
+
| 2. Enforce hard math (Ed25519) |
|
|
69
|
+
| 3. Approve in one tap (Inbox) |
|
|
70
|
+
+------------------+------------------+
|
|
71
|
+
| (human clicks Approve)
|
|
72
|
+
v
|
|
73
|
+
clearfills watch (local)
|
|
74
|
+
+-------------------------------------+
|
|
75
|
+
| * Atomic claim + 50 bps guard |
|
|
76
|
+
| * Fresh Ed25519 re-attestation |
|
|
77
|
+
| * IBKR Gateway (loopback/Tailscale) |
|
|
78
|
+
+-------------------------------------+
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 60-Second Quickstart
|
|
84
|
+
|
|
85
|
+
### 1. Try the Live Sandbox ($0)
|
|
86
|
+
1. Sign in at [clearfills.com/console](https://clearfills.com/console) (GitHub or Google).
|
|
87
|
+
2. Click **Launch 60-Second Sandbox Demo** on `Portfolio` to load a sample Personal + Corporate balance sheet and queue an `SGOV` T-bill sweep.
|
|
88
|
+
3. Open `Inbox` and tap **Approve & Execute** to inspect an Ed25519-signed execution receipt and SHA-256 audit trail. Click **Clear Sandbox Data** anytime to connect real accounts.
|
|
89
|
+
|
|
90
|
+
### 2. Connect Your AI Agent via MCP (No `pip install` Required)
|
|
91
|
+
Connect **Claude.ai** (OAuth 2.1), **Claude Code**, **Cursor**, or **Codex** to `https://clearfills-api.fly.dev/mcp`. See the full copy-paste guide in [`examples/claude_mcp_setup.md`](examples/claude_mcp_setup.md).
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Claude Code (Hosted Remote MCP)
|
|
95
|
+
claude mcp add --transport http clearfills https://clearfills-api.fly.dev/mcp \
|
|
96
|
+
--header "Authorization: Bearer cf_sk_..."
|
|
97
|
+
|
|
98
|
+
# Claude Code (Local offline firewall MCP via uvx)
|
|
99
|
+
claude mcp add clearfills -- uvx clearfills mcp
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 3. Python SDK
|
|
103
|
+
```python
|
|
104
|
+
from clearfills import FirewallService, PortfolioSnapshot, RiskPolicy, TradeProposal
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 4. Connect Live or Paper IBKR
|
|
108
|
+
```bash
|
|
109
|
+
# Generate paper or live config
|
|
110
|
+
clearfills init --mode paper
|
|
111
|
+
|
|
112
|
+
# Validate fail-closed config (Paper: port 4002 + DU* | Live: port 4001 + two-key opt-in)
|
|
113
|
+
CLEARFILLS_ALLOW_LIVE=1 clearfills validate --config .clearfills.yaml
|
|
114
|
+
|
|
115
|
+
# Run the local execution daemon for 1-tap Inbox approvals (add --dry-run to test safely)
|
|
116
|
+
CLEARFILLS_ALLOW_LIVE=1 CLEARFILLS_API_KEY="cf_sk_..." \
|
|
117
|
+
clearfills watch --config .clearfills.yaml --dry-run
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Runnable Examples
|
|
123
|
+
|
|
124
|
+
| Example | What It Shows |
|
|
125
|
+
| :--- | :--- |
|
|
126
|
+
| [`examples/tradingagents_safe_execution.py`](examples/tradingagents_safe_execution.py) | Wrap `TauricResearch/TradingAgents` debate output with `FirewallService`, enforce limit orders + hard stops, issue a 120s Ed25519 attestation, and verify single-use replay protection. |
|
|
127
|
+
| [`examples/ai_hedge_fund_safe_execution.py`](examples/ai_hedge_fund_safe_execution.py) | Route `virattt/ai-hedge-fund` multi-analyst portfolio decisions through per-sleeve risk rules (`active_trading` vs. `cash_equivalent`) with optional ClearFills Cloud 1-Tap Approval Inbox queuing. |
|
|
128
|
+
| [`examples/claude_mcp_setup.md`](examples/claude_mcp_setup.md) | Copy-paste setup for Claude.ai (OAuth 2.1 Remote MCP), Claude Code (`claude mcp add`), Cursor, and OpenAI Codex CLI. |
|
|
129
|
+
|
|
130
|
+
Run any Python example locally with zero broker credentials:
|
|
131
|
+
```bash
|
|
132
|
+
pip install clearfills
|
|
133
|
+
python examples/tradingagents_safe_execution.py
|
|
134
|
+
python examples/ai_hedge_fund_safe_execution.py
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Per-Sleeve Deterministic Risk Firewall
|
|
140
|
+
|
|
141
|
+
Zero LLM in the approval path. Every `TradeProposal` is routed to a sleeve and evaluated deterministically before a single-use Ed25519 attestation (120s TTL) is signed:
|
|
142
|
+
|
|
143
|
+
| Sleeve | Example Symbols | Stop-Loss | Max Notional | Global Kill-Switch & Daily Loss |
|
|
144
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
145
|
+
| `cash_equivalent` | `SGOV`, `BIL`, `CBIL`, `SHV` | Exempt | $500,000 | Fail-closed enforced |
|
|
146
|
+
| `core_index` | `VT`, `VTI`, `VOO`, `SPY`, `VEQT` | Exempt | $500,000 | Fail-closed enforced |
|
|
147
|
+
| `active_trading` | All other equities / swing | **Required** | $50,000 | Fail-closed enforced |
|
|
148
|
+
|
|
149
|
+
Every decision (`PROPOSAL_APPROVED`, `PROPOSAL_VETOED`, `DISPATCH_ALLOWED`, `DISPATCH_REJECTED`, `KILL_SWITCH_TRIPPED`) appends to a **SHA-256 hash-chained audit ledger**.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Repository Layout
|
|
154
|
+
|
|
155
|
+
- [`src/clearfills`](src/clearfills/): Unified `clearfills` Python package & CLI (`init`, `doctor`, `mcp`, `watch`, `sync`, `validate`, `redteam`, `serve`).
|
|
156
|
+
- [`packages/risk-firewall`](packages/risk-firewall/): Apache-2.0 `clearfills_firewall`, deterministic policy engine, per-sleeve rules, Ed25519 attestation authority, SHA-256 audit ledger, MCP stdio and FastAPI server.
|
|
157
|
+
- [`packages/clearfills-desk`](packages/clearfills-desk/): Apache-2.0 `clearfills_desk`, IBKR execution adapter (`whatIf` previews, delayed-quote metadata, multi-agent `clientId` retry), `clearfills-desk-mcp`, `clearfills sync`, and `clearfills watch`.
|
|
158
|
+
- [`examples/`](examples/): Runnable integration examples for `TradingAgents`, `ai-hedge-fund`, Claude, Cursor, and Codex.
|
|
159
|
+
- [`docs/QUICKSTART.md`](docs/QUICKSTART.md): Concise operator guide covering Portfolio, Inbox, Rules, Lab, and live IBKR setup.
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Security & Non-Custodial Guarantee
|
|
164
|
+
|
|
165
|
+
- **Zero credential custody:** AI agents never receive brokerage or banking passwords.
|
|
166
|
+
- **Fail-closed live execution:** Live IBKR requires both `ibkr.allow_live: true` in config and `CLEARFILLS_ALLOW_LIVE=1` in the execution environment, loopback/Tailscale-only transport, and a 50 bps fresh-quote slippage guard on `clearfills watch`.
|
|
167
|
+
- **Software only:** ClearFills is self-directed risk engineering and execution software, not an investment advisor, custodian, or broker-dealer.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# ClearFills — Coding Agent Default Integration Kit
|
|
2
|
+
|
|
3
|
+
Drop these snippets into any trading repository so **Claude Code**, **Cursor**, **Codex**, and **Antigravity** automatically route all trading/brokerage actions through the ClearFills deterministic Ed25519 pre-trade risk firewall instead of calling broker SDKs directly.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Project MCP Config (`.mcp.json` / `.cursor/mcp.json`)
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"mcpServers": {
|
|
12
|
+
"clearfills": {
|
|
13
|
+
"command": "uvx",
|
|
14
|
+
"args": ["--from", "clearfills-firewall", "clearfills-firewall-mcp"]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or one-liner for Claude Code:
|
|
21
|
+
```bash
|
|
22
|
+
claude mcp add clearfills -- uvx --from clearfills-firewall clearfills-firewall-mcp
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 2. `CLAUDE.md` / `AGENTS.md` Snippet
|
|
28
|
+
|
|
29
|
+
```markdown
|
|
30
|
+
## Pre-Trade Risk Firewall (ClearFills)
|
|
31
|
+
- **Never** pass raw IBKR, Alpaca, Polymarket, or Kalshi credentials to an LLM loop or submit unattested orders directly to a broker SDK.
|
|
32
|
+
- Always route every trade intent through the `clearfills` MCP server (`propose_trade`) or `clearfills_firewall.FirewallService` first.
|
|
33
|
+
- Require an unexpired, single-use Ed25519 `SignedAttestation` (120s TTL) before dispatching to any venue adapter.
|
|
34
|
+
- If the firewall returns `VETO`, `NONCE_ALREADY_SPENT`, or `KILL_SWITCH_TRIPPED`, halt and report the exact violation code — never split orders to evade risk caps and never retry a spent nonce.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 3. Cursor Rule (`.cursor/rules/clearfills-firewall.mdc`)
|
|
40
|
+
|
|
41
|
+
```markdown
|
|
42
|
+
---
|
|
43
|
+
description: Enforce ClearFills deterministic Ed25519 pre-trade risk firewall for all trading and brokerage code
|
|
44
|
+
globs: ["**/*.py", "**/*.ts", "**/*.tsx"]
|
|
45
|
+
alwaysApply: true
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
When writing or modifying code that proposes or executes trades on IBKR, Alpaca, Polymarket, Kalshi, or paper brokers:
|
|
49
|
+
1. Default to `clearfills-firewall` (`FirewallService` / `clearfills-firewall-mcp`) as the mandatory pre-trade gate.
|
|
50
|
+
2. Never emit unguarded `MKT` orders or orders without protective stops / bounded binary collateral.
|
|
51
|
+
3. Require `SignedAttestation` verification (`dispatch_check`) at the execution gateway boundary.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 4. Live IBKR Two-Key Safety Guard (`clearfills-desk`)
|
|
57
|
+
- Paper mode is restricted to loopback ports `4002`/`7497` and `DU*` accounts.
|
|
58
|
+
- Live mode (`execution_mode: live`) is fail-closed unless **all** conditions hold:
|
|
59
|
+
1. Loopback host (`127.0.0.1`/`localhost`) or explicit `ibkr.allow_tailnet_relay: true` for a Tailscale relay.
|
|
60
|
+
2. Live port (`4001`/`7496`) and explicit non-`DU` live `account_id` verified against `managedAccounts()`.
|
|
61
|
+
3. Two-key opt-in: `ibkr.allow_live: true` in YAML **and** `CLEARFILLS_ALLOW_LIVE=1` in the environment.
|
|
62
|
+
4. Valid single-use Ed25519 `SignedAttestation` verified via `dispatch_check()` before any IBKR API call.
|