Skip to content

Commit 2dad940

Browse files
authored
Follow-up: clarify market-data health readiness semantics (#6)
* Clarify /market-data/health readiness semantics in README * Remove pysha3 dependency to fix Ubuntu Py3.11 CI builds * Stabilize market-data adapter init/reconcile and guard dependency-review on forks * Fix Windows install by removing pysha3-prone dependency * Fix discover-subscribe/reconcile adapter wiring and add integration coverage * Add debug config endpoint and webhook decision tracing
1 parent c0c1102 commit 2dad940

49 files changed

Lines changed: 540 additions & 8145 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/dependency-review.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ permissions:
2525

2626
jobs:
2727
dependency-review:
28+
if: ${{ github.event.pull_request.head.repo.fork == false }}
2829
runs-on: ubuntu-latest
2930
steps:
3031
- name: 'Checkout repository'
3132
uses: actions/checkout@v4
3233
- name: 'Dependency Review'
3334
uses: actions/dependency-review-action@v4
3435
# Commonly enabled options, see https://github.com/actions/dependency-review-action#configuration-options for all available options.
35-
with:
36-
comment-summary-in-pr: always
36+
# Avoid PR comment write requirement that often fails on restricted tokens/forks
3737
# fail-on-severity: moderate
3838
# deny-licenses: GPL-1.0-or-later, LGPL-2.0-or-later
3939
# retry-on-snapshot-warnings: true

.github/workflows/python-app.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,20 @@ permissions:
1313
contents: read
1414

1515
jobs:
16-
build:
16+
tests:
1717

1818
runs-on: ubuntu-latest
1919

2020
steps:
2121
- uses: actions/checkout@v4
22-
- name: Set up Python 3.9
23-
uses: actions/setup-python@v3
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
2424
with:
25-
python-version: "3.9"
25+
python-version: "3.11"
26+
cache: "pip"
2627
- name: Install dependencies
2728
run: |
2829
python -m pip install --upgrade pip
29-
pip install black pytest
30-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31-
- name: Lint with black
32-
run: |
33-
black .
34-
- name: Test with unittest
35-
run: |
36-
python -m unittest discover
30+
pip install -r requirements.txt
31+
- name: Run tests
32+
run: pytest -q

.gitignore

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
logs/
1+
# Runtime logs / state
2+
logs/
23
*.log
4+
*.pid
5+
6+
# Local environments / caches
7+
.venv/
8+
venv/
9+
__pycache__/
10+
*.py[cod]
11+
.pytest_cache/
12+
13+
# Local secrets / credentials
14+
.env
15+
.env.*
16+
!.env.example
17+
gdrive_credentials.json
18+
oauth_credentials.json
19+
*.pem
20+
*.key
21+
*.p12
22+
23+
# Runtime trade artifacts
24+
archive/
325
paper_trades*.jsonl
426
paper_decisions*.jsonl
527
pending_confirmations.json
628
position_state.json
729
out.json
30+
31+
# Keep test fixtures
32+
!tests/**/*.jsonl
33+
data/risk_state.json

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,59 @@ This repo is inteded for use with Python 3.9
157157
./scripts/bash/run-docker-dev.sh
158158
```
159159

160+
161+
## Trading bot safety & verification
162+
163+
### Required environment variables
164+
165+
Use environment variables for credentials and **never commit secrets** to git:
166+
167+
- `POLYGON_WALLET_PRIVATE_KEY`
168+
- `OPENAI_API_KEY`
169+
- `CLOB_API_KEY` / `CLOB_SECRET` (if live CLOB auth is used)
170+
171+
Use `.env.example` as template and keep `.env` local only.
172+
173+
### Feature flags (safe defaults)
174+
175+
Core optional runtime paths are feature-flagged and should remain disabled unless explicitly testing:
176+
177+
- `MARKET_DATA_WS_ENABLED=0` (disable WS stream; default flow keeps running via existing path)
178+
- `MARKET_DATA_RTDS_ENABLED=0` (disable RTDS stream)
179+
- `DEBUG_ENDPOINTS_ENABLED=0` (disable admin/debug endpoints)
180+
181+
Boolean env values are parsed robustly (`0/1`, `true/false`, `yes/no`).
182+
183+
### Verification commands
184+
185+
Run these checks locally before deploying:
186+
187+
```bash
188+
pytest -q
189+
curl -s http://127.0.0.1:5000/market-data/metrics
190+
curl -s http://127.0.0.1:5000/market-data/health
191+
```
192+
193+
For a default safety smoke test, run with flags off:
194+
195+
```bash
196+
export MARKET_DATA_WS_ENABLED=0
197+
export MARKET_DATA_RTDS_ENABLED=0
198+
python agents/application/trade.py
199+
```
200+
201+
### Health endpoint semantics (`/market-data/health`)
202+
203+
`/market-data/health` is a **trading-readiness** health, not just process liveness:
204+
205+
- `ok=true` means market-data path is considered ready for trading decisions.
206+
- `ok=false` can be expected in offline/dev scenarios (e.g., no live WS traffic yet), even when the app process is stable.
207+
- `ws_connected` indicates websocket connectivity status.
208+
- `last_msg_age_s` indicates freshness of most recent market-data message.
209+
- `active_subscriptions` indicates current adapter subscription count.
210+
211+
For operational monitoring, treat API reachability + `/market-data/metrics` availability as process-level health, and `/market-data/health.ok` as readiness-to-trade.
212+
160213
## Architecture
161214

162215
The Polymarket Agents architecture features modular components that can be maintained and extended by individual community members.

agents/application/risk_manager.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,21 @@ def check_entry_allowed(
289289
now = now_ts or time.time()
290290
if getattr(settings, "KILL_SWITCH_ENABLED", False):
291291
if self.kill_switch_until_ts and now < float(self.kill_switch_until_ts):
292-
telemetry.set_gauge("market_data_kill_switch_active", 1)
293-
return False, "kill_switch_cooldown", {**details, "kill_switch_until": self.kill_switch_until_ts}
292+
# Guard against stale persisted cooldown from unrelated runs:
293+
# when no recent closed trades exist, clear stale cooldown and continue.
294+
recent = []
295+
try:
296+
recent = self._recent_closed_trades()[: int(settings.KILL_SWITCH_LOOKBACK_CLOSED)]
297+
except Exception:
298+
recent = []
299+
if not recent:
300+
try:
301+
self._clear_risk_state()
302+
except Exception:
303+
pass
304+
else:
305+
telemetry.set_gauge("market_data_kill_switch_active", 1)
306+
return False, "kill_switch_cooldown", {**details, "kill_switch_until": self.kill_switch_until_ts}
294307
# if cooldown expired, clear state
295308
if self.kill_switch_until_ts and now >= float(self.kill_switch_until_ts):
296309
try:

archive/stats_20260212_154030/paper_trades.jsonl

Whitespace-only changes.

archive/stats_20260212_154030/paper_trades_legacy.jsonl

Lines changed: 0 additions & 2 deletions
This file was deleted.

archive/stats_20260212_154030/paper_trades_legacy_20260208_180353.jsonl

Lines changed: 0 additions & 2 deletions
This file was deleted.

archive/stats_20260212_154030/paper_trades_legacy_20260209_070020.jsonl

Lines changed: 0 additions & 2 deletions
This file was deleted.

archive/stats_20260212_154030/paper_trades_legacy_20260209_123751.jsonl

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)