---
title: "MCP Portfolio Assistant"
description: "Use the Horizon MCP server to build an AI-powered portfolio management workflow in Claude Code."
icon: "wand-magic-sparkles"
---

This example shows a complete workflow using the Horizon MCP server through Claude Code: discovering markets, analyzing opportunities with Kelly criterion, placing trades, setting protective orders, and monitoring positions  - all through natural language.

## Setup

```bash
# Install
pip install horizon-sdk[mcp]

# Register with Claude Code
export HORIZON_API_KEY="your-key"
claude mcp add --transport stdio horizon -- python -m horizon.mcp
```

## The Workflow

### 1. Morning scan  - discover markets

```
You: Find me active bitcoin markets on Polymarket with recent activity
```

Claude calls `discover_markets(exchange="polymarket", query="bitcoin", limit=10)` and returns:

```
Found 6 active BTC markets on Polymarket:

1. will-btc-hit-100k  - "Will BTC hit $100k by March 2026?"
2. will-btc-hit-120k  - "Will BTC hit $120k by March 2026?"
3. btc-above-90k-feb  - "Will BTC close above $90k in February?"
4. btc-dominance-60  - "Will BTC dominance exceed 60%?"
5. btc-etf-outflows  - "Will BTC ETFs see net outflows this week?"
6. btc-halving-price  - "BTC price on next halving anniversary"
```

### 2. Analyze opportunity  - Kelly sizing

```
You: I think there's a 72% chance BTC hits 100k by March.
     The market is at 58 cents. My bankroll is $5,000.
     How much should I buy?
```

Claude calls `kelly_sizing(prob=0.72, price=0.58, bankroll=5000.0, fraction=0.25, max_size=200.0)`:

```
Kelly analysis for your BTC $100k thesis:

Edge: +14 cents (your 72% vs market's 58%)
Quarter Kelly optimal: 200 contracts (capped at max_size)

Breakdown:
  - Full Kelly fraction: 33.3% of bankroll
  - Quarter Kelly: 8.3% → $416 risked
  - At $0.58/contract: ~717 contracts uncapped
  - Capped at 200 contracts → $116 risk

The edge is strong. Quarter Kelly at 200 contracts is conservative
and well within risk limits.

Want me to place the order?
```

### 3. Place the trade

```
You: Yes, buy 200 contracts at 0.58
```

Claude calls `submit_order(market_id="will-btc-hit-100k", side="buy", price=0.58, size=200.0)`:

```
Order submitted:
  Order ID: p1
  Market: will-btc-hit-100k
  Side: buy
  Price: 0.58
  Size: 200 contracts
```

### 4. Add protection

```
You: Set a stop-loss at 0.40 and take-profit at 0.80 for that position
```

Claude calls `add_stop_loss(...)` and `add_take_profit(...)`:

```
Protection set:

Stop-loss:
  Trigger: 0.40 (sell 200 YES contracts)
  Max loss if triggered: ~$36

Take-profit:
  Trigger: 0.80 (sell 200 YES contracts)
  Profit if triggered: ~$44

Your position is now bracketed. The stop-loss and take-profit
will fire automatically when the market price hits those levels.
```

### 5. Check the portfolio

```
You: Show me everything  - positions, orders, pending stops
```

Claude calls `engine_status()`, `list_positions()`, `list_open_orders()`, and `list_contingent_orders()`:

```
Engine Status:
  Running: yes | Kill switch: off | Uptime: 12 min
  Daily PnL: -$0.20

Positions (1):
  will-btc-hit-100k: 200 YES @ 0.58
    Unrealized: -$0.20 | Exchange: paper

Open Orders (0):
  All filled.

Contingent Orders (2):
  1. Stop-loss: sell 200 YES @ 0.40 (pending)
  2. Take-profit: sell 200 YES @ 0.80 (pending)
```

### 6. Second market  - scan Kalshi

```
You: Are there similar BTC markets on Kalshi? Look for KXBTC
```

Claude calls `discover_markets(exchange="kalshi", query="KXBTC", limit=5)`:

```
Found 3 BTC markets on Kalshi:

1. KXBTC-26MAR31  - "BTC above $100k on March 31"
2. KXBTC-26FEB28  - "BTC above $95k on Feb 28"
3. KXBTC-26APR30  - "BTC above $110k on April 30"

KXBTC-26MAR31 looks like a direct analog to your Polymarket
position. If there's a price gap, that could be an arb.
```

### 7. End of day  - close out

```
You: Cancel all my open orders and show me final PnL
```

Claude calls `cancel_all_orders()` then `engine_status()`:

```
Canceled 0 orders (none were open).

Final status:
  Realized PnL: $0.00
  Unrealized PnL: +$4.00
  Daily PnL: +$4.00

Your will-btc-hit-100k position is up $4 on 200 contracts.
Stop-loss and take-profit are still armed.
```

## Full Session as a Script

For reproducibility, here's what the tool calls looked like:

```python
"""Equivalent Python code for the MCP session above."""

from horizon import tools

# 1. Discover
markets = tools.discover("polymarket", "bitcoin", limit=10)

# 2. Kelly sizing
sizing = tools.kelly_sizing(prob=0.72, price=0.58, bankroll=5000.0)
print(f"Optimal size: {sizing['optimal_size']} contracts")

# 3. Trade
order = tools.submit_order("will-btc-hit-100k", "buy", 0.58, 50.0)
print(f"Order ID: {order['order_id']}")

# 4. Protect
tools.add_stop_loss("will-btc-hit-100k", "yes", "sell", 50.0, 0.40)
tools.add_take_profit("will-btc-hit-100k", "yes", "sell", 50.0, 0.80)

# 5. Check
status = tools.engine_status()
positions = tools.list_positions()
contingent = tools.list_contingent_orders()

# 6. Discover Kalshi
kalshi_markets = tools.discover("kalshi", "KXBTC", limit=5)

# 7. Close out
tools.cancel_all_orders()
final = tools.engine_status()
print(f"Daily PnL: ${final['daily_pnl']:.2f}")
```

## Next Steps

<CardGroup cols={2}>
  <Card title="MCP Server Reference" icon="server" href="/integrations/mcp-server">
    Full tool and resource documentation.
  </Card>
  <Card title="Claude Code Setup" icon="terminal" href="/integrations/claude-code">
    Detailed setup instructions.
  </Card>
  <Card title="Kelly Sizing" icon="calculator" href="/examples/kelly-sizing">
    Deep dive into Kelly criterion functions.
  </Card>
  <Card title="Hedge Fund Workflow" icon="building-columns" href="/examples/hedge-fund-workflow">
    Full production deployment example.
  </Card>
</CardGroup>
