# Exits

Exits sell a position for you when it reaches a level you set: either exit knots, which apply to every position, or exits set on one position. They run on Koine's server against polled prices, so fast moves and thin pools fill worse than the level.

## The exit knots

Each is off until you tie it. Once tied, it applies to every open position, including ones you already hold.

| Knot | What it sells | When |
| --- | --- | --- |
| 💰 Get my cost back at | Enough to get the cost back. The rest rides | When a position is worth this many times its cost |
| 📈 Take profit at | The share set in 🥧 Take profit sells | When a position is worth this many times its cost |
| 🥧 Take profit sells | Sets the share. It doesn't sell by itself | Used by 📈 Take profit at |
| 📉 Trailing stop | All of it | When the price falls this far from its high, once the high was above cost |
| 🔻 Hard stop | All of it | When it's worth this much less than it cost |

📈 Take profit at does nothing until 🥧 Take profit sells is tied too. The bot warns you, and the position screen says "or it won't sell".

Presets are in [Knots](https://docs.koine.markets/terminal/knots#exits).

Source: trade/server/knots.ts (KNOTS, exitDue, describeExits), trade/server/bot.ts (knotScreen)

## Exits on one position

A position can have its own exits: under **🪜 This position's exits** on its screen in the bot, or on its token page on the web.

| Exit | What it sells | When | How you type it in the bot |
| --- | --- | --- | --- |
| 📈 Take | A share you set | When the position is worth this multiple of its cost | `25% at 2x` |
| 🔻 Stop | All that's left | When it's worth this much less than it cost. One per position | `40` (40% under cost) |
| 🎯 Limit sell | A share you set | When the price reaches this many US dollars, with an optional expiry (up to 90 days on the web; the bot sets no cap) | `25% at 0.0012`, or `25% at 0.0012 24h` |

- A position holds at most 12 of these.
- **Shares are of the position before any of these sold.** 25%, 25% and 50% end at nothing, with no dust. Together they can't promise more than 100%. If a share rounds to nothing because too little is held, it waits.
- **They fire once each,** one per check, a stop first, then the lowest level. A take or limit sell still going out holds the next one.
- **A take or a stop replaces your exit knots on that position. A limit sell adds to them.** **🪢 Use my exit knots here again** brings the knots back, and that's instant.
- A position that closes ends its exits. One reopened later starts with none.

Changes follow the knot rule:

- **A new or tighter exit applies at once.** If a new one's level is already passed, you're asked first.
- **Removing or loosening one waits your untie delay,** and you can stop the change. Until then the exit stays as it was.
- **Your exit knots stop applying to that position only after that delay,** if you have exit knots tied and a delay set. Until then both watch it, and whichever is due first sells.
- **One already selling can't be stopped.**

Source: trade/server/knots.ts (MAX_RUNGS, boundRung, parseRung, addRung, alterRung, removeRung, rungDue, restoreGlobalExits), trade/server/exits.ts (dueNow), trade/server/bot.ts (positionExitsScreen, RUNG_ASK), trade/server/web.ts (/web/exits/*)

## How the watcher works

- **It polls.** Every 5 seconds (`TRADE_EXIT_POLL_MS`), the watcher prices the open positions of every trader with an exit knot tied or an exit set on a position, using Jupiter's price API. Limit buys and price alerts are priced in the same pass.
- **It won't act on an old price.** A price fetched more than two polls ago is ignored, and a position with no price isn't checked.
- **Value is an estimate:** quantity times the current price, not what the pool would pay.
- **Cost is what you paid.** It comes from the SOL that left the wallet on each buy, less rent. A sell removes its share of the cost.
- **The high is what Koine has seen.** A trailing stop's high is the highest price the watcher has seen since you bought or since an exit started watching the position.

Source: trade/server/exits.ts (checkExits, price), trade/server/config.ts (exitPollMs), trade/server/orders.ts (record)

## How an exit sells

- It uses the normal order path at your sell slippage, on the position's nonce lane, so it replaces any sell you had pre-signed.
- On the first try it uses 🚀 Turbo (0.001 SOL tip) when that tip is at most 2% of the sale, and ⚡ Fast otherwise. A second try allows up to 5% and a third up to 10%. Retries also raise the priority fee cap 2.5× and 5×.
- Koine's fee and network fees apply. See [fees](https://docs.koine.markets/terminal/trading#fees).
- No confirm is needed. You get a message with what sold, why, and a Solscan link.
- If the wallet holds less of the token than Koine's record, the sale shrinks in proportion. If it holds none, the position closes and the exit doesn't run.

Source: trade/server/exits.ts (exitLanding, fire), trade/server/held.ts

## Once per position

- Each exit fires once per position. A position you close and reopen later starts over.
- Buying more of a position you still hold doesn't reset an exit that already fired.
- Only one exit sell runs per position at a time.
- When several are due at once, a stop that sells everything wins. Exit knots go in this order: hard stop, trailing stop, get my cost back, take profit.

Source: trade/server/exits.ts (doneOf, inFlight, dueNow), trade/server/knots.ts (EXIT_KEYS)

## If a sell fails

A failed exit is tried again on the next check while still due, up to 3 times. After that you get the last error, and that exit won't try again on that position. Sell it yourself if you still want out.

Source: trade/server/exits.ts (MAX_ATTEMPTS, fire)

## Tying and changing exit knots

- **Tying shows you first.** If tying would sell positions right away, the bot and the web list them and ask you to confirm. If prices can't be read at that moment, there's no list.
- **Loosening waits** your untie delay. Until it lands, the exit stays at the old level.

Source: trade/server/bot.ts (requestKnot, confirmTieScreen), trade/server/web.ts (/web/knots), trade/server/exits.ts (wouldSellNow)

## Limits

- **Fast moves fill past the level.** A fall between checks can sell well below your stop.
- **Thin pools fill for less** than the estimate.
- **A rug can beat a stop.** With no price or no route, nothing sells.
- **A stop isn't guaranteed.** After 3 failed tries it stops trying.
- **A sells halt holds exits.** Highs keep updating, and a due exit can fire after it lifts.
- **They don't run while Koine's server is down.**
- **Exported keys.** After a key export, whoever holds the key can move tokens out, and an exit can't sell what's gone.

Source: trade/server/exits.ts, trade/server/knots.ts (triggerNote)
