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

# Market making

> Run QuoteEngine safely with paper mode, inventory limits, spreads, bias, and operational checks.

QuoteEngine is the SimpleFunctions automated quoting workflow. It maintains bid/ask quotes for a prediction-market contract, adjusts around mid-price movement, applies inventory and exposure limits, and can run in paper mode before live execution.

Use this page for operational setup. Use [Real-Time Data API](/reference/realtime-data) when you want to build your own market-making system from raw orderbooks, trades, candles, and movers.

<Warning>
  QuoteEngine can place and cancel real orders when trading credentials and live execution are enabled. Start with `--paper`, inspect status, and keep limits small until the behavior is understood.
</Warning>

## Mental model

| Component      | Role                                                                                                           |
| -------------- | -------------------------------------------------------------------------------------------------------------- |
| Quote          | One configured market-making instruction for a ticker or Polymarket token.                                     |
| QuoteEngine    | Local daemon that refreshes market data, computes quote levels, places/cancels orders, and tracks state.       |
| Spread         | Base distance between bid and ask, in cents. Wider spread reduces adverse-selection risk but lowers fill rate. |
| Inventory skew | Moves quotes away from inventory you already hold, so the engine does not keep adding the same exposure.       |
| Bias           | Manual or thesis-driven directional lean, in cents. Positive bias is bullish; negative bias is bearish.        |
| Fade           | Temporary spread widening after a fill, then decay back toward the configured spread.                          |
| Paper mode     | Simulated fills from live data. No live orders. Use for onboarding and dry runs.                               |

## First safe run

Start with paper mode and tight limits:

```bash theme={null}
sf quote create KXRATECUT-26DEC31 \
  --paper \
  --spread 3 \
  --size 5 \
  --max-long 25 \
  --max-short 25 \
  --max-exposure 20 \
  --stop-loss 5 \
  --layers 1
```

Inspect the configured quote:

```bash theme={null}
sf quote list --json
sf quoteengine status --json
```

Start the engine in the foreground while testing:

```bash theme={null}
sf quoteengine start
```

After the behavior is understood, run it as a daemon:

```bash theme={null}
sf quoteengine start --daemon
sf quoteengine status --json
```

Stop the engine and cancel active quote orders:

```bash theme={null}
sf quoteengine stop
```

## Quote creation flags

```bash theme={null}
sf quote create <ticker> [options]
```

| Flag                   | Use                                                                                   |
| ---------------------- | ------------------------------------------------------------------------------------- |
| `--paper`              | Simulate fills from live data instead of placing live orders.                         |
| `--spread <n>`         | Base spread in cents. Default is `2`.                                                 |
| `--size <n>`           | Contracts per side per layer. Default is `5`.                                         |
| `--threshold <n>`      | Requote when mid moves more than `n` cents.                                           |
| `--max-long <n>`       | Max YES contracts.                                                                    |
| `--max-short <n>`      | Max NO contracts.                                                                     |
| `--max-exposure <n>`   | Max dollar exposure.                                                                  |
| `--stop-loss <n>`      | Stop if P\&L is below `-n` dollars.                                                   |
| `--no-skew`            | Disable inventory skew. Use only when you are intentionally running symmetric quotes. |
| `--bias <n>`           | Manual bias in cents, from `-10` to `10`.                                             |
| `--bias-mode <mode>`   | `manual`, `thesis`, or `off`.                                                         |
| `--thesis-id <id>`     | Use a specific thesis for auto-bias.                                                  |
| `--thesis-auto`        | Auto-pick the best matching thesis for this ticker.                                   |
| `--min-spread <n>`     | Minimum allowed spread in cents.                                                      |
| `--max-spread <n>`     | Maximum allowed spread in cents.                                                      |
| `--fade <n>`           | Widen spread by `n` cents after fill.                                                 |
| `--fade-decay <n>`     | Seconds for fill fade to decay. Default is `30`.                                      |
| `--layers <n>`         | Quote layers per side. Default is `1`.                                                |
| `--layer-spacing <n>`  | Cents between layers. Default is `1`.                                                 |
| `--requote-delay <ms>` | Debounce requotes.                                                                    |
| `--venue <name>`       | Force `kalshi` or `polymarket`; otherwise inferred from ticker shape.                 |

## Bias patterns

Use `--bias-mode off` or omit bias for neutral quoting:

```bash theme={null}
sf quote create KXRATECUT-26DEC31 --paper --spread 3 --size 5
```

Use manual bias when an external model or operator has a directional view:

```bash theme={null}
sf quote create KXRATECUT-26DEC31 \
  --paper \
  --spread 3 \
  --size 5 \
  --bias-mode manual \
  --bias 2
```

Use thesis bias when the quote should lean with a SimpleFunctions thesis:

```bash theme={null}
sf quote create KXRATECUT-26DEC31 \
  --paper \
  --spread 3 \
  --size 5 \
  --bias-mode thesis \
  --thesis-id <thesis-id>
```

Use `--thesis-auto` only when you are comfortable with automatic thesis matching:

```bash theme={null}
sf quote create KXRATECUT-26DEC31 \
  --paper \
  --spread 3 \
  --size 5 \
  --bias-mode thesis \
  --thesis-auto
```

## Operational loop

A production-style loop should be explicit:

<Steps>
  <Step title="Discover and inspect">
    ```bash theme={null}
    sf discover --quality --json
    sf inspect <ticker> --json
    sf book <ticker>
    ```
  </Step>

  <Step title="Create a paper quote">
    ```bash theme={null}
    sf quote create <ticker> --paper --spread 3 --size 5 --max-exposure 20 --stop-loss 5
    ```
  </Step>

  <Step title="Run and observe">
    ```bash theme={null}
    sf quoteengine start
    sf quoteengine status --json
    sf quote list --json
    ```
  </Step>

  <Step title="Adjust or pause">
    ```bash theme={null}
    sf quote pause <quoteId>
    sf quote resume <quoteId>
    sf quote cancel <quoteId>
    ```
  </Step>

  <Step title="Stop cleanly">
    ```bash theme={null}
    sf quoteengine stop
    ```
  </Step>
</Steps>

## Agent integration

For an external agent, separate research from execution:

```bash theme={null}
sf agent --plain \
  --new \
  --allow read,user_data,research \
  --deny trade,runtime,fs \
  --once "Find candidate markets for paper market making. Return tickers, liquidity, spread, and risks. Do not create quotes."
```

Then require a human or policy service to approve the quote command. A safe generated command should include `--paper`, `--max-exposure`, `--stop-loss`, and small size limits.

If Claude Code or Codex is driving the workflow, give it this boundary:

```text theme={null}
Allowed: sf discover, sf inspect, sf book, sf quote list, sf quoteengine status.
Approval required: sf quote create, sf quote pause, sf quote resume, sf quote cancel, sf quoteengine start, sf quoteengine stop.
Never unattended: live quote creation without --paper.
```

## Live execution checklist

Before removing `--paper`:

1. `sf status --json` shows expected auth and exchange configuration.
2. `sf quoteengine status --json` is understood and clean.
3. The quote has explicit `--max-long`, `--max-short`, `--max-exposure`, and `--stop-loss`.
4. The spread is wider than the minimum tick noise you observed in paper mode.
5. The operator knows how to run `sf quoteengine stop`.
6. A separate process monitors fills, P\&L, stale books, and exchange status.

## Related docs

<CardGroup cols={2}>
  <Card title="Real-Time Data API" href="/reference/realtime-data">
    Raw market data for custom quoting, replay, and research systems.
  </Card>

  <Card title="Trade intents" href="/build/trade-intents">
    Declarative execution workflow for non-market-making trades.
  </Card>

  <Card title="Headless agent" href="/build/headless-agent">
    Let Claude Code, Codex, cron, or CI drive `sf` safely.
  </Card>

  <Card title="Risk gates" href="/concepts/risk-gates">
    Portfolio and execution risk controls.
  </Card>
</CardGroup>
