> ## Documentation Index
> Fetch the complete documentation index at: https://mathematicalcompany.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Whale Copy-Trading Bot

> Score wallets, pick the best, and copy their trades at configurable scale.

<Note>**Pro Feature.** Requires a Pro or Ultra subscription. [Get started at api.mathematicalcompany.com](https://api.mathematicalcompany.com)</Note>

Score multiple wallets, select the highest-performing one, and automatically copy their trades with position sizing scaled to your bankroll.

## Full Code

```python theme={null}
"""Whale copy-trading: score wallets and copy the best."""

import horizon as hz
from horizon.context import FeedData

# ── Score candidate wallets ──
candidates = [
    "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
    "0x1234567890abcdef1234567890abcdef12345678",
    "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd",
]

print("Scoring wallets...")
scores = []
for addr in candidates:
    score = hz.score_wallet(addr)
    scores.append((addr, score))
    print(f"  {addr[:10]}... → {score.composite:.0f}/100 (win={score.win_rate:.0%})")

# Pick the best
scores.sort(key=lambda x: x[1].composite, reverse=True)
target_addr, target_score = scores[0]
print(f"\nTarget: {target_addr[:10]}... (score={target_score.composite:.0f})")

# ── Copy trades ──
config = hz.CopyTraderConfig(
    wallet_address=target_addr,
    size_scale=0.5,         # trade at 50% of whale's size
    max_position=50.0,
    delay_seconds=2.0,      # wait 2s after whale trades
    markets=["election-winner", "btc-100k"],
)

results = hz.copy_trades(config)
for r in results:
    print(f"  Copied: {r.side} {r.size:.0f} @ {r.price:.4f} on {r.market_id}")
```

## Pipeline Mode

Run the copy trader continuously inside `hz.run()`:

```python theme={null}
"""Continuous copy trading inside a live pipeline."""

import horizon as hz
from horizon.context import FeedData


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


# Copy trader pipeline function
copier = hz.copy_trader(
    wallet_address="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
    size_scale=0.5,
    max_position=50.0,
    delay_seconds=2.0,
)

hz.run(
    name="whale_copier",
    markets=["election-winner"],
    feeds={
        "polymarket": hz.PolymarketBook("election-winner"),
    },
    pipeline=[fair_value, copier],
    risk=hz.Risk(max_position=100, max_drawdown_pct=5),
    interval=2.0,
    mode="paper",
)
```

## How It Works

1. **`score_wallet()`** evaluates each candidate on win rate, ROI, Sharpe, and consistency
2. **`CopyTraderConfig`** configures the copy parameters:

* `size_scale` - fraction of whale's size to replicate (0.5 = half size)
* `delay_seconds` - wait before copying to avoid front-running detection
* `max_position` - hard cap on your position per market

3. **`copy_trades()`** fetches the whale's recent trades and replicates them
4. **`copy_trader()`** wraps this as a pipeline function for continuous operation

## Run It

```bash theme={null}
python examples/whale_copy_trader.py
```

## Inverse Mode

Fade a low-scoring wallet by taking the opposite side of their trades:

```python theme={null}
"""Reverse copy: fade a bad trader."""

import horizon as hz

# Find a wallet with exploitable patterns
analysis = hz.analyze_wallet("0xabcdefabcdefabcdefabcdefabcdefabcdefabcd")
if analysis.is_exploitable:
    print(f"Exploitable: {analysis.primary_strategy}")

    # Reverse copy: trade opposite to the bad wallet
    fader = hz.reverse_copy(
        wallet_address="0xabcdefabcdefabcdefabcdefabcdefabcdefabcd",
        size_scale=0.3,
        max_position=30.0,
    )

    # Or as a pipeline function
    fader_pipe = hz.reverse_copier(
        wallet_address="0xabcdefabcdefabcdefabcdefabcdefabcdefabcd",
        size_scale=0.3,
        max_position=30.0,
    )
```

See [Copy Trading](/copy-trading) and [Wallet Intelligence](/wallet-intelligence) for the full reference.
