Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/enforce-seren-polymarket-publisher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Enforce Seren Polymarket Publisher

on:
pull_request:
paths:
- "polymarket/**"
- ".github/workflows/enforce-seren-polymarket-publisher.yml"
push:
branches:
- main
paths:
- "polymarket/**"
- ".github/workflows/enforce-seren-polymarket-publisher.yml"

jobs:
enforce-publisher:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Block direct Polymarket API endpoints in maker runtimes/configs
run: |
set -euo pipefail
TARGETS=(
polymarket/maker-rebate-bot
polymarket/paired-market-basis-maker
polymarket/liquidity-paired-basis-maker
polymarket/high-throughput-paired-basis-maker
)
if grep -R -nE "https://(gamma-api|clob)\.polymarket\.com" "${TARGETS[@]}"; then
echo "::error::Direct Polymarket API endpoints are forbidden. Use api.serendb.com publisher routes only."
exit 1
fi

- name: Require Seren Polymarket Publisher endpoints in maker configs
run: |
set -euo pipefail
CONFIGS=(
polymarket/maker-rebate-bot/config.example.json
polymarket/paired-market-basis-maker/config.example.json
polymarket/liquidity-paired-basis-maker/config.example.json
polymarket/high-throughput-paired-basis-maker/config.example.json
)
for cfg in "${CONFIGS[@]}"; do
if ! grep -qE "https://api\.serendb\.com/publishers/polymarket-data/" "$cfg"; then
echo "::error file=$cfg::Missing Seren Polymarket publisher endpoint."
exit 1
fi
done

- name: Require runtime source-policy guard in maker scripts
run: |
set -euo pipefail
SCRIPTS=(
polymarket/maker-rebate-bot/scripts/agent.py
polymarket/paired-market-basis-maker/scripts/agent.py
polymarket/liquidity-paired-basis-maker/scripts/agent.py
polymarket/high-throughput-paired-basis-maker/scripts/agent.py
)
for script in "${SCRIPTS[@]}"; do
if ! grep -q "SEREN_POLYMARKET_PUBLISHER_PREFIX" "$script"; then
echo "::error file=$script::Missing SEREN_POLYMARKET_PUBLISHER_PREFIX runtime guard."
exit 1
fi
if ! grep -q "policy_violation: backtest data source must use Seren Polymarket publisher" "$script"; then
echo "::error file=$script::Missing explicit policy_violation guard for non-Seren backtest URLs."
exit 1
fi
if ! grep -q "missing_seren_api_key: set SEREN_API_KEY" "$script"; then
echo "::error file=$script::Missing SEREN_API_KEY hard requirement for publisher calls."
exit 1
fi
if ! grep -q '"Authorization": f"Bearer {api_key}"' "$script"; then
echo "::error file=$script::Missing Authorization Bearer header for publisher calls."
exit 1
fi
done
62 changes: 62 additions & 0 deletions polymarket/high-throughput-paired-basis-maker/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
name: high-throughput-paired-basis-maker
description: "Run a paired-market basis strategy on Polymarket with mandatory backtest-first gating before trade intents."
---

# High-Throughput Paired Basis Maker

## When to Use

- trade relative-value dislocations between logically linked Polymarket contracts
- enforce backtest-first validation before generating paired trade intents
- run a dry-run-first workflow for hedged pair execution

## Backtest Period

- Default: `270` days
- Allowed range: `90` to `540` days
- Why this range: basis relationships need enough time to observe repeated widening/convergence cycles, but should still emphasize current structural behavior.

## Workflow Summary

1. `load_backtest_pairs` pulls live market histories from the Seren Polymarket Publisher (Gamma + CLOB proxied), builds pairs from the active market universe, and timestamp-aligns each pair.
2. `simulate_basis_reversion` evaluates entry/exit behavior on basis widening and convergence.
3. `summarize_backtest` reports total return, annualized return, Sharpe-like score, max drawdown, hit rate, trade-rate, and pair-level contributions.
4. `sample_gate` fails backtest if `events < backtest.min_events` (default `200`).
5. `backtest_gate` blocks trade mode by default if backtest return is non-positive.
6. `emit_pair_trades` outputs two-leg trade intents (`primary` + `pair`) with risk caps.

## Execution Modes

- `backtest` (default): paired historical simulation only.
- `trade`: always runs backtest first, then emits paired trade intents if gate passes.

Live execution requires both:

- `execution.live_mode=true` in config
- `--yes-live` on the CLI

## Runtime Files

- `scripts/agent.py` - basis backtest + paired trade-intent runtime
- `config.example.json` - strategy parameters, live backtest defaults, and trade-mode sample markets
- `.env.example` - environment template for API credentials

## Quick Start

```bash
cd polymarket/high-throughput-paired-basis-maker
cp .env.example .env
cp config.example.json config.json
python3 scripts/agent.py --config config.json
```

## Run Trade Mode (Backtest-First)

```bash
python3 scripts/agent.py --config config.json --run-type trade
```

## Disclaimer

This skill can lose money. Basis spreads can persist or widen, hedge legs can slip, and liquidity can fail during volatility. Backtests are hypothetical and do not guarantee future results. This skill is software tooling and not financial advice. Use dry-run first and only trade with risk capital.
74 changes: 74 additions & 0 deletions polymarket/high-throughput-paired-basis-maker/config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"skill": "high-throughput-paired-basis-maker",
"execution": {
"dry_run": true,
"live_mode": false,
"require_positive_backtest": true
},
"backtest": {
"days": 270,
"days_range": {
"min": 90,
"max": 540
},
"participation_rate": 0.9,
"min_history_points": 72,
"min_events": 200,
"min_liquidity_usd": 5000,
"markets_fetch_page_size": 500,
"max_markets": 0,
"history_interval": "max",
"history_fidelity_minutes": 60,
"history_fetch_workers": 12,
"gamma_markets_url": "https://api.serendb.com/publishers/polymarket-data/markets",
"clob_history_url": "https://api.serendb.com/publishers/polymarket-data/prices-history"
},
"strategy": {
"bankroll_usd": 500,
"pairs_max": 6,
"min_seconds_to_resolution": 7200,
"min_edge_bps": 2.0,
"maker_rebate_bps": 2.3,
"expected_unwind_cost_bps": 1.5,
"adverse_selection_bps": 1.1,
"basis_entry_bps": 35,
"basis_exit_bps": 10,
"expected_convergence_ratio": 0.35,
"base_pair_notional_usd": 350,
"max_notional_per_pair_usd": 420,
"max_total_notional_usd": 1200,
"max_leg_notional_usd": 450
},
"state": {
"leg_exposure": {
"US-RECESSION-2026": 40,
"US-GDP-CONTRACTION-2026": -34
}
},
"markets": [
{
"market_id": "US-RECESSION-2026",
"pair_market_id": "US-GDP-CONTRACTION-2026",
"mid_price": 0.44,
"pair_mid_price": 0.39,
"seconds_to_resolution": 345600,
"basis_volatility_bps": 88
},
{
"market_id": "US-CPI-HOTTER-THAN-4",
"pair_market_id": "US-INFLATION-STICKY-4",
"mid_price": 0.36,
"pair_mid_price": 0.355,
"seconds_to_resolution": 259200,
"basis_volatility_bps": 41
},
{
"market_id": "FED-CUT-BEFORE-JULY",
"pair_market_id": "FED-HOLD-THROUGH-JULY",
"mid_price": 0.52,
"pair_mid_price": 0.47,
"seconds_to_resolution": 432000,
"basis_volatility_bps": 77
}
]
}
Loading