# Sell Automatically

> Arm an auto-sell on a launch, check that it runs, change its rules and turn it off. Auto-buy works the same way.

An auto-sell session sells the launch's token from its wallets, following rules you set, until its time or its
budget runs out. This guide arms one, checks that it runs, changes it and turns it off. It follows what the web
app's auto-trade window sends. [Auto-buy](#auto-buy) uses the same calls with its own paths.

You need:

- an upgraded session token in `$PROXIMA_JWT` ([Quickstart](/getting-started/quickstart/));
- a Solana launch, here `101250846193377`. It can be a draft (step 3 plans the session) or a token that is
  already live (step 3 runs it).

Token amounts are integer strings in base units (6 decimals for pump.fun). Market caps are in micro-USD, slippage in
basis points. `delay` is in milliseconds; `time` and `start_delay` are in seconds.

## 1. Read the current state

[Get auto-sell status](/reference/auto-sell/#get-auto-sell-status) tells you what exists already.

```bash
curl https://api-mig.proxima.tools/launch/autosell/status/101250846193377 \
  -H "Authorization: Bearer $PROXIMA_JWT"
```

```json
{ "status": "None" }
```

| `status` | Meaning | What to do |
| --- | --- | --- |
| `None` | No session. | Arm one (steps 2 and 3). |
| `Planned` | Saved, starts with the launch. | Change it with step 5, or discard it. |
| `Running`, `Paused` | Live. | Change it with step 5. Plan and run answer `409` `Task already running`. |
| `Completed`, `Cancelled`, `Failed` | Ended. | Arm a new one. `Failed` carries `info.status_reason`. |

**Keep:** `status`.

## 2. Write the rules

A session combines up to three modes in `modes`:

| Mode | Sells | Main fields |
| --- | --- | --- |
| `TimedExactIn` | A random amount between `min_amount` and `max_amount` every `delay` milliseconds | Up to 5 `layers`, each with optional `min_mcap`, `max_mcap` and `end_condition` |
| `McapLadder` | `sell_amount` once the market cap reaches each `target_mcap` | Targets in strictly increasing order |
| `SwapBack` | A share (`replication_factor`, in basis points) of each buy made by someone else | `trigger_condition`, `min_token_per_swap`, optional `whitelist`, up to 5 `layers` |

The session-level fields apply to every mode:

- `end_condition.time` stops the session after that many seconds. `0` means the 30-day maximum.
- `end_condition.amount` stops it once that many tokens are sold. `"0"` means no cap.
- `slippage` is in basis points.
- `start_delay` waits that many seconds before the first sell.
- `wallet_pubkeys` limits selling to some of the launch's wallets. `null` uses them all.

The app also refuses a `time` longer than `max_autosell_session_duration` from
[`GET /get-constants`](/reference/platform/#retrieve-constants). This body sells 1.5M to 4M tokens every 45 seconds above a $120,000
market cap, plus 20M tokens at $150,000 and 40M at $300,000:

```bash
cat > autosell.json <<'EOF'
{
  "modes": [
    {
      "TimedExactIn": {
        "layers": [
          {
            "min_amount": "1500000000000",
            "max_amount": "4000000000000",
            "delay": 45000,
            "min_mcap": 120000000000,
            "end_condition": { "amount": "60000000000000", "time": 21600 }
          }
        ]
      }
    },
    {
      "McapLadder": [
        { "target_mcap": 150000000000, "sell_amount": "20000000000000" },
        { "target_mcap": 300000000000, "sell_amount": "40000000000000" }
      ]
    }
  ],
  "end_condition": { "time": 0, "amount": "0" },
  "slippage": 1500,
  "start_delay": 300,
  "wallet_pubkeys": null
}
EOF
```

**Keep:** `autosell.json`. Later calls send the whole body again.

## 3. Arm it

Before the launch, [plan](/reference/auto-sell/#plan-auto-sell) the session. It is saved as `Planned` and starts when
[Launch](/reference/launch-execution/#launch) runs, before the deploy. Sending the plan again replaces it, so a
timed-out call can be repeated.

```bash
curl -X POST https://api-mig.proxima.tools/launch/autosell/plan/101250846193377 \
  -H "Authorization: Bearer $PROXIMA_JWT" \
  -H "Content-Type: application/json" \
  -d @autosell.json
```

```json
{ "ok": true, "message": "Successfully planned auto selling task" }
```

On a token that is already live, [run](/reference/auto-sell/#run-auto-sell) the session instead. It starts at once,
after `start_delay` if you set one, and is refused with `Token not launched` on a draft.

> **Danger:** A running session sells tokens from your wallets without asking again. If the call times out, read the status
> (step 4) before you send it again: a second call answers `409` `Task already running` once the first one started.
> If a `Planned` session exists, run starts it with the saved rules and ignores the body. Update the plan first if the
> rules changed.

```bash
curl -X POST https://api-mig.proxima.tools/launch/autosell/run/101250846193377 \
  -H "Authorization: Bearer $PROXIMA_JWT" \
  -H "Content-Type: application/json" \
  -d @autosell.json
```

```json
{ "ok": true, "message": "Successfully started auto selling task" }
```

**Keep:** nothing new. There is no session id: every call addresses the session by its launch id.

## 4. Check that it is armed

Read [Get auto-sell status](/reference/auto-sell/#get-auto-sell-status) again. A planned session reads `Planned`
until the launch, then `Running`. If it could not start with the launch, it reads `Failed` and
`info.status_reason` says why. The app polls this every 5 seconds.

```json
{
  "status": "Running",
  "info": {
    "params": { "…": "the rules you sent" },
    "started_at": 1793671512,
    "ended_at": null,
    "status_reason": null,
    "auto_sell_token_sold": 26500000000000,
    "auto_sell_native_profit": 2875000000,
    "auto_sell_usd_profit": 539060000,
    "modes": [
      {
        "id": "timed",
        "layers": [{ "id": "as_4217_l0", "state": "Active", "token_sold": 6500000000000, "sol_spent": 655000000 }]
      },
      {
        "id": "mcap_ladder",
        "layers": [
          { "id": "as_4217_0", "state": "Exhausted", "token_sold": 20000000000000, "sol_spent": 2220000000 },
          { "id": "as_4217_1", "state": "Active", "token_sold": 0, "sol_spent": 0 }
        ]
      }
    ]
  }
}
```

`modes[].id` is `timed`, `mcap_ladder` or `replication`. Each layer is `Active`, `Paused` or `Exhausted`. The
number inside a layer id is internal and differs from the launch id, so copy layer ids from here rather than
building them. `modes` stays empty until the session runs.

**Keep:** the layer ids you may want to pause or cancel.

## 5. Change it

[Update auto-sell](/reference/auto-sell/#update-auto-sell) replaces the rules of a `Planned`, `Running` or `Paused`
session. Send the full body, not only the fields that change. On a live session, layers whose ids are still present
keep what they already sold.

```bash
curl -X POST https://api-mig.proxima.tools/launch/autosell/update/101250846193377 \
  -H "Authorization: Bearer $PROXIMA_JWT" \
  -H "Content-Type: application/json" \
  -d @autosell.json
```

```json
{ "ok": true, "message": "Auto sell params updated", "wallet_set_unchanged": false, "wallets_added": 0 }
```

**Keep:** the body you sent. The next update starts from it.

To stop selling for a while without changing the rules, [pause](/reference/auto-sell/#pause-auto-sell) and
[resume](/reference/auto-sell/#resume-auto-sell). With no body, they act on the whole session. With
`{ "mode": "timed" }`, on one mode. With `{ "layer_id": "as_4217_l0" }`, on one layer. Pause needs a `Running`
session. Some launches run on an engine that only pauses whole sessions; there, `mode` and `layer_id` answer `422`.

```bash
curl -X POST https://api-mig.proxima.tools/launch/autosell/pause/101250846193377 \
  -H "Authorization: Bearer $PROXIMA_JWT" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "timed" }'
```

```json
{ "ok": true, "message": "Mode timed paused" }
```

## 6. Turn it off

[Cancel auto-sell](/reference/auto-sell/#cancel-auto-sell) with no body ends the whole session, whatever its
status, and sets it to `Cancelled`. Repeating it does no harm. With `mode` or `layer_id`, it removes only that part,
and the session must be `Running` or `Paused`.

```bash
curl -X POST https://api-mig.proxima.tools/launch/autosell/cancel/101250846193377 \
  -H "Authorization: Bearer $PROXIMA_JWT"
```

```json
{ "ok": true, "message": "Auto sell task successfully cancelled" }
```

[Discard auto-sell](/reference/auto-sell/#discard-auto-sell) sets the status back to `None`, to drop a planned session
or clear an ended one. It is refused with `409` `Cannot discard running session` while the session is `Running` or
`Paused`: cancel it first.

```bash
curl -X POST https://api-mig.proxima.tools/launch/autosell/discard/101250846193377 \
  -H "Authorization: Bearer $PROXIMA_JWT"
```

## Auto-buy

[Auto-buy](/reference/auto-buy/) buys the token from the launch's wallets. It has the same eight endpoints under
`/launch/autobuy/` (plan, run, update, status, pause, resume, cancel, discard), the same statuses and the same
rules for retrying. A planned auto-buy also starts with the launch. The body differs in a few places:

| | Auto-sell | Auto-buy |
| --- | --- | --- |
| Amounts | Tokens to sell | Quote currency to spend (lamports for SOL) |
| `SwapBack` minimum | `min_token_per_swap` | `min_sol_per_swap` |
| `McapLadder` step | `sell_amount`, targets increasing | `buy_amount`, targets decreasing |
| Layer ids | `as_…` | `ab_…` |
| Totals in the status | `auto_sell_token_sold`, `auto_sell_native_profit`, `auto_sell_usd_profit` | `auto_buy_token_bought`, `auto_buy_native_spent`, `auto_buy_usd_spent` |

## Next steps

- [Auto-sell reference](/reference/auto-sell/): every field of the three modes.
- [Launch a token](/guides/launch-a-token/): plan the session between saving the plan and launching.
- [WebSocket channels](/realtime/websocket/#runners): runner results pushed as they happen.
- [Follow a launch in real time](/guides/follow-a-launch/): watch balances and PnL move while the session sells.
