# Limit orders and price alerts

A limit buy spends SOL once a token's price or market cap falls to your level; a price alert sends you a message when a level is crossed. Both run on Koine's server against Jupiter prices polled about every 5 seconds.

## Limit buys

- Set one from a token's card in the bot (**🎯 Limit buy**) or its page on the web.
- In the bot, type the SOL and a level: `0.5 at 0.0012` for a US dollar price, `0.5 at 200k mc` for a market cap in dollars (`k`, `m` and `b` work), and an optional expiry: `0.5 at 0.0012 24h` or `2d`. Expiry is up to 90 days.
- The amount must be above 0 and at most 1,000 SOL. You can have 25 open at once.
- The coin must have been launched on Koine.
- The token must have a Jupiter price, and the price must still be above your level. A level it's already at is refused: buy it now instead.
- A market cap is turned into a price when you set it, from Jupiter's token list. A later change in supply doesn't move the level.
- Cancelling is instant, whatever your untie delay. Once it's buying, it's too late.
- `/limits` in the bot, or the limits tab on the web, lists them.

Source: trade/server/limits.ts (placeLimitBuy, cancelLimitBuy, MAX_LIMIT_BUYS), trade/server/bot.ts (parseLimitBuy, limitsScreen), trade/server/web.ts (/web/limits/*)

## When a limit buy triggers

It takes the same path as any buy: Koine's checks, your knots, a route and a send. It gets one try. If a knot holds it, the balance is short, there's no route or it fails on chain, it ends with a message and doesn't come back. If you need to accept changed terms, it's refused too. Only one limit buy per trader starts per check, so a second sees what the first did. A buys halt holds them; they can fire after it lifts if still due.

If Koine restarts while one is firing, it is settled from the order on record and never tried again.

Source: trade/server/limits.ts (checkLimitBuys, fire, sweepLimitBuys)

## Limit sells

A limit sell is one of a position's own exits. See [Exits on one position](https://docs.koine.markets/terminal/exits#exits-on-one-position). Removing one waits your untie delay, like any loosening.

Source: trade/server/knots.ts (openLimitSells, removeRung)

## What they can't do

- **They run on Koine's server.** While it's down, none fire.
- **They watch a polled price.** A price that jumps past your level and back between checks isn't seen.
- **They don't fill at your level.** They trade at the market when they fire, within your buy or sell slippage. If the price is worse than that, the transaction fails.

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

## Price alerts (web)

On the web you can set an alert for a token's price or market cap going above or below a level. The level must not already be crossed. You can have 25 open. Each fires once, as a message in Telegram or in your web inbox, with a link to the token in the terminal. Alerts are set and removed on the web; the bot has no alert screen.

Source: trade/server/watches.ts, trade/server/web.ts (/web/alerts), app/web/src/terminal/components/terminal/PriceAlerts.tsx
