Polymarket trading

From Niller2005/PolyFlup · View interactive version

Polymarket trading is an AI agent skill from the GitHub repository Niller2005/PolyFlup. Polymarket-specific terminology, trading strategies, and API reference.

How to use this skill

Skill file

Terminology & Concepts

Strategy Nuances

Atomic Hedging Execution (v0.6.0+)

Overview: The bot places entry+hedge pairs simultaneously to guarantee profit structure.

Batch Placement:

orders = [
    {"token_id": entry_token, "price": entry_price, "side": BUY, "post_only": use_post_only},
    {"token_id": hedge_token, "price": hedge_price, "side": BUY, "post_only": use_post_only}
]
# Both submitted in single API call
results = place_batch_orders(orders)

Combined Price Constraint:

POST_ONLY → GTC Fallback (Bug #10 Fix):

Fill Monitoring:

Emergency Liquidation (Partial Fill Recovery):

Pre-Settlement Exit (Confidence-Based):

Confidence Calculation Methods (v0.5.0+)

The bot supports two confidence calculation methods for A/B testing:

Additive Method (Default):

Bayesian Method (Alternative):

```python

evidence = (score - 0.5) × 2 # Scale to -1 to +1

log_LR = evidence × 3.0 × quality # Quality factor (0.7-1.5x)

log_odds += log_LR × weight

confidence = 1 / (1 + exp(-log_odds))

```

A/B Testing:

```sql

SELECT

AVG(CASE WHEN bias='UP' THEN edge ELSE -edge END) as avg_edge,

COUNT(*) as total,

SUM(CASE WHEN result='WIN' THEN 1 ELSE 0 END) as wins,

CAST(wins AS REAL) / COUNT(*) as win_rate

FROM trades

WHERE settled = 1

GROUP BY method;

```

Technical Requirements

Fees & Rebates (Crypto Markets, CLOB V2)

Source: https://docs.polymarket.com/trading/fees (verified 2026-10-27). Supersedes the older flat "1.54% taker / 0.15% rebate" notes.

CLOB V2 (live 2026-04-28)

Polymarket hard-cut over to CLOB V2. The old py-clob-client stopped working against production (V1-signed orders rejected, repo archived). PolyFlup uses py-clob-client-v2 (from py_clob_client_v2 import ...).

5-Minute Markets

Slug {asset}-updown-5m-{window_start_unix} (same Gamma/CLOB/fee/redeem behavior as 15m: min size 5, tick 0.01, CTF "v1" positions, crypto_fees_v2 0.07 rate). Enabled per market in MARKETS with a -5M suffix (BTC-5M); that key is the symbol stored in the DB. src/markets.py: parse_market, asset_of, window_bounds, slug_for, parse_slug, scale_seconds.

Strategy Notes (fee-aware)

Data API v2 (v1 retired 2026-10-24)

Base https://data-api.polymarket.com/v2/.... Responses are {"data": [...], "pagination": {"next_cursor": ...}} with snake_case keys. Follow next_cursor; offset and market= return 400 (use condition=).

Terminal Dashboard

uv run tui.py (src/tui/): read-only Rich dashboard (open positions with live midpoints, performance, recent trades, log tail). Keys q quit, r refresh, p pause. --db PATH inspects a downloaded production DB, --once renders a single frame, --no-wallet skips the balance lookup. It opens the DB with mode=ro, so it is safe to run next to the bot.

Common Code Patterns

Market Data

from src.trading.orders import get_midpoint, get_spread, check_liquidity
# Get accurate midpoint price
price = get_midpoint(token_id)
# Check if liquidity is good
if check_liquidity(token_id, size=100, warn_threshold=0.05):
    # Safe to trade

Order Placement

from src.trading.orders import place_batch_orders, place_market_order
# Atomic Batch Orders (Entry + Hedge)
orders = [
    {"token_id": entry_token, "price": 0.68, "side": "BUY", "size": 50.0, "post_only": True},
    {"token_id": hedge_token, "price": 0.31, "side": "BUY", "size": 50.0, "post_only": True}
]
results = place_batch_orders(orders)
# Market Sell (for emergency liquidation)
result = place_market_order(token_id, amount=10.0, side="SELL", order_type="FAK")

Standard Emoji Guide

Position Monitoring

Position Status (Atomic Hedging)

Order Lifecycle

Risk Management

System

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.