Skip to main content
Ultra Feature. Requires an Ultra subscription. Get started at api.mathematicalcompany.com
Execute large orders without moving the market. Estimate impact first, then choose from Adaptive TWAP, Iceberg Plus, or Sniper algorithms - or let the system pick automatically.

Full Code

"""Stealth execution: estimate impact and execute with minimal footprint."""

import horizon as hz

engine = hz.Engine()
engine.start_feed("polymarket", "polymarket_book", config_json='{"condition_id": "election-winner"}')

# ── Step 1: Estimate market impact ──
impact = hz.estimate_impact(
    engine,
    market_id="election-winner",
    side=hz.Side.Yes,
    size=500.0,
    feed_name="polymarket",
)

print(f"Impact Estimate:")
print(f"  Expected slippage:  {impact.expected_slippage_bps:.1f} bps")
print(f"  Price impact:       {impact.price_impact:.4f}")
print(f"  Estimated cost:     ${impact.estimated_cost:.2f}")
print(f"  Recommended algo:   {impact.recommended_algo}")
print(f"  Completion time:    {impact.estimated_time_seconds:.0f}s")

# ── Step 2: Auto-execute with best algorithm ──
result = hz.stealth_execute(
    engine,
    market_id="election-winner",
    side=hz.Side.Yes,
    order_side=hz.OrderSide.Buy,
    size=500.0,
    price=0.55,
    feed_name="polymarket",
    strategy="auto",       # auto-selects best algorithm
)

print(f"\nExecution Result:")
print(f"  Algorithm used:     {result.algorithm}")
print(f"  Filled:             {result.total_filled:.0f} contracts")
print(f"  Avg price:          {result.avg_fill_price:.4f}")
print(f"  Slippage:           {result.actual_slippage_bps:.1f} bps")
print(f"  Child orders:       {result.num_child_orders}")

Manual Algorithm Selection

Choose a specific stealth algorithm for fine-grained control:
"""Manual stealth algorithms."""

import horizon as hz

engine = hz.Engine()

# ── Adaptive TWAP: time-sliced with randomization ──
twap = hz.AdaptiveTWAP(
    engine,
    duration_secs=300,     # 5 minutes
    num_slices=20,
    randomize_timing=True, # ±20% jitter on slice timing
    randomize_size=True,   # ±30% jitter on slice size
)

# ── Iceberg Plus: hidden size with smart repricing ──
iceberg = hz.IcebergPlus(
    engine,
    show_size=10.0,
    reprice_on_move=True,  # adjust price when market moves
    max_drift=0.02,        # reprice if market moves >2 cents
)

# ── Sniper: wait for favorable moments to strike ──
sniper = hz.SniperAlgo(
    engine,
    patience_seconds=60,   # wait up to 60s for good price
    max_spread=0.03,       # only execute when spread < 3 cents
    min_size_available=20, # need 20+ contracts at target price
)

Configuration

Use StealthConfig for detailed control over execution parameters:
config = hz.StealthConfig(
    max_participation_rate=0.15,   # never exceed 15% of volume
    randomize_timing=True,
    randomize_size=True,
    max_impact_bps=50,             # abort if impact exceeds 50 bps
    cool_off_seconds=5,            # pause between child orders
)

result = hz.stealth_execute(
    engine,
    market_id="election-winner",
    side=hz.Side.Yes,
    order_side=hz.OrderSide.Buy,
    size=500.0,
    price=0.55,
    feed_name="polymarket",
    strategy="adaptive_twap",
    config=config,
)

Pipeline Mode

Run stealth execution from within a live strategy:
"""Stealth executor as a pipeline function."""

import horizon as hz
from horizon.context import FeedData


def fair_value(ctx: hz.Context) -> float:
    feed = ctx.feeds.get("polymarket", FeedData())
    return feed.price if feed.price > 0 else 0.50


def signal(ctx: hz.Context, fair: float) -> None:
    """When strong signal detected, queue a stealth order."""
    book = ctx.feeds.get("polymarket", FeedData())
    market_price = book.price if book.price > 0 else 0.50
    edge = fair - market_price

    if edge > 0.05:  # 5+ cent edge
        ctx.params["stealth_requests"] = [{
            "market_id": "election-winner",
            "side": "yes",
            "size": 200.0,
            "price": market_price + 0.01,
        }]


executor = hz.stealth_executor(
    strategy="auto",
    config=hz.StealthConfig(max_impact_bps=30),
)

hz.run(
    name="stealth_strategy",
    markets=["election-winner"],
    feeds={"polymarket": hz.PolymarketBook("election-winner")},
    pipeline=[fair_value, signal, executor],
    risk=hz.Risk(max_position=500, max_drawdown_pct=5),
    interval=1.0,
    mode="paper",
)

Run It

python examples/stealth_large_order.py
See Stealth Execution for the full reference.